Search Unity

Projector caustic effect broken in 5.4

Discussion in 'General Graphics' started by sfaok, Sep 1, 2016.

  1. sfaok

    sfaok

    Joined:
    Nov 27, 2012
    Posts:
    23
    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.

    ProjectorProblem.png

    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).

    Code (CSharp):
    1. Shader "FX/CausticsProjector" {
    2.     Properties {
    3.         _Color ("Color", Color) = (1,1,1,0)
    4.         _ShadowTex ("Cookie", 2D) = "black" { TexGen ObjectLinear }
    5.         _Size ("Grid Size", Float) = 1
    6.     }
    7.     Subshader {
    8.         Tags { "RenderType"="Transparent" "Queue"="Transparent" }
    9.         Pass {
    10.             ZWrite Off
    11.             Blend One One
    12.  
    13.             CGPROGRAM
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.  
    17.             #include "UnityCG.cginc"
    18.             struct v2f {
    19.                 float4 pos : SV_POSITION;
    20.                 float2 uv : TEXCOORD0;
    21.             };
    22.             sampler2D _ShadowTex;
    23.             float4 _ShadowTex_ST;
    24.             float4 _Color;
    25.             float4x4 unity_Projector;
    26.             fixed _Size;
    27.             v2f vert (appdata_tan v) {
    28.                 v2f o;
    29.                 o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    30.                 o.uv = TRANSFORM_TEX (mul (unity_Projector, v.vertex).xy, _ShadowTex) * _Size;
    31.                 return o;
    32.             }
    33.             half4 frag (v2f i) : COLOR {
    34.                 return tex2D (_ShadowTex, fmod (i.uv, (_Size) ) ) * _Color;
    35.             }
    36.             ENDCG
    37.         }
    38.     }
    39. }
     
  2. sfaok

    sfaok

    Joined:
    Nov 27, 2012
    Posts:
    23
    I've created a simple Unity (5.4.0) project that shows this problem:

    https://dl.dropboxusercontent.com/u/55755/ProjectorTest.zip

    When the transparent sphere is out of camera view, the projector brightens. Similarly if there are no transparent materials in the scene everything works as expected. Project works fine in Unity 5.3.4 and previous.