Jump to content
  • Advertisement
Sign in to follow this  
n00body

Circle in fragment shader

This topic is 4076 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I efficiently draw a circle in a texture, using a fragment shader? Similarly, how do I draw a rounded square?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!