This is a Tiny Renderer on CPU built from scratch, using OpenGL-similar API design. this project served as learning project and took quite a lot reference from project https://github.com/zauonlok/renderer for multi-platform depolying.
I intend to implement a shader-based renderer that runs on CPU from scratch using c++ with minimum dependencies, with the following features:
- CPU rasterization
- Shading via shaders
- Similar to OpenGL API
- Cross Platform (MacOS, Windows)
- Image and Geometry Processing
A simple example for creating a shader, simply inherit class Shader, you are able to access lighting, scene, mvp matrix, interpolated attributes and so on.
#include "src/api.hpp"
using namespace LuGL;
class ExampleShader : public Shader
{
public:
virtual v2f vert(const vdata in, const Entity * entity, const Scene & scene) const;
virtual vec4 frag(const v2f in, const Entity * entity, const Scene & scene) const;
};
v2f ExampleShader::vert(const vdata in, const Entity * entity, const Scene & scene) const
{
v2f out;
out.position = MVP_MATRIX * vec4(in.position, 1.0f);
out.texcoord = in.texcoord;
out.normal = MODEL_INV_TRANSPOSE * in.normal;
return out;
}
vec4 ExampleShader::frag(const v2f in, const Entity * entity, const Scene & scene) const
{
rgb color = rgb(
in.normal.x * 0.5f + 0.5f,
in.normal.y * 0.5f + 0.5f,
in.normal.z * 0.5f + 0.5f );
return vec4(color.normalized(), 1.0f);
}
8X MSAA | 4X MSAA | 2X MSAA | No AA |
---|---|---|---|
7 FPS | 10 FPS | 12 FPS | 21 FPS |
Code Sample in
src/sample/demo.cpp
Teapot | Spot |
---|---|
Triangle Normal Shading | Vertex Normal Shading |
---|---|
- Basic Math Liberary
- Basic Resource IO (.obj, .bmp)
- Basic Rasterization Implementation
- Basic Graphics Pipeline that runs on single thread
- Win32 Application API
- Simple Shaders (Unlit, VertexNormal, TriangleNormal)
- Hovering Camera by Mouse Drag
- Implement Barycentric Triangle Rastrization with Perspective Correction Interpolation
- Wireframe Display
- Multisample anti-aliasing (2X/4X/8X)
- Normal Mapping
- Read .mtl for Material
- Basic Lighting + Phong, Blinn Shaders
- Mipmapping
- Sky Box + Environment Map
- PBR
- PostProcessing Pass
- Shadow
- SSAO
- SS Reflection
- Alpha Test + Alpha Blending
- Multi-threading using openmp
- MacOS screenshot produce error BMP file
-
basic linear algebra
- vector
- quaternion
- matrix
-
IO
- BMP Format
- OBJ Format
-
Graphics
- basic rasterization algorithm
- colormap
- digit display
- programable shader
- MSAA
-
Others
- dynamic array
- quick sort
MacOS (Cocoa App)
Windows (Win32 App)
- compile
make macos
- run
./viewer
- compile
mingw32-make win32
- run
viewer