TerrainDetailLit.shader 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. Shader "Hidden/TerrainEngine/Details/UniversalPipeline/Vertexlit"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Main Texture", 2D) = "white" { }
  6. }
  7. SubShader
  8. {
  9. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"}
  10. LOD 100
  11. ZWrite On
  12. // Lightmapped
  13. Pass
  14. {
  15. Name "TerrainDetailVertex"
  16. HLSLPROGRAM
  17. // Required to compile gles 2.0 with standard srp library
  18. #pragma prefer_hlslcc gles
  19. #pragma exclude_renderers d3d11_9x
  20. #pragma target 2.0
  21. #pragma vertex Vert
  22. #pragma fragment Frag
  23. // -------------------------------------
  24. // Universal Pipeline keywords
  25. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  26. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  27. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  28. #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
  29. #pragma multi_compile _ _SHADOWS_SOFT
  30. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  31. // -------------------------------------
  32. // Unity defined keywords
  33. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  34. #pragma multi_compile _ LIGHTMAP_ON
  35. #pragma multi_compile_fog
  36. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  37. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  38. TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex);
  39. float4 _MainTex_ST;
  40. struct Attributes
  41. {
  42. float4 PositionOS : POSITION;
  43. float2 UV0 : TEXCOORD0;
  44. float2 UV1 : TEXCOORD1;
  45. float3 NormalOS : NORMAL;
  46. half4 Color : COLOR;
  47. UNITY_VERTEX_INPUT_INSTANCE_ID
  48. };
  49. struct Varyings
  50. {
  51. float2 UV01 : TEXCOORD0; // UV0
  52. float2 LightmapUV : TEXCOORD1; // Lightmap UVs
  53. half4 Color : TEXCOORD2; // Vertex Color
  54. half4 LightingFog : TEXCOORD3; // Vetex Lighting, Fog Factor
  55. #if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  56. float4 ShadowCoords : TEXCOORD4; // Shadow UVs
  57. #endif
  58. float4 PositionCS : SV_POSITION; // Clip Position
  59. UNITY_VERTEX_OUTPUT_STEREO
  60. };
  61. Varyings Vert(Attributes input)
  62. {
  63. Varyings output = (Varyings)0;
  64. UNITY_SETUP_INSTANCE_ID(input);
  65. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);
  66. // Vertex attributes
  67. output.UV01 = TRANSFORM_TEX(input.UV0, _MainTex);
  68. output.LightmapUV = input.UV1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  69. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.PositionOS.xyz);
  70. output.Color = input.Color;
  71. output.PositionCS = vertexInput.positionCS;
  72. // Shadow Coords
  73. #if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  74. output.ShadowCoords = GetShadowCoord(vertexInput);
  75. #endif
  76. // Vertex Lighting
  77. half3 NormalWS = input.NormalOS;
  78. Light mainLight = GetMainLight();
  79. half3 attenuatedLightColor = mainLight.color * mainLight.distanceAttenuation;
  80. half3 diffuseColor = LightingLambert(attenuatedLightColor, mainLight.direction, NormalWS);
  81. #ifdef _ADDITIONAL_LIGHTS
  82. int pixelLightCount = GetAdditionalLightsCount();
  83. for (int i = 0; i < pixelLightCount; ++i)
  84. {
  85. Light light = GetAdditionalLight(i, vertexInput.positionWS);
  86. half3 attenuatedLightColor = light.color * light.distanceAttenuation;
  87. diffuseColor += LightingLambert(attenuatedLightColor, light.direction, NormalWS);
  88. }
  89. #endif
  90. output.LightingFog.xyz = diffuseColor;
  91. // Fog factor
  92. output.LightingFog.w = ComputeFogFactor(output.PositionCS.z);
  93. return output;
  94. }
  95. half4 Frag(Varyings input) : SV_Target
  96. {
  97. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(input);
  98. half3 bakedGI = SampleLightmap(input.LightmapUV, half3(0.0, 1.0, 0.0));
  99. #if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
  100. half3 lighting = input.LightingFog.rgb * MainLightRealtimeShadow(input.ShadowCoords) + bakedGI;
  101. #else
  102. half3 lighting = input.LightingFog.rgb + bakedGI;
  103. #endif
  104. half4 tex = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.UV01);
  105. half4 color = 1.0;
  106. color.rgb = input.Color.rgb * tex.rgb * lighting;
  107. color.rgb = MixFog(color.rgb, input.LightingFog.w);
  108. return color;
  109. }
  110. ENDHLSL
  111. }
  112. Pass
  113. {
  114. Name "Depth"
  115. Tags{"LightMode" = "DepthOnly"}
  116. ZWrite On
  117. ColorMask 0
  118. HLSLPROGRAM
  119. // Required to compile gles 2.0 with standard srp library
  120. #pragma prefer_hlslcc gles
  121. #pragma exclude_renderers d3d11_9x
  122. #pragma target 2.0
  123. #pragma vertex DepthOnlyVertex
  124. #pragma fragment DepthOnlyFragment
  125. //--------------------------------------
  126. // GPU Instancing
  127. #pragma multi_compile_instancing
  128. #include "Packages/com.unity.render-pipelines.universal/Shaders/UnlitInput.hlsl"
  129. #include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
  130. ENDHLSL
  131. }
  132. Pass
  133. {
  134. Name "Meta"
  135. Tags{ "LightMode" = "Meta" }
  136. Cull Off
  137. HLSLPROGRAM
  138. // Required to compile gles 2.0 with standard srp library
  139. #pragma prefer_hlslcc gles
  140. #pragma exclude_renderers d3d11_9x
  141. #pragma vertex UniversalVertexMeta
  142. #pragma fragment UniversalFragmentMetaSimple
  143. #pragma shader_feature _SPECGLOSSMAP
  144. #include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitInput.hlsl"
  145. #include "Packages/com.unity.render-pipelines.universal/Shaders/SimpleLitMetaPass.hlsl"
  146. ENDHLSL
  147. }
  148. }
  149. //Fallback "VertexLit"
  150. }