Jump to content
  • Advertisement
Sign in to follow this  
Samurai Jack

Is it possible do layer HLSL shaders?

This topic is 4871 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!