Add dodge/burn tool
This commit is contained in:
@@ -173,6 +173,7 @@ impl InfopanelPane {
|
||||
tool,
|
||||
Tool::Draw | Tool::Pencil | Tool::Pen | Tool::Airbrush
|
||||
| Tool::Erase | Tool::Smudge | Tool::CloneStamp | Tool::HealingBrush | Tool::PatternStamp
|
||||
| Tool::DodgeBurn
|
||||
);
|
||||
|
||||
// Only show tool options for tools that have options
|
||||
@@ -197,6 +198,7 @@ impl InfopanelPane {
|
||||
Tool::CloneStamp => "Clone Stamp",
|
||||
Tool::HealingBrush => "Healing Brush",
|
||||
Tool::PatternStamp => "Pattern Stamp",
|
||||
Tool::DodgeBurn => "Dodge / Burn",
|
||||
_ => "Brush",
|
||||
}
|
||||
} else {
|
||||
@@ -358,6 +360,37 @@ impl InfopanelPane {
|
||||
self.render_raster_tool_options(ui, shared, false);
|
||||
}
|
||||
|
||||
Tool::DodgeBurn if is_raster_paint_tool => {
|
||||
ui.horizontal(|ui| {
|
||||
if ui.selectable_label(*shared.dodge_burn_mode == 0, "Dodge").clicked() {
|
||||
*shared.dodge_burn_mode = 0;
|
||||
}
|
||||
if ui.selectable_label(*shared.dodge_burn_mode == 1, "Burn").clicked() {
|
||||
*shared.dodge_burn_mode = 1;
|
||||
}
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Size:");
|
||||
ui.add(egui::Slider::new(shared.dodge_burn_radius, 1.0_f32..=500.0).logarithmic(true).suffix(" px"));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Exposure:");
|
||||
ui.add(egui::Slider::new(shared.dodge_burn_exposure, 0.0_f32..=1.0)
|
||||
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Hardness:");
|
||||
ui.add(egui::Slider::new(shared.dodge_burn_hardness, 0.0_f32..=1.0)
|
||||
.custom_formatter(|v, _| format!("{:.0}%", v * 100.0)));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Spacing:");
|
||||
ui.add(egui::Slider::new(shared.dodge_burn_spacing, 0.5_f32..=20.0)
|
||||
.logarithmic(true)
|
||||
.custom_formatter(|v, _| format!("{:.1}", v)));
|
||||
});
|
||||
}
|
||||
|
||||
Tool::Smudge if is_raster_paint_tool => {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Size:");
|
||||
|
||||
@@ -212,6 +212,13 @@ pub struct SharedPaneState<'a> {
|
||||
pub pattern_type: &'a mut u32,
|
||||
/// Pattern stamp: tile size in pixels
|
||||
pub pattern_scale: &'a mut f32,
|
||||
/// Dodge/Burn tool settings
|
||||
pub dodge_burn_radius: &'a mut f32,
|
||||
pub dodge_burn_hardness: &'a mut f32,
|
||||
pub dodge_burn_spacing: &'a mut f32,
|
||||
pub dodge_burn_exposure: &'a mut f32,
|
||||
/// 0 = dodge (lighten), 1 = burn (darken)
|
||||
pub dodge_burn_mode: &'a mut u32,
|
||||
/// Audio engine controller for playback control (wrapped in Arc<Mutex<>> for thread safety)
|
||||
pub audio_controller: Option<&'a std::sync::Arc<std::sync::Mutex<daw_backend::EngineController>>>,
|
||||
/// Video manager for video decoding and frame caching
|
||||
|
||||
@@ -240,6 +240,26 @@ fn apply_dab(current: vec4<f32>, dab: GpuDab, px: i32, py: i32) -> vec4<f32> {
|
||||
alpha * corrected.b + ba * current.b,
|
||||
alpha * corrected.a + ba * current.a,
|
||||
);
|
||||
} else if dab.blend_mode == 6u {
|
||||
// Dodge / Burn: power-curve exposure adjustment.
|
||||
// color_r: 0.0 = dodge, 1.0 = burn
|
||||
// Uses pow(channel, gamma) which is asymmetric across channels:
|
||||
// burn (gamma > 1): low channels compressed toward 0 faster than high ones → saturation increases
|
||||
// dodge (gamma < 1): low channels lifted faster than high ones → saturation decreases
|
||||
// This matches the behaviour of GIMP / Photoshop dodge-burn tools.
|
||||
let s = opa_weight * dab.opacity;
|
||||
if s <= 0.0 { return current; }
|
||||
|
||||
let rgb = max(current.rgb, vec3<f32>(0.0));
|
||||
var adjusted: vec3<f32>;
|
||||
if dab.color_r < 0.5 {
|
||||
// Dodge: gamma < 1 → brightens
|
||||
adjusted = pow(rgb, vec3<f32>(max(1.0 - s, 0.001)));
|
||||
} else {
|
||||
// Burn: gamma > 1 → darkens and increases saturation
|
||||
adjusted = pow(rgb, vec3<f32>(1.0 + s));
|
||||
}
|
||||
return vec4<f32>(clamp(adjusted, vec3<f32>(0.0), vec3<f32>(1.0)), current.a);
|
||||
} else {
|
||||
return current;
|
||||
}
|
||||
|
||||
@@ -617,6 +617,7 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
clone_src_offset: None,
|
||||
pattern_type: 0,
|
||||
pattern_scale: 32.0,
|
||||
dodge_burn_mode: 0,
|
||||
points: vec![
|
||||
StrokePoint { x: x0, y: y_lo, pressure: 1.0, tilt_x: 0.0, tilt_y: 0.0, timestamp: 0.0 },
|
||||
StrokePoint { x: mid_x, y: mid_y, pressure: 1.0, tilt_x: 0.0, tilt_y: 0.0, timestamp: 0.0 },
|
||||
@@ -4885,6 +4886,13 @@ impl StagePane {
|
||||
*shared.smudge_hardness,
|
||||
*shared.smudge_spacing,
|
||||
),
|
||||
RasterBlendMode::DodgeBurn => (
|
||||
lightningbeam_core::brush_settings::BrushSettings::default(),
|
||||
*shared.dodge_burn_radius,
|
||||
*shared.dodge_burn_exposure,
|
||||
*shared.dodge_burn_hardness,
|
||||
*shared.dodge_burn_spacing,
|
||||
),
|
||||
_ => (
|
||||
shared.active_brush_settings.clone(),
|
||||
*shared.brush_radius,
|
||||
@@ -4978,6 +4986,7 @@ impl StagePane {
|
||||
clone_src_offset: self.clone_stroke_offset,
|
||||
pattern_type: *shared.pattern_type,
|
||||
pattern_scale: *shared.pattern_scale,
|
||||
dodge_burn_mode: *shared.dodge_burn_mode,
|
||||
points: vec![first_pt.clone()],
|
||||
};
|
||||
let (dabs, dab_bbox) = BrushEngine::compute_dabs(&single, &mut stroke_state, 0.0);
|
||||
@@ -5069,6 +5078,7 @@ impl StagePane {
|
||||
clone_src_offset: self.clone_stroke_offset,
|
||||
pattern_type: *shared.pattern_type,
|
||||
pattern_scale: *shared.pattern_scale,
|
||||
dodge_burn_mode: *shared.dodge_burn_mode,
|
||||
points: vec![first_pt.clone()],
|
||||
};
|
||||
let (dabs, dab_bbox) = BrushEngine::compute_dabs(&single, &mut stroke_state, 0.0);
|
||||
@@ -5156,6 +5166,7 @@ impl StagePane {
|
||||
clone_src_offset,
|
||||
pattern_type: *shared.pattern_type,
|
||||
pattern_scale: *shared.pattern_scale,
|
||||
dodge_burn_mode: *shared.dodge_burn_mode,
|
||||
points: vec![prev_pt, curr_local],
|
||||
};
|
||||
let current_time = ui.input(|i| i.time);
|
||||
@@ -5220,6 +5231,7 @@ impl StagePane {
|
||||
clone_src_offset: self.clone_stroke_offset,
|
||||
pattern_type: *shared.pattern_type,
|
||||
pattern_scale: *shared.pattern_scale,
|
||||
dodge_burn_mode: *shared.dodge_burn_mode,
|
||||
points: vec![pt],
|
||||
};
|
||||
let (dabs, dab_bbox) = BrushEngine::compute_dabs(&single, stroke_state, dt);
|
||||
@@ -7586,6 +7598,9 @@ impl StagePane {
|
||||
Tool::PatternStamp => {
|
||||
self.handle_raster_stroke_tool(ui, &response, world_pos, lightningbeam_core::raster_layer::RasterBlendMode::PatternStamp, shared);
|
||||
}
|
||||
Tool::DodgeBurn => {
|
||||
self.handle_raster_stroke_tool(ui, &response, world_pos, lightningbeam_core::raster_layer::RasterBlendMode::DodgeBurn, shared);
|
||||
}
|
||||
Tool::SelectLasso => {
|
||||
self.handle_raster_lasso_tool(ui, &response, world_pos, shared);
|
||||
}
|
||||
@@ -8066,8 +8081,8 @@ impl StagePane {
|
||||
Tool::Erase => (*shared.eraser_radius, *shared.eraser_radius, 0.0_f32),
|
||||
Tool::Smudge
|
||||
| Tool::BlurSharpen
|
||||
| Tool::DodgeBurn
|
||||
| Tool::Sponge => (*shared.smudge_radius, *shared.smudge_radius, 0.0_f32),
|
||||
Tool::DodgeBurn => (*shared.dodge_burn_radius, *shared.dodge_burn_radius, 0.0_f32),
|
||||
_ => {
|
||||
let bs = &shared.active_brush_settings;
|
||||
let r = *shared.brush_radius;
|
||||
|
||||
Reference in New Issue
Block a user