I’m using a projector to create an underwater caustics effect using an animated texture.
Its been working fine since Unity 5.0, but on Unity 5.4 I’ve ran into a strange bug.
The image below shows a test scene. It consists of a plane, a sphere and a projector.
The left side is what I get when the sphere is opaque (standard, or any other shader). Everything is shaded correctly and the caustics dance on the sphere and plane perfectly fine. However if I include ANY transparent object in my scene (additive, alpha blended, fade etc.) the projector brightens significantly. The only difference between left and right is I’ve changed the sphere to a transparent material. The brightness also flickers on and off depending on view of sphere.
This happens using Unity standard assets only. It also happens using my custom shaders. The same exact test scene in Unity 5.3.4 works fine. I’ve tried the Unity 5.4.0f3 and the latest patched Unity 5.4.0p4.
Any help would be greatly appreciated.
Edit : My projector shader (though the standard asset also breaks the same).
Shader "FX/CausticsProjector" {
Properties {
_Color ("Color", Color) = (1,1,1,0)
_ShadowTex ("Cookie", 2D) = "black" { TexGen ObjectLinear }
_Size ("Grid Size", Float) = 1
}
Subshader {
Tags { "RenderType"="Transparent" "Queue"="Transparent" }
Pass {
ZWrite Off
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
sampler2D _ShadowTex;
float4 _ShadowTex_ST;
float4 _Color;
float4x4 unity_Projector;
fixed _Size;
v2f vert (appdata_tan v) {
v2f o;
o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
o.uv = TRANSFORM_TEX (mul (unity_Projector, v.vertex).xy, _ShadowTex) * _Size;
return o;
}
half4 frag (v2f i) : COLOR {
return tex2D (_ShadowTex, fmod (i.uv, (_Size) ) ) * _Color;
}
ENDCG
}
}
}