Shader text setup in a C# script

Hi all.

was a dilemma wether i post here or in scripting topic. I finally posted here, as the problem i got
seems to come from shader and not from script.

In a C# script i got a string variable with my shader text:
static string shader_code=“Shader “my_shaders/my_vcolor” {\n”+
etc etc etc…

script compiles ok, but at runtime, the shader code seems not to be compilable.

This comes at the line having the “CGPROGRAM\n”.

My question is simple:
Is it possible to have a surface shader code set up in a C# script ?
And if yes, could you please show a lil example code ?

thanks a lot !

regards.

No.

What about Unity - Scripting API: GL ? Isn’t the example what pitibonom asks for?

it is :slight_smile:

thanks martin. but it appears that this feature might be outdated and dont work anymore.
btw, i do this the crappy way:

  1. write a shader
  2. grab it into my script from the assets and do the job.
  3. whisper as UT could make all it’s customers life sooooooooooo much easier :wink:

thanks and have a nice day !

No, it has only ever worked for fixed function shaders.

The Unity runtime lacks the surface shader translator, Cg compiler, and HLSL and GLSL cross-compilers. This means that it can’t create functioning shader programs from these sources.

However, I believe you can provide pre-compiled shaders in ARB and D3D9 for desktops, or straight OpenGL ES for mobile platforms. For examples, create a new shader in Unity and click “Open compiled shader” in the inspector.

thanks a lot for all those infos.

#Daniel: nice clue :slight_smile: i gonna try this out !

Have a nice day