Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is there no Mat4::frustum_{lh,rh{,_gl}} ? #441

Open
Des-Nerger opened this issue Nov 30, 2023 · 4 comments
Open

Why is there no Mat4::frustum_{lh,rh{,_gl}} ? #441

Des-Nerger opened this issue Nov 30, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Des-Nerger
Copy link

Des-Nerger commented Nov 30, 2023

I thought that, not only Mat4::perspective_{lh,rh{,_gl}} requires more computation involving the nasty math::tan, it also doesn't allow us to construct matrices for stereoscopic projection: https://paulbourke.net/stereographics/stereorender

One could omit perspective (if the minimalistic approach were pursued), but frustum is an essential and fundamental thing to have for such a math library.

@bitshifter
Copy link
Owner

bitshifter commented Dec 17, 2023

I am not understanding what is being asked for here, could you explain exactly what feature you would like to see?

@bitshifter
Copy link
Owner

A more detailed explanation from https://www.opengl.org/archives/resources/faq/technical/transformations.htm

What are the pros and cons of using glFrustum() versus gluPerspective()? Why would I want to use one over the other?

glFrustum() and gluPerspective() both produce perspective projection matrices that you can use to transform from eye coordinate space to clip coordinate space. The primary difference between the two is that glFrustum() is more general and allows off-axis projections, while gluPerspective() only produces symmetrical (on-axis) projections. Indeed, you can use glFrustum() to implement gluPerspective(). However, aside from the layering of function calls that is a natural part of the GLU interface, there is no performance advantage to using matrices generated by glFrustum() over gluPerspective().

Since glFrustum() is more general than gluPerspective(), you can use it in cases when gluPerspective() can't be used. Some examples include projection shadows, tiled renderings, and stereo views.

Tiled rendering uses multiple off-axis projections to render different sections of a scene. The results are assembled into one large image array to produce the final image. This is often necessary when the desired dimensions of the final rendering exceed the OpenGL implementation's maximum viewport size.

In a stereo view, two renderings of the same scene are done with the view location slightly shifted. Since the view axis is right between the “eyes”, each view must use a slightly off-axis projection to either side to achieve correct visual results.

@Des-Nerger
Copy link
Author

Des-Nerger commented Dec 22, 2023

Sorry for not expanding the context enough.

A more detailed explanation from https://www.opengl.org/...

Yes. It's what I talked about. I haven't found an analogue of glFrustrum in glam, found only that of gluPerspective; which felt unjust. Of course one can construct glFrustum manually, but I thought glam is supposed to contain such conveniences by itself.

@bitshifter
Copy link
Owner

Further implementation details https://lmb.informatik.uni-freiburg.de/people/reisert/opengl/doc/glFrustum.html.

Also DirectX equivalents https://learn.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmmatrixperspectiveoffcenterlh and https://learn.microsoft.com/en-us/windows/win32/api/directxmath/nf-directxmath-xmmatrixperspectiveoffcenterrh.

Since I don't do much graphics programing I'm tagging these as help wanted to see if someone else wants to contribute them

@bitshifter bitshifter added the help wanted Extra attention is needed label Jan 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants