Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How can I tilt the near plane of camera?

Discussion in 'General Graphics' started by nyxassasin, Jul 14, 2022.

  1. nyxassasin

    nyxassasin

    Joined:
    Sep 30, 2015
    Posts:
    3
    I tried CalculateObliqueMatrix but didn't got the correct result and also in the docs it says that this is used to skew the frustum and not the near plane..
    I want the frustum to be the same, just tilt the near plane..
    Untitled.png
     
  2. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    560
    My hunch is that it's not possible without also tilting the far plane by the same amount. In a 3x3 linear transformation you have 3 basis vectors. How would you orient those 3 basis vectors to get that?
     
  3. JohnE4D

    JohnE4D

    Joined:
    Jul 1, 2021
    Posts:
    5
    You could do your own clipping after the fact. If you leave the camera near plane to your minimum value, you could add this code to your fragment shader to create the effect shown in the picture:


    Code (CSharp):
    1. float depth = input.vertex.z;
    2.     float clipY = input.vertex.y; // varies 0-1
    3.  
    4.     // define your min and max near planes
    5.     float minNearPlane = 1.0f;
    6.     float maxNearPlane = 1.5f;
    7.  
    8.     // determine your cutoff based on y level
    9.     cutoff = lerp(minNearPlane, maxNearPlane, clipY);
    10.  
    11.     // clips if depth is less than cuttoff
    12.     clip(depth - cutoff);
    This may give you issues if you want to know if the object is being clipped on the scripting side, but it should render as expected
     
  4. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    560
  5. c0d3_m0nk3y

    c0d3_m0nk3y

    Joined:
    Oct 21, 2021
    Posts:
    560
    This will give you a gap at the bottom of the screen, though. You can see that geometry is cut off.

    If you don't want that, you could probably also modify the vertex z coordinate in clip space in the vertex shader.