From 279e19c2d901ce69d4a2f2a5e1ba0f8401f14d42 Mon Sep 17 00:00:00 2001 From: papadanku <115061077+papadanku@users.noreply.github.com> Date: Sat, 13 Jul 2024 14:34:13 -0700 Subject: [PATCH] cCircles: Fixed mipmap selection math --- shaders/cCircles.fx | 12 ++++++------ shaders/shared/cGraphics.fxh | 10 ++++++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/shaders/cCircles.fx b/shaders/cCircles.fx index c84b21c..2765cad 100644 --- a/shaders/cCircles.fx +++ b/shaders/cCircles.fx @@ -69,10 +69,6 @@ float4 PS_Circles(VS2PS_Quad Input) : SV_TARGET0 // Shrink the UV so [-1, 1] fills a square float2 Tiles = (Input.Tex0.xy * _CircleAmount); - // Calculate pre-shift mips here - float2 TexIx = ddx(Tiles); - float2 TexIy = ddy(Tiles); - // Shift the tiles so they are ~0.5 units apart from each-other Tiles.x = (GetMod(trunc(Tiles.y), 2.0) == 1.0) ? Tiles.x + 0.25: Tiles.x - 0.25; @@ -80,7 +76,11 @@ float4 PS_Circles(VS2PS_Quad Input) : SV_TARGET0 float2 Tex = floor(Tiles) / _CircleAmount; // Get pixelated color information - float4 Color = tex2Dgrad(SampleTempTex0, Tex, TexIx, TexIy); + float2 TexSize = GetScreenSizeFromTex(Input.Tex0); + float LOD = max(0.0, log2(max(TexSize.x, TexSize.y) / _CircleAmount)); + + // Get texture information + float4 Color = tex2Dlod(SampleTempTex0, float4(Input.Tex0.xy, 0.0, LOD)); float Feature = 0.0; switch(_Select) @@ -141,7 +141,7 @@ float4 PS_Circles(VS2PS_Quad Input) : SV_TARGET0 OutputColor = lerp(_BackColor, OutputColor, Tiles.y > _Crop.z * 2.0); OutputColor = lerp(_BackColor, OutputColor, Tiles.y < (_CircleAmount - _Crop.w * 2.0)); - return float4(OutputColor, 1.0); + return float4(OutputColor.rgb, 1.0); } technique CShade_Circles diff --git a/shaders/shared/cGraphics.fxh b/shaders/shared/cGraphics.fxh index 7da89cd..ba1c7d6 100644 --- a/shaders/shared/cGraphics.fxh +++ b/shaders/shared/cGraphics.fxh @@ -85,4 +85,14 @@ return float2(0.0, 0.5) * max(0.0, log2(max(Lx, Ly))); } + int2 GetScreenSizeFromTex(float2 Tex) + { + return max(round(1.0 / fwidth(Tex)), 1.0); + } + + float2 GetPixelSizeFromTex(float2 Tex) + { + return 1.0 / GetScreenSizeFromTex(Tex); + } + #endif