Lux URP Terrain BaseMapGen.shader 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. Shader "Hidden/Lux URP/Terrain/Lit (Basemap Gen)"
  2. {
  3. Properties
  4. {
  5. // Layer count is passed down to guide height-blend enable/disable, due
  6. // to the fact that heigh-based blend will be broken with multipass.
  7. [HideInInspector] [PerRendererData] _NumLayersCount ("Total Layer Count", Float) = 1.0
  8. [HideInInspector] _Control("AlphaMap", 2D) = "" {}
  9. [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
  10. [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
  11. [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
  12. [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
  13. [HideInInspector] _Mask3("Mask 3 (A)", 2D) = "grey" {}
  14. [HideInInspector] _Mask2("Mask 2 (B)", 2D) = "grey" {}
  15. [HideInInspector] _Mask1("Mask 1 (G)", 2D) = "grey" {}
  16. [HideInInspector] _Mask0("Mask 0 (R)", 2D) = "grey" {}
  17. [HideInInspector] [Gamma] _Metallic0 ("Metallic 0", Range(0.0, 1.0)) = 0.0
  18. [HideInInspector] [Gamma] _Metallic1 ("Metallic 1", Range(0.0, 1.0)) = 0.0
  19. [HideInInspector] [Gamma] _Metallic2 ("Metallic 2", Range(0.0, 1.0)) = 0.0
  20. [HideInInspector] [Gamma] _Metallic3 ("Metallic 3", Range(0.0, 1.0)) = 0.0
  21. [HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
  22. [HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
  23. [HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
  24. [HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0
  25. [NoScaleOffset] _HeightMaps (" Height Maps (RGBA)", 2D) = "grey" {}
  26. [HideInInspector] _DstBlend("DstBlend", Float) = 0.0
  27. }
  28. Subshader
  29. {
  30. HLSLINCLUDE
  31. // Required to compile gles 2.0 with standard srp library
  32. #pragma prefer_hlslcc gles
  33. #pragma exclude_renderers d3d11_9x
  34. #pragma target 3.0
  35. // #define _METALLICSPECGLOSSMAP 1
  36. #define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
  37. #define _TERRAIN_BASEMAP_GEN
  38. #pragma shader_feature_local _TERRAIN_BLEND_HEIGHT
  39. #pragma shader_feature_local _MASKMAP
  40. #include "Includes/TerrainLitInput.hlsl"
  41. #include "Includes/TerrainLitPasses.hlsl"
  42. ENDHLSL
  43. Pass
  44. {
  45. Tags
  46. {
  47. "Name" = "_MainTex"
  48. "Format" = "ARGB32"
  49. "Size" = "1"
  50. }
  51. ZTest Always Cull Off ZWrite Off
  52. Blend One [_DstBlend]
  53. HLSLPROGRAM
  54. #pragma vertex Vert
  55. #pragma fragment Frag
  56. Varyings Vert(Attributes IN)
  57. {
  58. Varyings output = (Varyings)0;
  59. output.clipPos = TransformWorldToHClip(IN.positionOS.xyz);
  60. output.uvMainAndLM.xy = IN.texcoord;
  61. output.uvSplat01.xy = TRANSFORM_TEX(IN.texcoord, _Splat0);
  62. output.uvSplat01.zw = TRANSFORM_TEX(IN.texcoord, _Splat1);
  63. output.uvSplat23.xy = TRANSFORM_TEX(IN.texcoord, _Splat2);
  64. output.uvSplat23.zw = TRANSFORM_TEX(IN.texcoord, _Splat3);
  65. return output;
  66. }
  67. half4 Frag(Varyings IN) : SV_Target
  68. {
  69. half3 normalTS = half3(0.0h, 0.0h, 1.0h);
  70. half4 splatControl;
  71. half weight;
  72. half4 mixedDiffuse = 0.0h;
  73. half4 defaultSmoothness = 0.0h;
  74. half4 masks[4];
  75. float2 splatUV = (IN.uvMainAndLM.xy * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy;
  76. splatControl = SAMPLE_TEXTURE2D(_Control, sampler_Control, splatUV);
  77. #ifdef _TERRAIN_BLEND_HEIGHT
  78. half4 heights;
  79. heights.x = SAMPLE_TEXTURE2D(_HeightMaps, sampler_Splat0, IN.uvSplat01.xy).r;
  80. heights.y = SAMPLE_TEXTURE2D(_HeightMaps, sampler_Splat0, IN.uvSplat01.zw).g;
  81. heights.z = SAMPLE_TEXTURE2D(_HeightMaps, sampler_Splat0, IN.uvSplat23.xy).b;
  82. heights.w = SAMPLE_TEXTURE2D(_HeightMaps, sampler_Splat0, IN.uvSplat23.zw).a;
  83. half height;
  84. HeightBasedSplatModifyCombined(splatControl, heights, height);
  85. #endif
  86. SplatmapMix(IN.uvMainAndLM, IN.uvSplat01, IN.uvSplat23, splatControl, weight, mixedDiffuse, defaultSmoothness, normalTS);
  87. half smoothness = dot(splatControl, defaultSmoothness);
  88. return half4(mixedDiffuse.rgb, smoothness);
  89. }
  90. ENDHLSL
  91. }
  92. // Not used, not tweaked...
  93. Pass
  94. {
  95. Tags
  96. {
  97. "Name" = "_MetallicTex"
  98. "Format" = "R8"
  99. "Size" = "1/4"
  100. "EmptyColor" = "FF000000"
  101. }
  102. ZTest Always Cull Off ZWrite Off
  103. Blend One [_DstBlend]
  104. HLSLPROGRAM
  105. #pragma vertex Vert
  106. #pragma fragment Frag
  107. Varyings Vert(Attributes IN)
  108. {
  109. Varyings output = (Varyings)0;
  110. output.clipPos = TransformWorldToHClip(IN.positionOS.xyz);
  111. // This is just like the other in that it is from TerrainLitPasses
  112. output.uvMainAndLM.xy = IN.texcoord;
  113. output.uvSplat01.xy = TRANSFORM_TEX(IN.texcoord, _Splat0);
  114. output.uvSplat01.zw = TRANSFORM_TEX(IN.texcoord, _Splat1);
  115. output.uvSplat23.xy = TRANSFORM_TEX(IN.texcoord, _Splat2);
  116. output.uvSplat23.zw = TRANSFORM_TEX(IN.texcoord, _Splat3);
  117. return output;
  118. }
  119. half4 Frag(Varyings IN) : SV_Target
  120. {
  121. half3 normalTS = half3(0.0h, 0.0h, 1.0h);
  122. half4 splatControl;
  123. half weight;
  124. half4 mixedDiffuse;
  125. half4 defaultSmoothness;
  126. half4 masks[4];
  127. float2 splatUV = (IN.uvMainAndLM.xy * (_Control_TexelSize.zw - 1.0f) + 0.5f) * _Control_TexelSize.xy;
  128. splatControl = SAMPLE_TEXTURE2D(_Control, sampler_Control, splatUV);
  129. SplatmapMix(IN.uvMainAndLM, IN.uvSplat01, IN.uvSplat23, splatControl, weight, mixedDiffuse, defaultSmoothness, normalTS);
  130. half4 defaultMetallic = half4(_Metallic0, _Metallic1, _Metallic2, _Metallic3);
  131. half metallic = dot(splatControl, defaultMetallic);
  132. return metallic;
  133. }
  134. ENDHLSL
  135. }
  136. }
  137. }