Skip to content

Conversation

atlv24
Copy link
Contributor

@atlv24 atlv24 commented Sep 5, 2025

Objective

Solution

  • so it turns out a wrong optimization got made at some point, where a division by w was avoided by multiplying both sides of an inequality by w. This is wrong, because w can be negative, which should flip the inequality.
  • So instead, we document what it should be doing, which is computing the depth values and comparing to near plane, and then avoid the divison in a sign-aware way using sign and abs.

Testing

@atlv24 atlv24 added A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 5, 2025
@atlv24 atlv24 added this to the 0.17 milestone Sep 5, 2025
@atlv24 atlv24 changed the title Fix gizmos for real this time Fix gizmo new plane clipping bug Sep 5, 2025
@atlv24 atlv24 changed the title Fix gizmo new plane clipping bug Fix gizmo near plane clipping bug Sep 5, 2025
@mockersf mockersf added this pull request to the merge queue Sep 5, 2025
Copy link
Member

@chompaa chompaa left a comment

Choose a reason for hiding this comment

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

lgtm! fixed the repro

Merged via the queue into bevyengine:main with commit 021fe7a Sep 5, 2025
37 checks passed
@github-project-automation github-project-automation bot moved this to Done in Rendering Sep 5, 2025
@atlv24 atlv24 deleted the ad/fix-gizmos-2 branch September 9, 2025 15:17
github-merge-queue bot pushed a commit that referenced this pull request Oct 13, 2025
# Objective

- alternative to #21502
- also undoes #20890
- does not regress #19205
- fixes #21489 and #21479

## Solution

the fix i originally made was wrong. the reason it worked was because it
failed the conditional and did not clip the lines in some cases where
the original bug was exhibited. the condition was correct before, it
turns out, but the clipping logic is wrong: an epsilon is added, with a
comment saying it is to avoid falsely culling the vertex due to floating
point imprecision leaving it just barely in front of the near plane.
However, i do not see why an epsilon should be needed here, or why this
should be avoided: triangle primitives are regularly intersecting the
clipping plane, that is standard order of business. The entire primitive
is not discarded if only part of it is clipped, instead only the visible
pixels are rasterized.

## Testing

- original bug test case by Antony looks right
- both grid test cases look right
- gizmos examples look right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Gizmos flip axes when values are large

4 participants