Search Unity

GrabPass - solid color instead of skybox

Discussion in 'Shaders' started by kamac, Nov 19, 2015.

  1. kamac

    kamac

    Joined:
    Mar 21, 2014
    Posts:
    13
    Hey there.

    So, I am using GrabPass to achieve some nice looking, but still cheap effects. The thing is, there's no skybox grabbed, only the camera's clear color.

    Like this:



    I've seen that when other people use Grabpass, they don't seem to have this problem.

    Here's the shader I use (I use deferred rendering, btw):

    Code (CSharp):
    1. Shader "Custom/Effects/WindSlash"
    2. {
    3.     Properties
    4.     {
    5.         _NoiseTex("Bump (RGB)", 2D) = "bump" {}
    6.         _Alpha("Alpha", Float) = 1.0
    7.     }
    8.     SubShader
    9.     {
    10.         Tags{ "RenderType" = "Transparent" "Queue" = "Transparent" }
    11.        
    12.         GrabPass{ "_GrabTexture" }
    13.         Pass
    14.         {
    15.             CGPROGRAM
    16.             #pragma target 3.0
    17.             #pragma vertex vert
    18.             #pragma fragment frag
    19.             // make fog work
    20.             #pragma multi_compile_fog
    21.            
    22.             #include "UnityCG.cginc"
    23.  
    24.             struct appdata
    25.             {
    26.                 float4 vertex : POSITION;
    27.             };
    28.  
    29.             struct v2f
    30.             {
    31.                 float4 vertex : SV_POSITION;
    32.                 float4 scrPos : COLOR;
    33.             };
    34.  
    35.             sampler2D _GrabTexture;
    36.             float _Alpha;
    37.  
    38.             sampler2D _NoiseTex;
    39.            
    40.             v2f vert (appdata_base v)
    41.             {
    42.                 v2f o;
    43.                 o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    44.  
    45.                 o.scrPos = ComputeScreenPos(o.vertex);
    46.                 return o;
    47.             }
    48.            
    49.             fixed4 frag (v2f i) : SV_Target
    50.             {
    51.                 i.scrPos.xy /= i.scrPos.w;
    52.  
    53.                 fixed2 noise = UnpackNormal(tex2D(_NoiseTex, i.scrPos.xy + _Time * 0.3f)).xy;
    54.                 float w = (abs(noise.y) * 0.15f + 1.0f);
    55.                 fixed4 col = tex2D(_GrabTexture, i.scrPos.xy + noise.xy * 0.02f) * float4(1.0 * w, 1.0 * w, 1.6 * w, 1.0);
    56.                 fixed4 realCol = tex2D(_GrabTexture, i.scrPos.xy);
    57.                 return lerp(realCol, col, _Alpha);
    58.             }
    59.             ENDCG
    60.         }
    61.     }
    62. }
    63.  
    Is this the expected behavior? Any way to fix it, or will I have to go back to rendering the whole scene two times to draw it to a render texture first?
     
  2. StevenGerrard

    StevenGerrard

    Joined:
    Jun 1, 2015
    Posts:
    97
    Grabpass should work.
    Maybe check if your main camera's clear flags setting to "Skybox" ?