Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Creating shaders programmatically

Discussion in 'Getting Started' started by AntonioNoack, Apr 29, 2022.

  1. AntonioNoack

    AntonioNoack

    Joined:
    Mar 26, 2020
    Posts:
    7
    Hi,

    I am currently looking whether and how Unity can compile shaders on the fly.
    The use-case for this is an interactive, real-time signed distance function builder.
    Alternatively, you could build something like ShaderToy in Unity.

    How would I implement that? I only found samples where the shader was loaded from a file, and the C# Shader class has no public constructor.

    Whether the shader language is GLSL, HLSL or a graph doesn't matter that much as long as it is mostly completely customizable. I'd prefer a written language over a graph for easier function import from other sources.

    As a hacky way, it is maybe possible to create assets at runtime, and then load them?

    Thanks a lot,
    Antonio

    PS: I am posting this into "Getting Started", because I try to get started on my project . It probably isn't really a beginner question.
     
  2. AntonioNoack

    AntonioNoack

    Joined:
    Mar 26, 2020
    Posts:
    7
    PPS: I know you could theoretically create a static shader for every instruction, and then execute those instructions one by one on a series of framebuffers, but I'd like it to be performant .