-Tj- said:
I don't know about practical applications aside from balls and planets and other spherical things at this moment, but I do enjoy new tech.
I could potentially see the use of something like this in a game, but at the moment I'm kinda stumped as to what's going on. Thus, questions! (I haven't voted yet because I don't understand yet)
- Does this work only on shapes you've programmed in, or for ALL curved surfaces?
- Is this something that will work alongside other polygonal shapes, or does it replace the engine for drawing 3D completely?
- The way I'm thinking it's working at the moment, you're drawing the 3D object to some kind of buffer, then doing some edge processing to it to create a smoother curve, and outputting that to a texture, which is drawn to the screen?
My brain kinda sees some potential use of this, but maybe I'm not seeing enough info to know exactly what I'd use it for yet. If it only works on certain shapes, I don't think I'd use this over a regular polygon sphere, but if it will work on any shape, say a human figure or other non-primitive shapes, I can see more use for it.
Yes, the shapes have to be programmed in, but there is a mathematical process for converting from the original formula to the drawing formulae. It could probably be automated and should work for any shape that has two intersections per 'ray'. I haven't tried any more complicated ones yet, but if push comes to shove, build it in pieces.
I would prefer that polygons be drawn in software purely because I don't like the way opengl handles depth. I prefer full floating point ranges instead of 0.0 to 1.0, or 1.0 to 0.0. You don't have to worry about near and far clipping this way, unless you want to. Regardless, if you want to have the SGX do what it does best, you should be able to write to the depth buffer in software. Then the SGX would draw it's triangles, and you would follow it up with a second pass to fill in where the triangles didn't cover.
There is no edge processing, just edge formation via maths. (Heh, maths)
I've got nothing better to do, so I'll describe the process in an edit.
You start with your shape equation (sphere).
: x^2 + y^2 + z^2 = r^2
Substitute as if you were raytracing, where x,y,z is the ray direction; a,b,c is the offset from the camera; and t is the ray's scaling factor, meaning t*{x,y,z} = intersection point.
: (x*t - a)^2 + (y*t - b)^2 + (z*t - c)^2 = r^2
Solve for t.
: x*x*t*t - 2*x*t*a + a*a + y*y*t*t - 2*y*t*b + b*b + z*z*t*t - 2*z*t*c + c*c = r*r
: t*t*(x*x + y*y + z*z) - 2*t*(x*a + y*b + z*c) + a*a + b*b + c*c - r*r = 0
quadratic formula: t = ( 2*(x*a + y*b + z*c) +- sqrt( 4*(x*a + y*b + z*c)^2 - 4*(x*x + y*y + z*z)*(a*a + b*b + c*c - r*r) ) ) / ( 2*(x*x + y*y + z*z) )
Now, if both solutions are equal then the positive sqrt is equal to the negative sqrt. The only number that is both positive and negative is zero, so:
: sqrt( 4*(x*a + y*b + z*c)^2 - 4*(x*x + y*y + z*z)*(a*a + b*b + c*c - r*r) ) = 0
simplify: (x*a + y*b + z*c)^2 - (x*x + y*y + z*z)*(a*a + b*b + c*c - r*r) = 0
Think of it like we cut the sphere into two pieces: the piece we can see, and the piece we can't see. Where these two halves intersect forms the perimeter of the sphere from our point of view.
Now we have a projection of a sphere. How do we rasterize it? We use the same method again to eliminate another variable.
Solve for x.
: x*x*a*a + y*y*b*b + z*z*c*c + 2*x*a*y*b + 2*x*a*z*c + 2*y*b*z*c - x*x*(a*a + b*b + c*c - r*r) - (y*y + z*z)*(a*a + b*b + c*c - r*r) = 0
: -x*x*(b*b + c*c - r*r) + 2*x*a*(y*b + z*c) + y*y*b*b + z*z*c*c + 2*y*b*z*c - (y*y + z*z)*(a*a + b*b + c*c - r*r) = 0
quadratic formula: x = ( -2*a*(y*b + z*c) +- sqrt( 4*a*a*(y*b + z*c)^2 + 4*(b*b + c*c - r*r)*(y*y*b*b + z*z*c*c + 2*y*b*z*c - (y*y + z*z)*(a*a + b*b + c*c - r*r)) ) ) / ( -2*(b*b + c*c - r*r) )
Equate solutions.
: sqrt( 4*a*a*(y*b + z*c)^2 + 4*(b*b + c*c - r*r)*(y*y*b*b + z*z*c*c + 2*y*b*z*c - (y*y + z*z)*(a*a + b*b + c*c - r*r)) ) = 0
simplify: a*a*(y*b + z*c)^2 + (b*b + c*c - r*r)*(y*y*b*b + z*z*c*c + 2*y*b*z*c - (y*y + z*z)*(a*a + b*b + c*c - r*r)) = 0
Solve for y.
: a*a*(y*y*b*b + 2*y*b*z*c + z*z*c*c) + (b*b + c*c - r*r)*(-y*y*(a*a + c*c - r*r) - z*z*(a*a + b*b - r*r) + 2*y*b*z*c) = 0
: y*y*(a*a*b*b - (a*a + c*c - r*r)*(b*b + c*c - r*r)) + 2*y*b*z*c*(a*a + b*b + c*c - r*r) + z*z*(a*a*c*c - (a*a + b*b - r*r)*(b*b + c*c - r*r)) = 0
: -y*y*(c*c - r*r)*(a*a + b*b + c*c - r*r) + 2*y*b*z*c*(a*a + b*b + c*c - r*r) - z*z*(b*b - r*r)*(a*a + b*b + c*c - r*r) = 0
: -y*y*(c*c - r*r) + 2*y*b*z*c - z*z*(b*b - r*r) = 0
quadratic formula: y = ( -2*b*z*c +- sqrt( 4*(b*z*c)^2 - 4*(c*c - r*r)*z*z*(b*b - r*r) ) ) / ( -2*(c*c - r*r) )
simplify: y = ( b*z*c +- sqrt( (b*z*c)^2 - (c*c - r*r)*z*z*(b*b - r*r) ) ) / (c*c - r*r)
simplify: y = z*( b*c +- sqrt( (b*c)^2 - (c*c - r*r)*(b*b - r*r) ) ) / (c*c - r*r)
simplify: y = z*( b*c +- sqrt( r*r*b*b + r*r*c*c - r^4 ) ) / (c*c - r*r)
simplify: y = z*( b*c +- r*sqrt( b*b + c*c - r*r ) ) / (c*c - r*r)
This equation provides two solutions: the top and bottom of the sphere projection. Then you repeatedly feed y-values into one of the previous equations to produce pairs of x-values. Voila! Instant rasterization! I hope that clears things up, lol.