Lux URP Depth Only.shader 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. Shader "Lux URP/Depth Only"
  2. {
  3. Properties
  4. {
  5. [Header(Surface Options)]
  6. [Space(8)]
  7. [Enum(UnityEngine.Rendering.CullMode)]
  8. _Cull ("Culling", Float) = 2
  9. [Toggle(_ALPHATEST_ON)]
  10. _AlphaClip ("Alpha Clipping", Float) = 0.0
  11. _Cutoff (" Threshold", Range(0.0, 1.0)) = 0.5
  12. [Header(Surface Inputs)]
  13. [Space(8)]
  14. [MainTexture]
  15. _BaseMap ("Albedo (RGB) Alpha (A)", 2D) = "white" {}
  16. }
  17. SubShader
  18. {
  19. Tags
  20. {
  21. "RenderPipeline" = "UniversalPipeline"
  22. "RenderType" = "Opaque"
  23. "Queue" = "Geometry"
  24. }
  25. LOD 100
  26. // Depth -----------------------------------------------------
  27. // Pass needed to receive proper shadows
  28. Pass
  29. {
  30. Tags{"LightMode" = "DepthOnly"}
  31. ZWrite On
  32. ColorMask 0
  33. Cull [_Cull]
  34. HLSLPROGRAM
  35. // Required to compile gles 2.0 with standard srp library
  36. #pragma prefer_hlslcc gles
  37. #pragma exclude_renderers d3d11_9x
  38. #pragma target 2.0
  39. #pragma vertex DepthOnlyVertex
  40. #pragma fragment DepthOnlyFragment
  41. // -------------------------------------
  42. // Material Keywords
  43. #pragma shader_feature_local _ALPHATEST_ON
  44. //--------------------------------------
  45. // GPU Instancing
  46. #pragma multi_compile_instancing
  47. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  48. // Material Inputs
  49. CBUFFER_START(UnityPerMaterial)
  50. half _Cutoff;
  51. CBUFFER_END
  52. #if defined(_ALPHATEST_ON)
  53. TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap); float4 _BaseMap_ST;
  54. #endif
  55. struct VertexInput {
  56. float3 positionOS : POSITION;
  57. float2 texcoord : TEXCOORD0;
  58. UNITY_VERTEX_INPUT_INSTANCE_ID
  59. };
  60. struct VertexOutput {
  61. float4 positionCS : SV_POSITION;
  62. float2 uv : TEXCOORD0;
  63. };
  64. VertexOutput DepthOnlyVertex(VertexInput input)
  65. {
  66. VertexOutput output = (VertexOutput)0;
  67. UNITY_SETUP_INSTANCE_ID(input);
  68. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  69. #if defined(_ALPHATEST_ON)
  70. output.uv = TRANSFORM_TEX(input.texcoord, _BaseMap);
  71. #endif
  72. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  73. return output;
  74. }
  75. half4 DepthOnlyFragment(VertexOutput input) : SV_TARGET
  76. {
  77. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  78. #if defined(_ALPHATEST_ON)
  79. half mask = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv.xy).a;
  80. clip (mask - _Cutoff);
  81. #endif
  82. return 0;
  83. }
  84. ENDHLSL
  85. }
  86. // Depth Normal ---------------------------------------------
  87. // This pass is used when drawing to a _CameraNormalsTexture texture
  88. Pass
  89. {
  90. Name "DepthNormals"
  91. Tags{"LightMode" = "DepthNormals"}
  92. ZWrite On
  93. Cull[_Cull]
  94. HLSLPROGRAM
  95. #pragma exclude_renderers d3d11_9x
  96. #pragma target 2.0
  97. #pragma vertex DepthNormalVertex
  98. #pragma fragment DepthNormalFragment
  99. // -------------------------------------
  100. // Material Keywords
  101. #pragma shader_feature_local _ALPHATEST_ON // not per fragment!
  102. //--------------------------------------
  103. // GPU Instancing
  104. #pragma multi_compile_instancing
  105. // #pragma multi_compile _ DOTS_INSTANCING_ON // needs shader target 4.5
  106. #define DEPTHNORMALPASS
  107. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  108. CBUFFER_START(UnityPerMaterial)
  109. half _Cutoff;
  110. CBUFFER_END
  111. #if defined(_ALPHATEST_ON)
  112. TEXTURE2D(_BaseMap); SAMPLER(sampler_BaseMap); float4 _BaseMap_ST;
  113. #endif
  114. struct VertexInput {
  115. float3 positionOS : POSITION;
  116. float2 texcoord : TEXCOORD0;
  117. float3 normalOS : NORMAL;
  118. UNITY_VERTEX_INPUT_INSTANCE_ID
  119. };
  120. struct VertexOutput {
  121. float4 positionCS : SV_POSITION;
  122. float2 uv : TEXCOORD0;
  123. half3 normalWS : TEXCOORD1;
  124. };
  125. VertexOutput DepthNormalVertex(VertexInput input)
  126. {
  127. VertexOutput output = (VertexOutput)0;
  128. UNITY_SETUP_INSTANCE_ID(input);
  129. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  130. #if defined(_ALPHATEST_ON)
  131. output.uv.xy = TRANSFORM_TEX(input.texcoord, _BaseMap);
  132. #endif
  133. output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
  134. VertexNormalInputs normalInput = GetVertexNormalInputs(input.normalOS, float4(1,1,1,1)); //input.tangentOS);
  135. output.normalWS = NormalizeNormalPerVertex(normalInput.normalWS);
  136. return output;
  137. }
  138. half4 DepthNormalFragment(VertexOutput input) : SV_TARGET
  139. {
  140. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  141. #if defined(_ALPHATEST_ON)
  142. half mask = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, input.uv.xy).a;
  143. clip (mask - _Cutoff);
  144. #endif
  145. float3 normal = input.normalWS;
  146. return float4(PackNormalOctRectEncode(TransformWorldToViewDir(normal, true)), 0.0, 0.0);
  147. }
  148. ENDHLSL
  149. }
  150. // End Passes -----------------------------------------------------
  151. }
  152. FallBack "Hidden/InternalErrorShader"
  153. //CustomEditor "LuxURPUniversalCustomShaderGUI"
  154. }