SoftGLRender
Tiny C++ Software Renderer/Rasterizer, It implements the GPU's main rendering pipeline, including point, line, and polygon drawing, texture mapping, and emulates vertex shaders and fragment shaders, 3D models (GLTF) are loaded by assimp, and using GLM as math library.
The project also adds OpenGL and Vulkan renderers implementation, so you can switch between them in real time while running.
Source Code Structure
src
├── Base/ - Basic utility classes.
├── Render/ - Renderer abstraction.
| ├── Software/ - Software renderer implementation.
| ├── OpenGL/ - OpenGL renderer implementation.
| └── Vulkan/ - Vulkan renderer implementation.
└── Viewer/ - Code for Viewer, mainly include GLTF loading (based on Assimp), camera & controller,
| setting panel, and render pass management.
| You can switch between software renderer and OpenGL renderer in real time.
└── Shader/
├── GLSL/ - GLSL shader code.
└── Software/ - Simulate vertex shader & fragment shader using c++, several basic shaders
are embed such as blinn-phong lighting, skybox, PBR & IBL, etc.
Renderer abstraction
class Renderer {
public:
// framebuffer
virtual std::shared_ptr<FrameBuffer> createFrameBuffer(bool offscreen) = 0;
// texture
virtual std::shared_ptr<Texture> createTexture(const TextureDesc &desc) = 0;
// vertex
virtual std::shared_ptr<VertexArrayObject> createVertexArrayObject(const VertexArray &vertexArray) = 0;
// shader program
virtual std::shared_ptr<ShaderProgram> createShaderProgram() = 0;
// pipeline states
virtual std::shared_ptr<PipelineStates> createPipelineStates(const RenderStates &renderStates) = 0;
// uniform
virtual std::shared_ptr<UniformBlock> createUniformBlock(const std::string &name, int size) = 0;
virtual std::shared_ptr<UniformSampler> createUniformSampler(const std::string &name, const TextureDesc &desc) = 0;
// pipeline
virtual void beginRenderPass(std::shared_ptr<FrameBuffer> &frameBuffer, const ClearStates &states) = 0;
virtual void setViewPort(int x, int y, int width, int height) = 0;
virtual void setVertexArrayObject(std::shared_ptr<VertexArrayObject> &vao) = 0;
virtual void setShaderProgram(std::shared_ptr<ShaderProgram> &program) = 0;
virtual void setShaderResources(std::shared_ptr<ShaderResources> &uniforms) = 0;
virtual void setPipelineStates(std::shared_ptr<PipelineStates> &states) = 0;
virtual void draw() = 0;
virtual void endRenderPass() = 0;
};Software Renderer Features
Pipeline
- Vertex shading
- View Frustum culling (line & triangle)
- Perspective Correct Interpolation
- Back-Front face culling
- Point rasterization
- Line rasterization
- Triangle rasterization
- Fragment Shading
- Shader derivative
dFdxdFdy - Depth test
- Alpha blending
- Reversed Z
- Early Z
- MSAA
Texture
- Mipmaps
- Sample parameters:
Lod,Bias,Offset - Filtering
- NEAREST
- LINEAR
- NEAREST_MIPMAP_NEAREST
- LINEAR_MIPMAP_NEAREST
- NEAREST_MIPMAP_LINEAR
- LINEAR_MIPMAP_LINEAR
- Wrapping
- REPEAT
- MIRRORED_REPEAT
- CLAMP_TO_EDGE
- CLAMP_TO_BORDER
- CLAMP_TO_ZERO
- Image storage tiling and swizzling
- Linear: pixel values are stored line by line, commonly used as image RGBA buffer
- Tiled: block base storage, inside the block pixels are stored as
Linear - Morton: block base storage, inside the block pixels are stored as morton pattern (similar to zigzag)
Viewer Features
- Settings panel
- Orbit Camera Controller
- Blinn-Phong shading
- PBR & IBL shading
- Skybox CubeMap & Equirectangular
- FXAA
- ShadowMap
Optimization
- Multi-Threading: rasterization is block based with multi-threading support, currently the triangle traversal algorithm needs to be optimized.
- SIMD: SIMD acceleration is used to optimize performance bottlenecks, such as barycentric coordinate calculation, shader's varying interpolation, etc.
Showcase
Render Textured
Dependencies
Clone
git clone git@github.com:keith2018/SoftGLRender.git
cd SoftGLRender
git submodule update --init --recursiveBuild
mkdir build
cmake -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build --config ReleaseRun
cd bin/Release
./SoftGLRenderLicense
This code is licensed under the MIT License (see LICENSE).






