-
Notifications
You must be signed in to change notification settings - Fork 335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Outlines via masking & postprocessing in re_renderer
#1532
Conversation
as opposed to texel coordinates
230fed6
to
de51728
Compare
Breaking the compositing shader crashes the entire program for some reason, which makes exploration-by-experimentation much harder 😞 23-03-09_10.03.51.patched.mp4
|
@teh-cmc ah odd just ran into the compile issue on a branch I based upon here and got surprised. cherry-picking the fix over. |
The crash upon edit sounds like its on me - I added that check/error there not too long ago. Kinda surprised I didn't run into that so far. Would take that separately if you don't mind |
We confirmed that validation issue is about outputting a uvec from the fragment shader. Opened an issue here gfx-rs/naga#2270 |
We could confirm with @Wumpf that the validation error is coming from the use of a diff --git a/crates/re_renderer/shader/instanced_mesh.wgsl b/crates/re_renderer/shader/instanced_mesh.wgsl
index cc7a43be1..5254f730a 100644
@@ -62,6 61,6 @@ fn fs_main_shaded(in: VertexOut) -> @location(0) Vec4 {
}
@fragment
-fn fs_main_outline_mask(in: VertexOut) -> @location(0) UVec2 {
- return in.outline_mask;
fn fs_main_outline_mask(in: VertexOut) -> @location(0) Vec2 {
return Vec2(in.outline_mask);
}
diff --git a/crates/re_renderer/shader/outlines/jumpflooding_init.wgsl b/crates/re_renderer/shader/outlines/jumpflooding_init.wgsl
index 8b1b14d7c..85e1c3349 100644
--- a/crates/re_renderer/shader/outlines/jumpflooding_init.wgsl
b/crates/re_renderer/shader/outlines/jumpflooding_init.wgsl
@@ -2,10 2,10 @@
#import <../screen_triangle_vertex.wgsl>
@group(0) @binding(0)
-var mask_texture: texture_multisampled_2d<u32>;
var mask_texture: texture_multisampled_2d<f32>;
fn has_edge(closest_center_sample: UVec2, sample_coord: IVec2, sample_idx: i32) -> Vec2 {
- let mask_neighbor = textureLoad(mask_texture, sample_coord, sample_idx).xy;
let mask_neighbor = UVec2(textureLoad(mask_texture, sample_coord, sample_idx).xy);
return Vec2(closest_center_sample != mask_neighbor);
}
@@ -54,17 54,17 @@ fn main(in: VertexOutput) -> @location(0) Vec4 {
// TODO(andreas): Should we assert somehow on textureNumSamples here?
let center_coord = IVec2(Vec2(resolution) * in.texcoord);
- let mask_top_left = textureLoad(mask_texture, center_coord, 0).xy;
- let mask_right_top = textureLoad(mask_texture, center_coord, 1).xy;
- let mask_left_bottom = textureLoad(mask_texture, center_coord, 2).xy;
- let mask_bottom_right = textureLoad(mask_texture, center_coord, 3).xy;
let mask_top_left = UVec2(textureLoad(mask_texture, center_coord, 0).xy);
let mask_right_top = UVec2(textureLoad(mask_texture, center_coord, 1).xy);
let mask_left_bottom = UVec2(textureLoad(mask_texture, center_coord, 2).xy);
let mask_bottom_right = UVec2(textureLoad(mask_texture, center_coord, 3).xy);
var edge_pos_a_and_b = Vec4(0.0);
var num_edges_and_b = Vec2(0.0);
diff --git a/crates/re_renderer/src/renderer/outlines.rs b/crates/re_renderer/src/renderer/outlines.rs
index 4f8eaa033..24a574cae 100644
--- a/crates/re_renderer/src/renderer/outlines.rs
b/crates/re_renderer/src/renderer/outlines.rs
@@ -124,7 124,7 @@ impl OutlineMaskProcessor {
/// Format of the outline mask target.
///
/// Two channels with each 256 object ids.
- pub const MASK_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rg8Uint;
pub const MASK_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Rg8Unorm;
pub const MASK_MSAA_STATE: wgpu::MultisampleState = wgpu::MultisampleState {
count: ViewBuilder::MAIN_TARGET_SAMPLE_COUNT,
@@ -398,7 398,7 @@ impl OutlineMaskProcessor {
binding: 0,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture {
- sample_type: wgpu::TextureSampleType::Uint,
sample_type: wgpu::TextureSampleType::Float { filterable: false },
view_dimension: wgpu::TextureViewDimension::D2,
multisampled: true,
}, The error seems to come down to 1c1
< SPIR-V 1.0 module, <id> bound of 121
---
> SPIR-V 1.0 module, <id> bound of 122
74c74
< Output uint2* _115 : [[Location(0), Flat]];
---
> Output float2* _115 : [[Location(0)]];
135c135,136
< *_115 = _120;
---
> float2 _121 = ConvertUToF(_120);
> *_115 = _121; |
Fix incoming |
Fixed above, but there's more >.<
I checked before I started this that sampling an MSAA target works fine, but there must be some fineprint on what exactly is possible. Digging deeper now I checked before I started this that sampling a msaa texture should be supported. Need to dig a bit deeper |
Turns out I was involved in this very issue (or a similar one) a couple of years ago. gfx-rs/wgpu#2149 |
Seems actually that sampling MSAA texture is not a thing after all in WebGL? At least this ticket implies support won't come. gfx-rs/wgpu#2117 |
2eb5cc6
to
c643bcf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This took me way longer than I hoped to learn all the techniques involved and fully grasp everything that goes on in there... Really glad I did though, this is absolutely amazing on so many levels 🤯 .
Nothing blocking! 🚢
👏
re_renderer
(*) Only supports meshes so far!
Screen.Recording.2023-03-08.at.12.14.55.mov
This test scene is a bit over the top but demonstrates key abilities:
How it works is detailed in
renderer/outlines.rs
, after reading the comment there I'd recommend first reviewing the changes inview_builder.rs
, then the new draw methods inrenderer/outlines.rs
. If the process is not clear at that point better post questions, because from there on it only gets more complicated :)Checklist
Part of gfx-rs/naga#889