Advertisement
Guest User

Untitled

a guest
Jan 6th, 2021
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. Shader "Unlit/Terrain"
  2. {
  3. Properties
  4. {
  5. _TexArray("Texture Array", 2DArray) = "" {}
  6. _TexScale("Texture Scale", Float) = 1
  7. }
  8. SubShader
  9. {
  10. Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"}
  11. LOD 300
  12.  
  13. Pass
  14. {
  15. Tags {"LightMode" = "UniversalForward"}
  16.  
  17. ZWrite On
  18. Cull Back
  19.  
  20. HLSLPROGRAM
  21. #pragma prefer_hlslcc gles
  22. #pragma exclude_renderers d3d11_9x
  23. #pragma target 4.0
  24.  
  25. #pragma shader_feature _RECEIVE_SHADOWS_ON
  26.  
  27. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
  28. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
  29. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  30. #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
  31. #pragma multi_compile _ _SHADOWS_SOFT
  32. #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
  33.  
  34. #pragma vertex vert
  35. #pragma fragment frag
  36.  
  37. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  38.  
  39. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  40.  
  41. #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
  42.  
  43. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  44.  
  45. struct Attributes
  46. {
  47. float4 positionOS : POSITION;
  48. float3 normalOS : NORMAL;
  49. float4 tangentOS : TANGENT;
  50. float2 uv : TEXCOORD0;
  51. float4 color : COLOR;
  52. };
  53.  
  54. struct Varyings
  55. {
  56. float3 normalOS : NORMAL;
  57. half3 normalWS : TEXCOORD3;
  58.  
  59. float2 uv : TEXCOORD4;
  60. float4 color : COLOR;
  61.  
  62. #ifdef _MAIN_LIGHT_SHADOWS
  63. float4 shadowCoord : TEXCOORD6;
  64. #endif
  65.  
  66. float4 positionCS : SV_POSITION;
  67. float4 positionWS : TEXCOORD2;
  68. float4 positionOS : TEXCOORD5;
  69. };
  70.  
  71. float _TexScale;
  72.  
  73. TEXTURE2D_ARRAY(_TexArray);
  74. SAMPLER(sampler_TexArray);
  75.  
  76. Varyings vert(Attributes input)
  77. {
  78. Varyings output;
  79.  
  80. output.color = input.color * 255;
  81. output.uv = input.uv.xy;
  82.  
  83. VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
  84. VertexNormalInputs vertexNormalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
  85.  
  86. output.positionWS = float4(vertexInput.positionWS, 1);
  87. output.positionCS = vertexInput.positionCS;
  88. output.positionOS = input.positionOS;
  89.  
  90. output.normalWS = vertexNormalInput.normalWS;
  91.  
  92. #ifdef _MAIN_LIGHT_SHADOWS
  93. output.shadowCoord = GetShadowCoord(vertexInput);
  94. #endif
  95.  
  96. return output;
  97. }
  98.  
  99. half4 frag(Varyings input) : SV_Target
  100. {
  101. int index = ((int)floor(input.uv.x) & 1) | (((int)floor(input.uv.y) & 1) << 1) | (((int)floor(input.color.r) & 1) << 2);
  102.  
  103. float3 scaledWorldPos = input.positionWS / _TexScale;
  104.  
  105. float3 pWeight = abs(normalize(input.normalWS));
  106. pWeight /= pWeight.x + pWeight.y + pWeight.z;
  107.  
  108. float3 xP = SAMPLE_TEXTURE2D_ARRAY(_TexArray, sampler_TexArray, float2(scaledWorldPos.y, scaledWorldPos.z), index) * pWeight.x;
  109.  
  110. float3 yP = SAMPLE_TEXTURE2D_ARRAY(_TexArray, sampler_TexArray, float2(scaledWorldPos.x, scaledWorldPos.z), index) * pWeight.y;
  111.  
  112. float3 zP = SAMPLE_TEXTURE2D_ARRAY(_TexArray, sampler_TexArray, float2(scaledWorldPos.x, scaledWorldPos.y), index) * pWeight.z;
  113.  
  114. float3 col = xP + yP + zP;
  115.  
  116. return half4(col.x, col.y, col.z, 1);
  117. }
  118. ENDHLSL
  119. }
  120.  
  121. UsePass "Universal Render Pipeline/Lit/ShadowCaster"
  122.  
  123. UsePass "Universal Render Pipeline/Lit/DepthOnly"
  124. }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement