Sign in to follow this  
Roof Top Pew Wee

How to change "color operations" in FX files.

Recommended Posts

I've just started learning a bit about shaders and I'm trying to reproduce a lot of the fixed function stuff in .fx files. I understand how to grab colors from the vertex color or texture, and I understand that I can perform operations per-pixel in the pixel shader function. My question is how are color operations commonly switched? Should I just have many techniques which call different pixel shader functions in my .fx file according to the color opreations I desire? This seems like it could get messy if I start adding other things that I want to do depending on different "states". That is, if I have 3 different kinds of color operations, 3 different ways I want to apply colors, that's 9 techniques right there to handle all combinations. Add a 3rd "state" and the numbers get astronomical and impossible to manage. Is this just something that I have to deal with regarding shaders, or are there different ways to "combine" functions according to states. Thanks again, and I apologize for the poor terminology and lack perhaps basic question - this is pretty new stuff to me. --Vic--

Share this post


Link to post
Share on other sites
jollyjeffers    1570
This is a fairly common problem with shaders - combinatorial explosion.

There are various tactics that can be used such as writing code with lots of compile-time constants and then getting the compiler to generate 100's (or 1000's) of combinations from the same set of code.

You can always use constant parameters though, this way you can write a more generic set of shaders and have the application specify the finer details when it comes down to rendering.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for the info. A few follow-up questions.

I've heard that in SM3, you can have if statements. Is this true, and if so, is it expensive considering this is very low level code.

Quote:

You can always use constant parameters though, this way you can write a more generic set of shaders and have the application specify the finer details when it comes down to rendering.


I'm not quite sure I understand what you mean by this. Could you give me an example? Thanks.

--Vic--

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this