DeclareNormalsTexture.hlsl 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. #ifndef UNITY_DECLARE_NORMALS_TEXTURE_INCLUDED
  2. #define UNITY_DECLARE_NORMALS_TEXTURE_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  4. TEXTURE2D_X_FLOAT(_CameraNormalsTexture);
  5. SAMPLER(sampler_CameraNormalsTexture);
  6. float3 SampleSceneNormals(float2 uv)
  7. {
  8. float3 normal = SAMPLE_TEXTURE2D_X(_CameraNormalsTexture, sampler_CameraNormalsTexture, UnityStereoTransformScreenSpaceTex(uv)).xyz;
  9. #if defined(_GBUFFER_NORMALS_OCT)
  10. float2 remappedOctNormalWS = Unpack888ToFloat2(normal); // values between [ 0, 1]
  11. float2 octNormalWS = remappedOctNormalWS.xy * 2.0 - 1.0; // values between [-1, +1]
  12. normal = UnpackNormalOctQuadEncode(octNormalWS);
  13. #endif
  14. return normal;
  15. }
  16. float3 LoadSceneNormals(uint2 uv)
  17. {
  18. float3 normal = LOAD_TEXTURE2D_X(_CameraNormalsTexture, uv).xyz;
  19. #if defined(_GBUFFER_NORMALS_OCT)
  20. float2 remappedOctNormalWS = Unpack888ToFloat2(normal); // values between [ 0, 1]
  21. float2 octNormalWS = remappedOctNormalWS.xy * 2.0 - 1.0; // values between [-1, +1]
  22. normal = UnpackNormalOctQuadEncode(octNormalWS);
  23. #endif
  24. return normal;
  25. }
  26. #endif