InTerra_TerrainLit_Basemap_2022_2.shader 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. //NOTE! This file is based on Unity file "TerrainLit_Basemap.shader" which was used as a template for adding all the InTerra features.
  2. Shader "Hidden/InTerra/HDRP/TerrainLit_Basemap_2022_2"
  3. {
  4. Properties
  5. {
  6. // Following are builtin properties
  7. // Stencil state
  8. // Forward
  9. [HideInInspector] _StencilRef("_StencilRef", Int) = 0 // StencilUsage.Clear
  10. [HideInInspector] _StencilWriteMask("_StencilWriteMask", Int) = 3 // StencilUsage.RequiresDeferredLighting | StencilUsage.SubsurfaceScattering
  11. // GBuffer
  12. [HideInInspector] _StencilRefGBuffer("_StencilRefGBuffer", Int) = 2 // StencilUsage.RequiresDeferredLighting
  13. [HideInInspector] _StencilWriteMaskGBuffer("_StencilWriteMaskGBuffer", Int) = 3 // StencilUsage.RequiresDeferredLighting | StencilUsage.SubsurfaceScattering
  14. // Depth prepass
  15. [HideInInspector] _StencilRefDepth("_StencilRefDepth", Int) = 0 // Nothing
  16. [HideInInspector] _StencilWriteMaskDepth("_StencilWriteMaskDepth", Int) = 8 // StencilUsage.TraceReflectionRay
  17. // Blending state
  18. [HideInInspector] _ZWrite ("__zw", Float) = 1.0
  19. [HideInInspector] _CullMode("__cullmode", Float) = 2.0
  20. [HideInInspector] _ZTestDepthEqualForOpaque("_ZTestDepthEqualForOpaque", Int) = 4 // Less equal
  21. [HideInInspector] _ZTestGBuffer("_ZTestGBuffer", Int) = 4
  22. [HideInInspector] _TerrainHolesTexture("Holes Map (RGB)", 2D) = "white" {}
  23. // Caution: C# code in BaseLitUI.cs call LightmapEmissionFlagsProperty() which assume that there is an existing "_EmissionColor"
  24. // value that exist to identify if the GI emission need to be enabled.
  25. // In our case we don't use such a mechanism but need to keep the code quiet. We declare the value and always enable it.
  26. // TODO: Fix the code in legacy unity so we can customize the behavior for GI
  27. _EmissionColor("Color", Color) = (1, 1, 1)
  28. _MetallicTex("Metallic (RGB)", 2D) = "white" {}
  29. _Triplanar_MetallicAO("Metallic AO (RGB)", 2D) = "white" {}
  30. // HACK: GI Baking system relies on some properties existing in the shader ("_MainTex", "_Cutoff" and "_Color") for opacity handling, so we need to store our version of those parameters in the hard-coded name the GI baking system recognizes.
  31. _MainTex("Albedo", 2D) = "white" {}
  32. _Color("Color", Color) = (1,1,1,1)
  33. [ToggleUI] _SupportDecals("Support Decals", Float) = 1.0
  34. [ToggleUI] _ReceivesSSR("Receives SSR", Float) = 1.0
  35. }
  36. HLSLINCLUDE
  37. #pragma target 4.5
  38. #pragma only_renderers d3d11 playstation xboxone xboxseries vulkan metal switch
  39. #pragma shader_feature_local _DISABLE_DECALS
  40. #pragma shader_feature_local _TERRAIN_INSTANCED_PERPIXEL_NORMAL
  41. // InTerra Keywords
  42. #pragma shader_feature_local __ _TERRAIN_TRIPLANAR_ONE _TERRAIN_TRIPLANAR
  43. //enable GPU instancing support
  44. #pragma multi_compile_instancing
  45. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
  46. #pragma multi_compile _ _ALPHATEST_ON
  47. #define UNITY_2022_2_OR_NEWER
  48. #pragma vertex Vert
  49. #pragma fragment Frag
  50. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Basemap_Includes.hlsl"
  51. ENDHLSL
  52. SubShader
  53. {
  54. PackageRequirements { "com.unity.render-pipelines.high-definition":"[14.0.0,14.99.99]" }
  55. // This tags allow to use the shader replacement features
  56. Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Opaque" }
  57. // Caution: The outline selection in the editor use the vertex shader/hull/domain shader of the first pass declare. So it should not bethe meta pass.
  58. Pass
  59. {
  60. Name "GBuffer"
  61. Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
  62. Cull [_CullMode]
  63. ZTest [_ZTestGBuffer]
  64. Stencil
  65. {
  66. WriteMask [_StencilWriteMaskGBuffer]
  67. Ref [_StencilRefGBuffer]
  68. Comp Always
  69. Pass Replace
  70. }
  71. HLSLPROGRAM
  72. #pragma multi_compile _ DEBUG_DISPLAY
  73. #pragma multi_compile _ LIGHTMAP_ON
  74. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  75. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  76. #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
  77. #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
  78. // Setup DECALS_OFF so the shader stripper can remove variants
  79. #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT
  80. #pragma multi_compile_fragment _ LIGHT_LAYERS
  81. #define SHADERPASS SHADERPASS_GBUFFER
  82. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  83. #include "InTerra_TerrainLitTemplate.hlsl"
  84. #include "InTerra_TerrainLit_Basemap.hlsl"
  85. ENDHLSL
  86. }
  87. // Extracts information for lightmapping, GI (emission, albedo, ...)
  88. // This pass it not used during regular rendering.
  89. Pass
  90. {
  91. Name "META"
  92. Tags{ "LightMode" = "META" }
  93. Cull Off
  94. HLSLPROGRAM
  95. // Lightmap memo
  96. // DYNAMICLIGHTMAP_ON is used when we have an "enlighten lightmap" ie a lightmap updated at runtime by enlighten.This lightmap contain indirect lighting from realtime lights and realtime emissive material.Offline baked lighting(from baked material / light,
  97. // both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
  98. #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
  99. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  100. #include "InTerra_TerrainLitTemplate.hlsl"
  101. #include "InTerra_TerrainLit_Basemap.hlsl"
  102. ENDHLSL
  103. }
  104. Pass
  105. {
  106. Name "ShadowCaster"
  107. Tags{ "LightMode" = "ShadowCaster" }
  108. Cull[_CullMode]
  109. ZClip [_ZClip]
  110. ZWrite On
  111. ZTest LEqual
  112. ColorMask 0
  113. HLSLPROGRAM
  114. #define SHADERPASS SHADERPASS_SHADOWS
  115. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  116. #include "InTerra_TerrainLitTemplate.hlsl"
  117. #include "InTerra_TerrainLit_Basemap.hlsl"
  118. ENDHLSL
  119. }
  120. Pass
  121. {
  122. Name "DepthOnly"
  123. Tags{ "LightMode" = "DepthOnly" }
  124. Cull[_CullMode]
  125. // To be able to tag stencil with disableSSR information for forward
  126. Stencil
  127. {
  128. WriteMask [_StencilWriteMaskDepth]
  129. Ref [_StencilRefDepth]
  130. Comp Always
  131. Pass Replace
  132. }
  133. ZWrite On
  134. HLSLPROGRAM
  135. // In deferred, depth only pass don't output anything.
  136. // In forward it output the normal buffer
  137. #pragma multi_compile _ WRITE_NORMAL_BUFFER
  138. #pragma multi_compile_fragment _ WRITE_DECAL_BUFFER
  139. #pragma multi_compile _ WRITE_MSAA_DEPTH
  140. #define SHADERPASS SHADERPASS_DEPTH_ONLY
  141. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  142. #include "InTerra_TerrainLitTemplate.hlsl"
  143. #include "InTerra_TerrainLit_Basemap.hlsl"
  144. ENDHLSL
  145. }
  146. Pass
  147. {
  148. Name "Forward"
  149. Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
  150. Stencil
  151. {
  152. WriteMask [_StencilWriteMask]
  153. Ref [_StencilRef]
  154. Comp Always
  155. Pass Replace
  156. }
  157. // In case of forward we want to have depth equal for opaque mesh
  158. ZTest [_ZTestDepthEqualForOpaque]
  159. ZWrite [_ZWrite]
  160. Cull [_CullMode]
  161. HLSLPROGRAM
  162. #pragma multi_compile _ DEBUG_DISPLAY
  163. #pragma multi_compile _ LIGHTMAP_ON
  164. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  165. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  166. #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
  167. #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
  168. #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
  169. // Setup DECALS_OFF so the shader stripper can remove variants
  170. #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT
  171. // Supported shadow modes per light type
  172. #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH
  173. #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
  174. #define SHADERPASS SHADERPASS_FORWARD
  175. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  176. #include "InTerra_TerrainLitTemplate.hlsl"
  177. #include "InTerra_TerrainLit_Basemap.hlsl"
  178. ENDHLSL
  179. }
  180. UsePass "Hidden/Nature/Terrain/Utilities/PICKING"
  181. UsePass "HDRP/TerrainLit/SceneSelectionPass"
  182. }
  183. }