mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-23 22:48:07 -05:00
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:
@@ -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:
|
||||
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user