Hi guys,
Is there any possible way to dynamically add a pass or remove a pass from a shader at run time.
Though i can change shader to implement the effect I want, i don’t want to write two shader file that shader codes are almost the same.
There does not appear to be a way to remove a pass at run time unfortunately. The most obvious solution would be to be able to #ifdef out a pass, but those don’t work outside of the CGPROGRAM blocks.
You can however make it so it won’t render. The usual path people take for something like this is to #ifdef an early discard or flat color with zero alpha, but this means the pass is still processing a the pixel shader. Instead you can #ifdef the vertex output to be a single point behind the camera, or at 0,0,0. The vertices will be clipped by the near plane and the pixel shader will never even be called.
It’s probably better to just swap the shader though. You don’t have to write the whole shader twice to do it, you can use UsePass or a custom cginc to keep most of the code in one file.
I think you could use “#include” feature, put common used shader code to one place.
Or write a huge shader then split it with multi “#define”.
#include yes, that was my comment about using a custom cginc.
You cannot use #define (or more specifically #pragma multi_compile or #pragma shader_feature with #ifdef blocks) to remove passes, only to change the shader code within a pass.