Transparent water shader and problems with render queue
Hi there,
I wrote my own water shader and everything works fine in the scene view, but in the game view some objects with that shader are getting squashed together and render at a wrong position:
When moving the camera some objects start working again and others break. I tried to play around with the render queue and everything works when using the geometry queue instead of the transparent one. But using the geometry queue, the water somehow doesn't render above the background (small stripes shining through): So how can I fix that weird displacement bug? Thanks in advance!
Shader "Custom/WaterDisplace" {
Properties {
_Color("Color", Color) = (1.0, 1.0, 1.0, 1.0)
_Cube("Cubemap", CUBE) = "" {}
_MainTex ("Texture", 2D) = "white" {}
_Amount ("Amplitude", Range(0.001,1)) = 0.2
_Detail("Detail", Range(0.001,2)) = 0.5
_SpeedX("Speed", Range(0.001,3)) = 0.5
_SpeedY("Speed", Range(0.001,3)) = 0.5
}
SubShader {
Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Cull Off
LOD 100
CGPROGRAM
#pragma surface surf Lambert vertex:vert addshadow alpha
struct Input {
float2 uv_MainTex;
float3 worldRefl;
};
fixed4 _Color;
sampler2D _MainTex;
samplerCUBE _Cube;
float _Amount;
float _Detail;
float _SpeedX;
float _SpeedY;
void vert (inout appdata_full v) {
v.vertex.z = _Amount * (-0.5 + tex2Dlod(_MainTex, float4(float2(v.vertex.x * _Detail + _Time.x *_SpeedX, v.vertex.y * _Detail + _Time.x * _SpeedY), 0, 0)));
}
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = _Color.rgb;
o.Alpha = _Color.a;
o.Emission = texCUBE(_Cube, IN.worldRefl).rgb;
}
fixed4 LightingLambert(SurfaceOutput s, fixed3 lightDir, fixed atten)
{
fixed diff = abs(dot(s.Normal, lightDir));
fixed4 c;
c.rgb = s.Albedo * _LightColor0.rgb * (diff * atten * 2);
c.a = s.Alpha;
return c;
}
ENDCG
}
//Fallback "Diffuse"
}
Any ideas on what could cause this problem? It only occurs with more than one object using this shader.
Your answer
Follow this Question
Related Questions
Problem with overlapping objects and transparency 0 Answers
Leaves disappear in game mode 0 Answers
Shader Transparency problem 1 Answer
Buttons are not transparent against Grid 0 Answers
Best way to achieve color by data? 0 Answers