Skip to content

Commit

Permalink
cCircles: Fixed mipmap selection math
Browse files Browse the repository at this point in the history
  • Loading branch information
papadanku committed Jul 13, 2024
1 parent 04a6917 commit 279e19c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
12 changes: 6 additions & 6 deletions shaders/cCircles.fx
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,18 @@ 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;

// Create pixelated texcoords
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)
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions shaders/shared/cGraphics.fxh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 279e19c

Please sign in to comment.