Troubleshooting Shaders
From Multiverse
This article is a collection of shader hacks and tricks.
Contents |
Overview
Shaders are written in the Cg language, which has a C-like syntax. Unfortunately if you have a syntax error in your shader code, you won't get any kind of error message. Instead tools or other programs using your shader will simply crash with no error message.
Checking shader syntax
NVIDIA has made available a CG toolkit which can perform syntax checks on your shader code. It's a good idea to try compiling your shader code with these tools before you actually run Multiverse. Here's how to do it...
- Download and install the NVIDIA CG Toolkit.
- Open a command prompt window and "cd" to the folder containing your shader code.
- Run the program "cgc" on your shader code and check for errors.
Here is an example of output from a shader with errors:
C:\Program Files\Multiverse Tools\Media\GpuPrograms>cgc Terrain.cg Terrain.cg Terrain.cg(36) : error C0000: syntax error, unexpected ';', expecting ',' or ')' at token ";" Terrain.cg(36) : error C0501: type name expected at token ";"
A quick check of the shader code shows us that line 36 is:
float4 coverage; : TEXCOORD1;
Oops! Get that semicolon outta there! A quick edit, and our shader is now synactically correct!
Common problems
Surfaces all black in game
If you get an object or surface that comes out all black in the editor or game, this means that the code in a shader that is supposed to return the color at each pixel is failing. It could be it's got an error in it, or it is just failing to return the color to be drawn at a given pixel.
Surface does not appear in game
If a surface completely fails to be drawn in-game, it could be that the Vertex portion of the shader has a problem.
Problems with "scene_blend modulate"
Adding scene_blend modulate to a material definition will make the material transparent, but not in the way you want. First, on the left is a picture of how the effect looks. You can see right through the surface that has been textured with the material and only see the skybox!
Here is the shader text that creates this effect...
material domeglass
{
technique
{
pass
{
scene_blend modulate
ambient 1.0 1.0 1.0 1.0
diffuse 1.0 1.0 1.0 1
texture_unit
{
texture domeglass001.dds
}
}
}
A very odd effect indeed - but perhaps some interesting trick to be done with it? Imagine a starry sky skybox and this effect used to create a portal of some kind.
