From 07ed8027239f1569c18c804e39b4813e5ccf9bd3 Mon Sep 17 00:00:00 2001 From: RDW Date: Mon, 18 Mar 2024 17:27:49 +0100 Subject: [PATCH] Client: Fix the lightmap blending stage for terrain surfaces It's clear that the alpha channel should not be affecting the lighting stage as that's taking place prior to texture blending. --- Core/NativeClient/WebGPU/Shaders/TerrainGeometryShader.wgsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Core/NativeClient/WebGPU/Shaders/TerrainGeometryShader.wgsl b/Core/NativeClient/WebGPU/Shaders/TerrainGeometryShader.wgsl index ded3d102..3209dac1 100644 --- a/Core/NativeClient/WebGPU/Shaders/TerrainGeometryShader.wgsl +++ b/Core/NativeClient/WebGPU/Shaders/TerrainGeometryShader.wgsl @@ -159,11 +159,11 @@ fn fs_main(in: VertexOutput) -> @location(0) vec4f { let sunlightRayOrigin = -normalize(uPerSceneData.directionalLightDirection.xyz); let sunlightColorContribution = max(dot(sunlightRayOrigin, normal), 0.0); let directionalLightColor = sunlightColorContribution * sunlightColor; - let combinedLightContribution = clampToUnitRange(directionalLightColor + ambientColor) * lightmapTextureColor.a; + let combinedLightContribution = clampToUnitRange(directionalLightColor + ambientColor); // Screen blending increases the vibrancy of colors (see https://en.wikipedia.org/wiki/Blend_modes#Screen) let contrastCorrectionColor = clampToUnitRange(ambientColor + sunlightColor - (sunlightColor * ambientColor)); - let fragmentColor = clampToUnitRange(in.color * contrastCorrectionColor * combinedLightContribution * diffuseTextureColor.rgb + lightmapTextureColor.rgb); + let fragmentColor = in.color * contrastCorrectionColor * combinedLightContribution * diffuseTextureColor.rgb * lightmapTextureColor.a + lightmapTextureColor.rgb; // Should be a no-op if fog is disabled, since the fogFactor would be zero let foggedColor = mix(fragmentColor.rgb, uPerSceneData.fogColor.rgb, in.fogFactor);