painting fixes
This commit is contained in:
@@ -79,15 +79,19 @@ fn apply_dab(current: vec4<f32>, dab: GpuDab, px: i32, py: i32) -> vec4<f32> {
|
||||
let rr = (dx * dx + dy * dy) / (dab.radius * dab.radius);
|
||||
if rr > 1.0 { return current; }
|
||||
|
||||
// Two-segment linear falloff (identical to libmypaint calculate_opa)
|
||||
let h = clamp(dab.hardness, 0.001, 1.0);
|
||||
// Quadratic falloff: flat inner core, smooth quadratic outer zone.
|
||||
// r is the actual normalised distance [0,1]; h controls the hard-core radius.
|
||||
// Inner zone (r ≤ h): fully opaque.
|
||||
// Outer zone (r > h): opa = ((1-r)/(1-h))^2, giving a smooth bell-shaped dab.
|
||||
let h = clamp(dab.hardness, 0.0, 1.0);
|
||||
let r = sqrt(rr);
|
||||
var opa_weight: f32;
|
||||
if rr <= h {
|
||||
opa_weight = 1.0 + rr * (-(1.0 / h - 1.0));
|
||||
if h >= 1.0 || r <= h {
|
||||
opa_weight = 1.0;
|
||||
} else {
|
||||
opa_weight = h / (1.0 - h) + rr * (-h / (1.0 - h));
|
||||
let t = (1.0 - r) / (1.0 - h);
|
||||
opa_weight = t * t;
|
||||
}
|
||||
opa_weight = clamp(opa_weight, 0.0, 1.0);
|
||||
|
||||
if dab.blend_mode == 0u {
|
||||
// Normal: "over" operator
|
||||
|
||||
@@ -508,7 +508,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
if let Some(ref float_sel) = self.ctx.selection.raster_floating {
|
||||
if let Ok(mut gpu_brush) = shared.gpu_brush.lock() {
|
||||
if !gpu_brush.canvases.contains_key(&float_sel.canvas_id) {
|
||||
eprintln!("[CANVAS] lazy-init float canvas id={:?}", float_sel.canvas_id);
|
||||
gpu_brush.ensure_canvas(device, float_sel.canvas_id, float_sel.width, float_sel.height);
|
||||
if let Some(canvas) = gpu_brush.canvases.get(&float_sel.canvas_id) {
|
||||
let pixels = if float_sel.pixels.is_empty() {
|
||||
@@ -537,7 +536,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
);
|
||||
// On stroke start, upload the pre-stroke pixel data to both textures
|
||||
if let Some(ref pixels) = pending.initial_pixels {
|
||||
eprintln!("[STROKE] uploading initial_pixels for kf={:?} painting_float={}", pending.keyframe_id, self.ctx.painting_float);
|
||||
if let Some(canvas) = gpu_brush.canvases.get(&pending.keyframe_id) {
|
||||
canvas.upload(queue, pixels);
|
||||
}
|
||||
@@ -594,14 +592,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
);
|
||||
drop(image_cache);
|
||||
|
||||
// Debug frame counter (only active during strokes)
|
||||
static FRAME: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
let dbg_frame = FRAME.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
let dbg_stroke = self.ctx.painting_canvas.is_some();
|
||||
if dbg_stroke {
|
||||
eprintln!("[FRAME {}] painting_canvas={:?} painting_float={}", dbg_frame, self.ctx.painting_canvas, self.ctx.painting_float);
|
||||
}
|
||||
|
||||
// Get buffer pool for layer rendering
|
||||
let mut buffer_pool = shared.buffer_pool.lock().unwrap();
|
||||
|
||||
@@ -641,7 +631,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
antialiasing_method: vello::AaConfig::Msaa16,
|
||||
};
|
||||
|
||||
if dbg_stroke { eprintln!("[DRAW] background Vello render"); }
|
||||
if let Ok(mut renderer) = shared.renderer.lock() {
|
||||
renderer.render_to_texture(device, queue, &composite_result.background, bg_srgb_view, &bg_render_params).ok();
|
||||
}
|
||||
@@ -661,7 +650,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
// Clear to dark gray (stage background outside document bounds)
|
||||
// Note: stage_bg values are already in linear space for HDR compositing
|
||||
let stage_bg = [45.0 / 255.0, 45.0 / 255.0, 48.0 / 255.0, 1.0];
|
||||
if dbg_stroke { eprintln!("[COMPOSITE] background onto HDR"); }
|
||||
shared.compositor.composite(
|
||||
device,
|
||||
queue,
|
||||
@@ -776,7 +764,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let mut used = false;
|
||||
if let Ok(gpu_brush) = shared.gpu_brush.lock() {
|
||||
if let Some(canvas) = gpu_brush.canvases.get(&kf_id) {
|
||||
if dbg_stroke { eprintln!("[DRAW] GPU canvas blit layer={:?} kf={:?} canvas.current={}", rendered_layer.layer_id, kf_id, canvas.current); }
|
||||
let camera = crate::gpu_brush::CameraParams {
|
||||
pan_x: self.ctx.pan_offset.x,
|
||||
pan_y: self.ctx.pan_offset.y,
|
||||
@@ -804,7 +791,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
if !used_gpu_canvas {
|
||||
// Render layer scene to sRGB buffer, then convert to HDR
|
||||
if dbg_stroke { eprintln!("[DRAW] Vello render layer={:?} opacity={}", rendered_layer.layer_id, rendered_layer.opacity); }
|
||||
if let Ok(mut renderer) = shared.renderer.lock() {
|
||||
renderer.render_to_texture(device, queue, &rendered_layer.scene, srgb_view, &layer_render_params).ok();
|
||||
}
|
||||
@@ -822,7 +808,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
rendered_layer.blend_mode,
|
||||
);
|
||||
|
||||
if dbg_stroke { eprintln!("[COMPOSITE] layer={:?} opacity={} blend={:?} used_gpu_canvas={}", rendered_layer.layer_id, rendered_layer.opacity, rendered_layer.blend_mode, used_gpu_canvas); }
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("layer_composite_encoder"),
|
||||
});
|
||||
@@ -1017,7 +1002,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
// Blit the float GPU canvas on top of all composited layers.
|
||||
// The float_mask_view clips to the selection shape (None = full float visible).
|
||||
if dbg_stroke { eprintln!("[FRAME {}] float blit section: raster_floating={}", dbg_frame, self.ctx.selection.raster_floating.is_some()); }
|
||||
if let Some(ref float_sel) = self.ctx.selection.raster_floating {
|
||||
let float_canvas_id = float_sel.canvas_id;
|
||||
let float_x = float_sel.x;
|
||||
@@ -1026,7 +1010,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
let float_h = float_sel.height;
|
||||
if let Ok(gpu_brush) = shared.gpu_brush.lock() {
|
||||
if let Some(canvas) = gpu_brush.canvases.get(&float_canvas_id) {
|
||||
if dbg_stroke { eprintln!("[DRAW] float canvas blit canvas_id={:?} canvas.current={}", float_canvas_id, canvas.current); }
|
||||
let float_hdr_handle = buffer_pool.acquire(device, hdr_spec);
|
||||
if let (Some(fhdr_view), Some(hdr_view)) = (
|
||||
buffer_pool.get_view(float_hdr_handle),
|
||||
@@ -1051,7 +1034,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
float_mask_view.as_ref(),
|
||||
);
|
||||
let float_layer = lightningbeam_core::gpu::CompositorLayer::normal(float_hdr_handle, 1.0);
|
||||
if dbg_stroke { eprintln!("[COMPOSITE] float canvas onto HDR"); }
|
||||
let mut enc = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("float_canvas_composite"),
|
||||
});
|
||||
@@ -2189,7 +2171,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
antialiasing_method: vello::AaConfig::Msaa16,
|
||||
};
|
||||
|
||||
if self.ctx.painting_canvas.is_some() { eprintln!("[DRAW] overlay Vello render"); }
|
||||
if let Ok(mut renderer) = shared.renderer.lock() {
|
||||
renderer.render_to_texture(device, queue, &scene, overlay_srgb_view, &overlay_params).ok();
|
||||
}
|
||||
@@ -2203,7 +2184,6 @@ impl egui_wgpu::CallbackTrait for VelloCallback {
|
||||
|
||||
// Composite overlay onto HDR texture
|
||||
let overlay_layer = lightningbeam_core::gpu::CompositorLayer::normal(overlay_hdr_handle, 1.0);
|
||||
if self.ctx.painting_canvas.is_some() { eprintln!("[COMPOSITE] overlay onto HDR"); }
|
||||
let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {
|
||||
label: Some("overlay_composite_encoder"),
|
||||
});
|
||||
@@ -4758,7 +4738,11 @@ impl StagePane {
|
||||
[1.0f32, 1.0, 1.0, 1.0]
|
||||
} else {
|
||||
let c = if *shared.brush_use_fg { *shared.stroke_color } else { *shared.fill_color };
|
||||
[c.r() as f32 / 255.0, c.g() as f32 / 255.0, c.b() as f32 / 255.0, c.a() as f32 / 255.0]
|
||||
let s2l = |v: u8| -> f32 {
|
||||
let f = v as f32 / 255.0;
|
||||
if f <= 0.04045 { f / 12.92 } else { ((f + 0.055) / 1.055).powf(2.4) }
|
||||
};
|
||||
[s2l(c.r()), s2l(c.g()), s2l(c.b()), c.a() as f32 / 255.0]
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user