mafiesto4

Members
  • Content count

    3
  • Joined

  • Last visited

Community Reputation

639 Good

About mafiesto4

  • Rank
    Newbie

Personal Information

  • Location
    Poland
  1. 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.