I’ve added a toggle to my shader:
[Toggle(ENABLE_COLOR_BLEND)] _EnableColorBlend ("Enable Color Blend", Int) = 0
In the Subshader:
#pragma shader_feature ENABLE_COLOR_BLEND
And in the fragment shader:
#ifdef ENABLE_COLOR_BLEND color = lerp(_DryColor, _WetColor, _ColorBlend); #endif
And there it is in the inspector, and when I toggle it, color blending is turned on and the material is rendered as it should be. if I turn it off, it’s off.
But if I try to set it like this in code:
The material is rendered like if EnableColorBlend is off.
In the inspector it’s ticked, and as soon as I turn it off, it gets ticked again. (I set it in an Update) But for some reason, it’s still rendered like color blending is off.
And if I remove the SetInt above, and set it by hand, everything works fine.
Idea: If I set it by hand, there is a smooth transition (don’t know why) instead of an instant change in shade. Maybe by setting it constantly to 1, it always just starts the transition, but can’t finish it?
EDIT: Just checked it with a guard, and it still behaves the same.
if (Renderer.material.GetInt("_EnableColorBlend") == 0) Renderer.material.SetInt("_EnableColorBlend", 1);