Search Unity

Question Multipass clip shader question

Discussion in 'Shaders' started by Meaningless-Trinket, May 21, 2022.

  1. Meaningless-Trinket

    Meaningless-Trinket

    Joined:
    Apr 25, 2020
    Posts:
    83
    I want to clip out everything inside a view frustum with clipping planes and keep the outside.

    The frustum clips away the inside but keeps the outside.

    I did this with four planes and four materials on the game object.

    Is there a smarter way to do this?

    Can a multi pass clipping shader save clipped pieces from the planes with only one material?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Presumably you're using a custom shader that you're passing the plane to to
    clip()
    against?

    You could just pass this "view's" view projection matrix to the shader, and then do:
    Code (csharp):
    1. float4 frustumPos = mul(_CustomViewProjection, float4(worldPos.xyz, 1.0));
    2. if (!any(saturate(abs(frustumPos.xyz) - frustumPos.w))))
    3.   discard;