TerrainLit.shader 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. Shader "Universal Render Pipeline/Terrain/Lit"
  2. {
  3. Properties
  4. {
  5. [HideInInspector] [ToggleUI] _EnableHeightBlend("EnableHeightBlend", Float) = 0.0
  6. _HeightTransition("Height Transition", Range(0, 1.0)) = 0.0
  7. // Layer count is passed down to guide height-blend enable/disable, due
  8. // to the fact that heigh-based blend will be broken with multipass.
  9. [HideInInspector] [PerRendererData] _NumLayersCount ("Total Layer Count", Float) = 1.0
  10. // set by terrain engine
  11. [HideInInspector] _Control("Control (RGBA)", 2D) = "red" {}
  12. [HideInInspector] _Splat3("Layer 3 (A)", 2D) = "grey" {}
  13. [HideInInspector] _Splat2("Layer 2 (B)", 2D) = "grey" {}
  14. [HideInInspector] _Splat1("Layer 1 (G)", 2D) = "grey" {}
  15. [HideInInspector] _Splat0("Layer 0 (R)", 2D) = "grey" {}
  16. [HideInInspector] _Normal3("Normal 3 (A)", 2D) = "bump" {}
  17. [HideInInspector] _Normal2("Normal 2 (B)", 2D) = "bump" {}
  18. [HideInInspector] _Normal1("Normal 1 (G)", 2D) = "bump" {}
  19. [HideInInspector] _Normal0("Normal 0 (R)", 2D) = "bump" {}
  20. [HideInInspector] _Mask3("Mask 3 (A)", 2D) = "grey" {}
  21. [HideInInspector] _Mask2("Mask 2 (B)", 2D) = "grey" {}
  22. [HideInInspector] _Mask1("Mask 1 (G)", 2D) = "grey" {}
  23. [HideInInspector] _Mask0("Mask 0 (R)", 2D) = "grey" {}
  24. [HideInInspector][Gamma] _Metallic0("Metallic 0", Range(0.0, 1.0)) = 0.0
  25. [HideInInspector][Gamma] _Metallic1("Metallic 1", Range(0.0, 1.0)) = 0.0
  26. [HideInInspector][Gamma] _Metallic2("Metallic 2", Range(0.0, 1.0)) = 0.0
  27. [HideInInspector][Gamma] _Metallic3("Metallic 3", Range(0.0, 1.0)) = 0.0
  28. [HideInInspector] _Smoothness0("Smoothness 0", Range(0.0, 1.0)) = 0.5
  29. [HideInInspector] _Smoothness1("Smoothness 1", Range(0.0, 1.0)) = 0.5
  30. [HideInInspector] _Smoothness2("Smoothness 2", Range(0.0, 1.0)) = 0.5
  31. [HideInInspector] _Smoothness3("Smoothness 3", Range(0.0, 1.0)) = 0.5
  32. // used in fallback on old cards & base map
  33. [HideInInspector] _MainTex("BaseMap (RGB)", 2D) = "grey" {}
  34. [HideInInspector] _BaseColor("Main Color", Color) = (1,1,1,1)
  35. [HideInInspector] _TerrainHolesTexture("Holes Map (RGB)", 2D) = "white" {}
  36. [ToggleUI] _EnableInstancedPerPixelNormal("Enable Instanced per-pixel normal", Float) = 1.0
  37. }
  38. HLSLINCLUDE
  39. #pragma multi_compile_fragment __ _ALPHATEST_ON
  40. ENDHLSL
  41. SubShader
  42. {
  43. Tags { "Queue" = "Geometry-100" "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "UniversalMaterialType" = "Lit" "IgnoreProjector" = "False" "TerrainCompatible" = "True"}
  44. Pass
  45. {
  46. Name "ForwardLit"
  47. Tags { "LightMode" = "UniversalForward" }
  48. HLSLPROGRAM
  49. #pragma target 3.0
  50. #pragma vertex SplatmapVert
  51. #pragma fragment SplatmapFragment
  52. #define _METALLICSPECGLOSSMAP 1
  53. #define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
  54. // -------------------------------------
  55. // Universal Pipeline keywords
  56. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  57. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  58. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  59. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
  60. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  61. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  62. #pragma multi_compile _ SHADOWS_SHADOWMASK
  63. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  64. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  65. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  66. #pragma multi_compile_fragment _ _LIGHT_COOKIES
  67. #pragma multi_compile _ _CLUSTERED_RENDERING
  68. // -------------------------------------
  69. // Unity defined keywords
  70. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  71. #pragma multi_compile _ LIGHTMAP_ON
  72. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  73. #pragma multi_compile_fog
  74. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  75. #pragma multi_compile_instancing
  76. #pragma instancing_options norenderinglayer assumeuniformscaling nomatrices nolightprobe nolightmap
  77. #pragma shader_feature_local_fragment _TERRAIN_BLEND_HEIGHT
  78. #pragma shader_feature_local _NORMALMAP
  79. #pragma shader_feature_local_fragment _MASKMAP
  80. // Sample normal in pixel shader when doing instancing
  81. #pragma shader_feature_local _TERRAIN_INSTANCED_PERPIXEL_NORMAL
  82. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  83. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl"
  84. ENDHLSL
  85. }
  86. Pass
  87. {
  88. Name "ShadowCaster"
  89. Tags{"LightMode" = "ShadowCaster"}
  90. ZWrite On
  91. ColorMask 0
  92. HLSLPROGRAM
  93. #pragma target 2.0
  94. #pragma vertex ShadowPassVertex
  95. #pragma fragment ShadowPassFragment
  96. #pragma multi_compile_instancing
  97. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
  98. // -------------------------------------
  99. // Universal Pipeline keywords
  100. // This is used during shadow map generation to differentiate between directional and punctual light shadows, as they use different formulas to apply Normal Bias
  101. #pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW
  102. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  103. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl"
  104. ENDHLSL
  105. }
  106. Pass
  107. {
  108. Name "GBuffer"
  109. Tags{"LightMode" = "UniversalGBuffer"}
  110. HLSLPROGRAM
  111. #pragma exclude_renderers gles
  112. #pragma target 3.0
  113. #pragma vertex SplatmapVert
  114. #pragma fragment SplatmapFragment
  115. #define _METALLICSPECGLOSSMAP 1
  116. #define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
  117. // -------------------------------------
  118. // Universal Pipeline keywords
  119. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  120. //#pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  121. //#pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
  122. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
  123. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  124. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  125. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  126. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  127. // -------------------------------------
  128. // Unity defined keywords
  129. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  130. #pragma multi_compile _ LIGHTMAP_ON
  131. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  132. #pragma multi_compile_fragment _ _GBUFFER_NORMALS_OCT
  133. #pragma multi_compile_fragment _ _RENDER_PASS_ENABLED
  134. //#pragma multi_compile_fog
  135. #pragma multi_compile_instancing
  136. #pragma instancing_options norenderinglayer assumeuniformscaling nomatrices nolightprobe nolightmap
  137. #pragma shader_feature_local _TERRAIN_BLEND_HEIGHT
  138. #pragma shader_feature_local _NORMALMAP
  139. #pragma shader_feature_local _MASKMAP
  140. // Sample normal in pixel shader when doing instancing
  141. #pragma shader_feature_local _TERRAIN_INSTANCED_PERPIXEL_NORMAL
  142. #define TERRAIN_GBUFFER 1
  143. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  144. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl"
  145. ENDHLSL
  146. }
  147. Pass
  148. {
  149. Name "DepthOnly"
  150. Tags{"LightMode" = "DepthOnly"}
  151. ZWrite On
  152. ColorMask 0
  153. HLSLPROGRAM
  154. #pragma target 2.0
  155. #pragma vertex DepthOnlyVertex
  156. #pragma fragment DepthOnlyFragment
  157. #pragma multi_compile_instancing
  158. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
  159. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  160. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl"
  161. ENDHLSL
  162. }
  163. // This pass is used when drawing to a _CameraNormalsTexture texture
  164. Pass
  165. {
  166. Name "DepthNormals"
  167. Tags{"LightMode" = "DepthNormals"}
  168. ZWrite On
  169. HLSLPROGRAM
  170. #pragma target 2.0
  171. #pragma vertex DepthNormalOnlyVertex
  172. #pragma fragment DepthNormalOnlyFragment
  173. #pragma shader_feature_local _NORMALMAP
  174. #pragma multi_compile_instancing
  175. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
  176. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  177. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitDepthNormalsPass.hlsl"
  178. ENDHLSL
  179. }
  180. Pass
  181. {
  182. Name "SceneSelectionPass"
  183. Tags { "LightMode" = "SceneSelectionPass" }
  184. HLSLPROGRAM
  185. #pragma target 2.0
  186. #pragma vertex DepthOnlyVertex
  187. #pragma fragment DepthOnlyFragment
  188. #pragma multi_compile_instancing
  189. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
  190. #define SCENESELECTIONPASS
  191. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  192. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitPasses.hlsl"
  193. ENDHLSL
  194. }
  195. // This pass it not used during regular rendering, only for lightmap baking.
  196. Pass
  197. {
  198. Name "Meta"
  199. Tags{"LightMode" = "Meta"}
  200. Cull Off
  201. HLSLPROGRAM
  202. #pragma vertex TerrainVertexMeta
  203. #pragma fragment TerrainFragmentMeta
  204. #pragma multi_compile_instancing
  205. #pragma instancing_options assumeuniformscaling nomatrices nolightprobe nolightmap
  206. #pragma shader_feature EDITOR_VISUALIZATION
  207. #define _METALLICSPECGLOSSMAP 1
  208. #define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
  209. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitInput.hlsl"
  210. #include "Packages/com.unity.render-pipelines.universal/Shaders/Terrain/TerrainLitMetaPass.hlsl"
  211. ENDHLSL
  212. }
  213. UsePass "Hidden/Nature/Terrain/Utilities/PICKING"
  214. }
  215. Dependency "AddPassShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Add Pass)"
  216. Dependency "BaseMapShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Base Pass)"
  217. Dependency "BaseMapGenShader" = "Hidden/Universal Render Pipeline/Terrain/Lit (Basemap Gen)"
  218. CustomEditor "UnityEditor.Rendering.Universal.TerrainLitShaderGUI"
  219. Fallback "Hidden/Universal Render Pipeline/FallbackError"
  220. }