forked from 1b-agent/opencadstudio-upstream
fix(viewport): blit UV crop for off-canvas viewports
Refactor the per-viewport blit so a content viewport whose screen rect extends off the canvas composites the correct slice of its MSAA target to the visible portion of the surface, instead of being slammed against the canvas corner by an `(f32 as u32)` saturation on the negative offset. - blit.wgsl + Pipeline gain a small uniform buffer (`uv_offset` / `uv_scale`). `Primitive::prepare` computes the per-viewport crop from `screen_rect`'s on-canvas fraction and writes it via the new `upload_blit_uv` helper while it still has the `Queue`. - `Pipeline::render` now takes `vp_size` (full vp — MSAA / camera size) and `surface_dest` (visible intersection — blit destination) and reads the crop from the uniform; passes that don't have a non-empty surface intersection are skipped. - `Primitive::render` clips the full vp rect against the surface clip in `i32` and skips empty intersections. The earlier "skip GPU for inactive off-canvas viewports" workaround in `active_viewports` is no longer needed. - ViewCube draws only when its hosting vp is fully on-canvas (its own pipeline writes directly to the surface and would distort under a clamped `set_viewport`). With the GPU path correct for every vp position, drop `viewport_content_wires` from `paper_canvas_wires` — the inactive viewport CPU projection was only there to mask the blit bug and was duplicating the unified shader's output. The hit-test / snap path (`entity_wires_arc`, `wires_for_block`) still calls `viewport_content_wires` directly, so picking through inactive viewports keeps working. Co-Authored-By: Claude Opus 4.7 <[email protected]>
This commit is contained in:
1 parent
600717c1ec
commit
3d24dd5168
4 files changed
+160
-47
No files matched your search
+14
-4
@@ -1,13 +1,21 @@
|
||||
// blit.wgsl
|
||||
// Copies the MSAA-resolved texture to the surface target.
|
||||
// A full-screen NDC quad is drawn; the render pass viewport positions it
|
||||
// exactly over the shader widget's clip bounds in the surface.
|
||||
// Copies the MSAA-resolved texture to the surface target. A full-screen
|
||||
// NDC quad is drawn; the render pass viewport places it on the visible
|
||||
// sub-rectangle of the surface, and `u_blit.uv_scale / uv_offset` crops
|
||||
// the resolve texture to the corresponding portion of the full viewport
|
||||
// (so a viewport that extends off the canvas still composites correctly
|
||||
// from the on-surface side).
|
||||
|
||||
struct VertexOutput {
|
||||
@builtin(position) position: vec4<f32>,
|
||||
@location(0) uv: vec2<f32>,
|
||||
}
|
||||
|
||||
struct BlitUniforms {
|
||||
uv_offset: vec2<f32>,
|
||||
uv_scale: vec2<f32>,
|
||||
}
|
||||
|
||||
var<private> POSITIONS: array<vec2<f32>, 6> = array<vec2<f32>, 6>(
|
||||
vec2<f32>(-1.0, 1.0),
|
||||
vec2<f32>(-1.0, -1.0),
|
||||
@@ -37,8 +45,10 @@ fn vs_main(@builtin(vertex_index) idx: u32) -> VertexOutput {
|
||||
|
||||
@group(0) @binding(0) var t_resolved: texture_2d<f32>;
|
||||
@group(0) @binding(1) var s_resolved: sampler;
|
||||
@group(0) @binding(2) var<uniform> u_blit: BlitUniforms;
|
||||
|
||||
@fragment
|
||||
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
|
||||
return textureSample(t_resolved, s_resolved, in.uv);
|
||||
let uv = in.uv * u_blit.uv_scale + u_blit.uv_offset;
|
||||
return textureSample(t_resolved, s_resolved, uv);
|
||||
}
|
||||
Reference in new issue
Block a user