Skip to content

First draft of per-pixel color evaluation - #461

Open
mkeeter wants to merge 10 commits into
mainfrom
wgpu-color
Open

First draft of per-pixel color evaluation#461
mkeeter wants to merge 10 commits into
mainfrom
wgpu-color

Conversation

@mkeeter

@mkeeter mkeeter commented Aug 23, 2026

Copy link
Copy Markdown
Owner

This PR adds a WebGPU compute pass which evaluates per-pixel color expressions.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved shader correctness and color API issues can produce transparent output, incorrect effects, or unreported shape mismatches.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds WebGPU per-pixel color-expression evaluation to the voxel rendering pipeline.

Changes:

  • Adds color-expression buffers, bytecode input remapping, and a color compute pass.
  • Relocates voxel effects and updates shading to consume computed colors.
  • Adds shader-layout and GPU pipeline tests.
File summaries
File Description
fidget-wgpu/src/voxel/mod.rs Exposes effects and expands pipeline tests.
fidget-wgpu/src/voxel/effects/mod.rs Implements color buffers, submission, and shading integration.
fidget-wgpu/src/voxel/effects/shaders/color.wgsl Evaluates RGB expressions per pixel.
fidget-wgpu/src/voxel/effects/shaders/shade.wgsl Applies lighting to computed colors.
fidget-wgpu/src/voxel/effects/shaders/common.wgsl Defines packed voxel helpers.
fidget-wgpu/src/voxel/effects/shaders/merge.wgsl Merges indexed voxel images.
fidget-wgpu/src/voxel/effects/shaders/ssao.wgsl Computes GPU SSAO.
fidget-wgpu/src/voxel/effects/shaders/blur.wgsl Blurs SSAO output.
fidget-wgpu/src/pixel/mod.rs Updates shader helpers and tests.
fidget-wgpu/src/lib.rs Adds color types and shared bytecode preparation.
fidget-wgpu/Cargo.toml Adds layout-test dependency.
fidget-core/src/var/mod.rs Adds Debug to VarMap.
fidget-bytecode/src/lib.rs Adds bytecode input remapping.
demos/cli/src/main.rs Updates effects API usage.
Cargo.lock Records the new dependency.
Review details

Suppressed comments (4)

fidget-wgpu/src/voxel/effects/shaders/shade.wgsl:71

  • The grayscale branch no longer ORs in alpha, so every non-color render (including the CLI caller passing false) produces pixels with alpha 0 instead of the opaque pixels emitted before this change. Preserve the alpha byte in this branch as well.
    fidget-wgpu/src/voxel/effects/mod.rs:686
  • The public constructor accepts color expressions containing Var::V, and the internal evaluator supports ShapeVars, but this only public submission path always supplies an empty map. Such expressions therefore always fail with MissingVar and callers have no way to provide the required values. Expose a submit_color_with_vars path (as the pixel and voxel contexts do) or accept vars here.

This issue also appears in the following locations of the same file:

  • line 1100
  • line 1120
    fidget-wgpu/src/voxel/effects/mod.rs:1120
  • This unconditional println! makes a library render operation write to the application's stdout on every color pass, which can corrupt CLI output and add per-frame noise. Remove it (or use opt-in tracing if diagnostics are needed).
    fidget-wgpu/src/voxel/effects/mod.rs:1100
  • ColorError::BadShapeCount is never produced: MergeBuffers::image_count is recorded but never compared with the number of color entries. A mismatch therefore reaches the shader and either paints indexed pixels red or silently leaves extra colors unused instead of returning the documented error. Store the color count in ShapeColorBuffers and validate it here before creating bind groups.
  • Files reviewed: 10/15 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +2828 to +2832
.color_buffers(&[ShapeColor::Rgb {
r: VmShape::from(Tree::constant(0.0)),
g: VmShape::from(Tree::constant(1.0)),
b: VmShape::from(Tree::constant(0.25)),
}])
Comment thread fidget-wgpu/src/voxel/mod.rs
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.

2 participants