Output rotation matrix along with seamless UV

Terrain_SampleSeamlessUV now additionally returns a 2x2 rotation matrix which can be used to transform vectors and other data if necessary.

This also adds a function overload `Terrain_SampleSeamlessUV( float2 uv )` for cases when you don't need a rotation matrix. This will avoid breaking any shaders that rely on old implementation of this function
This commit is contained in:
wheatleymf
2025-11-29 18:20:57 +03:00
committed by Matt Stevens
parent 465240089f
commit e0c1c801c0

View File

@@ -73,7 +73,7 @@ class Terrain
// Get UV with per-tile UV offset to reduce visible tiling
// Works by offsetting UVs within each tile using a hash of the tile coordinate
float2 Terrain_SampleSeamlessUV( float2 uv )
float2 Terrain_SampleSeamlessUV( float2 uv, out float2x2 uvAngle )
{
float2 tileCoord = floor( uv );
float2 localUV = frac( uv );
@@ -89,6 +89,9 @@ float2 Terrain_SampleSeamlessUV( float2 uv )
float sinA = sin(angle);
float2x2 rot = float2x2(cosA, -sinA, sinA, cosA);
// Output rotation matrix
uvAngle = rot;
// Rotate around center
localUV = mul(rot, localUV - 0.5) + 0.5;
@@ -96,6 +99,12 @@ float2 Terrain_SampleSeamlessUV( float2 uv )
return tileCoord + frac(localUV + hash);
}
float2 Terrain_SampleSeamlessUV( float2 uv )
{
float2x2 dummy;
return Terrain_SampleSeamlessUV( uv, dummy );
}
// Move to another file:
//