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