Search Unity

5.4 Projection shader problem

Discussion in 'Shaders' started by ljarbo, Sep 26, 2016.

  1. ljarbo

    ljarbo

    Joined:
    May 3, 2013
    Posts:
    44
    I've updated unity from 5.3 to 5.4 and the Projection/multiply shader seems to have broke in some way?
    The projection is very saturated and also see-through? i.e it seems to ignore to "Ignore Layers" setting.

    If I look at the shader, it has correctly updated _Projector to unity_Projector.

    Any Ideas were to begin with this?

    ========= Edit

    This is the shader, its the standard Projector multiply.

    It seems to be something with the Blend pass parameter? I tried all Blend options, but it doesn't seem to work correctly.

    If Blend is set to of, the projection looks ok, ie not saturated, but I have no ignoring of other layers, so that wont work.

    Code (CSharp):
    1. Shader "Projector/Multiply" {
    2.     Properties {
    3.         _ShadowTex ("Cookie", 2D) = "gray" {}
    4.     }
    5.     Subshader {
    6.         Tags {"Queue"="Transparent"}
    7.         Pass {
    8.             ZWrite Off
    9.             ColorMask RGB
    10.             Blend DstColor Zero
    11.             Offset -1, -1
    12.  
    13.             CGPROGRAM
    14.             #pragma vertex vert
    15.             #pragma fragment frag
    16.             #include "UnityCG.cginc"
    17.            
    18.             struct v2f {
    19.                 float4 uvShadow : TEXCOORD0;
    20.                 float4 pos : SV_POSITION;
    21.             };
    22.            
    23.             float4x4 unity_Projector;
    24.             float4x4 unity_ProjectorClip;
    25.            
    26.             v2f vert (float4 vertex : POSITION)
    27.             {
    28.                 v2f o;
    29.                 o.pos = mul (UNITY_MATRIX_MVP, vertex);
    30.                 o.uvShadow = mul (unity_Projector, vertex);
    31.                 return o;
    32.             }
    33.            
    34.             sampler2D _ShadowTex;
    35.  
    36.             fixed4 frag (v2f i) : SV_Target
    37.             {
    38.                 fixed4 res = tex2Dproj (_ShadowTex, UNITY_PROJ_COORD(i.uvShadow));
    39.                 res.a = 1.0-res.a;
    40.  
    41.                 return res;
    42.             }
    43.             ENDCG
    44.         }
    45.     }
    46. }
     
    Last edited: Sep 26, 2016
  2. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    how about set to

    Blend SrcAlpha OneMinusSrcAlpha
     
  3. ljarbo

    ljarbo

    Joined:
    May 3, 2013
    Posts:
    44
    No, sorry, that didn't work. I did look at the options for the Blend previously and I did try them all, although I had my hopes for the one you suggested.

    With a fresh Unity 5.4 project, it seems to work, so there must be something else broken somewhere? It is totally ignoring "ignore layers" on projections and I have no clue how to kickstart it again? I did try to create new layers and set them to ignore. But it doesn't work..

    Thanks for trying.
     
  4. tsangwailam

    tsangwailam

    Joined:
    Jul 30, 2013
    Posts:
    280
    Wrong post. Sorry.
     
  5. ljarbo

    ljarbo

    Joined:
    May 3, 2013
    Posts:
    44
    If someone encounters this problem:

    Updating from 5.3 to 5.5 works.