Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into brp
Browse files Browse the repository at this point in the history
  • Loading branch information
pcwalton committed May 30, 2024
2 parents 58d4a57 + 4065098 commit fb56bca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
24 changes: 12 additions & 12 deletions crates/bevy_core_pipeline/src/auto_exposure/auto_exposure.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,25 @@ fn compute_average(@builtin(local_invocation_index) local_index: u32) {
count += bin_count;
}

var target_exposure = 0.0;
var avg_lum = settings.min_log_lum;

if count > 0u {
// The average luminance of the included histogram samples.
let avg_lum = sum / (f32(count) * 63.0)
avg_lum = sum / (f32(count) * 63.0)
* settings.log_lum_range
+ settings.min_log_lum;
}

// The position in the compensation curve texture to sample for avg_lum.
let u = (avg_lum - compensation_curve.min_log_lum) * compensation_curve.inv_log_lum_range;
// The position in the compensation curve texture to sample for avg_lum.
let u = (avg_lum - compensation_curve.min_log_lum) * compensation_curve.inv_log_lum_range;

// The target exposure is the negative of the average log luminance.
// The compensation value is added to the target exposure to adjust the exposure for
// artistic purposes.
target_exposure = textureLoad(tex_compensation, i32(saturate(u) * 255.0), 0).r
* compensation_curve.compensation_range
+ compensation_curve.min_compensation
- avg_lum;
}
// The target exposure is the negative of the average log luminance.
// The compensation value is added to the target exposure to adjust the exposure for
// artistic purposes.
let target_exposure = textureLoad(tex_compensation, i32(saturate(u) * 255.0), 0).r
* compensation_curve.compensation_range
+ compensation_curve.min_compensation
- avg_lum;

// Smoothly adjust the `exposure` towards the `target_exposure`
let delta = target_exposure - exposure;
Expand Down
13 changes: 6 additions & 7 deletions crates/bevy_ui/src/render/ui.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,7 @@ fn antialias(distance: f32) -> f32 {
return clamp(0.0, 1.0, 0.5 - distance);
}

fn draw(in: VertexOutput) -> vec4<f32> {
let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv);

fn draw(in: VertexOutput, texture_color: vec4<f32>) -> vec4<f32> {
// Only use the color sampled from the texture if the `TEXTURED` flag is enabled.
// This allows us to draw both textured and untextured shapes together in the same batch.
let color = select(in.color, in.color * texture_color, enabled(in.flags, TEXTURED));
Expand Down Expand Up @@ -161,8 +159,7 @@ fn draw(in: VertexOutput) -> vec4<f32> {
return vec4(color.rgb, saturate(color.a * t));
}

fn draw_background(in: VertexOutput) -> vec4<f32> {
let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv);
fn draw_background(in: VertexOutput, texture_color: vec4<f32>) -> vec4<f32> {
let color = select(in.color, in.color * texture_color, enabled(in.flags, TEXTURED));

// When drawing the background only draw the internal area and not the border.
Expand All @@ -173,9 +170,11 @@ fn draw_background(in: VertexOutput) -> vec4<f32> {

@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
let texture_color = textureSample(sprite_texture, sprite_sampler, in.uv);

if enabled(in.flags, BORDER) {
return draw(in);
return draw(in, texture_color);
} else {
return draw_background(in);
return draw_background(in, texture_color);
}
}
2 changes: 1 addition & 1 deletion examples/3d/auto_exposure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn setup(

commands.spawn(PointLightBundle {
point_light: PointLight {
intensity: 5000.0,
intensity: 2000.0,
..default()
},
transform: Transform::from_xyz(0.0, 0.0, 0.0),
Expand Down

0 comments on commit fb56bca

Please sign in to comment.