I need some simple "ball" rasterization routine in C.
I cooked myself something based on midpoint-Bresenham algorithm (to see in wikipedia) where I first calculate circle points in x-y screen plane
// XXX
// XXXXX
// XXXXXX
// XXXXXXX
// XXXXXXXX
// XXXXXXXX
// XXXXXXXXX
// XXXXXXXXX
// XXXXXXXXX
then for each scanline I go with the 'second' midpoint, this time in x-z plane and update depth buffer z values.
It seems to work though it has some troubles to it. For example,
Perspective transformation as far as I know does not cast balls to circles but probably ellipses so that my algorithm of rasterizing it as circles is not quite correct.
For small circles there is a jump between one point balls that look like
// #
then when getting closer it jumps immediately to something like
// # //##### //##### // #
or
// ## //###### //###### // ##
I'm not sure if this is consequence of midpoint algorithm or I'm making something wrong.
Other question is when I get this algorithm, then I would like a shading version of it. I need for example to know normal for each of pixels of my rasterized balls (to use it for dot with light ray). Could someone provide some formula for this normal for pixel?
Maybe there is some faster way of shading it?
In short I need some advice to improve the thing I have, especially I want shaded version of it (more important to work than be perfect but some improvements on exactness would be right too).