Search Unity

2 pass Surface shader with vertex modifier, 2nd pass not receiving new verts?

Discussion in 'Shaders' started by CDF, Jun 15, 2017.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    I'm probably wrong here, but thought that a 2nd pass in a surface shader would receive any modifications made in the first pass? Doesn't seem to be the case.

    For example.

    - 1st pass modifies a plane mesh by scaling its vertices by 1000 using a vert function
    - 2nd pass just has a surface function that sets the color to red

    The result is: only the original location of the verts are colored red.

    What I'm trying to do:

    Create a large plane (water) that reads in the camera depth texture to draw some shore edge effects. I can't write to the depth buffer and do this, because the depth would always be at the water. Thus creating shore everywhere. I want to draw water with depth then use a second pass to add shadows. I just need that second pass to operate on the same vertices the first pass did :(
     
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Each pass consists of both a vertex shader and a fragment shader. The output from the vertex shader is interpolated and sent to the fragment shader. It is not stored anywhere and in that sense it's not a modification. (Though there is an option for that.)

    Simple solution, add the same vertex shader to the surface shader of the 2nd pass.
     
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Thanks