Search Unity

Question Cull camera to avoid rendering things under a certain y

Discussion in 'General Graphics' started by dccoo, Oct 15, 2022.

  1. dccoo

    dccoo

    Joined:
    Oct 3, 2015
    Posts:
    161
    Pretty straight-forward question: given a value for the y axis, is it possible to make the camera not render things under this value?

    I'm using an orthographic camera (although I don't think it makes any difference).

    upload_2022-10-15_4-2-36.png

    The image shows an example of what I want, culling things under y = 1.

    The rotation of the camera doesn't change this criteria. The part under y = 1 must be seen by other cameras, I just need this effect for a single camera.
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,059
    Maybe use stencils for this?
    That way you have an infinite plane at the desired Y location and you switch it to the stencil layer when desired
     
  3. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    672
    You could use a scissor rect but don't know if there is a way to set it via the camera
    https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.EnableScissorRect.html

    Another alternative would be setting the SV_ClipDistance and SV_CullDistance semantics in the vertex shader. Downside is that you need a custom shader.

    You could also render to a smaller render texture first and then copy it.

    It may also work to fill the bottom of the depth buffer with 0 (or 1 because of reverse z) before rendering.
     
    DevDunk likes this.