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

Use dual-source blending for rendering the sky #17672

Merged
merged 7 commits into from
Feb 11, 2025

Conversation

ecoskey
Copy link
Contributor

@ecoskey ecoskey commented Feb 4, 2025

Objective

Since previously we only had the alpha channel available, we stored the mean of the transmittance in the aerial view lut, resulting in a grayer fog than should be expected.

Solution

  • Calculate transmittance to scene in render_sky with two samples from the transmittance lut
  • use dual-source blending to effectively have per-component alpha blending

@ecoskey ecoskey added A-Rendering Drawing game state to the screen D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 4, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Feb 4, 2025
@alice-i-cecile
Copy link
Member

@mate-h this one is for you :)

@mate-h
Copy link
Contributor

mate-h commented Feb 4, 2025

I've had an initial look at this, and using dual source blending is a great idea, the diff looks good to me. I went to test things out and noticed some inaccuracies between what I expect to see ground truth, vs the results seem to be shifting colors in the rendered geometry toward orange.
I dug a bit deeper and it's likely an issue in either how we sample the transmittance lut or how we calculate the transmittance though the atmosphere for a path segment to the scene depth from the camera using that function.
I will continue investigating and testing this further.

I pushed all my testing code to the https://github.com/mate-h/bevy/tree/atmosphere-test branch and will keep working on that.

Screenshot 2025-02-04 at 12 22 05 AM

thanks @mate-h for more debugging help and your fancy reference
raymarcher!
@mate-h
Copy link
Contributor

mate-h commented Feb 7, 2025

After this last iteration and more thorough testing we were able to identify the source of the issue. I've tested both cases of the geometry above and below the horizon and the math checks out compared to the raymarched reference.
Test case for when the ray intersects the ground:
image

Test case for when the ray does not intersect the ground (else block):
image

@@ -118,6 +118,23 @@ fn sample_transmittance_lut(r: f32, mu: f32) -> vec3<f32> {
return textureSampleLevel(transmittance_lut, transmittance_lut_sampler, uv, 0.0).rgb;
}

//should be in bruneton_functions, but wouldn't work in that module bc imports. What to do wrt licensing?
Copy link
Contributor

@mate-h mate-h Feb 7, 2025

Choose a reason for hiding this comment

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

I think we should just leave a comment saying that the license in the bruneton_functions.wgsl file applies to this function, or come up with some way to reorganize the imports. Also just in general, since the code is not exaclty the same as bruneton's verison, it is a WGSL re-write, not sure how the licensing works because I am no legal expert. but does it still apply?

Copy link
Contributor

Choose a reason for hiding this comment

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

If it's a direct port with no significant practical changes then I'd say the license still applies.

@mate-h
Copy link
Contributor

mate-h commented Feb 8, 2025

@alice-i-cecile this one is ready for final review and merge when you get a chance!

@alice-i-cecile
Copy link
Member

Needs a second rendering review :)

@@ -118,6 +118,23 @@ fn sample_transmittance_lut(r: f32, mu: f32) -> vec3<f32> {
return textureSampleLevel(transmittance_lut, transmittance_lut_sampler, uv, 0.0).rgb;
}

//should be in bruneton_functions, but wouldn't work in that module bc imports. What to do wrt licensing?
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be resolved before we can merge. I'd leave a little comment here.

Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

image
image

Can still see the sun shining when it's night, which didn't seem to be the case on main.

@mate-h
Copy link
Contributor

mate-h commented Feb 10, 2025

Good point! There is a couple issues on main that may be unrelated to this PR:

  1. The shadow maps are broken on OSX
  2. The PBR is not yet integrated to the atmosphere, I started working on that now at https://github.com/mate-h/bevy/tree/pbr-atmosphere

So we might see light on objects in this example because of shadows maps not working, and the directional light not being occluded by the atmosphere or the planet earth. As far as I can tell this has not changed compared to main.

@tychedelia
Copy link
Contributor

So we might see light on objects in this example because of shadows maps not working, and the directional light not being occluded by the atmosphere or the planet earth. As far as I can tell this has not changed compared to main.

I tested this PR on macOS and main on windows so that would make sense!

Copy link
Contributor

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

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

Confirmed on windows. LGTM pending other comments!

@tychedelia tychedelia added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Feb 10, 2025
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

The comment about the license needs to be resolved before I can merge this. To resolve this:

  1. Mention that this is related to the bruneton_functions
  2. Credit the original author in the comment
  3. Name the license that it's used under in that comment.

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Feb 10, 2025
@ecoskey ecoskey added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Feb 10, 2025
@ecoskey
Copy link
Contributor Author

ecoskey commented Feb 10, 2025

@alice-i-cecile fixed! :)

@alice-i-cecile alice-i-cecile added this pull request to the merge queue Feb 10, 2025
Merged via the queue into bevyengine:main with commit 83370e0 Feb 11, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants