I wrote a pretty simple surface shader for water, two textures, reads UV’s from each and blends them with lerp,
scrolling UV’s in different directions.
I don’t pass in UV’s, I calculate them from a single float param I pass in.
Works great in editor…
However on device… I only see one scrolling texture… not 2 blended textures scrolling… but yet its not failing and doing a fallback render.
What is going on ? Does unity remove bits of shaders ?
Why does it work in unity, but only partially on iPhone 6s
Help appreciated, thanks.
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_Texture2 ("Texture2", 2D) = "white" {}
_TextDepth("Depth", 2D) = "white" {} //use red channel for depth, color tint (move this to alpha of main texture later)
_TintCol ("Tint Color", Color) = (1,1,1)
_DeepCol ("Deep Color", Color) = (.5,.6,.8)
_Tile ("WaterTiling", Range(0,20)) = 12.0
_ScrollOffset("Dual Water Offset", Range(0,1)) = 0.0 //param passed in from script
}
SubShader
{
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert nolightmap
struct Input
{
float2 uv_MainTex;
//float2 uv_Tex2;
//float4 color : COLOR; //vertex color
};
sampler2D _MainTex;
sampler2D _Texture2;
sampler2D _TextDepth;
float3 _TintCol;
float3 _DeepCol;
float _ScrollOffset;
float _Tile;
void surf (Input IN, inout SurfaceOutput o)
{
float2 uv2Water; //assume scrolling UV along Y axis
uv2Water.y = IN.uv_MainTex.y * _Tile * 1.123 + _ScrollOffset;
//read in 2 textures from sam8 12.0e texture for water blending 50%-50%
uv2Water.x = IN.uv_MainTex.x * _Tile - _ScrollOffset;
//float lrp = IN.color.a;
fixed3 maincol = tex2D(_MainTex, uv2Water);
uv2Water.x = uv2Water.x + _ScrollOffset + _ScrollOffset;
fixed3 othercol = tex2D(_Texture2, uv2Water);
fixed3 depth = tex2D(_TextDepth, IN.uv_MainTex);
//fixed4 blended = lerp( maincol, othercol, IN.color.a);
fixed3 blended = lerp( maincol, othercol, .5);
blended.rgb *= lerp( (1,1,1), _DeepCol, depth.r);
//o.Albedo = blended.rgb * IN.color.rgb * _TintCol; //dual texture blended, plus tinted output
o.Albedo.rgb = blended.rgb * _TintCol.rgb; //dual texture blended, plus tinted output
o.Alpha = 1.0; //not transparent
}
ENDCG
}