-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
base: main
Are you sure you want to change the base?
Changes from all commits
e208198
74b9d7f
2bbd809
84b87e5
ed7f031
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 |
---|---|---|
|
@@ -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? | ||
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. This needs to be resolved before we can merge. I'd leave a little comment here. |
||
fn sample_transmittance_lut_segment(r: f32, mu: f32, t: f32) -> vec3<f32> { | ||
let r_t = get_local_r(r, mu, t); | ||
let mu_t = clamp((r * mu + t) / r_t, -1.0, 1.0); | ||
|
||
if ray_intersects_ground(r, mu) { | ||
return min( | ||
sample_transmittance_lut(r_t, -mu_t) / sample_transmittance_lut(r, -mu), | ||
vec3(1.0) | ||
); | ||
} else { | ||
return min( | ||
sample_transmittance_lut(r, mu) / sample_transmittance_lut(r_t, mu_t), vec3(1.0) | ||
); | ||
} | ||
} | ||
|
||
fn sample_multiscattering_lut(r: f32, mu: f32) -> vec3<f32> { | ||
let uv = multiscattering_lut_r_mu_to_uv(r, mu); | ||
return textureSampleLevel(multiscattering_lut, multiscattering_lut_sampler, uv, 0.0).rgb; | ||
|
@@ -130,23 +147,31 @@ fn sample_sky_view_lut(r: f32, ray_dir_as: vec3<f32>) -> vec3<f32> { | |
return textureSampleLevel(sky_view_lut, sky_view_lut_sampler, uv, 0.0).rgb; | ||
} | ||
|
||
fn ndc_to_camera_dist(ndc: vec3<f32>) -> f32 { | ||
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. Note here that there is also a bevy PBR builtin for this 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. I believe that function only returns the "parallel" distance from the camera to the object, i.e. 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. Oh true I didn't think about the bindings, scratch that :D |
||
let view_pos = view.view_from_clip * vec4(ndc, 1.0); | ||
let t = length(view_pos.xyz / view_pos.w) * settings.scene_units_to_m; | ||
return t; | ||
} | ||
|
||
// RGB channels: total inscattered light along the camera ray to the current sample. | ||
// A channel: average transmittance across all wavelengths to the current sample. | ||
fn sample_aerial_view_lut(uv: vec2<f32>, depth: f32) -> vec4<f32> { | ||
let view_pos = view.view_from_clip * vec4(uv_to_ndc(uv), depth, 1.0); | ||
let dist = length(view_pos.xyz / view_pos.w) * settings.scene_units_to_m; | ||
fn sample_aerial_view_lut(uv: vec2<f32>, t: f32) -> vec3<f32> { | ||
let t_max = settings.aerial_view_lut_max_distance; | ||
let num_slices = f32(settings.aerial_view_lut_size.z); | ||
// Offset the W coordinate by -0.5 over the max distance in order to | ||
// align sampling position with slice boundaries, since each texel | ||
// stores the integral over its entire slice | ||
let uvw = vec3(uv, saturate(dist / t_max - 0.5 / num_slices)); | ||
// Each texel stores the value of the scattering integral over the whole slice, | ||
// which requires us to offset the w coordinate by half a slice. For | ||
// example, if we wanted the value of the integral at the boundary between slices, | ||
// we'd need to sample at the center of the previous slice, and vice-versa for | ||
// sampling in the center of a slice. | ||
let uvw = vec3(uv, saturate(t / t_max - 0.5 / num_slices)); | ||
let sample = textureSampleLevel(aerial_view_lut, aerial_view_lut_sampler, uvw, 0.0); | ||
// Treat the first slice specially since there is 0 scattering at the camera | ||
let delta_slice = t_max / num_slices; | ||
let fade = saturate(dist / delta_slice); | ||
// Since sampling anywhere between w=0 and w=t_slice will clamp to the first slice, | ||
// we need to do a linear step over the first slice towards zero at the camera's | ||
// position to recover the correct integral value. | ||
let t_slice = t_max / num_slices; | ||
let fade = saturate(t / t_slice); | ||
// Recover the values from log space | ||
return exp(sample) * fade; | ||
return exp(sample.rgb) * fade; | ||
} | ||
|
||
// PHASE FUNCTIONS | ||
|
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.
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?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.
If it's a direct port with no significant practical changes then I'd say the license still applies.