Confused about what kind of shader I need for this?

I’m a complete beginner. Rendered my first triangle and rectangle today. Now I’m trying to render a rectangle with smooth corners, but I’m not sure what shaders I will need for this. As input ideally I want to provide upper-left corner position (for now, let’s say in screen coordinates) plus width and height, or center + height and width would also work. Corner radius can be hard-coded.

Now, from these two references:

What a vertex shader outputs information for one vertex, and fragment shader outputs information for one pixel. What I want in GPU is given the coordinates as described above, it should draw a full rectangle with rounded corners. So I will provide one input, and it will output many pixels. There are lots of examples on shadertoy (e.g. Shader - Shadertoy BETA) and similar sites but I don’t understand the language they’re using. Their shaders look nothing like the ones in e.g. tutorials. I’m using version 330 core. I’m not interested in GLES.

What do I need to look at next for this?




I would forget shaders for a moment and focus on what your requirements are. How do you want the edges to look? What about the rounded corners? How does this object need to occlude against or blend with other objects (or does it)? Are the edge pixels colored the same as the interior “fill” region of the rectangle or differently? Do you want the interior filled with some color or completely transparent?

Without knowing the answers yet, one strawman proposal to consider is to just render a quad textured with an image of a rounded rectangle.