Search Unity

Render Target in Grabpass and Forward Shader ? (deferred)

Discussion in 'Shaders' started by Quatum1000, Aug 27, 2017.

  1. Quatum1000

    Quatum1000

    Joined:
    Oct 5, 2014
    Posts:
    889
    Hi everyone,

    I have created a forward transparent water shader in deferred mode. The shader use a grabpass to build refraction and and cost foam line. The structure of the shader is like this:

    Code (CSharp):
    1. SubShader{
    2.     Tags{ "Queue" = "Transparent" }
    3.     LOD 300
    4.     Cull [_Culling]
    5.     Zwrite Off
    6.     GrabPass{ "_GrabTexture" }
    7.     #pragma surface surf StandardSpecularWater nolightmap keepalpha nofog
    8.     #pragma target 4.0
    9.     #include "Includes/WaterPBSLighting.cginc"
    10.  
    11.     sampler2D _GrabTexture;
    12.     sampler2D _CameraDepthTexture;
    13.  
    14.     struct Input {
    15.         float2 uv_NormalMap; // master uvs
    16.         float3 viewDir;
    17.         float3 worldPos;
    18.         float4 screenPos;
    19.         float3 worldNormal;
    20.         INTERNAL_DATA
    21.     };
    22.  
    23.     void surf(Input IN, inout SurfaceOutputStandardSpecularWater o) {
    24.            edge_blend_area = xxxxxxxx;
    25.            // Write out Edge blend data into a RT?
    26.     }
    27. }
    28.  
    All the stuff works fine until here.

    The edge_blend_area depth is already calculated correctly, where the water plane intersect any other mesh.
    Untitled-1.jpg

    Now I'd like to write out the edge_blend_area as gray scale depth data into a render-target inside the surf pass. Or is there any possibility to write the info out into a render-target?

    At least I want to have a render target it based on the edge blend mask. I'd like to prevent to render all the stuff twice as a proxy.

    Further I read many stuff about MRTs and the special decal thread. But all this doesn't help me really. Any ideas?

    Thank you.
     
    Last edited: Aug 27, 2017