Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Shader "Unlit/Terrain"
- {
- Properties
- {
- _TexArray("Texture Array", 2DArray) = "" {}
- _TexScale("Texture Scale", Float) = 1
- }
- SubShader
- {
- Tags { "RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline" "IgnoreProjector" = "True"}
- LOD 300
- Pass
- {
- Tags {"LightMode" = "UniversalForward"}
- ZWrite On
- Cull Back
- HLSLPROGRAM
- #pragma prefer_hlslcc gles
- #pragma exclude_renderers d3d11_9x
- #pragma target 4.0
- #pragma shader_feature _RECEIVE_SHADOWS_ON
- #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
- #pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
- #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
- #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
- #pragma multi_compile _ _SHADOWS_SOFT
- #pragma multi_compile _ _MIXED_LIGHTING_SUBTRACTIVE
- #pragma vertex vert
- #pragma fragment frag
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/Shaders/LitInput.hlsl"
- #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
- struct Attributes
- {
- float4 positionOS : POSITION;
- float3 normalOS : NORMAL;
- float4 tangentOS : TANGENT;
- float2 uv : TEXCOORD0;
- float4 color : COLOR;
- };
- struct Varyings
- {
- float3 normalOS : NORMAL;
- half3 normalWS : TEXCOORD3;
- float2 uv : TEXCOORD4;
- float4 color : COLOR;
- #ifdef _MAIN_LIGHT_SHADOWS
- float4 shadowCoord : TEXCOORD6;
- #endif
- float4 positionCS : SV_POSITION;
- float4 positionWS : TEXCOORD2;
- float4 positionOS : TEXCOORD5;
- };
- float _TexScale;
- TEXTURE2D_ARRAY(_TexArray);
- SAMPLER(sampler_TexArray);
- Varyings vert(Attributes input)
- {
- Varyings output;
- output.color = input.color * 255;
- output.uv = input.uv.xy;
- VertexPositionInputs vertexInput = GetVertexPositionInputs(input.positionOS.xyz);
- VertexNormalInputs vertexNormalInput = GetVertexNormalInputs(input.normalOS, input.tangentOS);
- output.positionWS = float4(vertexInput.positionWS, 1);
- output.positionCS = vertexInput.positionCS;
- output.positionOS = input.positionOS;
- output.normalWS = vertexNormalInput.normalWS;
- #ifdef _MAIN_LIGHT_SHADOWS
- output.shadowCoord = GetShadowCoord(vertexInput);
- #endif
- return output;
- }
- half4 frag(Varyings input) : SV_Target
- {
- int index = ((int)floor(input.uv.x) & 1) | (((int)floor(input.uv.y) & 1) << 1) | (((int)floor(input.color.r) & 1) << 2);
- float3 scaledWorldPos = input.positionWS / _TexScale;
- float3 pWeight = abs(normalize(input.normalWS));
- pWeight /= pWeight.x + pWeight.y + pWeight.z;
- float3 xP = SAMPLE_TEXTURE2D_ARRAY(_TexArray, sampler_TexArray, float2(scaledWorldPos.y, scaledWorldPos.z), index) * pWeight.x;
- float3 yP = SAMPLE_TEXTURE2D_ARRAY(_TexArray, sampler_TexArray, float2(scaledWorldPos.x, scaledWorldPos.z), index) * pWeight.y;
- float3 zP = SAMPLE_TEXTURE2D_ARRAY(_TexArray, sampler_TexArray, float2(scaledWorldPos.x, scaledWorldPos.y), index) * pWeight.z;
- float3 col = xP + yP + zP;
- return half4(col.x, col.y, col.z, 1);
- }
- ENDHLSL
- }
- UsePass "Universal Render Pipeline/Lit/ShadowCaster"
- UsePass "Universal Render Pipeline/Lit/DepthOnly"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement