Skip to content

ImGuizmo: Support infinite-far-plane reversed-z#210

Open
troughton wants to merge 1 commit intoCedricGuillemet:masterfrom
troughton:patch-1
Open

ImGuizmo: Support infinite-far-plane reversed-z#210
troughton wants to merge 1 commit intoCedricGuillemet:masterfrom
troughton:patch-1

Conversation

@troughton
Copy link
Copy Markdown

It is possible to create valid projection matrices where the far plane is at infinity, in which case the ray direction will be NaN. We can avoid this by shifting the far plane closer in NDC space.

PathogenDavid added a commit to PathogenDavid/ThreeL that referenced this pull request Jul 24, 2023
Had to fix some minor issues with ImGuizmo not playing nice with left-handed reverse-z infinite-far perspective matrices.
Thanks for Thomas here for saving me the effort of tracking down the ComputeCameraRay issue: CedricGuillemet/ImGuizmo#210
@m-schuetz
Copy link
Copy Markdown

m-schuetz commented Aug 14, 2024

Thanks for that pointer. This, together with hardcoding gContext.mReversed = true in ComputeContext() made it work for me. I'm also using projection matrix with reverse-z and infinite far.

@hrydgard
Copy link
Copy Markdown

hrydgard commented Dec 8, 2025

I had to do the same, the reverse detection doesn't work.

For reference, here's my proj matrix (Vulkan):

void Matrix4x4::SetProjectionInfReverse(float near_plane, float fov_vert, float aspect) {
	clear();
	float f = 1.0f / tanf(fov_vert * 0.5f);
	xx = f / aspect;
	yy = f;
	wz = near_plane;
	zw = -1.0f;
}

As a side note, with fp32 Z, today there's really no reason to use any other projection matrix than this. It achieves great distribution over the numeric range, and far planes are effectively obsolete. And even fits in a float4... you don't need a full matmul.

hrydgard added a commit to hrydgard/ImGuizmo that referenced this pull request Dec 8, 2025
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.

3 participants