YohannDR / rasterizer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rasterizer

CPU based rasterizer

An experimental CPU based rasterizer, which contains basic features and is inspired by OpenGL.

Features

Below is a list of the different features available in this project :

Triangle rendering

Given a list of 3 points in Normalized Device Coordinates (NDC) space, the standard transformation pipeline (model, view, projection, viewport) is applied and the triangle is rendered in screen space while being filled with its color.

thumbnail thumbnail

Camera

A simple camera can be used to view the scene, its position and center can be changed, as well as its FOV and near/far clip planes. The corresponding view and projection matrices based on these values are forwarded to the renderer.

thumbnail

Color interpolation

The colors between the points are linearly interpolated inside of the triangle, thus resulting in a blend between the colors.

thumbnail

Textures

Textures can be loaded from a file (either PNG or JPG) and applied to any triangle by using texture coordinates. The texture is merged with the interpolated color showed previously.

thumbnail thumbnail

Depth buffer

The depth buffer allows triangles that should be rendered behind other triangles to be partially discarded (on a fragment basis), which allows correct 3D order rendering and overlap.

thumbnail

3D models

3D models using the Obj format can be loaded and rendered.

thumbnail

Each object has its own position, rotation and scaling and they can be modified independently.

thumbnail

Lights

The support for 8 simultaneous lights is currently in place, each light uses the Phong illumination model (ambiant, diffuse, specular).

The lights also support attenuation (linear, quadratic and radius).

thumbnail thumbnail thumbnail thumbnail

Materials

Each object can have its own material, which is used to impact how light reflects off of it.

Blending

Blending makes use of the alpha component, it can blend multiple colors together, allowing for transprency.

I used the same operations and equations as OpenGL for this, at least what this page says about it.

Also most of them aren't tested, since the only one that's really useful is srcAlpha, 1-srcAlpha, Add.

thumbnail

Stencil buffer

A very basic stencil buffer was implemented, it supports writing to the buffer when the color buffer is written to, and discarding fragments based on the value of the buffer.

It's currently used to create a simple outline effect on the models.

thumbnail

Perspective correction

Perspective correction is implemented in the renderer, allowing for correct texture and color interpolation.

thumbnail

Back face culling

Back face culling is technically implemented, however it doesn't fully work properly (it discards faces that it shouldn't)

External libraries

SudoMaths

SudoMaths is a 3D oriented Maths library that I made myself, currently used to handle all the Vector/Matrix maths.

Glad is a C binding for the OpenGL APi, I use it in conjuction with ImGui to render.

Glfw is an API used to handle native Windows.

ImGui is a graphical user interface library, I use it for the UI parts of the application.

Stb image is image loading library, currently used to load the textures.

Stb image is a 3D model loader library, currently used to load the obj models.

Resources

Here's a few of the resources and documentations I used for this project :

Transformation pipeline

Barycentric coordinates and interpolation

3D model loading

Lighting

Light attenuation

Stencil buffer

Blending

Perspective correction

Back face culling

About


Languages

Language:C++ 100.0%