-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Implement irradiance volumes. #10268
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
Changes from all commits
eed7a5e
98bb888
cba53fb
b44606b
fb06e35
2a2ad49
7c45a73
a09e905
b52f2c3
1ba097e
d5f03cc
97b918c
5c098dc
3cd80d1
6f52710
3fec44d
e6b87d7
6828b57
61a218d
e2ede68
c031ea7
b213c42
04b9b9c
ca1d55b
526765b
626a331
01614c0
4d94307
8715322
4133486
4012944
3658f09
4679047
33e04e0
f11974a
a1fd586
ec66539
e154aff
9b3adbe
bd1ad68
5aa7d07
4b93e7a
58d8ae7
b33d265
e37a2f9
4bd2a59
1d68172
d41d09d
802a787
4b14471
5601bda
6488c9f
6327f5a
19472e1
cec1780
52e3e6e
ee22f27
b6fa053
c849267
c2a79f3
11e5379
c6c3043
211740d
5ca61e7
108b931
27e4322
40c6e22
7d213ba
9391113
3405756
3894285
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #import bevy_pbr::forward_io::VertexOutput | ||
| #import bevy_pbr::irradiance_volume | ||
| #import bevy_pbr::mesh_view_bindings | ||
|
|
||
| struct VoxelVisualizationIrradianceVolumeInfo { | ||
| transform: mat4x4<f32>, | ||
| inverse_transform: mat4x4<f32>, | ||
| resolution: vec3<u32>, | ||
| // A scale factor that's applied to the diffuse and specular light from the | ||
| // light probe. This is in units of cd/m² (candela per square meter). | ||
| intensity: f32, | ||
| } | ||
|
|
||
| @group(2) @binding(100) | ||
| var<uniform> irradiance_volume_info: VoxelVisualizationIrradianceVolumeInfo; | ||
|
|
||
| @fragment | ||
| fn fragment(mesh: VertexOutput) -> @location(0) vec4<f32> { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do the cubes appear to be gray+shaded? I was thinking we would want to show essentially an "unlit" solid-color cube the color of the probe.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They are doing what you suggested, I'm fairly sure. I don't see any shading. I believe the gray comes from the grayish background color, which is roughly the same in Blender so the indirect light from it is captured in the probe. The sides of the cubes will be a mix of the gray from the background with the colors of the floor visible from that cube side. The relative mix of gray vs. floor color is based on how much that side of the cube can "see".
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the irradiance volumes are sampling the clear color/background? Seems strange. ClearColor shouldn't be used for lighting. Only a Skybox if specified, but not the clear color itself.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In reality it's sampling the "world" in Blender which happens to be dark gray by default. Would you prefer that I change it to black? Or would you rather the world reflect the colors of the floor? (It can't be transparent because we don't have alpha here.) From a physical perspective it's kind of arbitrary what we pick since the concept of "empty space with no color" doesn't exist in the real world.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah I think that would be better. Or drop in a skybox and use that.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I added a skybox and re-baked the irradiance volume. It looks right to my eyes. |
||
| // Snap the world position we provide to `irradiance_volume_light()` to the | ||
| // middle of the nearest texel. | ||
| var unit_pos = (irradiance_volume_info.inverse_transform * | ||
| vec4(mesh.world_position.xyz, 1.0f)).xyz; | ||
| let resolution = vec3<f32>(irradiance_volume_info.resolution); | ||
| let stp = clamp((unit_pos + 0.5) * resolution, vec3(0.5f), resolution - vec3(0.5f)); | ||
| let stp_rounded = round(stp - 0.5f) + 0.5f; | ||
| let rounded_world_pos = (irradiance_volume_info.transform * vec4(stp_rounded, 1.0f)).xyz; | ||
|
|
||
| // `irradiance_volume_light()` multiplies by intensity, so cancel it out. | ||
| // If we take intensity into account, the cubes will be way too bright. | ||
| let rgb = irradiance_volume::irradiance_volume_light( | ||
| mesh.world_position.xyz, | ||
pcwalton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mesh.world_normal) / irradiance_volume_info.intensity; | ||
|
|
||
| return vec4<f32>(rgb, 1.0f); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.