My current shader code can be found here. I’m currently trying to break the different parts of the shader (ultimately vertex shader, triplanar, dissolve and glow) into separate passes for better hygiene and readabiliity.
However, when I try to encapsulate everything currently in the SubShader into a pass, I get the error,
Parse error: syntax error, unexpected TOK_PASS, expecting TOK_SETTEXTURE or '}' at line
Can anybody help me get this shader structured correctly?
Thanks in advance,
Surface shaders don’t work the same way as regular shaders. Instead they generate a subset of vert/frag shaders in their own passes - hence why you can’t encapsulate a surface shader in a pass; you’ll end up with passes within passes, which syntactically isn’t allowed. I would also note that passes don’t work that way either - you really want to keep active pass count to a minimum. Each pass in use has its own overhead, so when possible it’s best to keep everything within one pass. Passes also aren’t linked, so if you split parts of a shader into different passes nothing will work.
If you really want to separate these parts of the shader, you can instead put them into different functions - all functions in CG/HLSL are inlined, so doing this won’t have any performance impact. If that isn’t enough level of separation, you can create individual include files for each part of the shader, then include them in the main file.