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
Fill and Stroke polygon #63
Comments
I'm not able to reproduce the problem you've described.
|
You must have amazing eyes to spot the slightest bleed-through occurring there :).
I'm not following your logic. In theory, brush polygons could fill just up to the inner boundaries of outlining strokes, but you'd have to dispense with anti-aliasing. However that won't be an acceptable option until screen pixels get a lot smaller. In the meantime, attempting to brush fill just up to the inner boundaries of outline strokes would look silly since anti-aliasing would guarantee background bleed-through. Anyhow, I'm still not seeing that there's a problem (at least with my inferior eyes :)). Edited: See solution below. |
Yes, much better :).
I think the principles will be the same irrespective of the implementation. The rasterizer just produces an alpha mask, so the brush and the stroke would each have an alpha mask. Then it's a matter of blending with these 2 masks where the blend function would give the stroke mask preference over the brush mask. |
I've worked out a blend function that works very well ...
And here's an example of blending overlapping semitransparent colors using the above function. And this is the same polygon/polyline using the existing overlapping draw method ... Edit: Here's a very simple example application ... |
I'm sorry but I can't see how that helps. You're just using back buffers to construct the filled polygon and I can already do that with just a single buffer. The end user can even do it with layers and the right blend mode. This has to work for arbitrary bitmaps, and be reasonable performant, so fixing it in a back buffer is IMO not the way to go. I'll have a look at the rasterizer when I get a spare moment but it'll probably be a while before I have time for any serious effort. |
Well I guess it could be done with a single 'buffer' as long as you keep the two alpha channels (one for brush and one for stroke) separate in that buffer. But to me that's simply a data storage preference unless I'm missing your point (again). The rasterizing (ie alpha mask construction) of brush and stroke must be done separately (or at least stored separately) so the renderer will know how to blend the respective brush and stroke colors onto the image.
I'm not sure what you mean by 'arbitrary bitmaps' but I agree that performance would be an issue (ie using the approach I suggested above).
Good luck with that :). I've had a fairly decent look and haven't yet figured out what Mattias does there (and I've written my own rasterizer / renderer for my own graphics library so I have a fairly decent idea of the principles). |
Here's one way to do it with a single buffer:
That's a problem. One of the reasons we introduced VPR was that we couldn't fix bugs in the old rasterizer because nobody understood it. I can see that the way we do the stroke is to take the outline polyline, offset it by half the stroke width and add it to a polypolygon. Take the outline again, offset it by negative half the stroke width, reverse the direction and add it to the polypolygon. |
Support the proposal |
I agree that this is a really sad inherent in most existing libraries |
To the best of my knowledge it isn't currently possible to fill and stroke a polygon in one go.
Currently in order to draw a filled polygon with a stroke one has to:
PolylineFS(...)
Grow(...)
PolygonFS(...)
While this might appear to work fine there are several problems:
For example the following polygon (stroke: 1px clBlack32, fill: clWhite32):
Raw image:
Rendered on top of checkerboard (slightly visible inside border):
Rendered on top of red layer (notice how the red bleeds through inside border):
Grow()
orTClipperOffset
actually matches the inner polygon of the shape produced byPolylineFS
since they're produced by different implementation that are probably based on different algorithms.I know that Mattias at one point mentioned the possibility of having VPR handle both filling and stroking, but as far as I can tell this feature never materialized.
I propose that functionality be added that combines fill and stroke to produce 100% pixel coverage within the polygon.
Note that I'm aware that the problem can be avoided when using purely opaque colors by simply not offsetting the inner polygon, but for semitransparent colors it is required.
The text was updated successfully, but these errors were encountered: