Sign in to follow this  

Managing shaders

This topic is 4099 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

I started recently making use of shaders in my project (DirectX, HLSL) and I'm having trouble figuring out how best (when and where) to set the various constants that the shaders depend on. I've only got like, two of them that I've made so far but I have stuff like effect->SetSomeConstant("SomeConstant", SOME_BIT_OF_INFORMATION_THAT_IS_NEVER_AVAILABLE_WHEN_I_WANT_IT) scattered absolutely everwhere. I'm vaguely envisioning some kind of callback system where I say MagicalMysteryBoxOfShaders->SetShaderConstant("SomeConstant", SOME_BIT_OF_INFORMATION_THAT_HOPEFULLY_IS_HANDY_NOW) and it loops through a list of pointers and updates them all (probably each frame). Is this a good idea? How do you do it? If I go ahead with this is there anything else that I could use this kind of system for (so I can design it somewhat generically) or am I going to have all this functionality (callbacks?) sitting around just to update shaders?

Share this post


Link to post
Share on other sites
I recommend splitting up your shader constants into engine constants and user constants. For engine constants write down a list of constants that every shader should have, for example projection transform, global ambient, light position, light direction, etc. These engine constants will be calculated and set by the engine.

The other set, user constants should be completely shader dependent. Each shader has a metadata file that describes these constants. Artists who design models can set engine constants and user constants for the meshes and these constants will be kept in the mesh file.

Finally, when it comes to setting everything up, you just do something like:

foreach engineConst in engineConstants
engineConst.Set();

foreach userConst in userConstants
userConst.Set();

Then you can add the callback functions using a similar mechanism (in case you want to update user constants every frame).

Share this post


Link to post
Share on other sites

This topic is 4099 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.

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