Skip to main navigation Skip to search Skip to main content

Retrieval-Augmented Generation for Geometric Code Synthesis
: LLM-Assisted Procedural Shader Authoring via SDFs

  • Niloufar Moradijam

    Student thesis: Master's Thesis

    Abstract

    Procedural 2D graphics based on Signed Distance Functions offer resolution-independent,
    fully parameterised visual assets well-suited to real-time game engines. Authoring these
    assets requires specialised knowledge of HLSL and mathematical modelling, creating a
    significant barrier to entry for artists and developers without a shader programming
    background. This thesis presents a system that removes that barrier by enabling users
    to generate, edit, animate, and apply visual effects to procedural 2D SDF-based shader
    assets through natural language alone, without writing a single line of HLSL.
    The system is built around a Retrieval-Augmented Generation architecture. A con
    strained LLM generation pipeline, combining Google Gemini for HLSL code synthesis
    with GPT-4o Vision for iterative visual verification, was used to autonomously boot
    strap a Knowledge Base of 200+ verified SDF primitives. At generation time, a shape
    decomposition service breaks complex natural language requests into retrievable com
    ponents; cosine-similarity search over semantic embedding vectors retrieves the most
    relevant verified HLSL examples from the Knowledge Base; and an augmented prompt
    instructs the LLM to compose the retrieved primitives into a new shape rather than
    synthesising geometry from scratch. The resulting HLSL is assembled into a complete
    Unity ShaderGraph asset by a deterministic C# backend, guaranteeing structural cor
    rectness independently of LLM output quality. All functionality is exposed through a
    conversational Unity Editor tool: an IMGUI chatbot backed by a 26-state machine, si
    multaneously accessible as a web interface on a local HTTP server, supporting the full
    asset lifecycle from initial generation through editing, animation, and visual effects.
    A controlled experiment of 200 runs evaluated five LLM backends (Google Gemini
    3 Pro Preview, Gemini 3.1 Pro, OpenAI GPT-5.4, Anthropic Claude Sonnet 4.6, and
    Moonshot Kimi K2.6) under RAG and direct generation conditions across four shape
    groups varying in complexity and Knowledge Base membership. RAG raised the average
    VLM quality score by 0.74 points (6.48 to 7.22) over direct generation, while reducing
    cost for simple shapes. Among the tested models, Gemini 3.1 Pro achieved the best
    overall combination of quality, reliability, and cost ($0.036 per shape, 93.3% success
    rate, 8.53 VLM score, 98.7% compile rate); Claude Sonnet 4.6 offered a 2.8 to 11
    times speed advantage at competitive quality. Automated VLM scoring agreed with
    human judgement on average, with statistically indistinguishable mean scores, though
    only a modest per-item correlation (Pearson r = 0.32). The results demonstrate that
    RAG-based composition from a curated library of verified primitives is a substantially
    more reliable strategy for geometric code generation than direct synthesis, and that
    the combined system enables non-expert users to produce high-quality procedural 2D
    shader assets through natural language in a practical Unity Editor workflow.
    Date of Award2026
    Original languageEnglish (American)
    Awarding Institution
    • FH OÖ
    SupervisorOliver Krauss (Supervisor)

    Studyprogram

    • Interactive Media

    Cite this

    '