A ray-tracing renderer implemented in Java. The renderer supports Obj file reading, polygon drawing, object space transformation/projection, clipping, Z-buffer, ambient lighting, and Phong-model lighting.
1. compile: `javac -cp ./src ./src/client/Main.java`
2. run: `java -cp ./src client.Main [filename]`
[filename] can be empty, or use any simp file names.
The renderer uses Phong lighting model to calculate pixel values:
There are three options for the rendering style:
- Flat
- Gouraud
- Phong
In flat shading, one averages the vertices of a polygon to find a center point on the primitive. If there are normals present at the vertices, then the renormalized average of these normals is used the normal for the lighting calculation:
N = normalize(𝑁1+𝑁2+𝑁3).
Otherwise the face normal is used:
N = normalize((V2 - V1) X (V3 – V1)).
Using the center point with the normal, apply the lighting model to get a lighting value (RGB vector). The lighting-calculation is using the same color for all pixels in the polygon.
At each vertex of a polygon, find a normal. If the vertex is from an obj file and has a specified normal, use it. Otherwise, the face normal is at every vertex. At each vertex, apply the lighting model to get a lighting value. Then blerp these lighting values across the polygon, using the blerped value as the pixel value at each pixel.
Find a normal at each vertex as with gouraud shading. Normals are blerped, so as the camera space points, and color across the polygon. At each pixel, used the blerped point, normal, and color in the lighting model to obtain a pixel value for the pixel.
This renderer can import obj files and choose which shading style to use. Here is an example:
