I am trying to get a layered effects with multiple transparent or Alpha textures on a single object. When creating things like a waterfall, flowing river ect. I like to use multiple planes layered on top of each other with different alpha values, scroll direction, ect. to give the effect of flowing water. I’m curious if this can all be done on a single plane instead?
You can with a shader that samples multiple textures and blends them together. You can scroll the uvs to make the water flow. I think it’s better to do it all in one shader so you won’t have any z-fighting and it probably helps the performance.
This is a simple surface shader that blends A B and C in that order.
Shader "Custom/Blend 3"
{
Properties
{
_Color ("Color", COLOR) = (1, 1, 1, 1)
_MainTex ("Texture A (RGB)", 2D) = "black" {}
_TextureB ("Texture B (RGB)", 2D) = "black" {}
_TextureC ("Texture C (RGB)", 2D) = "black" {}
_FlowSpeedA ("Flow Speed A (UV X, UV Y)", VECTOR) = (0, 0, 0, 0)
_FlowSpeedB ("Flow Speed B (UV X, UV Y)", VECTOR) = (0, 0, 0, 0)
_FlowSpeedC ("Flow Speed C (UV X, UV Y)", VECTOR) = (0, 0, 0, 0)
}
SubShader
{
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
LOD 200
ZWrite Off
CGPROGRAM
#pragma surface surf Lambert alpha
fixed4 _Color;
sampler2D _MainTex;
sampler2D _TextureB;
sampler2D _TextureC;
float4 _FlowSpeedA;
float4 _FlowSpeedB;
float4 _FlowSpeedC;
struct Input
{
float2 uv_MainTex;
float2 uv_TextureB;
float2 uv_TextureC;
};
void surf (Input i, inout SurfaceOutput o)
{
fixed4 srcA = tex2D(_MainTex, i.uv_MainTex + _FlowSpeedA.xy * _Time.x);
fixed4 srcB = tex2D(_TextureB, i.uv_TextureB + _FlowSpeedB.xy * _Time.x);
fixed4 srcC = tex2D(_TextureC, i.uv_TextureC + _FlowSpeedC.xy * _Time.x);
fixed4 col = fixed4(
srcA.rgb * srcA.a + srcB.rgb * srcB.a * (1 - srcA.a),
srcA.a + srcB.a * (1 - srcA.a));
fixed4 colB = fixed4(
col.rgb * col.a + srcC.rgb * srcC.a * (1 - col.a),
col.a + srcC.a * (1 - col.a)) * _Color;
o.Albedo = colB.rgb;
o.Alpha = colB.a;
}
ENDCG
}
FallBack "Transparent/VertexLit"
}
Thank you for taking the time to write this. I rarely write code for shaders and you made it really simple to follow