-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add configurable shadow rendering #124
Conversation
This is just a draft. Don't merge, only evaluate. The renderer can now draw shadows via shadow mapping. This is used to collect shadows from rendered meshes and project them onto the ground plane (which is a plane mesh primitive). The `CommandBuffer::draw_meshes_*` family of functions now has a flag, whether the drawing should cast shadows. The `DrawMeshMode` enum has a new `FlatWithShadows` variant that can collect shadows. The structure is much more flexible internally in the renderer, but since the renderer does not support transparency yet, the outside usage is restricted. Known problems: - Vulkan validation errors for image layout transitions (this is probably not our fault, but it looks scary), - Screenshots with transparent background can now see ground, because it is not transparent. We can alternatively not render the ground plane for screenshots, - The ground is not transparent, objects are not visible from below, - We needed to disable the ground and shadows for `Edges` shading mode, because edges don't write their depth, meaning the ground would overwrite them - Possibly much more... Please evaluate this PR and let me know if we want to merge it as-is (or with minor fixes), not merge it at all, or work on the transparency issues.
046cfaa
to
4044b98
Compare
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.
Nice and it does all that we discussed.
Let's disable shadows for transparent screenshots.
Thanks! I'll have a fresh look at the code later and clean it up before merging. |
I've given it some thought and think that proper (or at least not terribly incorrect) transparency is within our grasp. Probably less than a day of work. I'll update the PR with that next week. If anyone wants to review the code, I can merge this first and add transparency with another PR to make the reviewer's job easier. |
Ready for review. |
Yeah, I believe that is a matcap rendering glitch, I've seen it before too. Don't exactly know what's causing it tbh.
Yes. For the same reason as before. We are already smoothing the shadows by doing PCF (percentage closer filtering) https://developer.nvidia.com/gpugems/gpugems/part-ii-lighting-and-shadows/chapter-11-shadow-map-antialiasing We could increase the number of samples to get marginally better results, but my machines already struggle with it when running on intel GPUs - this would make us require capable hardware for everyone, unless we had a flag to turn it down. Not sure if that's worth it. I can show you how to up the shadow quality so that you can experiment with different values. Currently, we treat the ground plane as just another mesh in the renderer that just uses a different
Not sure what you mean. We already have a fully transparent (not endless, but very large) ground. If the objects were transparent, you would see the shadow there, and you already can in the |
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.
As long as it is what I saw at your computer, we are good to merge. Have you considered setting the ground plane size according to scene's bounding box though?
Ok, I'll do it |
I still discovered some screenshot transparency issues with the new transparent ground. I'll need to investigate. Will merge after that is fixed. |
The renderer can now draw shadows via shadow mapping. This is used to collect
shadows from rendered meshes and project them onto the ground plane (which is a
plane mesh primitive).
The
CommandBuffer::draw_meshes_*
family of functions now has a flag, whetherthe drawing should cast shadows. The
DrawMeshMode
enum has a newFlatWithShadows
variant that can collect shadows. The structure is much moreflexible internally in the renderer, but not yet exposed. Also, the renderer now internally supports transparency, but the only way to render a transparent object is to provide a transparent color to the
flat_shading_color
option - that color is used forDrawMeshMode::FlatWithshadows
.Known problems:
our fault, but it looks scary),
it is not transparent. We can alternatively not render the ground plane for
screenshots.