Stacking Cg Shaders

In my engine, I load Cg shaders from pairs of vertex / pixel shader files. I would like to be able to stack the shaders in order to combine them (lighting + material, etc.). Without waiting for the shaders to break into separate functions and then creating one script shader chain out of them, do you know of any good ways to stack different shaders in Cg?

+1


a source to share


1 answer


Sounds a bit like what you want, like the Dynamic Shader Link feature in DirectX 11? The Cg interface feature lets you do simlar things. This allows you to reconfigure shaders so that you can easily and cleanly do things like change how the lighting is calculated or change the type of material.

For example, let's say you want to write a shader, but must be able to change how the lighting is calculated. You can define a Light interface that has a function that will calculate the light in some way. Elsewhere, you implement the Light interface like CoolLight and UberLight. At runtime, you can specify which implementation of the Light interface should be used, in much the same way as you specify other parameters.



To see what you want, I recommend looking at the Cg User Guide ( http://developer.download.nvidia.com/cg/Cg_2.2/CgUsersManual.pdf ). If you are looking for "General Parameters and Interfaces" then there is a small example.

+2


a source







All Articles