OpenGL: creating complex and smooth polygons

In my OpenGL project, I want to dynamically create smooth polygons, similar to the following:

enter image description here

The problem mainly depends on the smoothing process. My procedure up to this point is, firstly, creating a VBO with randomly placed vertices.

Then, in my fragment shader (I use the programmable function pipeline), the smoothing process should occur or, in other words, create curves from previously defined "lines" between the vertices.

And this is precisely the problem: I am not very good at complex mathematical algorithms that will check if a point is inside a "smooth polygon" or not.

+6
source share
1 answer

At first you cannot do this in the fragment shader. The fragment shader is limited to setting the final (ish) color of the β€œpixel” (which is basically, but not exactly, the actual pixel) before it is written to the screen. He cannot create new points on the curve.

This page gives a good overview of the various algorithms for creating smooth curves.

The general approach is to split a pair of points into several points using a geometric shader, and then render them like a regular polygon. But I do not know the details. Try searching bezier geometry shader .

Wait, I'm lying. I found a program here that does this in the fragment shader.

+3
source

Source: https://habr.com/ru/post/914413/


All Articles