Restaura l'antialiasing de fcos al port Metal de cube_lines

This commit is contained in:
2026-05-04 12:42:49 +02:00
parent ef37a7a2e6
commit dff5d6fab2

View File

@@ -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);