An application for rendering scenes using either Blinn-Phong shading, or physically based shading.
Note that Windows and Linux are supported.
Access the report that goes alongside this code here
This repo was originally hosted on Azure Devops and later migrated to Github, hence the lack of commit history.
- Visual Studio 2019 must be installed
- Make must be installed
- Clone the repository and navigate to the project root directory
- Run
call Scripts/GenerateVisualStudioFiles.batto generate the Visual Studio configuration files using Premake - Open the
PBR.slnsolution file in Visual Studio, and build all the projects
- Clone the repository and navigate to the project root directory
- Run
./Scripts/GenerateLinuxMakeFiles.shto generate the make configuration files using Premake - Run
apt-get install libxcursor-dev libxrandr-dev libxinerama-dev libxi-devto install all the x11 libraries required to build glfw - Run
makeand thenmake config=releaseto build all the projects in both debug and release configurations
- The program can be run:
- Inside Visual Studio
- Or by running the executable directly, which is located in the
Application/bin/Release/Application/orApplication/bin/Debug/Application/directories. When doing this, make sure that the working directory is correctly set toApplication/
- Navigate to the
Application/directory - Run
./bin/Debug/Application/Applicationor./bin/Release/Application/Application
Note that the Release build runs significantly faster than the Debug build
- Operating the camera is done in the following manner:
- Moving the mouse + left click pans the camera
- Moving the mouse + right click rotates the camera
- Scroll wheel zooms the camera in and out
- By default, the Blinn-Phong renderer and scene are running on start up. Switching between the two renderers and scenes is then done in the following manner:
- Pressing p will switch to the physically based renderer and scene
- Pressing b will switch to the Blinn-Phong renderer and scene
- The application window can be resized to whatever size, and the renderers will adjust accordingly
An intuitive API is made available to allow the user to define their own scenes. Alternatively, the TestSceneFactory class can be used to load some pre-made ones. All scene creation code should be invoked from the Workspace class. Different scenes are created for the two renderers:
- Blinn-Phong scenes are created by calling the
BlinnPhongScene::create()method - Models loaded in Blinn-Phong mode are added to the scene using the
addModel(...)method, which takes in aReference(a wrapper forstd::shared_ptr) to aModelobject, as well as a transform matrix - Blinn-Phong point lights are added to the scene using the
addPointLight(...)method, which takes in aReferenceto aPointLightobject
- Physically based scenes are created by calling the
PBRScene::create()method - Models loaded in PBR mode are added to the scene using the
addModel(...)method, which takes in aReferenceto aModelobject, as well as a transform matrix - Physically based point lights are added to the scene using the
addPointLight(...)method, which takes in aReferenceto aPointLightobject
Different point lights are intended for use with the two renderers:
- Blinn-Phong point lights are created using the
BlinnPhongPointLight::create()method - Physically based point lights are created using the
PBRPointLight::create()method
Models can be created in two different ways:
If reading in a model from an external file, the Model class's constructor can be invoked with two arguments:
- The first argument is an
std::stringthat contains the filepath - The second argument is an instance of the
Model::MaterialModelenum that specifies the mode that the model's materials should be loaded with. It should be one of:Model::MaterialModel::BLINN_PHONGif reading in a 3D model that is intended to be used in a Blinn-Phong scene with the Blinn-Phong renderer. The loader has been validated to work with.objfilesModel::MaterialModel::PBRif reading in a 3D model that is intended to be used in a physically based scene with the physically based renderer. The loader has been validated to work with.fbxfiles
Alternatively, a model can be created using the ModelFactory class. This class generates models with a single simple mesh. Models are created through the model factory by using the ModelFactory::create(...) method. Two arguments need to be supplied, with a third optional one:
- The first argument is an instance of the
ModelFactory::MeshTypeenum that specifies the type of mesh to create. It should be one of:ModelFactory::MeshType::CUBEwhen wanting to create a cube meshModelFactory::MeshType::SPHEREwhen wanting to create a UV sphere mesh
- The second argument is a
Referenceto aMaterialobject which may be one of two implementations, depending on what scene and renderer the model will be used with: either aBlinnPhongMaterialor aPBRMaterial. When setting up these materials prior to passing them to the model factory, it may be necessary to create textures. This can be done using theTextureclass - The third argument is optional, and only used when a UV sphere is being created. This argument specifies the Level Of Detail (LOD) of the resulting mesh. The default value is 32
Scenes can be submitted to the renderer using the Renderer::drawScene(...) method, which takes in two arguments:
- The first argument is a
Referenceto aSceneobject (the base class ofBlinnPhongSceneandPBRScene) - The second argument is a
Cameraobject
Switching between the two renderer implementations can be done by calling the setRendererType(...) method. This method takes in a singular argument that is an instance of the Renderer::RendererType enum, and specifies the renderer implementation to switch to. It can be either one of: Renderer::RendererType::BLINN_PHONG or Renderer::RendererType::PBR.