DepthNormalsPass.hlsl 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #ifndef UNIVERSAL_DEPTH_ONLY_PASS_INCLUDED
  2. #define UNIVERSAL_DEPTH_ONLY_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. float4 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. return float4(PackNormalOctRectEncode(TransformWorldToViewDir(input.normalWS, true)), 0.0, 0.0);
  36. }
  37. #endif