Bez popisu
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.

SimpleLitDepthNormalsPass.hlsl 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #ifndef UNIVERSAL_SIMPLE_LIT_DEPTH_NORMALS_PASS_INCLUDED
  2. #define UNIVERSAL_SIMPLE_LIT_DEPTH_NORMALS_PASS_INCLUDED
  3. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  4. #if defined(LOD_FADE_CROSSFADE)
  5. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"
  6. #endif
  7. #if defined(_ALPHATEST_ON) || defined(_NORMALMAP)
  8. #define REQUIRES_UV_INTERPOLATOR
  9. #endif
  10. struct Attributes
  11. {
  12. float4 positionOS : POSITION;
  13. float4 tangentOS : TANGENT;
  14. float2 texcoord : TEXCOORD0;
  15. float3 normal : NORMAL;
  16. UNITY_VERTEX_INPUT_INSTANCE_ID
  17. };
  18. struct Varyings
  19. {
  20. float4 positionCS : SV_POSITION;
  21. #if defined(REQUIRES_UV_INTERPOLATOR)
  22. float2 uv : TEXCOORD1;
  23. #endif
  24. #ifdef _NORMALMAP
  25. half4 normalWS : TEXCOORD2; // xyz: normal, w: viewDir.x
  26. half4 tangentWS : TEXCOORD3; // xyz: tangent, w: viewDir.y
  27. half4 bitangentWS : TEXCOORD4; // xyz: bitangent, w: viewDir.z
  28. #else
  29. half3 normalWS : TEXCOORD2;
  30. half3 viewDir : TEXCOORD3;
  31. #endif
  32. UNITY_VERTEX_INPUT_INSTANCE_ID
  33. UNITY_VERTEX_OUTPUT_STEREO
  34. };
  35. Varyings DepthNormalsVertex(Attributes input)
  36. {
  37. Varyings output = (Varyings)0;
  38. UNITY_SETUP_INSTANCE_ID(input);
  39. UNITY_TRANSFER_INSTANCE_ID(input, output);
  40. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  41. #if defined(REQUIRES_UV_INTERPOLATOR)
  42. output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
  43. #endif
  44. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  45. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  46. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normal, input.tangentOS);
  47. #if defined(_NORMALMAP)
  48. half3 viewDirWS = GetWorldSpaceNormalizeViewDir(vertexInput.positionWS);
  49. output.normalWS = half4(normalInput.normalWS, viewDirWS.x);
  50. output.tangentWS = half4(normalInput.tangentWS, viewDirWS.y);
  51. output.bitangentWS = half4(normalInput.bitangentWS, viewDirWS.z);
  52. #else
  53. output.normalWS = half3(NormalizeNormalPerVertex(normalInput.normalWS));
  54. #endif
  55. return output;
  56. }
  57. void DepthNormalsFragment(
  58. Varyings input
  59. , out half4 outNormalWS : SV_Target0
  60. #ifdef _WRITE_RENDERING_LAYERS
  61. , out float4 outRenderingLayers : SV_Target1
  62. #endif
  63. )
  64. {
  65. UNITY_SETUP_INSTANCE_ID(input);
  66. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  67. #if defined(_ALPHATEST_ON)
  68. Alpha(SampleAlbedoAlpha(input.uv, TEXTURE2D_ARGS(_BaseMap, sampler_BaseMap)).a, _BaseColor, _Cutoff);
  69. #endif
  70. #if defined(LOD_FADE_CROSSFADE)
  71. LODFadeCrossFade(input.positionCS);
  72. #endif
  73. #if defined(_GBUFFER_NORMALS_OCT)
  74. float3 normalWS = normalize(input.normalWS);
  75. float2 octNormalWS = PackNormalOctQuadEncode(normalWS); // values between [-1, +1], must use fp32 on some platforms
  76. float2 remappedOctNormalWS = saturate(octNormalWS * 0.5 + 0.5); // values between [ 0, 1]
  77. half3 packedNormalWS = PackFloat2To888(remappedOctNormalWS); // values between [ 0, 1]
  78. outNormalWS = half4(packedNormalWS, 0.0);
  79. #else
  80. #if defined(_NORMALMAP)
  81. half3 normalTS = SampleNormal(input.uv, TEXTURE2D_ARGS(_BumpMap, sampler_BumpMap));
  82. half3 normalWS = TransformTangentToWorld(normalTS, half3x3(input.tangentWS.xyz, input.bitangentWS.xyz, input.normalWS.xyz));
  83. #else
  84. half3 normalWS = input.normalWS;
  85. #endif
  86. normalWS = NormalizeNormalPerPixel(normalWS);
  87. outNormalWS = half4(normalWS, 0.0);
  88. #endif
  89. #ifdef _WRITE_RENDERING_LAYERS
  90. uint renderingLayers = GetMeshRenderingLayer();
  91. outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
  92. #endif
  93. }
  94. #endif