Triplannar UVs Node Function

Triplannar is expensive. Here is a snippet for virtually free triplannar which does not blend textures and thus has no performance impact. Good for terrains. Now with large worlds and origin shift support

This forum thread is a copy of the earlier-made discord thread so people can find the code here as well

// Normalize the world normal to ensure it's a unit vector
float3 n = normalize(Input0);
// Calculate the absolute values of the normal to find the dominant axis
float3 absN = abs(n);
// Initialize UV coordinates
float2 uv = float2(0.0, 0.0);

// Calculate tiling value from Input2 (assuming Input2 is your scale factor)
float tiling = Input2 * 0.001f;
// Apply GetLargeWorldsTileOffset with proper parameter
float3 worldPosWithOffset = Input1 + GetLargeWorldsTileOffset(1.0f / tiling);
// Apply tiling
worldPosWithOffset = worldPosWithOffset * tiling;

// Determine the dominant axis and generate UVs accordingly
if (absN.x > absN.y && absN.x > absN.z)
{
    // X is the dominant axis
    uv = float2(-worldPosWithOffset.z, worldPosWithOffset.y);
}
else if (absN.y > absN.z)
{
    // Y is the dominant axis
    uv = worldPosWithOffset.xz;
}
else
{
    // Z is the dominant axis
    uv = worldPosWithOffset.xy;
}
Output0 = float4(uv.x, uv.y, 0, 0);
1 Like