From 538a714086976c415ecf7f884fd05aba41a8aeba Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Tue, 23 Oct 2018 00:16:23 +0000 Subject: [PATCH] Fade out microtextures with higher textures LODs. Fixes incorrectly applied microtextures in LA machineguns. --- Src/Graphics/New3D/R3DShaderQuads.h | 13 ++++++++++--- Src/Graphics/New3D/R3DShaderTriangles.h | 13 ++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Src/Graphics/New3D/R3DShaderQuads.h b/Src/Graphics/New3D/R3DShaderQuads.h index 01995d5..bffef3d 100644 --- a/Src/Graphics/New3D/R3DShaderQuads.h +++ b/Src/Graphics/New3D/R3DShaderQuads.h @@ -438,9 +438,16 @@ vec4 GetTextureValue() } if (microTexture) { - vec2 scale = (baseTexSize / 128.0) * microTextureScale; - vec4 tex2Data = textureR3D( tex2, ivec2(0), vec2(128.0), fsTexCoord.st * scale); - tex1Data = (tex1Data+tex2Data)/2.0; + vec2 scale = (baseTexSize / 128.0) * microTextureScale; + vec4 tex2Data = textureR3D( tex2, ivec2(0), vec2(128.0), fsTexCoord * scale); + + float lod = mip_map_level(fsTexCoord * scale * vec2(128.0)); + + float blendFactor = max(lod - 1.5, 0.0); // bias -1.5 + blendFactor = min(blendFactor, 1.0); // clamp to max value 1 + blendFactor = (blendFactor + 1.0) / 2.0; // 0.5 - 1 range + + tex1Data = mix(tex2Data, tex1Data, blendFactor); } if (alphaTest) { diff --git a/Src/Graphics/New3D/R3DShaderTriangles.h b/Src/Graphics/New3D/R3DShaderTriangles.h index f051998..9272d6c 100644 --- a/Src/Graphics/New3D/R3DShaderTriangles.h +++ b/Src/Graphics/New3D/R3DShaderTriangles.h @@ -210,9 +210,16 @@ vec4 GetTextureValue() } if (microTexture) { - vec2 scale = (baseTexSize / 128.0) * microTextureScale; - vec4 tex2Data = textureR3D( tex2, ivec2(0), vec2(128.0), fsTexCoord.st * scale); - tex1Data = (tex1Data+tex2Data)/2.0; + vec2 scale = (baseTexSize / 128.0) * microTextureScale; + vec4 tex2Data = textureR3D( tex2, ivec2(0), vec2(128.0), fsTexCoord * scale); + + float lod = mip_map_level(fsTexCoord * scale * vec2(128.0)); + + float blendFactor = max(lod - 1.5, 0.0); // bias -1.5 + blendFactor = min(blendFactor, 1.0); // clamp to max value 1 + blendFactor = (blendFactor + 1.0) / 2.0; // 0.5 - 1 range + + tex1Data = mix(tex2Data, tex1Data, blendFactor); } if (alphaTest) {