Add mathcode-3d volumetric mode#110
Conversation
There was a problem hiding this comment.
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-3dpreset injs/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. |
|
|
||
| depthTexture?.destroy(); | ||
| depthTexture = device.createTexture({ | ||
| size, |
There was a problem hiding this comment.
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).
| size, | |
| size: [size[0], size[1], 1], |
| depthStencil: { | ||
| format: "depth24plus", | ||
| depthWriteEnabled: true, | ||
| depthCompare: "less", | ||
| }, |
There was a problem hiding this comment.
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.
| depthStencil: { | |
| format: "depth24plus", | |
| depthWriteEnabled: true, | |
| depthCompare: "less", | |
| }, | |
| ...(config.volumetric | |
| ? { | |
| depthStencil: { | |
| format: "depth24plus", | |
| depthWriteEnabled: true, | |
| depthCompare: "less", | |
| }, | |
| } | |
| : {}), |
| } | ||
| : { | ||
| enable: false, | ||
| }, |
There was a problem hiding this comment.
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.
| ["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, | ||
| }, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
🎬 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 |
Co-authored-by: Christopher Mayfield <cdm@ap0.org>
Co-authored-by: Christopher Mayfield <cdm@ap0.org>
|
@copilot apply changes based on the comments in this thread |
1 similar comment
|
@copilot apply changes based on the comments in this thread |
Agent-Logs-Url: https://github.com/ap0ught/matrix/sessions/16aa6974-8f15-4245-bb4e-38c93d556493 Co-authored-by: ap0ught <41078+ap0ught@users.noreply.github.com>
Implemented in commit Applied the review-thread fixes:
Screenshot (mathcode-3d WebGL):
Implemented in commit Applied the review-thread fixes:
Screenshot (mathcode-3d WebGL): |
Summary
mathcode-3dpreset (volumetric mathcode glyph rain).Test plan
/?version=mathcode-3d&renderer=webgpuand confirm depth/forward motion./?version=mathcode-3d&renderer=webgland confirm volumetric rendering.Notes
js/config.js,js/webgl/rainPass.js,js/webgpu/rainPass.js.Summary
mathcode-3dpreset (volumetric mathcode glyph rain).Test plan
/?version=mathcode-3d&renderer=webgpuand confirm depth/forward motion./?version=mathcode-3d&renderer=webgland confirm volumetric rendering.