DepthNormalsPass.hlsl 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #ifndef UNIVERSAL_DEPTH_NORMALS_PASS_INCLUDED
  2. #define UNIVERSAL_DEPTH_NORMALS_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  4. struct Attributes
  5. {
  6. float4 positionOS : POSITION;
  7. float4 tangentOS : TANGENT;
  8. float2 texcoord : TEXCOORD0;
  9. float3 normal : NORMAL;
  10. UNITY_VERTEX_INPUT_INSTANCE_ID
  11. };
  12. struct Varyings
  13. {
  14. float4 positionCS : SV_POSITION;
  15. float2 uv : TEXCOORD1;
  16. float3 normalWS : TEXCOORD2;
  17. UNITY_VERTEX_INPUT_INSTANCE_ID
  18. UNITY_VERTEX_OUTPUT_STEREO
  19. };
  20. Varyings DepthNormalsVertex(Attributes input)
  21. {
  22. Varyings output = (Varyings)0;
  23. UNITY_SETUP_INSTANCE_ID(input);
  24. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  25. output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
  26. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  27. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normal, input.tangentOS);
  28. output.normalWS = NormalizeNormalPerVertex(normalInput.normalWS);
  29. return output;
  30. }
  31. half4 DepthNormalsFragment(Varyings input) : SV_TARGET
  32. {
  33. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  34. Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
  35. #if defined(_GBUFFER_NORMALS_OCT)
  36. float3 normalWS = normalize(input.normalWS);
  37. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms.
  38. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  39. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  40. return half4(packedNormalWS, 0.0);
  41. #else
  42. float3 normalWS = NormalizeNormalPerPixel(input.normalWS);
  43. return half4(normalWS, 0.0);
  44. #endif
  45. }
  46. #endif