From dff5d6fab2a8ffaa33c407756e491e3a56951da6 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 4 May 2026 12:42:49 +0200 Subject: [PATCH] Restaura l'antialiasing de fcos al port Metal de cube_lines --- shaders/cube_lines/cube_lines.frag.msl | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/shaders/cube_lines/cube_lines.frag.msl b/shaders/cube_lines/cube_lines.frag.msl index 1b63517..29f7dfd 100644 --- a/shaders/cube_lines/cube_lines.frag.msl +++ b/shaders/cube_lines/cube_lines.frag.msl @@ -5,12 +5,12 @@ using namespace metal; // MSL port of cube_lines.vk.glsl. The original Shadertoy is ~780 lines and // uses every GLSL trick (mat3 chains, arrays, fwidth-based AA, swap macros). // -// Notes on compromises in this port: -// - fcos() in the GLSL uses fwidth() with a fallback that depends on -// iResolution.y. To avoid threading iResolution through ~10 helpers, this -// port uses the simpler `fcos = cos` path (equivalent to defining AA_ALL -// in the original). Edges may be slightly less smooth than the Vulkan/GL -// versions; cosmetic only. +// Notes: +// - fcos() uses fwidth() like the GLSL original to soften high-frequency +// terms. The GLSL fallback path that divides by iResolution.y when +// fwidth returns 0/NaN/Inf is omitted here; the main fwidth-based +// branch covers virtually all fragments and the fallback is rarely +// hit in practice. // - Optional Shadertoy defines (ANIM_SHAPE, ANIM_COLOR, ROTATION_SPEED, // CAMERA_*, USE_COLOR, AA_*, ONLY_BOX, etc.) are left at their defaults // just like the .vk.glsl ships them. @@ -45,7 +45,10 @@ static float3x3 rotz(float a) { return float3x3(float3(c, s, 0.0), float3(-s, c, 0.0), float3(0.0, 0.0, 1.0)); } -static float3 fcos(float3 x) { return cos(x); } +static float3 fcos(float3 x) { + float3 w = fwidth(x); + return cos(x) * smoothstep(float3(3.14 * 2.0), float3(0.0), w); +} static float3 getColor(float3 p) { p = abs(p);