- Home /
Blending 3 textures using a shader
I want to create a shader that enables 3 texture blending, I have looked at the following code: http://www.unifycommunity.com/wiki/index.php?title=Blend_2_Textures and I'm trying to extend it, my pseudocode looks as follows:
if blending is > 0
texture2 ConstantColor(0, 0, 0, [_Blend])
else if blending is < 0
texture3 ConstantColor(0, 0, 0, -[_Blend])
My shader looks like this:
Shader "My First Shader" {
Properties {
_Blend ("Blend", Range (-1, 1) ) = 0
_MainTex ("Texture 1", 2D) = ""
_Texture2 ("Texture 2", 2D) = ""
_Texture3 ("Texture 3", 2D) = ""
}
SubShader {
Pass {
SetTexture[_MainTex]
if([_Blend] > 0) //<-- Parse error: syntax error at line 14
{
SetTexture[_Texture2]
{
ConstantColor (0,0,0, [_Blend])
Combine texture Lerp(constant) previous
}
}
else if([_Blend] < 0)
{
SetTexture[_Texture3]
{
ConstantColor (0,0,0, -[_Blend])
Combine texture Lerp(constant) previous
}
}
}
}
}
When I try to use it my object looks pink and Unity throws the following error
Parse error: syntax error at line 14
How can I access _[Blend] value on a conditional statement?
Answer by simonmc · Apr 10, 2012 at 09:53 PM
I don't believe you can use conditionals in a shaderlab program like you are attempting to do here. You would need to make a pass that includes a CG program.
Apparently you're right :D but I found a workaround. Thanks.
I'm also very interested in the solution for this. Please post it, thanks!
Your answer
