Circle in fragment shader
How do I efficiently draw a circle in a texture, using a fragment shader?
Similarly, how do I draw a rounded square?
I can think of a couple ways you might be able to do it abusing texture coordinates and the mathematical properties of a circle. But they're not pretty.
The easy way is to render geometry that looks like a circle while a texture is the active render target. Fragment shaders aren't pixel-plotting devices, they're pixel (fragment) coloring devices. It's usually pretty difficult to do anything resembling traditional arbitrary drawing -- they're the endpoints of a highly parallelized stream processing system.
The easy way is to render geometry that looks like a circle while a texture is the active render target. Fragment shaders aren't pixel-plotting devices, they're pixel (fragment) coloring devices. It's usually pretty difficult to do anything resembling traditional arbitrary drawing -- they're the endpoints of a highly parallelized stream processing system.
Then tell me the non-pretty methods. It's not for a production-ready project, it's just a learning exercise.
switch to rendering to rexture, then
x^2 + y^2 = r^2 //pitagoras says so
isnt it simple ? :)
about squares with rounded corners: you can find source of some graphic library for c, but as i remind the algorithm is rather complex, though
x^2 + y^2 = r^2 //pitagoras says so
isnt it simple ? :)
about squares with rounded corners: you can find source of some graphic library for c, but as i remind the algorithm is rather complex, though
As I recall, I got it working once (but lost the code in a hard-drive corruption) and could get rounded squares with a tiny modification to my circle code. It was basically determining if the point was inside the circle/rounded square, shading with the fill color if so, and with alpha otherwise.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement