Multi-Compile shaders toggling Properties

I was wondering if it’s possible to use the multi-compile shader functionality to also show/hide some of the properties of the shader. I did some quick research but didn’t find anything on that quickly.

I know one way would be to have a custom MaterialDrawer and then use that to only show some of the properties, that would clean some of that up, but I’d prefer for them to not be in the compiled shader at all if they’re not needed.

#pragma multi_compile is explicitly intended for including all possible variants, though specific variants can be excluded from the build using a ShaderVariantCollection. If you only want variants that have explicitly been enabled (ie: material assets exist with the features enabled) then #pragma shader_feature is what you want, though again a ShaderVariantCollection can be used to include variants that don’t exist.

Neither of these will hide things in the inspector on their own. For that a custom MaterialDrawer or a custom material editor script (see the Standard Shader) are the best options for that, though I too would love to be able to just have something like this to toggle stuff rather than needing to write a custom editor each time:

[Toggle(THINGY_ON)] _Thingy (“Enable Thingy”, Float) = 1
[ShowProperty(THINGY_ON)] _ThingyStrength (“Thingy Strength”, Range(0, 42)) = 7
[ShowProperty(THINGY_ON)] _ThingyCombobulation (“Thingy Combobulation”, Range(-4, 1)) = -1.142515

5 Likes

Yeah, I ended up using a custom material drawer, but a solution like the one you proposed would have been preferrable and easier to maintain :smile:

1 Like