-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Parallax-corrected cubemaps for reflection probes (adopted) #22582
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
Conversation
Bevy doesn't currently ever apply parallax correction to cubemaps, so reflections are rendered as though the environment were infinitely far away. This is often acceptable for outdoor scenes in which the environment is very distant, but for indoor scenes and dense environments this is undesirable. The standard solution for this problem is *parallax correction*, in which each reflection probe is augmented with a bounding box, and a raytrace is performed against the bounding box in order to determine the proper direction for sampling the cubemap. This commit implements parallax correction in Bevy in an opt-in manner. Add the `ParallaxCorrect` component to a `LightProbe` with an `EnvironmentMapLight` in order to opt into it. The bounding box used for parallax correction is assumed to be identical to the bounding box of the influence of the reflection probe itself. This is a reasonable default and matches what Blender does; it's what you want when you have, for example, a cubemap that captures the interior of a rectangular room. However, a future follow-up PR may wish to extend this so that the bounding box used for parallax correction might not coincide with the bounding box used for the influence of the reflection probe. This would require increasing the GPU size of the light probe data, so in order to keep this patch small and self-contained, I opted to defer this potential future enhancement to a follow-up. The patch is generally straightforward, adding only the minimal enhancements to the `LightProbe` trait and the GPU representation of light probes needed to propagate the parallax correction flag through the rendering pipeline. Additionally, this commit fixes a bug whereby the transform of each cubemap reflection probe wasn't being taken into account in the shader. I believe that this was being masked because most cubemaps are rendered in world space and therefore most cubemap reflection probes have an identity rotation. A new example, `pccm`, has been added, demonstrating the effect of parallax correction. It shows a scene consisting of an outer textured cube with an inner rotating reflective cube. The outer textured cube contains a reflection probe containing a snapshot of the scene (prerendered in Blender). Parallax correction can be toggled on and off in the example in order to demonstrate its effect.
|
(blocked until assets pr merges) |
|
Merged assets PR :) |
pcwalton
left a comment
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.
Up to y’all whether this review counts given that this is 99% my code, but LGTM anyway :)
I'll say that your review + vero's review sums to 1 approval :) |
superdump
left a comment
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.
Looks good to me.

Objective
Solution
Testing