Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/materials/SnareMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ const CAGE_VERTEX = /* glsl */ `

float halfWidth = uWidth * uWidthScale * widthMul;
// Every filament is an arc with two loose ends, so it tapers at both.
halfWidth *= mix(1.0, pow(sin(clamp(t, 0.0, 1.0) * PI), 0.35), 0.85);
halfWidth *= mix(1.0, pow(max(sin(clamp(t, 0.0, 1.0) * PI), 0.0), 0.35), 0.85);
if (role > 0.5 && role < 1.5) halfWidth *= mix(1.0, uColumnTaper, t);
halfWidth *= flash * uFade;

Expand Down Expand Up @@ -376,7 +376,7 @@ const CAGE_FRAGMENT = /* glsl */ `

// The loose ends fade as well as thin. A ribbon that only narrows leaves a
// hard dot at each tip, and every filament here has two of them.
alpha *= pow(sin(clamp(vT, 0.0, 1.0) * PI), 0.35);
alpha *= pow(max(sin(clamp(vT, 0.0, 1.0) * PI), 0.0), 0.35);
alpha *= flicker * vFlash * vDim * uFade * uPassOpacity * uOpacity;

vec2 screenUV = gl_FragCoord.xy / uResolution;
Expand Down
12 changes: 12 additions & 0 deletions src/materials/SnareMaterial.pow.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { readFileSync } from 'node:fs';
import { fileURLToPath } from 'node:url';

test('snare taper uses max(sin, 0) so pow never sees a negative base', () => {
const src = readFileSync(fileURLToPath(new URL('./SnareMaterial.js', import.meta.url)), 'utf8');
const hits = [...src.matchAll(/pow\(\s*(?:sin|max\(sin)/g)];
assert.equal(hits.length, 2);
assert.equal([...src.matchAll(/pow\(\s*max\(sin\(/g)].length, 2);
assert.equal([...src.matchAll(/pow\(\s*sin\(/g)].length, 0);
});