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

Remove hand tuning of light projection near/far for a scene in CSM example #312

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lhog
Copy link

@lhog lhog commented Jun 24, 2022

No description provided.

@JoeyDeVries
Copy link
Owner

@arbmarton is this PR something you're aware of and do you agree?

@arbmarton
Copy link

@JoeyDeVries no it is not something I'm aware of.

@lhog Thank you for taking an interest in the CSM example! Could you please elaborate on the changes? I hadn't read the diff yet completely but please note that the article on the website heavily references the code. So with a code update an article update is needed too, and I currently do not have the time for that, maybe in august.

@arbmarton
Copy link

arbmarton commented Jul 11, 2022

Also if you have suggestions I think it would be best to discuss them on the Disqus page under the article, in that way others can learn from our trail of thought talking about your ideas. I'm subscribed to email notifications, so I will definitely see your comment there.

@lhog
Copy link
Author

lhog commented Jul 11, 2022

Could you please elaborate on the changes?

Apart from some cosmetic changes, the essence of it is to teach how to fit znear/zfar values to match the current scene.
You had hand tuning of Z params // Tune this parameter according to the scene, which used somewhat arbitrary multiplications/divisions.

Instead the code takes all scene objects (cubes and ground plane) and project them in light view space. Upon the projection, minimum and maximum values of Z are calculated and then applied to construct light-space projection matrix. Ideally there should be additional checks on whether an object lies within AABB of main camera frustum re-projected into light view space, but I don't think I actually implemented it.

As for the site change, you have

Before creating the actual projection matrix we are going to increase the size of the space covered by the near and far plane of the light frustum. We do this by "pulling back" the near plane, and "pushing away" the far plane. In the code we achieve this by dividing or multiplying by zMult. This is because we want to include geometry which is behind or in front of our frustum in camera space. Think about it: not only geometry which is in the frustum can cast shadows on a surface in the frustum!

So this will need to change to explain how znear and zfar could be calculated from the scene itself (though in a slightly naive way)

@JoeyDeVries
Copy link
Owner

While automatic tuning is beneficial, I don't think going straight to automatic tuning would work for the article's educational strength. It would be a lot of information straight at once. I'll leave the specifics to you @arbmarton and wether you want to include this, but if you do it's best suited as an extra at (or close to) the end of the chapter in my opinion.

@lhog
Copy link
Author

lhog commented Jul 11, 2022

Up to you guys, but I found myself guessing why zMult was 10 and not something else and why there is conditional multiplication/division. Fitting to a scene bounds sounds more natural to me.

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