Skip to content

Commit c10b031

Browse files
committed
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
1 parent 16809db commit c10b031

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

game/addons/base/Assets/shaders/terrain/TerrainCommon.hlsl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class Terrain
7373

7474
// Get UV with per-tile UV offset to reduce visible tiling
7575
// Works by offsetting UVs within each tile using a hash of the tile coordinate
76-
float2 Terrain_SampleSeamlessUV( float2 uv )
76+
float2 Terrain_SampleSeamlessUV( float2 uv, out float2x2 uvAngle )
7777
{
7878
float2 tileCoord = floor( uv );
7979
float2 localUV = frac( uv );
@@ -89,13 +89,22 @@ float2 Terrain_SampleSeamlessUV( float2 uv )
8989
float sinA = sin(angle);
9090
float2x2 rot = float2x2(cosA, -sinA, sinA, cosA);
9191

92+
// Output rotation matrix
93+
uvAngle = rot;
94+
9295
// Rotate around center
9396
localUV = mul(rot, localUV - 0.5) + 0.5;
9497

9598
// Apply random offset
9699
return tileCoord + frac(localUV + hash);
97100
}
98101

102+
float2 Terrain_SampleSeamlessUV( float2 uv )
103+
{
104+
float2x2 dummy;
105+
return Terrain_SampleSeamlessUV( uv, dummy );
106+
}
107+
99108
// Move to another file:
100109

101110
//

0 commit comments

Comments
 (0)