Skip to content

Commit 85f29b0

Browse files
committed
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.
1 parent d7f2589 commit 85f29b0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

game/addons/base/Assets/shaders/terrain.shader

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ PS
173173
for ( int i = 0; i < 4; i++ )
174174
{
175175
float2 layerUV = texUV * g_TerrainMaterials[ i ].uvscale;
176-
float2 seamlessUV = Terrain_SampleSeamlessUV( layerUV );
176+
177+
float2x2 uvRotation;
178+
float2 seamlessUV = Terrain_SampleSeamlessUV( layerUV, uvRotation );
177179

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

184186
float3 normal = ComputeNormalFromRGTexture( nho.rg );
185187
normal.xz *= g_TerrainMaterials[ i ].normalstrength;
188+
189+
// Rotate normal map to match seamless UV angle and avoid shading errors
190+
normal.xy = mul( uvRotation, normal.xy );
191+
186192
normal = normalize( normal );
187193

188194
albedos[i] = SrgbGammaToLinear( bcr.rgb );

0 commit comments

Comments
 (0)