Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion game/addons/base/Assets/shaders/terrain.shader
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ PS
for ( int i = 0; i < 4; i++ )
{
float2 layerUV = texUV * g_TerrainMaterials[ i ].uvscale;
float2 seamlessUV = Terrain_SampleSeamlessUV( layerUV );

float2x2 uvRotation;
float2 seamlessUV = Terrain_SampleSeamlessUV( layerUV, uvRotation );

Texture2D tBcr = Bindless::GetTexture2D( g_TerrainMaterials[ i ].bcr_texid );
Texture2D tNho = Bindless::GetTexture2D( g_TerrainMaterials[ i ].nho_texid );
Expand All @@ -183,6 +185,10 @@ PS

float3 normal = ComputeNormalFromRGTexture( nho.rg );
normal.xz *= g_TerrainMaterials[ i ].normalstrength;

// Rotate normal map to match seamless UV angle and avoid shading errors
normal.xy = mul( uvRotation, normal.xy );

normal = normalize( normal );

albedos[i] = SrgbGammaToLinear( bcr.rgb );
Expand Down
11 changes: 10 additions & 1 deletion game/addons/base/Assets/shaders/terrain/TerrainCommon.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -89,13 +89,22 @@ 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;

// Apply random offset
return tileCoord + frac(localUV + hash);
}

float2 Terrain_SampleSeamlessUV( float2 uv )
{
float2x2 dummy;
return Terrain_SampleSeamlessUV( uv, dummy );
}

// Move to another file:

//
Expand Down