- Home /
Splat Map with transition texture?
Hi! I have been following catlikecoding's tutorial on this terrain editor and i need help figuring out how or where i would add a texture to the shader in order to transition from one texture to the other. At the moment it just lerps between the two textures which looks not like the style i am going for.
This is how it looks right now
This is the result of that transition texture i'd like to implement where the texture blends a bit more uneven, likely achieved through an extra noise texture? (picture from endless legend)
this is the code i have from catlikecoding
Shader "Custom/TerrainShader"
{
Properties {
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Terrain Texture Array", 2DArray) = "white" {} //add our epic 2D texture arrays
_GridTex ("Grid Texture", 2D) = "white" {}
_BumpMap ("Normal Map", 2D) = "bump" {}
_NormalScalar ("Normal Scalar", Range(0,100)) = 0.01
_NormalWeight ("Normal Weight", Range(0,5)) = 1
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Specular ("Specular", Color) = (0.2, 0.2, 0.2)
_BackgroundColor ("Background Color", Color) = (0,0,0) //color unexplored areas will be tinted to
[Toggle(SHOW_MAP_DATA)] _ShowMapData ("Show Map Data", Float) = 0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf StandardSpecular fullforwardshadows vertex:vert
#pragma target 3.5
#pragma multi_compile _ GRID_ON
#pragma multi_compile _ HEX_MAP_EDIT_MODE
#pragma shader_feature SHOW_MAP_DATA
#include "HexMetrics.cginc"
#include "HexCellData.cginc"
UNITY_DECLARE_TEX2DARRAY(_MainTex);
struct Input {
float4 color : COLOR;
float3 worldPos;
float3 terrain;
float4 visibility; //float 4 instead of 3 to accomodate exploration state as well
#if defined(SHOW_MAP_DATA)
float mapData;
#endif
};
void vert (inout appdata_full v, out Input data) {
UNITY_INITIALIZE_OUTPUT(Input, data);
//data.terrain = v.texcoord2.xyz;
float4 cell0 = GetCellData(v, 0);
float4 cell1 = GetCellData(v, 1);
float4 cell2 = GetCellData(v, 2);
data.terrain.x = cell0.w; //terrain type stored in last component w
data.terrain.y = cell1.w;
data.terrain.z = cell2.w;
data.visibility.x = cell0.x; //cell visibilty stored in first component x
data.visibility.y = cell1.x;
data.visibility.z = cell2.x;
data.visibility.xyz = lerp(0.25, 1, data.visibility.xyz); //make it not fully dark
data.visibility.w = cell0.y * v.color.x + cell1.y * v.color.y + cell2.y * v.color.z; //exploration state
#if defined(SHOW_MAP_DATA)
data.mapData = cell0.z * v.color.x + cell1.z * v.color.y + cell2.z * v.color.z;
#endif
}
half _Glossiness;
fixed3 _Specular;
fixed4 _Color;
sampler2D _GridTex;
half3 _BackgroundColor;
sampler2D _BumpMap;
fixed _NormalScalar;
fixed _NormalWeight;
//make texture coordinates, sample array, modulate sample with splat map
float4 GetTerrainColor (Input IN, int index) {
float3 uvw = float3(IN.worldPos.xz * (2 * TILING_SCALE), IN.terrain[index]); //coord scaled down so texture doesnt tile too often
float4 c = UNITY_SAMPLE_TEX2DARRAY(_MainTex, uvw);
return c * (IN.color[index] * IN.visibility[index]); //color can be treated as array as it represents 0 = r, 1 = g, etc
}
void surf (Input IN, inout SurfaceOutputStandardSpecular o) {
fixed4 c =
//last coordinate is texarray index
GetTerrainColor(IN, 0) +
GetTerrainColor(IN, 1) +
GetTerrainColor(IN, 2);
fixed4 grid = 1;
#if defined(GRID_ON)
//the whole 5sqrt3, 20sqrt3 hexagon thing to calculate grid tex size correctly
float2 gridUV = IN.worldPos.xz;
gridUV.x *= 1 / (4 * 8.66025404); //inner radius of cells four times in order to move two cells to right
gridUV.y *= 1 / (2 * 15.0); //frwd dist between cell centers is 15
grid = tex2D (_GridTex, gridUV); //gridUV insteadof IN.worldPos.xz
#endif
float explored = IN.visibility.w;
o.Albedo = c.rgb * grid * _Color * explored;
#if defined(SHOW_MAP_DATA)
o.Albedo = IN.mapData * grid;
#endif
o.Specular = _Specular * explored;
o.Smoothness = _Glossiness;
o.Occlusion = explored; //without this the surface specular has a fresnel effect which we dont want
o.Emission = _BackgroundColor * (1 - explored);
o.Alpha = c.a;
//really ugly add
o.Normal = UnpackScaleNormal(tex2D(_BumpMap, _NormalScalar * IN.worldPos.xz), _NormalWeight);
}
ENDCG
}
FallBack "Diffuse"
}
hu.png
(326.5 kB)
original.jpg
(117.8 kB)
Comment