| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373 |
- //NOTE! This file is based on Unity file "TerrainLitBasemapGen.shader" which was used as a template for adding all the InTerra features.
- Shader "Hidden/InTerra/Lit (Basemap Gen)"
- {
- Properties
- {
- // Layer count is passed down to guide height-blend enable/disable, due
- // to the fact that heigh-based blend will be broken with multipass.
- [HideInInspector] [PerRendererData] _NumLayersCount ("Total Layer Count", Float) = 1.0
- [HideInInspector] _Control("AlphaMap", 2D) = "" {}
- [HideInInspector] _Splat0 ("Layer 0 (R)", 2D) = "white" {}
- [HideInInspector] _Splat1 ("Layer 1 (G)", 2D) = "white" {}
- [HideInInspector] _Splat2 ("Layer 2 (B)", 2D) = "white" {}
- [HideInInspector] _Splat3 ("Layer 3 (A)", 2D) = "white" {}
- [HideInInspector] _Mask3("Mask 3 (A)", 2D) = "grey" {}
- [HideInInspector] _Mask2("Mask 2 (B)", 2D) = "grey" {}
- [HideInInspector] _Mask1("Mask 1 (G)", 2D) = "grey" {}
- [HideInInspector] _Mask0("Mask 0 (R)", 2D) = "grey" {}
- [HideInInspector] [Gamma] _Metallic0 ("Metallic 0", Range(0.0, 1.0)) = 0.0
- [HideInInspector] [Gamma] _Metallic1 ("Metallic 1", Range(0.0, 1.0)) = 0.0
- [HideInInspector] [Gamma] _Metallic2 ("Metallic 2", Range(0.0, 1.0)) = 0.0
- [HideInInspector] [Gamma] _Metallic3 ("Metallic 3", Range(0.0, 1.0)) = 0.0
- [HideInInspector] _Smoothness0 ("Smoothness 0", Range(0.0, 1.0)) = 1.0
- [HideInInspector] _Smoothness1 ("Smoothness 1", Range(0.0, 1.0)) = 1.0
- [HideInInspector] _Smoothness2 ("Smoothness 2", Range(0.0, 1.0)) = 1.0
- [HideInInspector] _Smoothness3 ("Smoothness 3", Range(0.0, 1.0)) = 1.0
- [HideInInspector] _DstBlend("DstBlend", Float) = 0.0
- }
- Subshader
- {
- HLSLINCLUDE
- #pragma target 3.0
- #define _METALLICSPECGLOSSMAP 1
- #define _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A 1
- #define _TERRAIN_BASEMAP_GEN
- #pragma shader_feature_local _MASKMAP
- #pragma shader_feature_local __ _TERRAIN_TRIPLANAR_ONE _TERRAIN_TRIPLANAR
- #pragma shader_feature_local _TERRAIN_DISTANCEBLEND
- #pragma shader_feature_local __ _LAYERS_TWO _LAYERS_EIGHT
- #include "InTerra_URP_DefinedGlobalKeywords.hlsl"
- #define INTERRA_TERRAIN
- #if defined(_TERRAIN_TRIPLANAR) || defined(_TERRAIN_TRIPLANAR_ONE)
- #ifdef _TERRAIN_TRIPLANAR_ONE
- #define TRIPLANAR_TINT
- #endif
- #undef _TERRAIN_TRIPLANAR
- #undef _TERRAIN_TRIPLANAR_ONE
- #endif
- #include "InTerra_TerrainLitInput.hlsl"
- #include "InTerra_TerrainLitPasses.hlsl"
- ENDHLSL
- PackageRequirements { "com.unity.render-pipelines.universal":"[12.1,19.0]" }
- //Tags {"RenderPipeline" = "UniversalRenderPipeline" }
- Pass
- {
- Tags
- {
- "Name" = "_MainTex"
- "Format" = "ARGB32"
- "Size" = "1"
- }
- ZTest Always Cull Off ZWrite Off
- Blend One [_DstBlend]
- HLSLPROGRAM
- #pragma vertex Vert
- #pragma fragment Frag
- Varyings Vert(Attributes IN)
- {
- Varyings output = (Varyings) 0;
- output.clipPos = TransformWorldToHClip(IN.positionOS.xyz);
- // NOTE : This is basically coming from the vertex shader in TerrainLitPasses
- // There are other plenty of other values that the original version computes, but for this
- // pass, we are only interested in a few, so I'm just skipping the rest.
- output.uvMainAndLM.xy = IN.texcoord;
- output.uvSplat01.xy = TRANSFORM_TEX(IN.texcoord, _Splat0);
- output.uvSplat01.zw = TRANSFORM_TEX(IN.texcoord, _Splat1);
- #ifndef _LAYERS_TWO
- output.uvSplat23.xy = TRANSFORM_TEX(IN.texcoord, _Splat2);
- output.uvSplat23.zw = TRANSFORM_TEX(IN.texcoord, _Splat3);
- #ifdef _LAYERS_EIGHT
- output.uvSplat45.xy = TRANSFORM_TEX(IN.texcoord, _Splat4);
- output.uvSplat45.zw = TRANSFORM_TEX(IN.texcoord, _Splat5);
- output.uvSplat67.xy = TRANSFORM_TEX(IN.texcoord, _Splat6);
- output.uvSplat67.zw = TRANSFORM_TEX(IN.texcoord, _Splat7);
- #endif
- #endif
- return output;
- }
- half4 Frag(Varyings IN) : SV_Target
- {
- half3 normalTS = half3(0.0h, 0.0h, 1.0h);
- half4 splatControl;
- half weight;
- half4 mixedDiffuse = 0.0h;
- half metallic;
- half occlusion;
- half smoothness;
- float2 uv[_LAYER_COUNT];
- float4 inUV[_LAYER_COUNT/2];
- inUV[0] = IN.uvSplat01;
- #ifndef _LAYERS_TWO
- inUV[1] = IN.uvSplat23;
- #ifdef _LAYERS_EIGHT
- inUV[2] = IN.uvSplat45;
- inUV[3] = IN.uvSplat67;
- #endif
- #endif
- uvArray(uv, inUV);
- SplatmapMix(IN.uvMainAndLM, uv, float3(0, 0, 0), float3(0, 0, 0), IN.positionWS, weight, mixedDiffuse, smoothness, metallic, occlusion, normalTS);
- return half4(mixedDiffuse.rgb, smoothness);
- }
- ENDHLSL
- }
- Pass
- {
- Tags
- {
- "Name" = "_MetallicTex"
- "Format" = "RGBA32"
- "Size" = "1/4"
- "EmptyColor" = "FF000000"
- }
- ZTest Always Cull Off ZWrite Off
- Blend One [_DstBlend]
- HLSLPROGRAM
- #pragma vertex Vert
- #pragma fragment Frag
- Varyings Vert(Attributes IN)
- {
- Varyings output = (Varyings)0;
- output.clipPos = TransformWorldToHClip(IN.positionOS.xyz);
- // This is just like the other in that it is from TerrainLitPasses
- output.uvMainAndLM.xy = IN.texcoord;
- output.uvSplat01.xy = TRANSFORM_TEX(IN.texcoord, _Splat0);
- output.uvSplat01.zw = TRANSFORM_TEX(IN.texcoord, _Splat1);
- #ifndef _LAYERS_TWO
- output.uvSplat23.xy = TRANSFORM_TEX(IN.texcoord, _Splat2);
- output.uvSplat23.zw = TRANSFORM_TEX(IN.texcoord, _Splat3);
- #ifdef _LAYERS_EIGHT
- output.uvSplat45.xy = TRANSFORM_TEX(IN.texcoord, _Splat4);
- output.uvSplat45.zw = TRANSFORM_TEX(IN.texcoord, _Splat5);
- output.uvSplat67.xy = TRANSFORM_TEX(IN.texcoord, _Splat6);
- output.uvSplat67.zw = TRANSFORM_TEX(IN.texcoord, _Splat7);
- #endif
- #endif
- return output;
- }
- half4 Frag(Varyings IN) : SV_Target
- {
- half3 normalTS = half3(0.0h, 0.0h, 1.0h);
- half4 splatControl;
- half weight;
- half4 mixedDiffuse;
- half4 defaultSmoothness;
- half4 masks[4];
- half metallic;
- half occlusion;
- half smoothness;
- float2 uv[_LAYER_COUNT];
- float4 inUV[_LAYER_COUNT/2];
- inUV[0] = IN.uvSplat01;
- #ifndef _LAYERS_TWO
- inUV[1] = IN.uvSplat23;
- #ifdef _LAYERS_EIGHT
- inUV[2] = IN.uvSplat45;
- inUV[3] = IN.uvSplat67;
- #endif
- #endif
- uvArray(uv, inUV);
- SplatmapMix(IN.uvMainAndLM, uv, float3(0, 0, 0), float3(0, 0, 0), IN.positionWS, weight, mixedDiffuse, smoothness, metallic, occlusion, normalTS);
- return float4(metallic, occlusion, splatControl.r, SAMPLE_TEXTURE2D(_Splat0, sampler_Splat0, uv[0]).r * 1e-5f);
- }
- ENDHLSL
- }
- Pass
- {
- Tags
- {
- "Name" = "_TriplanarTex"
- "Format" = "ARGB32"
- "Size" = "1"
- }
- ZTest Always Cull Off ZWrite Off
- Blend One [_DstBlend]
- HLSLPROGRAM
- #pragma vertex Vert
- #pragma fragment Frag
- #define _TERRAIN_BASEMAP_GEN_TRIPLANAR
- Varyings Vert(Attributes IN)
- {
- Varyings output = (Varyings)0;
- output.clipPos = TransformWorldToHClip(IN.positionOS.xyz);
- // This is just like the other in that it is from TerrainLitPasses
- output.uvMainAndLM.xy = IN.texcoord;
- output.uvSplat01.xy = TRANSFORM_TEX(IN.texcoord, _Splat0);
- return output;
- }
- half4 Frag(Varyings IN) : SV_Target
- {
- half3 normalTS = half3(0.0h, 0.0h, 1.0h);
- half4 splatControl = float4(1, 0, 0, 0);
- half weight;
- half4 mixedDiffuse;
- half4 defaultSmoothness;
- half metallic;
- half occlusion;
- half smoothness;
- float2 uv[_LAYER_COUNT];
- half4 albedo[_LAYER_COUNT];
- float4 mask[_LAYER_COUNT];
- float4 inUV[_LAYER_COUNT/2];
- inUV[0] = IN.uvSplat01;
- #ifndef _LAYERS_TWO
- inUV[1] = IN.uvSplat23;
- #ifdef _LAYERS_EIGHT
- inUV[2] = IN.uvSplat45;
- inUV[3] = IN.uvSplat67;
- #endif
- #endif
- uvArray(uv, inUV);
- SplatmapMix(IN.uvMainAndLM, uv, float3(0, 0, 0), float3(0, 0, 0), IN.positionWS, weight, mixedDiffuse, smoothness, metallic, occlusion, normalTS);
- #ifdef _TERRAIN_DISTANCEBLEND
- uv[0] *= (_DiffuseRemapOffset0.r + 1) * _HT_distance_scale;
- #endif
- mask[0] = Mask(0);
- mask[0] = RemapMask(0);
- mask[0] *= weight;
- albedo[0] = SAMPLE_TEXTURE2D(_Splat0, sampler_Splat0, uv[0]) * weight;
- albedo[0].rgb *= DiffuseRemap(0).xyz;
- albedo[0].a = Smoothness(0).x;
- return half4(albedo[0].rgb, albedo[0].a);
- }
- ENDHLSL
- }
- Pass
- {
- Tags
- {
- "Name" = "_Triplanar_MetallicAO"
- "Format" = "RGBA32"
- "Size" = "1/4"
- }
-
- ZTest Always Cull Off ZWrite Off
- Blend One [_DstBlend]
- HLSLPROGRAM
- #pragma vertex Vert
- #pragma fragment Frag
- #define _TERRAIN_BASEMAP_GEN_TRIPLANAR
- Varyings Vert(Attributes IN)
- {
- Varyings output = (Varyings)0;
- output.clipPos = TransformWorldToHClip(IN.positionOS.xyz);
- // This is just like the other in that it is from TerrainLitPasses
- output.uvMainAndLM.xy = IN.texcoord;
- output.uvSplat01.xy = TRANSFORM_TEX(IN.texcoord, _Splat0);
- return output;
- }
- half4 Frag(Varyings IN) : SV_Target
- {
- half3 normalTS = half3(0.0h, 0.0h, 1.0h);
- half4 splatControl = float4(1, 0, 0, 0);
- half weight;
- half4 mixedDiffuse;
- half4 defaultSmoothness;
- half metallic;
- half occlusion;
- half smoothness;
- float2 uv[_LAYER_COUNT];
- float4 mask[_LAYER_COUNT];
- float4 inUV[_LAYER_COUNT/2];
- inUV[0] = IN.uvSplat01;
- #ifndef _LAYERS_TWO
- inUV[1] = IN.uvSplat23;
- #ifdef _LAYERS_EIGHT
- inUV[2] = IN.uvSplat45;
- inUV[3] = IN.uvSplat67;
- #endif
- #endif
- uvArray(uv, inUV);
- SplatmapMix(IN.uvMainAndLM, uv, float3(0, 0, 0), float3(0, 0, 0), IN.positionWS, weight, mixedDiffuse, smoothness, metallic, occlusion, normalTS);
- mask[0] = Mask(0);
- mask[0] = RemapMask(0);
-
- mask[0] *= weight;
- #ifdef _TERRAIN_NORMAL_IN_MASK
- occlusion = mask[0].r;
- #else
- occlusion = mask[0].g;
- #endif
-
- #ifndef _TERRAIN_MASK_MAPS
- metallic = _Metallic0;
- #else
- metallic = mask[0].r;
- #endif
- return float4(metallic, occlusion, 0, SAMPLE_TEXTURE2D(_Splat0, sampler_Splat0, uv[0]).r * 1e-5f);
- }
- ENDHLSL
- }
- }
- }
|