2

I want to create Shaders in Runtime in Unity. Is there any way? I found that article Creating GLSL Shaders at Runtime in Unity3D but this is no more working because Unity doesn't accept
new Material({shader_code_here});
It requires new Material(Shader.Find("{Shader name in project}");

Any help appreciated, thanks.

14
  • You can create a material and set its properties in runtime. Do you really need to create the whole shader in runtime? This is not common. Commented Apr 6, 2020 at 20:39
  • 1
    @Daniel Yes, I need to create Shaders dynamically. Commented Apr 6, 2020 at 20:41
  • @Siberhecy: Are you certain? Are you sure you cannot possibly achieve the effect you're trying to achieve in some other way? Commented Apr 6, 2020 at 20:49
  • @NicolBolas Yes because I can't predict what will happen to 3D object. Player will select what should happen to 3D object. Example player selected "Glowing", "UV Animate", "Additional Texture to Main Texture" then Shader will be created according to these variants. That's why I am saying I can't predict. I don't want to use If-else statements because they're bad for performance. Commented Apr 6, 2020 at 20:57
  • 1
    @Siberhecy: "I don't want to use If-else statements because they're bad for performance." First, no, they're not. Second, compiling a shader in the middle of your application is definitely bad for performance. Commented Apr 6, 2020 at 20:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.