Transform tangent normal along seamless UV angle

Previous implementation of seamless UV was sampling tangent normal map 'as is', without transforming vectors to be inline with the UV rotation angle - which resulted into NdotL shading errors. This is now corrected and tangent vector accounts for UV rotation.
This commit is contained in:
wheatleymf
2025-11-29 18:28:28 +03:00
committed by Matt Stevens
parent e0c1c801c0
commit 556e4db9fb

View File

@@ -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 );
@@ -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 );