Skip to content

Switch to f32 for GeometryBuffer depth#381

Merged
mkeeter merged 8 commits intomainfrom
geometry-buffer-f32-depth
Dec 21, 2025
Merged

Switch to f32 for GeometryBuffer depth#381
mkeeter merged 8 commits intomainfrom
geometry-buffer-f32-depth

Conversation

@mkeeter
Copy link
Copy Markdown
Owner

@mkeeter mkeeter commented Dec 7, 2025

This makes it easier to send the GeometryBuffer to the GPU as a f32x4 texture. I previously just used bitcasting, but It turns out that a small u32 produces a denormalized float, and some GPUs will just round it to zero (!)

Thanks to @alexneufeld for tracking this down in mkeeter/halfspace#1

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

This PR changes the depth field in GeometryPixel from u32 to f32 to resolve GPU denormalization issues where small u32 values, when bitcast to f32, could be rounded to zero on some GPUs. This change propagates through the rendering pipeline, affecting type conversions, comparisons, and GPU texture formats.

Key Changes

  • Changed GeometryPixel::depth from u32 to f32 in the core raster library
  • Updated all depth comparisons from integer (e.g., p.depth > 0) to floating-point (e.g., p.depth > 0.0)
  • Modified GPU shader bindings to use texture_2d<f32> instead of texture_2d<u32> and removed bitcasting operations

Reviewed changes

Copilot reviewed 12 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
fidget-raster/src/lib.rs Changed GeometryPixel::depth type from u32 to f32 with updated documentation
fidget-raster/src/render3d.rs Replaced try_into().unwrap() conversions with direct as f32 casts for depth calculations
fidget-raster/src/effects.rs Updated all depth comparisons from integer to floating-point literals (0 → 0.0)
fidget/tests/render3d.rs Updated test assertions to compare depth against f32 values instead of integers
demos/viewer/src/shaders/geometry.wgsl Changed texture type from texture_2d<u32> to texture_2d<f32> and removed bitcast operations for normals
demos/viewer/src/draw3d.rs Updated texture format from Rgba32Uint to Rgba32Float and changed sample type to non-filterable float
demos/cli/src/main.rs Updated depth comparisons to use 0.0 and modified heightmap calculation to work with f32
demos/web-editor/crate/src/lib.rs Updated depth comparison to use 0.0 instead of 0
fidget/Cargo.toml, fidget-raster/Cargo.toml, Cargo.toml, Cargo.lock Bumped versions from 0.4.1 to 0.4.2 for affected crates
CHANGELOG.md Added entry documenting the type change for version 0.4.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread demos/cli/src/main.rs Outdated
Comment thread fidget-raster/src/render3d.rs Outdated
@mkeeter mkeeter merged commit d4ef79b into main Dec 21, 2025
13 checks passed
@mkeeter mkeeter deleted the geometry-buffer-f32-depth branch December 21, 2025 15:18
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