igloo
October 19, 2015, 3:49am
1
In my shader I like to change the used UV channel. the condition does NOT change for the selected material so doing the if statement for very vertex for every frame is unnecessary.
_UVChannel ("UV Channel", Int) = 1
...
fixed2 uv : TEXCOORD0;
fixed2 uv2 : TEXCOORD1;
...
if( _UVChannel == 1.0)
uv = v.uv;
else
uv = v.uv2;
o.uv = TRANSFORM_TEX(uv, _MainTex);
I could have created multiple shaders, but is there other solution?
Wondering can there be anything like:
Category {
if (_UVChannel > 0)
SubShader { ... }
else {
SubShader { ... }
}
}
Unanswered 7 year old topic exists:
http://forum.unity3d.com/threads/shaderlab-if-statement.8904/
P.S can not reply the old thread because:
“(You have insufficient privileges to reply here.)”
2344766–158647–UnlitSelectTexture.shader (978 Bytes)
Neyl
October 19, 2015, 5:13am
2
Yo can use #pragma multi_compile directive to create multiple shader variants and “KeywordEnum” property drawer to enable\disable keywords.
But be careful with keywords. There is a limit of 128 keywords in project.
1 Like
jvo3dc
October 19, 2015, 11:24am
3
If it’s a material setting exposed in the material editor, it’s advised to use shader_feature instead of multi_compile.
So then it becomes something like:
#pragma shader_feature _ _USE_UV1_FOR_UV0
#ifdef _USE_UV1_FOR_UV0
fixed2 uv : TEXCOORD1;
#else
fixed2 uv : TEXCOORD0;
#endif
You’ll need to use a script to actually define or undefine the _USE_UV1_FOR_UV0 keyword.
bgolus
October 20, 2015, 4:30am
4
In fact you don’t.
[Toggle(_USE_UV1_FOR_UV0)] _SwapUVs (“Swap UVs”, Float) = 1.0
http://docs.unity3d.com/ScriptReference/MaterialPropertyDrawer.html