Skip to content

Commit

Permalink
[debug] Thicken lines and show winding
Browse files Browse the repository at this point in the history
  • Loading branch information
armansito authored and DJMcNab committed Jul 29, 2024
1 parent 0cb809c commit 71c930c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions vello/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl DebugRenderer {
&module,
"linesoup_vert",
"solid_color_frag",
wgpu::PrimitiveTopology::LineList,
wgpu::PrimitiveTopology::TriangleStrip,
wgpu::ColorTargetState {
format: target_format,
blend: None,
Expand Down Expand Up @@ -317,14 +317,15 @@ impl DebugRenderer {
);

let linepoints_uniforms = [
LinepointsUniforms::new(Color::CYAN, 10.),
LinepointsUniforms::new(Color::DARK_CYAN, 10.),
LinepointsUniforms::new(Color::RED, 80.),
];
let linepoints_uniforms_buf = recording.upload_uniform(
"linepoints uniforms",
bytemuck::bytes_of(&linepoints_uniforms),
);

/*
recording.draw(DrawParams {
shader_id: self.clear_tint,
instance_count: 1,
Expand All @@ -333,7 +334,7 @@ impl DebugRenderer {
resources: vec![],
target,
clear_color: None,
});
});*/
if params.debug.check_bits(DebugLayers::BOUNDING_BOXES) {
recording.draw(DrawParams {
shader_id: self.bboxes,
Expand All @@ -349,7 +350,7 @@ impl DebugRenderer {
recording.draw(DrawParams {
shader_id: self.linesoup,
instance_count: bump.lines,
vertex_count: 2,
vertex_count: 4,
vertex_buffer: Some(captured.lines),
resources: vec![uniforms_buf],
target,
Expand Down Expand Up @@ -492,10 +493,22 @@ struct LinesoupIn {
@location(1) p1: vec2f,
}
const LINE_THICKNESS: f32 = 4.;
const WIND_DOWN_COLOR: vec3f = vec3(0., 1., 0.);
const WIND_UP_COLOR: vec3f = vec3(1., 0., 0.);
@vertex
fn linesoup_vert(@builtin(vertex_index) vid: u32, line: LinesoupIn) -> VSOut {
let p = select(line.p0, line.p1, vid == 1u) / vec2f(f32(uniforms.width), f32(uniforms.height));
return VSOut(map_to_ndc(p), vec4(0.7, 0.5, 0., 1.));
let quad_corner = quad_vertices[quad_fill_indices[vid]] - vec2(0.5);
let v = line.p1 - line.p0;
let m = mix(line.p0, line.p1, 0.5);
let s = vec2(LINE_THICKNESS, length(v));
let vn = normalize(v);
let r = mat2x2(vn.y, -vn.x, vn.x, vn.y);
let p = (m + r * (s * quad_corner)) / vec2f(f32(uniforms.width), f32(uniforms.height));
//let color = vec4(0.7, 0.5, 0., 1.);
let color = vec4(select(WIND_UP_COLOR, WIND_DOWN_COLOR, v.y >= 0.), 1.);
return VSOut(map_to_ndc(p), color);
}
////////////
Expand Down

0 comments on commit 71c930c

Please sign in to comment.