-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Better outlining for solid geometry #8689
Comments
I've implemented the above, and it's pretty good! Except when faces are nearly edge-on with the camera, in which case it's a bit too eager: In the solid-outlines branch. |
Also I think it should be possible to do this computation in the vertex shader instead of the fragment shader to improve performance, but I'm going to get it working well in the fragment shader before I try that. |
Ok after spending way too much time on this, I've gotten it pretty good, but as expected it's impossible to completely avoid artifacts with this approach of rendering separate lines with a depth bias. Note the "tails" sticking into the solid geometry, and the generally rubbish look here due to lack of anti-aliasing. We can fix both problems with a single-pass technique as described in these papers: Two Methods for Antialiased Wireframe Drawing with Hidden Line Removal Both should offer much better performance than rendering GL_LINES in a separate command, and look nicely anti-aliased, too. However, they're both tricky (and less efficient) to implement without geometry shaders, which sadly WebGL lacks. |
I'm very interested if anyone has any ideas or knows of any other good papers for outline rendering. |
I was optimistic that #8646 would be sufficient for outlining solid geometry (e.g. untextured buildings), but it's not quite. It's pretty good (not great) when the volumes are entirely convex, but outlines in concave parts of the model get swallowed. For example:
![image](https://user-images.githubusercontent.com/924374/76856086-a4628000-68a6-11ea-881e-8eaf605b9736.png)
There should be an outline at the red arrow, but there's not because the outline completely fails the depth test against the two adjacent faces.
I think the best solution to this problem is to bias the depth of the outlines toward the camera so that they are visible. But we can't bias them too much, or outlines on back faces will show through the front faces.
WebGL's built-in
polygonOffset
doesn't quite work here, for two reasons:polygonOffset
can only bias triangle depth, not line depth. Biasing triangle depth is not ideal because it can interfere withpickPosition
. Biasing outlines can too, but they're a far less important part of the scene.polygonOffset
doesn't work with log depth, so we have to implement it ourselves. (partially done, perhaps poorly, as part of Fix log depth woes #8600)Some people advocate using the stencil buffer to render outlines. But no approach I've seen or can think of is able to avoid showing outlines "through" solid geometry when multiple outlined faces are rendered in a single draw call.
So here's my half-baked idea for properly biasing outlines:
I haven't implemented this or completely convinced myself that it will work, yet.
The text was updated successfully, but these errors were encountered: