• Create Account

# drawing a pixel accurate sphere

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1lomateron  Members   -  Reputation: 489

Like
0Likes
Like

Posted 24 September 2012 - 06:28 AM

So to draw a pixel accurate circle I need only to have 3 vertices representing an Equilateral triangle and draw a circle inside it.
Now to draw a pixel accurate sphere I need to have tetrahedron and draw an sphere inside it.
I think its much better than having lost of vertices representing the sphere and doesn't matter how close you are you will always see perfect pixel sphere.
The only bad thing is when the camera gets inside the edges of the tetrahedron.
Has anyone done this?

Edited by lomateron, 24 September 2012 - 06:44 AM.

### #2clb  Members   -  Reputation: 2143

Like
0Likes
Like

Posted 24 September 2012 - 07:07 AM

Are you referring to using a pixel shader to produce the fill of the circle/sphere appropriately, and use an alpha blend/reject to exclude the excessly rasterized pixels?

If so, you can rasterize a sphere in the same way than a circle, if you just billboard the single triangle to always face the viewer. This guarantees that the triangle always encloses all the pixels required to draw the sphere. Also, since the vertices are billboarded, they'll never clip to the camera near plane.
Me+PC=clb.demon.fi | C++ Math and Geometry library: MathGeoLib, test it live! | C++ Game Networking: kNet | 2D Bin Packing: RectangleBinPack | Use gcc/clang/emcc from VS: vs-tool | Resume+Portfolio | gfxapi, test it live!

### #3CryZe  Members   -  Reputation: 769

Like
0Likes
Like

Posted 24 September 2012 - 07:16 AM

Raytrace the sphere inside the pixel shader and use the resulting depth as SV_Depth (Conservative Depth if you were using DX11). Hustle Kings basically did the same thing. You get a completely perfect sphere (the normals can be calculated from the intersection position) and only need 3 vertices (or any other amount, depending on your implementation)

The only bad thing is when the camera gets inside the edges of the tetrahedron.

You could render only the backfaces of the tetrahedron to solve that problem.

Edited by CryZe, 24 September 2012 - 07:27 AM.

### #4lomateron  Members   -  Reputation: 489

Like
0Likes
Like

Posted 24 September 2012 - 09:34 AM

I have a problem, i am drawing many spheres(using billboard triangle), their depth is aleatory. So if i draw a sphere in front and then draw another deeper, in a way that i can see the two intersected, (if the background is black)there will be a black pointy patch in the deeper sphere caused by the pointy triangle that is nearer, I cant think of a solution to this, the depht stencil is limited to the vertex depht not the pixel in the pixel shader.
Using directx 10

Edited by lomateron, 24 September 2012 - 09:37 AM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS