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. Dismiss Notice

Extending a shader from script?

Discussion in 'Shaders' started by LightrockerRon, Mar 17, 2015.

  1. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    I tried to search for that topic but could not really found an adequate answer.

    Is it possible to extend an existing shader/material with an own function by script? I only want to modify the color result of a fragment/pixel shader but without knowing, what the original shaders are doing.Those things are achievable with high-level shaders in own frameworks by calling the original main function and modifying the output. But is this also possible in Unity?

    This functionality is required for a plug-in, which must be able to adjust only the final color of every existing object.
     
  2. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    520
    The shaders don't use true functions. The "functions" you use are actually copied to the place where you use them, (while actual functions wouldn't be). That means you would have to copy your function into the shader at run-time, which is very complicated and I don't think unity has any built in way of doing it.

    Much simpler solution is to change material's properties to alternate shader's behavior. For example you could do different things with the color based on this parameter.

    P.S. It's "high-level shader languages". Shaders don't have levels.
     
  3. LightrockerRon

    LightrockerRon

    Joined:
    Mar 17, 2015
    Posts:
    12
    Thank you for your answer. Unfortunately your suggestion about changing the source material/values is not sufficient for my need because I cannot know, what a (user) shader will do with it. It would be more like a pre-processing step but I require a post one.

    Maybe it is time for the next Unity version to introduce shader components/modules, which can be connected via input and output pins/variables. But such a step is unlikely after the introduction of the universally applicable standard shader for physically based rendering.

    So I have to restrict the scope of my plug-in in the meantime.

    P.S.: After re-reading my query "high-level shaders" sounded a bit strange for me, too. But I did not edit it because I did not meant the shader assemblies nor the units on the GPU. I use the word "shader" also for describing the source code and that one can be written in a high-level language so the code becomes high-level, too.
     
  4. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    520
  5. zoran404

    zoran404

    Joined:
    Jan 11, 2015
    Posts:
    520