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);
3 Likes

Can you explain the difference of usage inside actual graph between this and Flax’s triplanar material nodes( Triplanar Normal Map, Triplanar Texture )?

Flax triplannar performs the sampling so you cant really customize that + it performs blending (so thats 3 samples unless there is some optimization under the hood which could bring it down to a variable 1-2 samples for blends).

My TriplannarUV does not sample anything and instead gives you a triplannar world-space UV map which you can use to sample anything any way you want. You can drag it into a UV input of an image sampler and itd be like no performance penalty compared to the full effect (so you can use it everywhere for instance for snow covers or terrains if you dont mind the lack of blends) or use the Y component to sample materialA and X/Z to sample material B and customize the appearance of a material instead of sampling the same thing thrice. Its just more customizable. In homeostasis we dont need the blends most of the time but we need procedural materials on terrain and such so we use this often and at basically 0 perf impact.

1 Like