UnlitDepthNormalsPass.hlsl 1.6 KB

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