Changelog - v0012 07/Aug/2005 Making a constant which defines the size of the superpixels Realtime rendering system - . First-hit optimisation for spheres . One light source, no shadowing yet apart from dark side of objects . Can render 500 spheres with 10fps on my 2.2GHz laptop The optimisation - Based on bounding boxes, the first-ray intersection code does not have to check every object at every pixel It uses the fact that you are doing the interesction tests along a scanline, and then moving to the next scanline down Further optimisations - Spheres can have z-boundaries, so once a sphere intersection test has been successful for a pixel you don't need to check all other spheres, because some have no way of coming close. This might get in the way of CSG, which i think is imminently possible. CSG - A method - Get all the entry and exit points of all the spheres at this pixel Order entry and exit points with the nearest to the viewer first Have an array of flags, one for each sphere For each point, starting at the viewer: If you are entering a sphere, set that sphere's flag If you are leaving a sphere, clear that sphere's flag Check against the formula for this CSG eg. ( A | B ) & ( C - D ) If we are already inside A and C and we have just left D the values are: A=1 B=0 C=1 D=0 So the equation's value is 1 The first time the result is 1 is where the ray intersects the CSG The surface properties of the point are those of the sphere we have just enetered/left