No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SpeedTreeUtility.hlsl 1.1KB

1234567891011121314151617181920212223242526272829303132
  1. #ifndef UNIVERSAL_SPEEDTREE_UTILITY
  2. #define UNIVERSAL_SPEEDTREE_UTILITY
  3. uint2 ComputeFadeMaskSeed(float3 V, uint2 positionSS)
  4. {
  5. uint2 fadeMaskSeed;
  6. // Is this a reasonable quality gate?
  7. if (IsPerspectiveProjection())
  8. {
  9. // Start with the world-space direction V. It is independent from the orientation of the camera,
  10. // and only depends on the position of the camera and the position of the fragment.
  11. // Now, project and transform it into [-1, 1].
  12. float2 pv = PackNormalOctQuadEncode(V);
  13. // Rescale it to account for the resolution of the screen.
  14. pv *= _ScreenParams.xy;
  15. // The camera only sees a small portion of the sphere, limited by hFoV and vFoV.
  16. // Therefore, we must rescale again (before quantization), roughly, by 1/tan(FoV/2).
  17. pv *= UNITY_MATRIX_P._m00_m11;
  18. // Truncate and quantize.
  19. fadeMaskSeed = asuint((int2)pv);
  20. }
  21. else
  22. {
  23. // Can't use the view direction, it is the same across the entire screen.
  24. fadeMaskSeed = positionSS;
  25. }
  26. return fadeMaskSeed;
  27. }
  28. #endif