Skip to content

Clipspace implementations for left/righted-handed coordinate systems and [-1,1] and [0,1] clipspace #198

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

Merged
merged 13 commits into from
May 23, 2021

Conversation

raedwulf
Copy link
Contributor

No description provided.

michael-g and others added 5 commits May 13, 2021 23:18
This commit adds the function `glm_perspective_lh_zo`, modelled on the
implementation of glm_perspective, but amended to provide a left-hand
coordinate system expected by DirectX, Metal and Vulkan (per the GLM
project's `glm/detail/setup.hpp`). It uses a clip-space of zero-to-one.

The function is tested against a longhand version of the algorithm it
seeks to implement as well as against the output of the GLM project's
`glm::perspectiveLH_ZO` function. This commit adds a new subdirectory
`test/glm_cmp` which contains a basic CMake file and `main.cpp`. An
interested user should link or copy or clone the GLM project into this
directory. The `main` function can be used to print the reference data
used so others can verify behaviour in the future, or add new literal
reference values.
This commit adds the RH/ZO perspective function. It does so in the new
file `cam_rh_zo.h` and further refactors the LH variant into new file
`cam_lh_zo.h`. This creates some churn in the tests and configuration
files as new test files were added as well, and all these changes found
their way into the build files.

Tests passing on Linux.
This commit adds functions `glm_perspective_lh_no` and
`glm_perspective_rh_no` to the code. Unit tests are added and this
commit follows the new pattern of adding the a new file per
coordinate-system and clip-space tuple.

. Makefile.am updated
. removed test/glm_cmp project stub
. unit tests include naive implementations to as well as magic number
  ref-data generated by the corresponding GLM functions.

No tests run yet on Windows or Mac.
Add the initial implementations of the left-handed and right-handed
coordinate systems as well as clipspace depth values of [-1, 0] and
[0, 1].
@raedwulf
Copy link
Contributor Author

@michael-g @recp The tests are still failing but it's a start for some early reviewing

raedwulf and others added 2 commits May 14, 2021 15:25
@michael-g
Copy link
Contributor

Will hopefully do some more later on, but this is a huge amount of work you've done, @raedwulf. Awesome stuff.

@recp
Copy link
Owner

recp commented May 14, 2021

Hi @raedwulf, @michael-g,

Sorry for the late response :/

Many thanks for this work, as @michael-g said this is a huge work.

Should we separate files by persp_[lh|rh]_[no|zo].h, ortho_[lh|rh]_[no|zo].h ... or proj_[lh|rh]_[no|zo].h and view_[lh|rh]_[no|zo].h ?

Also there is a struct api, we should add wrappers fo this change into include/cglm/stuct/clipspace. Struct is just wrappers to existing array api.

@raedwulf
Copy link
Contributor Author

I'll look into the struct API. Currently we do have an extra separation for view too. Would proj just be the combination of ortho and persp? @recp

@recp
Copy link
Owner

recp commented May 15, 2021

Would proj just be the combination of ortho and persp?

Yes, but I'm not sure which way is better, separating them or joining them. There are lot of persp functions and maybe come more for both ortho and persp, in this case separating them may be good idea.

@recp recp linked an issue May 15, 2021 that may be closed by this pull request
#define CGLM_CLIP_CONTROL_LH_NO (CGLM_CLIP_CONTROL_LH_BIT | CGLM_CLIP_CONTROL_NO_BIT)
#define CGLM_CLIP_CONTROL_RH_ZO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_ZO_BIT)
#define CGLM_CLIP_CONTROL_RH_NO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_NO_BIT)

Copy link
Owner

Choose a reason for hiding this comment

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

Can we add these options to docs/source/opt.rst? People can recognize the options quickly when reading docs.

@recp
Copy link
Owner

recp commented May 15, 2021

Maybe this is not one of goal of the PR and out of scope, but I'm wonder that should cglm need anything else to support LH. For instance transforms (matrix rotations, quaternions, vector rotations...).

Also there are frustum helpers in frustum.h e.g extracts planes, corners... Unproject functions in project.h... I'm not sure what else should be done to fully support LH.

Actually users should achieve same rotation around X and Y by negating angle but Z should remain same I think. Maybe we should discuss these in another issue[s].

@recp
Copy link
Owner

recp commented May 17, 2021

@raedwulf ping.

I think we need to add tests for other functions too, after that we can merge this PR if there are no any issues

@michael-g
Copy link
Contributor

Do you have a sense of how you'd like to approach the testing? We could continue with the small amount of work I've done and paste a load of magic numbers into the tests, or go ahead with the new repository which compares cglm implementations again the glm library? The former is much more of a unit test, obviously, but the latter has its own benefits.

@raedwulf
Copy link
Contributor Author

I looked into the struct API and I can get it done soonish :) thanks @michael-g that would be great!

@recp
Copy link
Owner

recp commented May 17, 2021

Do you have a sense of how you'd like to approach the testing? We could continue with the small amount of work I've done and paste a load of magic numbers into the tests, or go ahead with the new repository which compares cglm implementations again the glm library? The former is much more of a unit test, obviously, but the latter has its own benefits.

@michael-g I think we should add unit tests first then library-to-library test can be written later. The magic numbers could come from the math instead of glm directly, or both maybe, glm also needs tests... I have just created a repo called cglm-libtests, the name can be changed with better one...

I looked into the struct API and I can get it done soonish :)

Awesome!

@recp
Copy link
Owner

recp commented May 20, 2021

It would be nice to finish this work asap, I can merge this PR and we can add tests with new PRs maybe?

@raedwulf @michael-g any progress?

@raedwulf
Copy link
Contributor Author

@recp Just a bit busy last few days, but I'll spend some time this weekend to finalise things with the struct api.

@recp
Copy link
Owner

recp commented May 20, 2021

@raedwulf great 🤗, thanks

@michael-g
Copy link
Contributor

It would be nice to finish this work asap, I can merge this PR and we can add tests with new PRs maybe?

@raedwulf @michael-g any progress?

Sorry, I've been busy with work and family stuff.

If only we could auto-gen a bunch of tests using results from GLM...

@raedwulf
Copy link
Contributor Author

I pushed the struct api stuff @recp @michael-g

@recp
Copy link
Owner

recp commented May 23, 2021

@raedwulf awesome work,

There was no need to add clip control to default strruct api like this:

CGLM_INLINE
mat4s
glms_frustum(float left,   float right,
             float bottom, float top,
             float nearZ,  float farZ) {
#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO
  return glms_frustum_lh_zo(left, right, bottom, top, nearZ, farZ);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO
  return glms_frustum_lh_no(left, right, bottom, top, nearZ, farZ);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO
  return glms_frustum_rh_zo(left, right, bottom, top, nearZ, farZ);
#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO
  return glms_frustum_rh_no(left, right, bottom, top, nearZ, farZ);
#endif
}

clip control already done in glm_frustum() this could be just a wrapper as before. But since you did it, let's keep it.

@recp
Copy link
Owner

recp commented May 23, 2021

Now we need to add tests ;)

@raedwulf
Copy link
Contributor Author

Ahh, yeah that's true. That file could be reverted with no problems though.

@recp
Copy link
Owner

recp commented May 23, 2021

@raedwulf @michael-g I'm going to merge this PR, but let's improve this by adding tests, bug fixes with new PRs...

This is still valid question for me: #198 (comment)

Feel free to open issues and bring tests, bugfixes

@raedwulf @michael-g many thanks for this work 🤗

@recp recp merged commit 9ac291c into recp:master May 23, 2021
@recp
Copy link
Owner

recp commented May 23, 2021

@raedwulf @michael-g the PR is merged, many thanks 🤗 🎉

Let's write tests ;)

@michael-g
Copy link
Contributor

@raedwulf, kudos, amazing work. Will try to contribute this week to the testing code. Again: is there a source of reference implementations?

@raedwulf
Copy link
Contributor Author

Hey @michael-g, they are based on the cglm source code and the glm code for the differences.

@warmwaffles
Copy link

@raedwulf Love this! Thank you so much for pushing this through.

@raedwulf
Copy link
Contributor Author

@warmwaffles thanks! We're still in the process of testing this and any feedback will be great!

@recp
Copy link
Owner

recp commented May 26, 2021

We should announce this feature after the tests are done e.g. reddit, gamedev... I'll try what I can... After used by community then more improvements can be made.

Great to have great community 🎉

@quadroli
Copy link
Contributor

Wow, been following along this project for a while, glad to see it come to fruition, excellent work all at @michael-g @raedwulf and @recp for the insights, kudos 🥳

@quadroli
Copy link
Contributor

Quick question, are there noticeable to changes on how to use the library now?

@recp
Copy link
Owner

recp commented May 28, 2021

@quadroli thanks,

are there noticeable to changes on how to use the library now

Actually not, just optionally it is possible to use other clipspaces rather than OpenGL's one now, if there are no any bugs

@quadroli
Copy link
Contributor

Awesome 👍
Love the new look to, iss clean 🧼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TODO: Make cglm work with Metal, Vulkan and DirectX Support for Vulkan NDC.
5 participants