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.

Question Arbitrary world to screen space?

Discussion in 'High Definition Render Pipeline' started by snacktime, Feb 4, 2021.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,353
    Having a hard time with this one. I'm in a custom post process shader and want to get positionSS from an arbitrary positionWS. To use for sampling the input texture.
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,353
    This appears to be it, although I have some artifacts which might be due to this being wrong or world space outside of the screen not sure yet.

    Code (csharp):
    1.  
    2. uint2 ComputeScreenPosition(float3 positionWS) {
    3.         float2 positionNDC = ComputeNormalizedDeviceCoordinates(positionWS, UNITY_MATRIX_VP);
    4.         positionNDC /= _ScreenSize.zw;
    5.         return uint2(positionNDC.x, positionNDC.y);
    6.     }
    7.