Step46: Doing 3D

wip

The aim of this article is to explain how we can represent 3 dimensionnals elements on screen. Amiga is a very limited machine so 3D is liimited, but lot of nice things are doiable on Amiga.

What is 3D ?

Basically, the Amiga hardware have been thought to create 2D games. But it is possible to display 3D world on it. It took time to acheive this but some greate 3D demos and 3D games have been done on Amiga 500.

« 3D » is roughly the ability to express the « depth »of a scene. In early days of computers, somes games and demos used tricks to give the sensations of a 3D world. 

In 1974 the game « spasim » (« Space Simulator ») can be considered as the first 3D game

In 1983 « Star wars » arcade game

In 1984 « Rescue on Fractalus » with some landscapes (voxels landscapes)

1984, « I robot » from Atari (Arcade game), surely the first 3D game with filled faces

There are also « fake » 3D representation, like the 2D technic called « isometric 3D ». An example is « Desert Strike » on Amiga

In demo the first effects that was done in 3D was the « starfield »

For example Unit A intro in 1988

Transformation of points

The first things when you want to do realtime 3D on a computer is to transform point. The transformation have to convert a point in a 3D world into a point on screen (2D space). This is called a « projection ».

In current hardware it is very common to do these computings. To compute screen coordinates of a 3D object, you need to transform its local coordinates to screen coordinates going through several transformations:

Local coordinates -> Apply local animation (rotation) -> Apply world translation -> Apply camera rotation and position -> Projection on screen

The computing imply floating points and divisions. Sadly the Amiga does not have any floating point computation. Moreover the integer division and multiplication costed lot of time. So we used integers to stores the coordinates (with fixed point system), sinus and cosinus where precomputed into tables. All the above transformation where baked into one single matrix. So using 12 multiplications per point, you could acheived a 3D transformation. Of course, the first systems where simplified (only rotating objects, non world translation, no camera). The operations could be reduced to 9 multiplication per points.

Perspective

The perspective is the 3D to 2D projection that allow farer point to look closer to the center of screen. This give the impression of « 3D ».

TODO: Add my perspective formula

Rotation

Before doing projection, you could also do a rotation of the point in 3D space. For doing this you have to use sinus and cosinus. We compute a « matrix » and apply it to all point. On Amiga to have fastest running time, we used self modified code. That means the values of the matrix were diretly changed into the memory so that the code can do immediate multiplications instead of getting the data from memory.

A 2D rotation is looking like this:

A 3D Rotation is the multiplication of 3 roations around axis X Y and Z.

(c is « cos », s is « sin »)

As I said, cosinus and sinus can be precomputed into a table. All elements of the formula can also be computed only once, as the three angles are constant for all points. This formula is for rotation. If you also want to add translations, you have to use a 4×4 matrix.

The cost of such a formula is huge because there are multiplication.

In term of « cycles », here are some comparaison :

ADD in byte or word take 4 to 8 cycles

MULS or MULU take 70 cycles

(and DIVU 140 cycles)

TODO: Add a rotation formula.

Displaying 3D

Wireframe

The first 3D objects where displayed in wireframe. On Amiga, the blitter was able to draw line, so this was easy. You only had to compute position of point. The « clipping » can be the tricky part here. « Clipping » means computing the intersection with border when the line is going out of screen.

Filled faces / Flat shading

Using blitter, you could also filled the surfaces. The line drawing was planned to support fill (one point per line). This was « easy » to draw vectors then fill them. On Amiga, you have bitplanes. So first filled 3D objects where using few colors (4), but also transparency (mix of bitplanes). The « glenz » effect was easy on Amiga.

Textures

That’s the tricky part. On Amiga, there was nothing to display textured 3D. To acheive this you had to compute the 3d object pixel per pixel and then convert the result to bitplanes. That was very expensive in computing. Some people used the « chunky » method to easy the diplay (chunky = use copper tricks to have big pixels on screen and allow easy display of colored pixels). The texture mapping had to be done line by line using the « scanline » algorithm.

TODO Add « scanline » illustration. Check if this is the right work in english.

TODO: Add demo that use each of the 3D type listed above.

Example of nice 3D demos

Trip to mars (1990)

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Ce site utilise Akismet pour réduire les indésirables. En savoir plus sur comment les données de vos commentaires sont utilisées.