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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Compute depth 01

Discussion in 'Shaders' started by kokichi88, Sep 24, 2015.

  1. kokichi88

    kokichi88

    Joined:
    Mar 3, 2014
    Posts:
    13
    Hi guys, I don't understand how unity calculate depth 01. Formula is described in CgInclude is :
    Code (CSharp):
    1. #define COMPUTE_DEPTH_01 -(mul( UNITY_MATRIX_MV, v.vertex ).z * _ProjectionParams.w)
    Why not is
    Code (csharp):
    1. #define COMPUTE_DEPTH_01 (mul( UNITY_MATRIX_MV, v.vertex ).z * _ProjectionParams.w)
    without subtract.
     
  2. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    Probably because by, I believe, OpenGL convention, the z component for view space positions in front of the camera are negative... So the minus sign should actually bring them back to positive values.
     
  3. kokichi88

    kokichi88

    Joined:
    Mar 3, 2014
    Posts:
    13
    I got it, thanks you