Now we'll start a series of articles, in asm language for the Amiga, dedicated to 3D routines creation with the following features:
- DOUBLE BUFFERING - ROTATION ON 3 AXIS - ZOOM - SORTING ( Z-VALUES & PRE-DETERMINED PRIORITY ) - LINES - NORMAL SURFACES - TRANSPARENT SURFACES!!! - HIDDEN FACES - DITHERING - CLIPPINGONLY I'D HAVE A LOT OF REQUEST, I'LL WRITE ARTICLES ABOUT:
- TEXTURE MAPPING - GOURAUD SHADING - PHONG SHADING - MOVING LIGHT SOURCE ON 3 AXIS
Send e-mail specifying your prefs (also completely different subjects, ex: compression and decompression algos)
It is a way of obtaining smoother anims, you need two or more memory blocks: while one block is showed, the other is used to calculate next frame. When rendering operation is done, the two buffers are swapped.
ROTATION ON 3 AXIS
Rotation can be done on one, two or three axis (X,Y,Z). Routine we'll consider will rotate points on all three axis, using a pre-calculated cos/sin table to speed up math operations.
ZOOM
Zoom is used to enlarge/reduce object's dimensions, such as this object gets get closer or further from us.
SORTING
One of the bigger problems is certainly the one related to sorting routine. You have to give a drawing priority to faces building our object. This priority is needed in some cases: let's see when.
Here there is a pratical example: a 3D cube is made up of 6 faces (in our example number of points is unneeded); in any way you turn it, you'll see a maximum of three faces. Remaining 3 faces are not visible by the observer (HIDDEN FACES!), so it is perfectly unuseful to draw them. While things seem to be easy for this kind of faces, everything gets harder for visible ones.
In this example, visible faces will never overlap, so it is perfectly unuseful give them a drawing priority (it is not important the order they are drawn).
In a more complex example, you should give a priority to all faces, to avoid that hidden parts are drawn before the visible ones.
In this case, a Z-sort is necessary to balance the drawing. To set down it in words, after you have rotated and zoomed the object, you have to get only Z coords and create table a median distance of every face, once calculated you will sort faces up: starting from the further part of the object to the closest part.
NORMAL SURFACES
They are simple filled and faces overlapped to the surrounding ones. TRANSPARENT SURFACES
Transparent surfaces have to be calculated but not showed. You have to be able to see through them: in this case inner faces have to be shown Returning to the cube: 3 visible faces and 3 not; for transparent faces, you'll need to show also hidden faces.
HIDDEN FACES
By a simply algo you can understand whether a face is visible or not (in this case we will not draw it, for gaining maximum speed).
DITHERING
This procedure is used to add grid mask of points, to have intermediate colours and shadow effects.
CLIPPING
It is used when a face exists from the visible zone of the screen. With this routine it is possible to draw just visible parts of faces.
TEXTURE MAPPING
This is a technique to map bitmaps to polygons. It is often used in DOOM style-game, this pic have to be calculated and rotated.
GOURAUD SHADING
Math method to choose a face colour from its and light source rotation degree . Light is supposed to be constant from the polygon.
PHONG SHADING
Here you have to calculate face colour point by point, reducing faces scaling. PHONG is better than GOURAUD, but requires more operations and more powerful machines.
MOVING LIGHT SOURCE ON 3 AXIS
With both GOURAUD and PHONG SHADING you need coords (x,y,z) of a light point to allow computation of lighting colours, by moving this light source, all object illumination should change.
In this article we'll consider only first 3 points, others will be discussed in next months.
DOUBLE BUFFERING
In this example, I have used 6 memory blocks, to obtain an effect similar to Motion Blur).
In "calcolascreen" i do compute the next frame while I show the others in sequence, so we'll have:
screen1 = last computed frame
screen2 = 1 frame before the last
screen3 = 2 frame before the last
screen4 = 3 frame before the last
screen5 = 4 frame before the last
Once cleared showing sequence, I use the blitter to clear bitplane contents (CalcolaScreen).
SwapScreen: ** Change Screen Pointer for next frame move.l CalcolaScreen a to