- Home /
Question by
gwiazdorrr · Nov 04, 2014 at 10:58 AM ·
shaderkeyword
How to force Terrain to use assigned material's keywords?
I ran into a problem recently: Terrain seems to ignore assigned materials' keywords and I haven't found a workaround.
Given this shader:
Shader "KeywordTest"
{
Properties
{
[Toggle] TEST_KEYWORD ("TEST_KEYWORD", Float) = 0
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert
#pragma multi_compile DUMMY TEST_KEYWORD_ON
struct Input
{
float2 dummy;
};
void surf (Input IN, inout SurfaceOutput o)
{
o.Albedo = fixed3(0,0,1);
#ifdef TEST_KEYWORD_ON
o.Albedo = fixed3(1,0,0);
#else
o.Albedo = fixed3(0,1,0);
#endif
}
ENDCG
}
}
In the material preview it works exactly as expected: the sphere is either entirely red (TEST_KEYWORD checkbox checked) or green (unchecked) terrain. However, when the material gets assigned to a Terrain, the Terrain will always be green. I imagine this is because terrain only has the materialTemplate
property, which suggests material gets copied internally and for some reason keywords get omitted.
Has anyone found a workaround that doesn't involve creating multiple materials/shaders?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613170707im_/https://answers.unity.com/themes/thub/images/avi.jpg)