Skip to content
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

Outline rendering glitches in wasm #19

Closed
luca-della-vedova opened this issue May 16, 2023 · 6 comments
Closed

Outline rendering glitches in wasm #19

luca-della-vedova opened this issue May 16, 2023 · 6 comments

Comments

@luca-della-vedova
Copy link

Hi and thanks for the great crate!

We are using the crate for our application, we insert a Flat SetOutlineDepth component and show the outline when the mouse is hovering.
While this looks great on a desktop (Linux, AMD64, integrated GPU with Vulkan) build:

desktop_view.webm

It looks very odd on wasm:

wasm_view.webm

The code is exactly the same, do you have any idea what might be happening?

@komadori
Copy link
Owner

The effect you're seeing is Z-fighting between the outline and the stencil. Since the fix for gfx-rs/naga#14, bevy_mod_outline uses a depth offset to separate the outline and stencil. For some reason, the required separation is much larger in WebGL than the native back-ends. I'm still investigating.

@komadori
Copy link
Owner

The issue is, due to gfx-rs/wgpu#4553, the floating point error in the depth values is much bigger with the WebGL backend than non-OpenGL backends, requiring a much bigger depth bias. I've added a GL-specific workaround to bevy_mod_outline which avoids the increased floating point error at the cost of some performance.

Released in 0.4.2.

@luca-della-vedova
Copy link
Author

Wow I had a feeling the fix was tricky but didn't think it would require this depth of digging.
Thanks a lot for looking into it and releasing the fix so quickly!

@dannymcgee
Copy link

Hi there! Unfortunately it seems like this issue has cropped up again (or maybe my particular hardware setup is just immune to the previous fix). I forked this locally and was able to fix the issue by increasing the offset to a cartoonishly large amount, which doesn't seem to have introduced any negative side effects. (I can email you before & after screenshots if that would be helpful.)

This is the change I made:

out.normalised_depth = 0.5 + 0.5 * (out_z / clip_pos.w);

    out.normalized_depth = 10.0 + 0.5 * (out_z / clip_pos.w);

Would be happy to open a PR if you'd like to incorporate it, but no hard feelings if you'd prefer to try a more robust solution or wait for an upstream fix from wgpu.

@komadori
Copy link
Owner

komadori commented Oct 31, 2023

@dannymcgee I've opened a new issue, #26, for what I believe is the same issue you're experiencing. Please let me know if the screenshot on that issue resembles what you're seeing.

@dannymcgee
Copy link

Sorry I missed your update last week @komadori. Yes, that is exactly what I was seeing — thanks for the quick response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants