Jump to content
  • Advertisement
Sign in to follow this  
mafiesto4

Shader Permutations

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

Hey,

I wonder what is the best way to handle multiple shader permutations? I wrote a blog post http://flaxengine.com/blog/flax-facts-4-shaders-parser/ where I described how we do it in Flax Engine.

The thing is we want to avoid having too many shader versions and to try compile shaders offline (reduce amount of compilations at runtime). It's a little bit manual kind of job because you have to write all possible sets of permutating macros but it has some advantages, eg. it's quite deterministic and you can provide different amount of macros per permutation:

META_PS(false)
META_PERMUTATION_2(NO_SPECULAR=1, USE_IES_PROFILE=0)
META_PERMUTATION_4(NO_SPECULAR=0, USE_IES_PROFILE=1, SKIP_STH=1, BUMP_COLORS=4)
META_PERMUTATION_3(NO_SPECULAR=1, USE_IES_PROFILE=1, BUMP_COLOR=2)
void PS_Spot(Model_VS2PS input, out float4 output : SV_Target0)
{ 

    ...

    GBuffer gBuffer = SampleGBuffer(uv);
    output = GetLighting(Light, gBuffer, shadow, true, true);

#ifdef BUMP_COLORS
    output *= BUMP_COLORS;
#endif

#if USE_IES_PROFILE
    output *= ComputeLightProfileMultiplier(IESTexture, gBuffer.WorldPos, Light.LightPos, -Light.LightDir);
#endif
} 

Plus we don't have to store used macros after shader compilation but just access permutations by index so it's faster to pick a proper shader version during rendering.

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!