Skip to content

Far clipping plane cuts at twice the declared distance - #82

Closed
zoncabe wants to merge 1 commit into
HailToDodongo:mainfrom
zoncabe:fix-far-clipping
Closed

zoncabe wants to merge 1 commit into
HailToDodongo:mainfrom
zoncabe:fix-far-clipping

Conversation

@zoncabe

@zoncabe zoncabe commented Sep 14, 2026

Copy link
Copy Markdown

t3d_mat4_perspective mixes two depth conventions. Result: geometry stays
visible until twice the far plane passed to t3d_viewport_set_projection.

mat->m[2][2] = far / (near - far);

Cause

Constant term is written for the -1..1 depth convention, which carries a factor
of two:

m[3][2] = -2 * far * near / (far - near)

Z term is written for the 0..1 convention, which does not:

m[2][2] = far / (near - far)

Clip Z at eye distance d comes out as:

z = far/(far-near) * d - 2*far*near/(far-near)

Clipping tests z <= w, and w is d. Solving:

d * near/(far-near) <= 2*far*near/(far-near)
d <= 2*far

With the matching term -(far + near)/(far - near) the same solve gives
d <= far.

Near plane is unaffected: it solves to d >= near either way.

Measurement

Four posts on one axis, 10 metres apart, FPS camera walking the line, both
planes printed on screen. Far plane set to 25 metres, geometry disappears at
50.

Screenshots of both builds attached, before and after the fix. Both ROMs are
attached as well.

Fix

mat->m[2][2] = -(far + near) / (far - near);

Impact

Behaviour change, visible in every existing project. Scenes tuned against the
current behaviour lose whatever sat between the declared plane and its double.
Depth precision improves: that range currently compresses into the tail of the
depth buffer.

@HailToDodongo

Copy link
Copy Markdown
Owner

already fixed in PR #81

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