- Home /
Fixed Shader with multiple AlphaBlended Layers ?
I'm trying to make a shader that takes 3 textures with alphas, and 3 numbers(Range 0 to 1) and draws a material made up of the 3 layers stacked on top of each other with the 3 numbers used to control the global alpha of that particular texture. This images is a visual example of what I'm hoping for:
In code, this is the closest I've got so far with a fixed shader:
Shader "Custom/Unlit - 3 Layer - AlphaBlended" {
Properties {
_Tex1 ("Layer 1 Texture", 2D) = "white" {}
_Tex2 ("Layer 2 Texture", 2D) = "white" {}
_Tex3 ("Layer 3 Texture", 2D) = "white" {}
_Fade1 ("Layer 1 Alpha", Range(0,1)) = 1
_Fade2 ("Layer 2 Alpha", Range(0,1)) = 1
_Fade3 ("Layer 3 Alpha", Range(0,1)) = 1
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 100
Lighting Off
Cull Back
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
Pass {
SetTexture [_Tex1] {constantColor(1,1,1,[_Fade1]) combine texture * constant}
SetTexture [_Tex2] {constantColor(1,1,1,[_Fade2]) combine texture lerp (texture) previous}
SetTexture [_Tex3] {constantColor(1,1,1,[_Fade3]) combine texture lerp (texture) previous}
}
}
}
This is close, however, you'll notice that I'm not using the "constant" on the second and third layer to fade-out the texture. If I could write it the way I think it should be the second and third SetTexture would be:
SetTexture [_Tex2] {constantColor(1,1,1,[_Fade2]) combine texture lerp (texture * constant) previous}
Unfortunately, multiplying 2 sources in the argument of a lerp is not allowed as far as I can tell. Anyone got an idea of how to do achieve this? fyi, this is intended for iOS devices.
Thanks for any help, Mike