Is it possible do layer HLSL shaders?

Started by
1 comment, last by acid2 18 years, 5 months ago
Greetings! I was wondering if it is possible to layer HLSL effects. For example "n" vertex shader programs and "m" pixel shader programs. In vertex you might have skinned and normal geometry rendering and in pixel there could be normal rendering, N dot L or DOT3, Cartoon rendering etc... Or is it that I have to describe each and every combination of pixel and vertex shader? Thank you in advance!
Advertisement
Using standard HLSL there's no good way of doing this... you can create convoluted sequences of compile-time "defines" that you switch on and off to create different combinations, or you can try and paste little sections of code together with string matching (the prospect scares me personally)... you can make things a little better by abstracting off your pieces into functions and then combining function calls, but the whole thing will eventually turn into a messy string manipulation problem that is normally highly error-prone...

The only good solution that I've seen is Sh (http://libsh.org) which treats shaders as C++ "program objects". These objects in turn can be combined together and pretty much arbitrary ways (attaching outputs of one to inputs of another, combining two together into the union of inputs and outputs, and much more) with simple C++ operators. Sh will handle all of the details for you. This may not be the ideal solution for you as right now Sh only has ARB_*_program and GLSL backends (both OpenGL), but a Direct3D backend is in the works, so you may at least want to keep an eye on it.
Maybe im misunderstanding the question, but could you not uses passes to solve this problem? Passes don't mean too much in HLSL, so if you wanted to render n.l lighting, you'd just run pass 0, if you only wanted cartoon you only run pass 1, if you want both you run both passes.

A problem with this is clear - all of your shaders are in the same file - not good! However, there is a solution to this. Look into "fragment linkers".
Ollie"It is better to ask some of the questions than to know all the answers." ~ James Thurber[ mdxinfo | An iridescent tentacle | Game design patterns ]

This topic is closed to new replies.

Advertisement