- Home /
CG shader is treated as GLSL and doesn't compile
Hi, I need a shader to support vertex colors, so I followed this tutorial here: http://en.wikibooks.org/wiki/Cg_Programming/Unity/Smooth_Specular_Highlights and made the modifications so it showed the vertex color. I also added Texture sampling.
The shader was created and tested in a different project/scene I need it in, just to have a clean work environment. There it works as I want it to.
Creating a new shader in my real project and copypasting the shader's code into the newly created shader, results in errors during shader compilation, such as:
"Material doesn't have a texture property '_MainTex'" "GLSL vertex shader: 73: ERROR: '' unsupported construction at line 13" (that's where "CGPROGRAM" is written in the shader's code)
The second error message suggests that the shader is being compiled by a GLSL-compiler and not a CG-compiler.
Is there a way to set the type of shader explicitly to CG so Unity does not try to compile it as GLSL?
I have also tried to copypaste the unmodified tutorial code above into the shader, but the GLSL error persists.
If you post the shader code, we can perhaps spot the issue.
If you go to any shader and hit "Open Compiled" you'll see that Unity actually compiles your shader multiple times into different formats so yes, it probably was compiling it into GLSL when it threw the error.
Having said that. Rarely do I get an error writing a shader that actually has anything to do with the line the mistake is on. You probably have an error somewhere in your CG thats stopping it from compiling.
For what it's worth, the line numbers reported by shader compilation are often totally worthless. Confusingly, I think they refer to lines in the lower level code which is generated by the compiler, and not the user-level code we write.
Ok... the way I created the new shader was the problem. I copypasted the shader code from the tutorial above into the newly created shader and then replaced the properties section and the two passes. However, there was an invisible character added when pasting. This character was invisible in the Visual Studio editor. The compiler errors are gone.
Now I have the problem that it doesn't look like it did when I tested it in a separate environment. Should I create a new thread/question here for this or just append it to this one?
Thank you for your help so far.