- #UNITY TERRAIN SPLATMAP TEXTURE EDGE BLENDING HOW TO#
- #UNITY TERRAIN SPLATMAP TEXTURE EDGE BLENDING DOWNLOAD#
The easiest way to create the above in Unity is to set up a textured quad facing the camera, then use tPixel() to build a texture according to the numbers you get out of your linear interpolation functions given above. You can see here how the final result comes out between (grid-aligned) world tiles / chunks, with the 2D / bilerped example above, being the middle tile between 4 pure colour tiles: (You can see that bilinear interpolation specifically operates on quads.) Next, try to Lerp() in 2D, also known as bilerp() to create an interpolation on a quadrilateral with 4 colours, one at each of the corners of the quad: (expanded vertically so you can see it more clearly) Once you're on the right track, you can figure things out from there.įirst, try to recreate the below image using Mathf.Lerp(), to create a controlled 1D interpolation between two adjacent colours: If you’re having any problems implementing these into a specific shader or would like to know any more information, just let me know in the comments.Let's start with some basics: in this case linear interpolation (and its limitations), using pure colours. The cginc file is all you need to implement custom height-blending and height-lerping into any of your projects. Currently this doesn’t include any of the textures used in this post – if I manage to find any I’m sure can be redistributed legally I’ll add them to the archive.ĭownload “Heightblending - Shader Include” heightblend.cginc_.zip – Downloaded 2203 times – 5 KB The following package includes this cginc file and the 3 example shaders used for this post, with a few added improvements. The float4 versions also includes alpha weighted versions of the float4 methods. This file also includes heightlerp functions for each of these, although of course lerp only applies to the 2 way versions. I’ve prepared a cginc include file which includes 2 way, 3 way and 4 way versions of heightblend for float, float2, float3 and float4 data. If I was actually using this scene I would probably increase the heightblend factor somewhat to soften the transitions, but it serves as a clear example of the differences. Example Scene Example scene using heightblending terrain shader Ground closeup with default terrain shader Ground closeup with heightblended terrain shader I will likely cover this in a future post. It can also be used in other creative ways, such as a snow shader – by factoring the y value into the height on one side, and reducing the other height by snow depth, a much more realistic snow cover effect can be achieved. If you want to add further maps such as normals, or PBR data that is also done using the same heightlerp function. You can combine multiple sets of lerp together to blend multiple textures as required. Much better! That is in essence the complete effect. Albedo = heightlerp ( v1, h1, v2, h2, t ) This interpolates from a left value to a right value, based on a control value. The simplest way to achieve this is using the lerp function. The final result should transition from sand on the left to rock on the right. I’ll probably review all the individual products at some point, but in short – it’s brilliant.įor these examples we’ll simply use a default plane with the UV X coordinate used to control the blending. I signed up for the Indie Substance Live pay-to-own package about a year ago and never looked back. Materials used were all acquired from Substance Source. Secondly the sand is low and flat, and the rocks are tall and pointy, which should ensure a clear blend when the height factor comes into play. The most obvious reason is that large difference in the brightness of the two images will make the interpolation very obvious. I’ll use the following two textures for this example, for a couple of reasons.
#UNITY TERRAIN SPLATMAP TEXTURE EDGE BLENDING DOWNLOAD#
There’s a cginc to download at the end so you can quickly and easily implement these effects into your own shaders.
#UNITY TERRAIN SPLATMAP TEXTURE EDGE BLENDING HOW TO#
In this post we’ll be looking at how to implement texture blending, starting with a basic linear blend and ending up with a fancy height-blended approach. A rarer example is an effect where the blending is controlled by world position, or even procedural noise.Įverything here is written using C# or HLSL/Cg in Unity, but the maths and principal are valid for any DirectX or OpenGL engine. Another reasonably common example is a model where this data is fed in through the vertex colors instead of a texture map. These are usually controller by a splat map, where each color channel dictates the amount of a given texture to use. The most common example of this is for terrain shaders, or shaders for terrain type objects. Many of the shaders I find myself writing require some sort of blending between textures.