From ee80298ca4b4fb810b02334508e11c5405aa77d2 Mon Sep 17 00:00:00 2001 From: Pokechu22 Date: Sat, 16 Oct 2021 12:41:46 -0700 Subject: [PATCH] VideoCommon: Implement diagonal LOD Note that both GLSL and HLSL provide a fwidth (fragment width) function defined as `fwidth(p) = abs(dFdx(p)) + abs(dFdy(p))`. However, it's easy enough to implement this ourselves (and it makes the code a bit more obvious). --- Source/Core/VideoCommon/PixelShaderGen.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Core/VideoCommon/PixelShaderGen.cpp b/Source/Core/VideoCommon/PixelShaderGen.cpp index dd2d9f41ad..bff76d4246 100644 --- a/Source/Core/VideoCommon/PixelShaderGen.cpp +++ b/Source/Core/VideoCommon/PixelShaderGen.cpp @@ -662,9 +662,8 @@ uint WrapCoord(int coord, uint wrap, int size) {{ // IRs), but (at least per the software renderer) actual LOD is S28.4. How does this work? // Also, note that we can make some assumptions due to use of a SamplerState version of the BP // configuration, which tidies things compared to whatever nonsense games can put in. - // TODO: This doesn't support diagonal LOD out.Write(R"( - float2 uv_delta = max(uv_delta_x, uv_delta_y); + float2 uv_delta = diag_lod ? uv_delta_x + uv_delta_y : max(uv_delta_x, uv_delta_y); float max_delta = max(uv_delta.x / 128.0, uv_delta.y / 128.0); // log2(x) is undefined if x <= 0, but in practice it seems log2(0) is -infinity, which becomes INT_MIN. // If lod_bias is negative, adding it to INT_MIN causes an underflow, resulting in a large positive value.