Skip to content

maxbrundev/Rasterizer

Repository files navigation

Realtime CPU Software Rasterizer

rasterizer

Description

A CPU-based software rasterizer designed to explore low-level rendering techniques and principles. This project implements various rasterization features without relying on hardware acceleration, making it a great educational and experimentation project for graphics programming.

Features

  • Triangle Rasterization

  • Line Rasterization

  • Texture Mapping

  • Clipping

  • Mipmapping

  • MSAA

  • Vertex pass

  • Fragment pass

  • Depth Writing

  • Depth Testing

  • OBJ Parsing

  • WIP Shadow Mapping
    shadows

GL Rasterizer API

An OpenGL-inspired API that encapsulates its own Rendering State and manages internal buffers to provide a streamlined interface for Drawing, handling Buffers, and processing Shaders.

uint32_t VAO;
uint32_t VBO;
uint32_t EBO;

std::vector<Geometry::Vertex> vertices = {
	{{-1.0f, 0.0f, -1.0f}},
	{{-1.0f, 0.0f, 1.0f}},
	{{1.0f, 0.0f, 1.0f}},
	{{1.0f, 0.0f, -1.0f}}
};

std::vector<uint32_t> indices = { 0, 1, 2, 2, 3, 0 };

GLRasterizer::GenBuffers(1, &VBO);
GLRasterizer::BindBuffer(GLR_ARRAY_BUFFER, VBO);
GLRasterizer::BufferData(GLR_ARRAY_BUFFER,
	vertices.size() * sizeof(Geometry::Vertex),
	vertices.data());

GLRasterizer::GenBuffers(1, &EBO);
GLRasterizer::BindBuffer(GLR_ELEMENT_ARRAY_BUFFER, EBO);
GLRasterizer::BufferData(GLR_ELEMENT_ARRAY_BUFFER,
	indices.size() * sizeof(uint32_t),
	indices.data());

GLRasterizer::GenVertexArrays(1, &VAO);
GLRasterizer::BindVertexArray(VAO);

GLRasterizer::BindBuffer(GLR_ARRAY_BUFFER, VBO);
GLRasterizer::BindBuffer(GLR_ELEMENT_ARRAY_BUFFER, EBO);

GLRasterizer::BindVertexArray(0);

GLRasterizer::UseProgram(shaderInstance);
GLRasterizer::BindVertexArray(VAO);
GLRasterizer::DrawElements(GLR_TRIANGLES, static_cast<uint32_t>(indices.size()));
GLRasterizer::BindVertexArray(0);

Roadmap

  • Rendering Enhancements:

    • Renderer:
      The current Renderer is minimal; to enhance modularity and extensibility, a rework is required to support a stateful pipeline and accommodate multiple render passes.
    • Anti-aliasing:
      Refine the existing MSAA implementation and explore additional multi-sampling techniques (e.g., FXAA, SMAA) to effectively reduce aliasing artifacts while maintaining performance.
    • Mipmapping:
      Optimize the mipmap generation algorithm for improved texture sampling and memory efficiency, and rework the adaptive level-of-detail (LOD) system to increase realtime performance and visual quality.
    • Shadow Mapping:
      Implement a robust shadow mapping pipeline that addresses common challenges (e.g., shadow acne, depth biasing) to achieve dynamic shadows.
  • Rework Architecture:
    Overhaul the current architecture to develop a modular, game engine–style framework. This includes providing an OpenGL-like API for rasterizer-related functions, thereby facilitating easier integration and future expansion.

  • UI Integration:
    Implement a dedicated Panel to allow realtime control over:

    • Rasterization settings
    • Render passes
    • Scene management
      ...
  • Global Optimization:

    • SIMD
    • Tile Based Rasterization

Software

  • Visual Studio 2022

Dependencies

  • SDL2 (Windowing and inputs)
  • GLM (Mathematics)
  • stb_image (Image Loader)
  • Premake5 (Project generation)

Compiling sources

Premake5 is used to generate project files. To generate the project, execute GenerateProject.bat. By default, GenerateProject.bat will generate project files for Visual Studio 2022. If you want to use another version of Visual Studio you can execute GenerateProject.bat from the command line with the Visual Studio version as argument. (ex: .\GeneratedProject.bat vs2019)

Video and Screenshots

cppRasterizer

Sponza rendered with MSAA x8 sponzaRasterizer

Polygon Rasterization Mode primitiveMode

Texture Filtering TextureFilter Left Linear, Right Nearest.

Mipmapping mipmaps Left mipmaps off, Right mipmaps on.

Clipping

clipping
Frustum plane distances have been reduced to highlight clipping

Licence

This project is licenced under an MIT Licence.