Skip to content

Tiny software renderer/rasterizer in C++ with no external libraries

Notifications You must be signed in to change notification settings

math-araujo/tiny-renderer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tiny Renderer

A basic software renderer based on Sokolov's Tiny Renderer and Gabriel Gambetta's Compute Graphics from Scratch.

Description

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:

  1. Wire frame model: draw lines between the vertices of the triangles of the model using the Bresenham's Line Algorithm;

  2. Filled triangles: fill the triangles with a random color by drawing horizontal lines between the triangle left and right ends;

  3. 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;

  4. 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;

  5. UV Textures: add textures to the image rendered using depth buffering and back face culling;

  6. Perspective Projection: add perspective projection;

  7. Gouraud Perspective: similar to the previous image, but using Gouraud Shading instead of textures to color the pixels;

  8. View Transform: add a camera transform to change the camera's point of view;

  9. 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.

Gallery

Head Model

Wire frame model
1 - Wire frame model
Filled triangles
2 - Filled triangles
Model with back face culling
3 - Back Face Culling
Depth Buffering
4 - Depth buffering
UV Textures
5 - UV Textures
Perspective Projection
6 - Perspective Projection
Gouraud Perspective
7 - Gouraud Perspective
View Transformation
8 - View Transform
Gouraud Shading
9 - Our GL using Gouraud Shading
Basic Texture
10 - Our GL using Basic Texture
Tangent Space Normal Mapping Texture
11 - Our GL using Normal Mapping
Phong Illumination
12 - Our GL using Phong

Diablo 3 Pose

Wire frame model
1 - Wire frame model
Filled triangles
2 - Filled triangles
Model with back face culling
3 - Back Face Culling
Depth Buffering
4 - Depth buffering
UV Textures
5 - UV Textures
Perspective Projection
6 - Perspective Projection
Gouraud Perspective
7 - Gouraud Perspective
View Transformation
8 - View Transform
Gouraud Shading
9 - Our GL using Gouraud Shading
Basic Texture
10 - Our GL using Basic Texture
Tangent Space Normal Mapping Texture
11 - Our GL using Normal Mapping
Phong Illumination
12 - Our GL using Phong

Building

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.

About

Tiny software renderer/rasterizer in C++ with no external libraries

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published