-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix shadows for billboarded Sprite3D's #72638
Fix shadows for billboarded Sprite3D's #72638
Conversation
ded7a81
to
1790355
Compare
Sorry, my mistake; I see the page on code style now and I'll set up my format checker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
I am unsure about the naming of the new builtin so I would like to discuss this with other rendering contributors as soon as we are back to merging new features/ enhancements. Accordingly I am bumping this to the 4.1 milestone
1790355
to
87d4172
Compare
87d4172
to
3d99715
Compare
3d99715
to
91eb0ca
Compare
@clayjohn I think this is more of a bug than an enhancement since the shadows will be incorrect for billboarded Sprite3D's without this change. Currently the only way to accomplish billboarded Sprite3D's with shadows is by employing a workaround |
This comment was marked as off-topic.
This comment was marked as off-topic.
@ZainWD Please don't bump PRs without contributing significant new information. Use the 👍 reaction button on the first post instead. |
I don't think this is a good solution. If you're making a 2 player game with side by side screen (yeah people still make those), or if you have additional viewports for other reasons, you'll have two different camera that both show the billboard in a different way, but only for one shadows will be correct. Billboard is a technique that doesn't work well with shadows. If you're using it for LOD purposes, a billboard is only used when the object is far enough away that a shadow doesn't matter. If you're using it for something like a name above a player or a healthbar, than it just can't cast a shadow. In this case the object should not be billboarded in the shader but you should orient it in code. |
91eb0ca
to
d08bebe
Compare
@BastiaanOlij You're totally correct that this wouldn't make sense in any scenario with multiple cameras in the scene. I'd add to your example stereo rendering, where the shadows would be generated based on billboarding to the e.g. left camera and be slightly incorrect for the other eye. I also agree with you that most uses of billboards should not use shadows and will not benefit from this change, but this use case can simple disable shadows. However, I disagree that this makes this solution not worth having. As is, a beginner trying to create a single camera sprite game with 3D lighting (a la Octopath Traveler or Cult of the Lamb) will have to rotate the sprites in software themselves. I think this use case should work as intuitively out-of-the-box to avoid hurting a beginner who simply wants their |
I think this change makes sense, but the class reference must be modified to mention that this approach won't work in multi-viewport or XR scenarios. In this case, the only workaround I know is to render multiple Sprite3Ds with different layers (and changing each viewport's visible layers accordingly). |
@Calinou That would be a separate PR in the docs repo eh? I'll look into updating the |
In VR we always use quads that are properly positioned and aren't view aligned so there is stability in orientation regardless of the player turning their heads. |
Class reference changes should be done in That said, a separate PR for the 3D lights and shadows page on godot-docs is welcome. |
75fd218
to
709b4cb
Compare
Sorry for the delay in such a simple change: it's currently summer in Canada. I changed
I linked this PR since that could help a developer if they wanted to determine for which camera the shadow would be rendered (e.g. always wanting the shadow to be from a specific camera even with multiple cameras in the scene), but in most cases I would expect the billboards enabled and shadows enabled combination of settings to be a mistake when multiple cameras are used (e.g. couch co-op). |
709b4cb
to
86d64e9
Compare
I also added the same note under |
It might be worth refactoring |
e99c837
to
3e7e295
Compare
I also missed making this fix to the compatibility rendering backend so I've added those now and verified the 3D billboarded sprites shadows on all rendering backends |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking such a long time to review this. It took awhile to discuss with other contributors and then I kept poking at it and dropping it again.
Overall, I think the implementation looks great. I don't think there is a better way to implement this and I think you have done everything correctly.
While fixing the couple spelling issues in the docs, I would suggest rebasing on latest Edit: Done myself. |
3e7e295
to
eab9569
Compare
Thanks! |
This resolves #69026 and resolves #41420 in the
master
branch based on my reading of @clayjohn's suggested approach: the "main" camera transform is piped into the shader and the billboard always faces that transform, even when rendering shadow passes. I tested with both forward and mobile rendering backends.The
main_cam_inv_view_matrix
needed is added tostruct SceneData
since it seemed like "scene data" and there might be a future case for using it elsewhere in the shader. If it would make more sense for a conditionaluniform
to be used (like for other material features), I can change that.