A high-performance, cross-platform, CPU-based software renderer written from scratch in modern C++20. This project demonstrates rasterization techniques, including terrain generation from noise, model loading, and custom shader effects, with all windowing and input handled by SDL2.
- High-Performance Software Rendering: Optimized for multi-core CPUs.
- Procedural Terrain Generation: Creates dynamic landscapes using OpenSimplex noise.
- Custom Shader Support: A flexible shader system for implementing custom lighting and color effects.
- Model and Texture Loading: Supports
.objfor 3D models and a custom.bytesformat for textures. - Cross-Platform: Uses CMake to build and run on Windows, macOS, and Linux.
- Modern C++20: Leverages modern C++ features for clean, efficient, and maintainable code.
- C++20 compatible compiler (e.g., MSVC v143+, GCC 13+, Clang 16+)
- CMake 3.14+
- SDL2: Handled automatically via
FetchContentif not found on your system.
This project is configured with CMake and can be built using the command line or your favorite C++ IDE.
- Launch Visual Studio and select "Open a local folder".
- Navigate to and select the root directory of the
CPU_Rasterizerproject. - Visual Studio will automatically detect
CMakeLists.txtand configure the project. - Once configured, select the desired target (CPU_Rasterizer or terrain_demo) from the "Select Startup Item" dropdown in the main toolbar.
- Press the green Run button (
▶️ ) to build and run the selected demo.
- Launch CLion and select File > Open.
- Navigate to and select the project's root
CMakeLists.txtfile or the project folder. - CLion will automatically load and sync the CMake project.
- In the top-right corner, select the desired target (CPU_Rasterizer or terrain_demo) from the configurations dropdown.
- Click the Run (
▶️ ) or Debug (🐞) button to build and run.
- Make sure you have the C++ Extension Pack and CMake Tools extensions from Microsoft installed.
- Open the
CPU_Rasterizerproject folder in VS Code. - A prompt will ask you to configure the project; select Yes. If it doesn't, open the Command Palette (
Ctrl+Shift+P) and run CMake: Configure. - Use the status bar at the bottom to:
- Select the build variant (
Debug,Release, etc.). - Select the active build target (
[CPU_Rasterizer]or[terrain_demo]). - Click the Build button or press
F7. - Click the Run button or press
Ctrl+F5.
- Select the build variant (
- Clone the repository:
git clone [https://github.com/luckynee/CPU_Rasterizer.git](https://github.com/luckynee/CPU_Rasterizer.git) cd CPU_Rasterizer - Configure the build (creates a
builddirectory):# For a Release build cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
- Build the executables:
# This command works for Makefiles, Ninja, and MSBuild cmake --build build - Run the demos (executables are inside the
builddirectory):# Run the core engine demo ./build/CPU_Rasterizer # Run the terrain demo ./build/terrain_demo
- 3D Models:
.obj. A standard, widely supported format for 3D geometry. - Textures:
.bytes. A custom raw pixel data format used by this project for simplicity and fast loading.
src/core_engine/— Core rasterizer engine, math utilities, and shader classes.src/demos/— Source code for the demo applications.resource/— Contains.objmodels and.bytestextures.
- If you encounter build errors, ensure your compiler fully supports C++20.
- On Windows, the
SDL2.dllis automatically copied next to the executables. If the program fails to start with a DLL error, clean your build directory and rebuild.
Note for Windows users:
- The project directory path should not contain spaces. MinGW has known issues handling spaces in directory paths, which can cause build failures.
CMake Build Types:
- This project supports three CMake build types:
Debug,Release, andRelWithDebInfo. - You can specify the build type when configuring CMake, for example:
cmake -DCMAKE_BUILD_TYPE=Release ...