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

Polygonal overlay renderer #29

Open
JujuAdams opened this issue May 21, 2023 · 2 comments
Open

Polygonal overlay renderer #29

JujuAdams opened this issue May 21, 2023 · 2 comments
Labels
feature 💭 It would be extra good if...

Comments

@JujuAdams
Copy link
Owner

Requires triangulation algo

@JujuAdams JujuAdams added the feature 💭 It would be extra good if... label May 21, 2023
@xotmatrix
Copy link

xotmatrix commented May 21, 2023

Requires triangulation algo

Not necessarily. If you can draw it to a dedicated surface and then composite it, you can do it very cheaply. Draw it as a triangle fan using an XOR-like blending mode. As each triangle is drawn, any out-of-bounds pixels that might be formed from concave polygons erase themselves like magic once the polygon is complete. This is akin to the "crossing number" point-in-polyon test, where any pixel that is hit an even number of times is outside the polygon and does not appear in the resulting rasterization. It does mean that self-intersecting polygons can appear to have holes in them, which may or may not be a desired feature.

I use the technique here:
https://xotmatrix.github.io/demos/gm-niccc/index.html

I simplified this code a bit but I think it is still valid:

gpu_set_blendmode_ext(bm_inv_dest_alpha, bm_zero);
draw_set_color(palette[polyColor]);
surface_set_target(blit);
draw_clear_alpha(c_black, 0.0);
            
draw_primitive_begin(pr_trianglefan);
            
for (var i=0; i<polyVerts; i++) {
    var vertIndex = buffer_read_byte(scene);
    draw_vertex(vertX[vertIndex], vertY[vertIndex]);
}
            
draw_primitive_end();

surface_reset_target();
gpu_set_blendmode(bm_normal);
            
draw_surface_ext(blit, 0, 0, scaleB, scaleB, 0, c_white, 1.0);

@xotmatrix
Copy link

xotmatrix commented Jun 22, 2023

I just realized I had a much simpler demonstration that lets you draw polygons so you can see how it behaves.
https://xotmatrix.github.io/demos/concave-poly-trick/index.html
DuckDuckGo_2023-06-22_19-02-43

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 💭 It would be extra good if...
Projects
None yet
Development

No branches or pull requests

2 participants