InTerra_TerrainLit_Basemap.shader 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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"
  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. #define _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. #pragma vertex Vert
  48. #pragma fragment Frag
  49. #include "Packages/com.unity.render-pipelines.high-definition/Runtime/Material/TerrainLit/TerrainLit_Basemap_Includes.hlsl"
  50. ENDHLSL
  51. SubShader
  52. {
  53. PackageRequirements { "com.unity.render-pipelines.high-definition":"[12.0,13.99.99]" }
  54. // This tags allow to use the shader replacement features
  55. Tags{ "RenderPipeline" = "HDRenderPipeline" "RenderType" = "Opaque" }
  56. // 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.
  57. Pass
  58. {
  59. Name "GBuffer"
  60. Tags { "LightMode" = "GBuffer" } // This will be only for opaque object based on the RenderQueue index
  61. Cull [_CullMode]
  62. ZTest [_ZTestGBuffer]
  63. Stencil
  64. {
  65. WriteMask [_StencilWriteMaskGBuffer]
  66. Ref [_StencilRefGBuffer]
  67. Comp Always
  68. Pass Replace
  69. }
  70. HLSLPROGRAM
  71. #pragma multi_compile _ DEBUG_DISPLAY
  72. #pragma multi_compile _ LIGHTMAP_ON
  73. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  74. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  75. #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
  76. #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
  77. // Setup DECALS_OFF so the shader stripper can remove variants
  78. #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT
  79. #pragma multi_compile_fragment _ LIGHT_LAYERS
  80. #define SHADERPASS SHADERPASS_GBUFFER
  81. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  82. #include "InTerra_TerrainLitTemplate.hlsl"
  83. #include "InTerra_TerrainLit_Basemap.hlsl"
  84. ENDHLSL
  85. }
  86. // Extracts information for lightmapping, GI (emission, albedo, ...)
  87. // This pass it not used during regular rendering.
  88. Pass
  89. {
  90. Name "META"
  91. Tags{ "LightMode" = "META" }
  92. Cull Off
  93. HLSLPROGRAM
  94. // Lightmap memo
  95. // 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,
  96. // both direct and indirect lighting) will hand up in the "regular" lightmap->LIGHTMAP_ON.
  97. #define SHADERPASS SHADERPASS_LIGHT_TRANSPORT
  98. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  99. #include "InTerra_TerrainLitTemplate.hlsl"
  100. #include "InTerra_TerrainLit_Basemap.hlsl"
  101. ENDHLSL
  102. }
  103. Pass
  104. {
  105. Name "ShadowCaster"
  106. Tags{ "LightMode" = "ShadowCaster" }
  107. Cull[_CullMode]
  108. ZClip [_ZClip]
  109. ZWrite On
  110. ZTest LEqual
  111. ColorMask 0
  112. HLSLPROGRAM
  113. #define SHADERPASS SHADERPASS_SHADOWS
  114. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  115. #include "InTerra_TerrainLitTemplate.hlsl"
  116. #include "InTerra_TerrainLit_Basemap.hlsl"
  117. ENDHLSL
  118. }
  119. Pass
  120. {
  121. Name "DepthOnly"
  122. Tags{ "LightMode" = "DepthOnly" }
  123. Cull[_CullMode]
  124. // To be able to tag stencil with disableSSR information for forward
  125. Stencil
  126. {
  127. WriteMask [_StencilWriteMaskDepth]
  128. Ref [_StencilRefDepth]
  129. Comp Always
  130. Pass Replace
  131. }
  132. ZWrite On
  133. HLSLPROGRAM
  134. // In deferred, depth only pass don't output anything.
  135. // In forward it output the normal buffer
  136. #pragma multi_compile _ WRITE_NORMAL_BUFFER
  137. #pragma multi_compile_fragment _ WRITE_DECAL_BUFFER
  138. #pragma multi_compile _ WRITE_MSAA_DEPTH
  139. #define SHADERPASS SHADERPASS_DEPTH_ONLY
  140. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  141. #include "InTerra_TerrainLitTemplate.hlsl"
  142. #include "InTerra_TerrainLit_Basemap.hlsl"
  143. ENDHLSL
  144. }
  145. Pass
  146. {
  147. Name "Forward"
  148. Tags{ "LightMode" = "Forward" } // This will be only for transparent object based on the RenderQueue index
  149. Stencil
  150. {
  151. WriteMask [_StencilWriteMask]
  152. Ref [_StencilRef]
  153. Comp Always
  154. Pass Replace
  155. }
  156. // In case of forward we want to have depth equal for opaque mesh
  157. ZTest [_ZTestDepthEqualForOpaque]
  158. ZWrite [_ZWrite]
  159. Cull [_CullMode]
  160. HLSLPROGRAM
  161. #pragma multi_compile _ DEBUG_DISPLAY
  162. #pragma multi_compile _ LIGHTMAP_ON
  163. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  164. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  165. #pragma multi_compile_fragment _ SHADOWS_SHADOWMASK
  166. #pragma multi_compile_fragment PROBE_VOLUMES_OFF PROBE_VOLUMES_L1 PROBE_VOLUMES_L2
  167. #pragma multi_compile_fragment SCREEN_SPACE_SHADOWS_OFF SCREEN_SPACE_SHADOWS_ON
  168. // Setup DECALS_OFF so the shader stripper can remove variants
  169. #pragma multi_compile_fragment DECALS_OFF DECALS_3RT DECALS_4RT
  170. // Supported shadow modes per light type
  171. #pragma multi_compile_fragment SHADOW_LOW SHADOW_MEDIUM SHADOW_HIGH SHADOW_VERY_HIGH
  172. #pragma multi_compile USE_FPTL_LIGHTLIST USE_CLUSTERED_LIGHTLIST
  173. #define SHADERPASS SHADERPASS_FORWARD
  174. #include "InTerra_HDRP_DefinedGlobalKeywords.hlsl"
  175. #include "InTerra_TerrainLitTemplate.hlsl"
  176. #include "InTerra_TerrainLit_Basemap.hlsl"
  177. ENDHLSL
  178. }
  179. UsePass "Hidden/Nature/Terrain/Utilities/PICKING"
  180. UsePass "HDRP/TerrainLit/SceneSelectionPass"
  181. }
  182. }