Skip to content

Add mathcode-3d volumetric mode#110

Merged
ap0ught merged 5 commits into
masterfrom
replace-regl
Apr 23, 2026
Merged

Add mathcode-3d volumetric mode#110
ap0ught merged 5 commits into
masterfrom
replace-regl

Conversation

@ap0ught
Copy link
Copy Markdown
Owner

@ap0ught ap0ught commented Apr 22, 2026

Summary

  • Add a new mathcode-3d preset (volumetric mathcode glyph rain).
  • Enable depth testing + depth buffer for volumetric WebGL rain rendering.
  • Add a depth buffer + pipeline depth state for WebGPU volumetric rendering.

Test plan

  • Open /?version=mathcode-3d&renderer=webgpu and confirm depth/forward motion.
  • Open /?version=mathcode-3d&renderer=webgl and confirm volumetric rendering.

Notes

  • Changes are limited to: js/config.js, js/webgl/rainPass.js, js/webgpu/rainPass.js.

Summary

  • Add a new mathcode-3d preset (volumetric mathcode glyph rain).
  • Enable depth testing for volumetric WebGL rain rendering.
  • Add a depth buffer/pipeline depth for WebGPU volumetric rendering.

Test plan

  • Open /?version=mathcode-3d&renderer=webgpu and confirm depth/forward motion.
  • Open /?version=mathcode-3d&renderer=webgl and confirm volumetric rendering.

x
Made-with: Cursor:
@ap0ught ap0ught marked this pull request as ready for review April 22, 2026 16:29
Copilot AI review requested due to automatic review settings April 22, 2026 16:29
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new mathcode-3d version preset to render volumetric mathcode glyph rain, and updates both renderer backends to support depth-based rendering for 3D/volumetric modes.

Changes:

  • Add mathcode-3d preset in js/config.js (volumetric mathcode tuning: density/forward motion/palette, etc.).
  • WebGL: allocate a depth-enabled FBO for volumetric rendering and enable depth testing in the rain render pass.
  • WebGPU: add depth pipeline state and create/attach a depth texture for the rain render pass.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
js/config.js Introduces the new mathcode-3d version preset and its parameter defaults.
js/webgl/rainPass.js Adds depth-buffered output + depth test configuration for volumetric WebGL rain rendering.
js/webgpu/rainPass.js Adds depth pipeline state and a depth render attachment texture for WebGPU rain rendering.

Comment thread js/webgpu/rainPass.js Outdated

depthTexture?.destroy();
depthTexture = device.createTexture({
size,
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device.createTexture for depthTexture is passed size as a 2-element array. WebGPU GPUExtent3D requires a 3D extent (e.g. [width, height, 1] or { width, height, depthOrArrayLayers: 1 }), and this can throw at runtime on strict implementations. Update the depth texture creation to include the 3rd dimension (matching makeRenderTarget / makeComputeTarget).

Suggested change
size,
size: [size[0], size[1], 1],

Copilot uses AI. Check for mistakes.
Comment thread js/webgpu/rainPass.js Outdated
Comment on lines +260 to +264
depthStencil: {
format: "depth24plus",
depthWriteEnabled: true,
depthCompare: "less",
},
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depth testing/writes are enabled unconditionally in the WebGPU render pipeline and a full-size depth texture is allocated every resize, even for non-volumetric (2D) rendering. This adds memory + bandwidth overhead and can introduce subtle seam behavior on the fullscreen quad (depthCompare less + depth writes). Consider only enabling depthStencil (and creating/attaching depthTexture) when config.volumetric is true.

Suggested change
depthStencil: {
format: "depth24plus",
depthWriteEnabled: true,
depthCompare: "less",
},
...(config.volumetric
? {
depthStencil: {
format: "depth24plus",
depthWriteEnabled: true,
depthCompare: "less",
},
}
: {}),

Copilot uses AI. Check for mistakes.
Comment thread js/webgl/rainPass.js Outdated
Comment on lines +186 to +201
}
: {
enable: false,
},
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Depth testing with depthWriteEnabled/func: "less" is being combined with additive blending for volumetric glyphs. Because glyph quads are not rendered in guaranteed front-to-back order (depth varies per column over time), far fragments can be blended into the target before a nearer fragment writes depth, so the result is not reliable occlusion. If true occlusion is required, consider a depth pre-pass (depth-only then color with depthCompare equal and depthWrite disabled) or otherwise ensure near-to-far draw ordering / adjust blending strategy.

Copilot uses AI. Check for mistakes.
Comment thread js/config.js
Comment on lines +667 to +702
["mathcode-3d"]: {
font: "mathcode",
volumetric: true,

// Favor readability in depth: fewer columns than 2D mathcode,
// higher density, and a moderate forward motion.
numColumns: 44,
density: 1.35,
forwardSpeed: 0.22,

animationSpeed: 0.75,
cycleSpeed: 0.045,
fallSpeed: 0.55,
raindropLength: 0.55,

// Keep 3D "tunnel" clean.
isPolar: false,
slant: 0,

baseBrightness: -0.85,
baseContrast: 1.6,
bloomStrength: 0.8,
bloomSize: 0.45,
highPassThreshold: 0,

cursorColor: hsl(0.55, 1, 0.95),
cursorIntensity: 2.2,
palette: [
{ color: hsl(0.55, 0.9, 0.0), at: 0.0 },
{ color: hsl(0.55, 1.0, 0.35), at: 0.55 },
{ color: hsl(0.56, 1.0, 0.8), at: 0.9 },
{ color: hsl(0.57, 1.0, 1.0), at: 1.0 },
],

glyphRandomFlip: true,
},
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new version preset (mathcode-3d) is added, but there is no automated smoke coverage to ensure it boots cleanly on at least WebGL (and ideally WebGPU when available). Since the repo already has Playwright version smoke coverage (e.g. VERSION_SAMPLES in tests), please add mathcode-3d to that matrix (or add a targeted test) so regressions in volumetric/depth setup are caught.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 18f41f8.

mathcode-3d is now included in smoke coverage via VERSION_SAMPLES in tests/matrix-smoke.spec.js, and the renderer depth-path fixes from the same review thread are included in that commit.

Screenshot: /home/runner/work/matrix/matrix/test-results/mathcode-3d-webgl.png

Made-with: Cursor:
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 22, 2026

🎬 PR Preview Deployed!

Your changes are now available for testing:

Preview URL: https://ap0ught.github.io/matrix/pr-110/

Test Links:

The preview will be updated automatically when you push new commits.


Preview deployed from commit 18f41f8

cursoragent and others added 2 commits April 22, 2026 16:41
Co-authored-by: Christopher Mayfield <cdm@ap0.org>
Co-authored-by: Christopher Mayfield <cdm@ap0.org>
@ap0ught
Copy link
Copy Markdown
Owner Author

ap0ught commented Apr 22, 2026

@copilot apply changes based on the comments in this thread

1 similar comment
@ap0ught
Copy link
Copy Markdown
Owner Author

ap0ught commented Apr 23, 2026

@copilot apply changes based on the comments in this thread

Copy link
Copy Markdown

Copilot AI commented Apr 23, 2026

@copilot apply changes based on the comments in this thread

Implemented in commit 18f41f8.

Applied the review-thread fixes:

  • WebGPU depth is now volumetric-only and uses a 3D extent ([w, h, 1]) for depth texture creation.
  • WebGPU depth attachment is only set when volumetric mode is active.
  • WebGL volumetric rendering now uses a depth pre-pass, then additive color pass with depth compare equal to avoid order-dependent additive/depth artifacts.
  • Added smoke coverage for version=mathcode-3d in tests/matrix-smoke.spec.js.

Screenshot (mathcode-3d WebGL): /home/runner/work/matrix/matrix/test-results/mathcode-3d-webgl.png

@copilot apply changes based on the comments in this thread

Implemented in commit 18f41f8.

Applied the review-thread fixes:

  • WebGPU depth is now volumetric-only and uses a 3D extent ([w, h, 1]) for depth texture creation.
  • WebGPU depth attachment is only set when volumetric mode is active.
  • WebGL volumetric rendering now uses a depth pre-pass, then additive color pass with depth compare equal to avoid order-dependent additive/depth artifacts.
  • Added smoke coverage for version=mathcode-3d in tests/matrix-smoke.spec.js.

Screenshot (mathcode-3d WebGL): /home/runner/work/matrix/matrix/test-results/mathcode-3d-webgl.png

@ap0ught ap0ught merged commit 37f2b82 into master Apr 23, 2026
5 checks passed
@ap0ught ap0ught deleted the replace-regl branch April 23, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants