Skip to content

Fix line rendering when one endpoint is behind the camera.#33

Open
mrdoob wants to merge 1 commit intogoogle:masterfrom
mrdoob:master
Open

Fix line rendering when one endpoint is behind the camera.#33
mrdoob wants to merge 1 commit intogoogle:masterfrom
mrdoob:master

Conversation

@mrdoob
Copy link

@mrdoob mrdoob commented Dec 17, 2025

Made with Claude Opus 4.5.

Problem

Lines with one endpoint behind the camera (w <= 0) were being incorrectly rendered or disappearing entirely. The perspective division (P.x / P.w) produces invalid values when w <= 0, causing the line's rectangle polygon to have garbage coordinates before clipping could occur.

Solution

Clip line endpoints to w > epsilon before computing the screen-space direction (dx, dy). This ensures valid perspective division and proper rectangle construction, allowing the subsequent polygon clipping to work correctly.

Test

The fix can be verified with three.js examples that render grid lines extending toward the camera (e.g., webgl_materials_car, webxr_vr_teleport). Before the fix, grid lines close to the camera would break/disappear. After the fix, they render continuously to the screen edges.

Before After
webgl_materials_car webgl_materials_car
webxr_vr_teleport webxr_vr_teleport

Change-Id: I99a2909eaa8de03c664d51c9441b59ea96ed6cd5
@skal65535
Copy link

Looks like the dEQP test suite could use an extra test for this case of line rendering...

(https://github.com/KhronosGroup/VK-GL-CTS)

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