A basic software renderer based on Sokolov's Tiny Renderer and Gabriel Gambetta's Compute Graphics from Scratch.
This repository implements a basic software renderer including space transformations (model-view, projection and viewport), a simple rasterizer and elementary shading functions.
The code is structured to reproduce the output of each chapter of Sokolov's book, including four types of shaders for the last chapter. The result of executing the code is 12 images, whose descriptions are given below.
Note that the implementation was incremental; therefore a posterior image likely uses the algorithms implemented on previous images (e.g. to render image 8, it's necessary to use almost all the algorithms used in images 1 to 7).
A brief summary of the images generated and the algorithms implemented:
-
Wire frame model: draw lines between the vertices of the triangles of the model using the Bresenham's Line Algorithm;
-
Filled triangles: fill the triangles with a random color by drawing horizontal lines between the triangle left and right ends;
-
Back Face Culling: discard triangles that aren't visible based on the angle between the surface normal and the view vector, and colors the visible triangles proportionaly to the dot product of these vectors;
-
Depth Buffering: for each pixel, determines the visible triangle (if any) by ordering the triangles using the z-coordinate, fixing the problems of the Painter's algorithm; see more details here: Hidden Surface Removal;
-
UV Textures: add textures to the image rendered using depth buffering and back face culling;
-
Perspective Projection: add perspective projection;
-
Gouraud Perspective: similar to the previous image, but using Gouraud Shading instead of textures to color the pixels;
-
View Transform: add a camera transform to change the camera's point of view;
-
Our GL: corresponds to images 9 to 12. Uses the previous algorithms to render a model and use shading functions, such as Gouraud, a basic texture, a tangent space normal mapping texture and Phong shading.
Head Model
Diablo 3 Pose
Requirements: C++17, CMake >= 3.12
git clone https://github.com/math-araujo/tiny-renderer.git
cd tiny-renderer
cd build
cmake ..
cmake --build .
(add other CMake options as desired e.g. cmake --build . --config Release
)
Run: for example, Debug\main.exe
or Release\main.exe
on MSVC or ./main
on Linux
Command-line arguments: path (parts separated by /
) to the .obj file to be rendered e.g. Release\main.exe obj/diablo3_pose/diablo3_pose.obj
; if no command-line argument is provided, the Head Model is used.