Skip to content

Commit a744f98

Browse files
Fix the basic brush not rendering on WebGL2 (#5011)
Split the basic brush scatter into one pass per field so it renders on WebGL2
1 parent 3649d84 commit a744f98

1 file changed

Lines changed: 35 additions & 18 deletions

File tree

‎node-graph/nodes/brush/src/basic_brush/pipeline.rs‎

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ impl WgpuPipeline for BasicBrushPipeline {
9696
}
9797

9898
struct Scatter {
99-
pipeline: wgpu::RenderPipeline,
99+
density: wgpu::RenderPipeline,
100+
stamp: wgpu::RenderPipeline,
100101
layout: wgpu::BindGroupLayout,
101102
sampler: wgpu::Sampler,
102103
}
@@ -179,7 +180,7 @@ impl Scatter {
179180
constants: &[("CUTOFF_SIGMA", SIGMA_CUTOFF as f64), ("LUT_SIZE", LUT_SIZE as f64), ("LUT_V_MAX", LUT_V_MAX), ("LUT_T_MAX", LUT_T_MAX)],
180181
..Default::default()
181182
};
182-
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
183+
let mut descriptor = wgpu::RenderPipelineDescriptor {
183184
label: Some("basic_brush_density_pipeline"),
184185
layout: Some(&pipeline_layout),
185186
vertex: wgpu::VertexState {
@@ -198,11 +199,7 @@ impl Scatter {
198199
blend: Some(wgpu::BlendState { color: additive, alpha: additive }),
199200
write_mask: wgpu::ColorWrites::ALL,
200201
}),
201-
Some(wgpu::ColorTargetState {
202-
format: DENSITY_FORMAT,
203-
blend: Some(wgpu::BlendState { color: union, alpha: union }),
204-
write_mask: wgpu::ColorWrites::ALL,
205-
}),
202+
None,
206203
],
207204
}),
208205
primitive: wgpu::PrimitiveState {
@@ -213,8 +210,22 @@ impl Scatter {
213210
multisample: wgpu::MultisampleState::default(),
214211
multiview_mask: None,
215212
cache: None,
216-
});
217-
Self { pipeline, layout, sampler }
213+
};
214+
let density = device.create_render_pipeline(&descriptor);
215+
let stamp_targets = [
216+
None,
217+
Some(wgpu::ColorTargetState {
218+
format: DENSITY_FORMAT,
219+
blend: Some(wgpu::BlendState { color: union, alpha: union }),
220+
write_mask: wgpu::ColorWrites::ALL,
221+
}),
222+
];
223+
descriptor.label = Some("basic_brush_stamp_pipeline");
224+
if let Some(fragment) = &mut descriptor.fragment {
225+
fragment.targets = &stamp_targets;
226+
}
227+
let stamp = device.create_render_pipeline(&descriptor);
228+
Self { density, stamp, layout, sampler }
218229
}
219230

220231
fn bind(&self, device: &wgpu::Device, globals: &wgpu::Buffer, kernel: &wgpu::TextureView) -> wgpu::BindGroup {
@@ -250,15 +261,21 @@ impl Scatter {
250261
depth_slice: None,
251262
})
252263
};
253-
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
254-
label: Some("basic_brush_density_pass"),
255-
color_attachments: &[attachment(&target.density), attachment(&target.stamp)],
256-
..Default::default()
257-
});
258-
pass.set_pipeline(&self.pipeline);
259-
pass.set_bind_group(0, bind, &[]);
260-
pass.set_vertex_buffer(0, buffer.slice(..));
261-
pass.draw(0..4, 0..instances);
264+
let passes = [
265+
("basic_brush_density_pass", &self.density, [attachment(&target.density), None]),
266+
("basic_brush_stamp_pass", &self.stamp, [None, attachment(&target.stamp)]),
267+
];
268+
for (label, pipeline, attachments) in passes {
269+
let mut pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
270+
label: Some(label),
271+
color_attachments: &attachments,
272+
..Default::default()
273+
});
274+
pass.set_pipeline(pipeline);
275+
pass.set_bind_group(0, bind, &[]);
276+
pass.set_vertex_buffer(0, buffer.slice(..));
277+
pass.draw(0..4, 0..instances);
278+
}
262279
}
263280
}
264281

0 commit comments

Comments
 (0)