[4] Tile Blending
11/20/2023, 11:48pm
One of the new features I worked on this year is Tile Blending. It's now possible to have smooth transitions between two different tile types, which is really nice for stuff like pathways and finer terrain details.
Each tile now has background, foreground, and mask layers. The mask layer determines how much influence the foreground and background has on the final texture of the tile. I generated the masks and arranged them into a blob tileset:
Then the terrain shader does some basic blending:
...
float3 backgroundUv;
backgroundUv.xy = uv.xy;
backgroundUv.z = IN.customColor.x;
fixed4 backgroundColor = UNITY_SAMPLE_TEX2DARRAY(_MainTexArray, backgroundUv);
float3 foregroundUv;
foregroundUv.xy = uv.xy;
foregroundUv.z = IN.customColor.y;
fixed4 foregroundColor = UNITY_SAMPLE_TEX2DARRAY(_MainTexArray, foregroundUv);
float3 maskUv;
maskUv.xy = uv.xy;
maskUv.z = IN.customColor.z; // Using custom vertex data for third set of UVs
fixed4 maskColor = UNITY_SAMPLE_TEX2DARRAY(_MaskTexArray, maskUv);
fixed4 c = lerp(backgroundColor, foregroundColor, maskColor.a) * _Color;
...
It's not perfect (There's probably more efficient ways to do this without 3 sets of UVs) but it's a good first step and a lot better than having sharp tile transitions everywhere.
You can paint tile masks manually, but the real star is the auto-blend option that decides which mask to use based on neighboring tiles of the same type:
Planning to make more improvements soon.
- Declan (@dooskington)