Giter Site home page Giter Site logo

angelo1211 / softwarerenderer Goto Github PK

View Code? Open in Web Editor NEW
586.0 17.0 62.0 215.02 MB

Software rendering engine with PBR. Built from scratch on C++.

License: MIT License

C++ 94.97% CMake 5.03%
rendering-engine 3d-graphics prototype software-rendering physically-based-rendering parallelization rasterization graphics sdl2 c-plus-plus

softwarerenderer's Introduction

Simple Software Graphics Engine(SSGE): A real-time and interactive 3D Renderer built from scratch in C++

SSGE is the result of a two month long learning project with the aim of building a real-time 3D renderer from scratch in C++. It is capable of modern Physically Based Rendering(PBR) without making use of any third party graphics libraries such as OpenGL, DirectX or Vulkan. It is entirely software based and does not utilize any hardware acceleration throughout it's rendering pipeline. SSGE can run on both Windows and Linux machines by leveraging CMAKE for executable building and compiling and SDL2 for OS and hardware-level abstraction.

Performance wise, it is capable of running scenes containing medium size meshes of ~50k triangles and 4 light sources at a relatively stable frame rate of 30fps (Of course, your mileage may vary) while running the very demanding PBR shader. To achieve this it makes heavy use of multithreading, SIMD directives and various other optimizations such as early backface culling, frustum culling and texture tiling among others.

You can download a demo of it for your machine here:

Project is now on hold :(

Unfortunately this project is no longer maintained. I got hired to work at Rockstar Games as a Graphics Programmer shortly after posting this and don't have the time to work on a sideproject of this size anymore. I plan on keeping it up (as well as my other major graphics project HRE) so others can see what it took me to break into the industry. I will still be helping anyone who runs into any issues with it or has any questions about it. Feel free to reach me here or at my twitter about this or any other GFX topic you'd like to talk about! Thanks to everyone who checked this project out! :D

Render Samples

Louis XIV de France, Louvre, Paris. Scan by HoangHiepVu

Utah teapots with 5 different materials

Chest PBR Test model from @Emackey

Cerberus PBR test model by Andrew Maximov

Orbiting the chest

Development & Feedback

I am planning on starting a series of blog posts sometime soon that will explain some of the cooler components of the engine and how I went about implementing them. I also feel it would be helpful to other beginners if I were to elaborate on some of the components that gave me the most trouble, such as how to design the general architecture of the engine, how to profile, optimize and bug fix your code and lastly how I personally tackled learning Computer Graphics coming from a non-cs background.

Goals

  1. Demonstrate my C++ Knowledge
  2. Satisfy a life long curiosity about computer graphics
  3. Keep the renderer Real-Time (original goal was 16ms actual ~29ms)
  4. Minimize external library usage to minimum
  5. Multiplatform development
  6. Use modern computer graphics techniques
  7. Learn to self-manage and architect "large" projects

I set these goals above as my learning targets for the project before I began and I have to say that I am very happy with how much progress I managed to make with most of them. If you're interested, I gave a talk that went more in detail about this and the journey in itself and you can find the slides for it here:

Talk Slides

Main Features

Rendering

  • Parallelized forward renderer
  • Programmable vertex & fragment shaders using C++ virtual functions
  • Physically Based Shading
  • Metallic workflow
  • Cook-Torrance specular BRDF ( w/lambert diffuse)
  • Perspective Correct Interpolation
  • Tangent Space Normal Mapping
  • Ambient Occlusion mapping
  • Reverse (AKA logarithmic) Z-Buffering [1,0]
  • Pre-vertex shader back-face Culling
  • View Frustrum culling
  • Gapless triangle rasterizer
  • Fast Gamma correction
  • Directional Lighting
  • Bilinear Texture Filtering
  • Seamless texture repeat
  • Flat, Gouraud, Phong, Blinn-Phong shaders (deprecated in favor of PBR)

Engine

  • SDL2 Backend
  • Multiplatform executables
  • Scene Switching
  • Free moving camera
  • Orbiting Camera mode
  • Camera FOV controls
  • Templated Vector Math / Linear algebra library
  • .Obj file parser
  • Scene content outlined in .txt file
  • Texture tiling to reduce cache misses
  • Multithreading per object and vectorization within lighting shader
  • Fully commented for future referencing
  • Image loading through stb-image
  • Axis aligned Bounding Box generation and reconstruction

Known Issues

  • Moire Pattern and specular aliasing due to lack of texture minification
  • Dark metallic objects due to lack of Image Based Lighting (or similar solution)
  • Jaggies from lack of antialiasing
  • No shadows causing undesired illumination in some models
  • Stuttering during slow rotations from lack of sub-pixel precision

References

I've moved most of the sources into a separate page on the wiki for easier navigation and indexing. However, here are some of the ones I utilized the most:

Model & Texture Acknowledgements

If any of the above textures or meshes have been mis-acknowledged, are misattributed, or missing a proper reference please send me a DM on Twitter or email me at the address inside the source files and I'll fix it immediately.

License

MIT License

Copyright (c) 2018 Angel Ortiz

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

softwarerenderer's People

Contributors

angelo1211 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

softwarerenderer's Issues

Performance scaling?

Very nice work! I am curious whether you have tried this on a many-core CPU, with 32 or 64 cores? Does the performance scale well?

Missing License

Hey Angel,

I saw your post on twitter and checked the project. I've been looking for candidates that I can use as experiments for ISPC, the Intel SPMD Program Compiler. I'd love to use this project, you've done a very good job with organization so I think it's a good fit. However I can't experiment with your code as it's unlicensed.

If you were to choose MIT or Apache 2.0 I'd love to experiment with ISPC implementations for certain functions.

Namely:
void SoftwareRenderer::drawTriangularMesh(Model * currentModel)
void Rasterizer::drawTriangles(Vector3f *vertices, IShader &shader, Buffer *pixelBuffer, Buffer *zBuffer)

Cheers,

Pete

A more "standard" build

I saw you produced a binary for Windows with some variation of the Mingw theme, but I was curious how the Visual Studio toolchain would fair. It looks like there are bits of syntax and constants that are not part of the C++ spec, so I inserted into geometry.h

`#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif

define M_1_PIf32 (0.318309886183790671537767526745028724) /* 1/pi */`

That went OK for a while but I borked hard with:

`
C:\Repos\SoftwareRenderer\include\shader.h(286): warning C4305: 'initializing': truncation from 'double' to 'float'
C:\Repos\SoftwareRenderer\include\shader.h(304): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
C:\Repos\SoftwareRenderer\include\shader.h(314): warning C4244: '=': conversion from 'double' to 'float', possible loss of data
C:\Repos\SoftwareRenderer\include\shader.h(381): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(382): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(383): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(386): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(387): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(388): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(389): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(390): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(391): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(392): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(393): error C2131: expression did not evaluate to a constant
C:\Repos\SoftwareRenderer\include\shader.h(378): note: failure was caused by a read of a variable outside its lifetime
C:\Repos\SoftwareRenderer\include\shader.h(378): note: see usage of 'this'
C:\Repos\SoftwareRenderer\include\shader.h(399): error C3863: array type 'Vector3f [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(405): error C3001: 'simd': expected an OpenMP directive name
C:\Repos\SoftwareRenderer\include\shader.h(407): error C3863: array type 'Vector3f [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(409): error C3863: array type 'float [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(414): error C3863: array type 'float [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(415): error C3863: array type 'float [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(417): error C3863: array type 'Vector3f [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(418): error C3863: array type 'float [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(419): error C3863: array type 'Vector3f [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(422): error C3863: array type 'Vector3f [maxLights]' is not assignable
C:\Repos\SoftwareRenderer\include\shader.h(425): warning C4305: 'argument': truncation from 'double' to 'const T'

`

Unfortunately I don't know at all what happens around line 378 but here it is

` const int maxLights = numLights;

    //Fresnel, normal distribution function and geometry occlusion 
    Vector3f F[maxLights];`

Improve build and usage instructions

It is not clear how to build and use the software. I initially did cmake .; make; ./softwareRenderer. Only after I did mkdir build; cd build; cmake ..; make; ./softwareRenderer could I test the program.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.