painting fixes
This commit is contained in:
@@ -94,7 +94,6 @@ impl CanvasPair {
|
||||
/// in `raw_pixels` / PNG files). The values are decoded to linear premultiplied
|
||||
/// before being written to the canvas, which operates entirely in linear space.
|
||||
pub fn upload(&self, queue: &wgpu::Queue, pixels: &[u8]) {
|
||||
eprintln!("[CANVAS] upload: {}x{} pixels={}", self.width, self.height, pixels.len());
|
||||
// Decode sRGB-premultiplied → linear premultiplied for the GPU canvas.
|
||||
let linear: Vec<u8> = pixels.chunks_exact(4).flat_map(|p| {
|
||||
let r = (srgb_to_linear(p[0] as f32 / 255.0) * 255.0 + 0.5) as u8;
|
||||
@@ -269,10 +268,8 @@ impl GpuBrushEngine {
|
||||
let needs_new = self.canvases.get(&keyframe_id)
|
||||
.map_or(true, |c| c.width != width || c.height != height);
|
||||
if needs_new {
|
||||
eprintln!("[CANVAS] ensure_canvas: creating new CanvasPair for kf={:?} {}x{}", keyframe_id, width, height);
|
||||
self.canvases.insert(keyframe_id, CanvasPair::new(device, width, height));
|
||||
} else {
|
||||
eprintln!("[CANVAS] ensure_canvas: reusing existing CanvasPair for kf={:?}", keyframe_id);
|
||||
}
|
||||
self.canvases.get_mut(&keyframe_id).unwrap()
|
||||
}
|
||||
@@ -306,7 +303,6 @@ impl GpuBrushEngine {
|
||||
depth_or_array_layers: 1,
|
||||
};
|
||||
|
||||
eprintln!("[DAB] render_dabs keyframe={:?} count={}", keyframe_id, dabs.len());
|
||||
for dab in dabs {
|
||||
// Per-dab bounding box
|
||||
let r_fringe = dab.radius + 1.0;
|
||||
@@ -415,9 +411,7 @@ impl GpuBrushEngine {
|
||||
queue.submit(Some(compute_enc.finish()));
|
||||
|
||||
// Swap: the just-written dst becomes src for the next dab.
|
||||
eprintln!("[DAB] dispatched bbox=({},{},{},{}) current_before_swap={}", x0, y0, x1, y1, canvas.current);
|
||||
canvas.swap();
|
||||
eprintln!("[DAB] after swap: current={}", canvas.current);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -418,7 +418,7 @@ impl FocusIconCache {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_or_load(&mut self, icon: FocusIcon, icon_color: egui::Color32, ctx: &egui::Context) -> Option<&egui::TextureHandle> {
|
||||
fn get_or_load(&mut self, icon: FocusIcon, icon_color: egui::Color32, display_size: f32, ctx: &egui::Context) -> Option<&egui::TextureHandle> {
|
||||
if !self.icons.contains_key(&icon) {
|
||||
let (svg_bytes, svg_filename) = match icon {
|
||||
FocusIcon::Animation => (focus_icons::ANIMATION, "focus-animation.svg"),
|
||||
@@ -435,7 +435,8 @@ impl FocusIconCache {
|
||||
);
|
||||
let svg_with_color = svg_data.replace("currentColor", &color_hex);
|
||||
|
||||
if let Some(texture) = rasterize_svg(svg_with_color.as_bytes(), svg_filename, 120, ctx) {
|
||||
let render_size = (display_size * ctx.pixels_per_point()).ceil() as u32;
|
||||
if let Some(texture) = rasterize_svg(svg_with_color.as_bytes(), svg_filename, render_size, ctx) {
|
||||
self.icons.insert(icon, texture);
|
||||
}
|
||||
}
|
||||
@@ -1310,12 +1311,13 @@ impl EditorApp {
|
||||
|
||||
// Icon area - render SVG texture
|
||||
let icon_color = egui::Color32::from_gray(200);
|
||||
let icon_center = rect.center_top() + egui::vec2(0.0, 50.0);
|
||||
let icon_display_size = 60.0;
|
||||
let title_area_height = 40.0;
|
||||
let icon_display_size = rect.width() - 16.0;
|
||||
let icon_center = egui::pos2(rect.center().x, rect.min.y + (rect.height() - title_area_height) * 0.5);
|
||||
|
||||
// Get or load the SVG icon texture
|
||||
let ctx = ui.ctx().clone();
|
||||
if let Some(texture) = self.focus_icon_cache.get_or_load(icon, icon_color, &ctx) {
|
||||
if let Some(texture) = self.focus_icon_cache.get_or_load(icon, icon_color, icon_display_size, &ctx) {
|
||||
let texture_size = texture.size_vec2();
|
||||
let scale = icon_display_size / texture_size.x.max(texture_size.y);
|
||||
let scaled_size = texture_size * scale;
|
||||
|
||||
@@ -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