Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build #37

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion assets/scenes/sponza.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sceneID": "Sponza",
"sceneID": "sponza",
"skybox": {"id": "barcelona",
"hdr": true,
"resolution": 512
Expand Down
22 changes: 15 additions & 7 deletions assets/shaders/ComputeShaders/clusterShader.comp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ layout (std430, binding = 1) buffer clusterAABB{
};
layout (std430, binding = 2) buffer screenToView{
mat4 inverseProjection;
uvec4 tileSizes;
uvec2 screenDimensions;
uint tileSizeX;
uint tileSizeY;
uint tileSizeZ;
uint padding1;
vec2 tileSizePx;
vec2 viewPxSize;
float scale;
float bias;
uint padding2;
uint padding3;
};

//Shared between all clusters
Expand All @@ -29,14 +37,14 @@ void main(){
const vec3 eyePos = vec3(0.0);

//Per Tile variables
uint tileSizePx = tileSizes[3];
uint tileIndex = gl_WorkGroupID.x +
gl_WorkGroupID.y * gl_NumWorkGroups.x +
gl_WorkGroupID.z * (gl_NumWorkGroups.x * gl_NumWorkGroups.y);

//Calculating the min and max point in screen space
vec4 maxPoint_sS = vec4(vec2(gl_WorkGroupID.x + 1, gl_WorkGroupID.y + 1) * tileSizePx, -1.0, 1.0); // Top Right
vec4 minPoint_sS = vec4(gl_WorkGroupID.xy * tileSizePx, -1.0, 1.0); // Bottom left
// Calculating the min and max point in screen space
// tileSizePx is 1/x so we have to divide again to get a y*x
vec4 maxPoint_sS = vec4(vec2(gl_WorkGroupID.x + 1, gl_WorkGroupID.y + 1) / tileSizePx, -1.0, 1.0); // Top Right
vec4 minPoint_sS = vec4(gl_WorkGroupID.xy / tileSizePx, -1.0, 1.0); // Bottom left

//Pass min and max to view space
vec3 maxPoint_vS = screen2View(maxPoint_sS).xyz;
Expand Down Expand Up @@ -89,7 +97,7 @@ vec4 clipToView(vec4 clip){

vec4 screen2View(vec4 screen){
//Convert to NDC
vec2 texCoord = screen.xy / screenDimensions.xy;
vec2 texCoord = screen.xy * viewPxSize.xy;

//Convert to clipSpace
// vec4 clip = vec4(vec2(texCoord.x, 1.0 - texCoord.y)* 2.0 - 1.0, screen.z, screen.w);
Expand Down
21 changes: 13 additions & 8 deletions assets/shaders/PBRClusteredShader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ in VS_OUT{
vec3 T;
vec3 B;
vec3 N;
mat3 TBN;
} fs_in;

//Dir light uniform
Expand Down Expand Up @@ -61,10 +60,16 @@ struct LightGrid{
};
layout (std430, binding = 2) buffer screenToView{
mat4 inverseProjection;
uvec4 tileSizes;
uvec2 screenDimensions;
uint tileSizeX;
uint tileSizeY;
uint tileSizeZ;
uint padding1;
vec2 tileSizePx;
vec2 viewPxSize;
float scale;
float bias;
uint padding2;
uint padding3;
};
layout (std430, binding = 3) buffer lightSSBO{
PointLight pointLight[];
Expand Down Expand Up @@ -158,10 +163,10 @@ void main(){

//Locating which cluster you are a part of
uint zTile = uint(max(log2(linearDepth(gl_FragCoord.z)) * scale + bias, 0.0));
uvec3 tiles = uvec3( uvec2( gl_FragCoord.xy / tileSizes[3] ), zTile);
uvec3 tiles = uvec3( uvec2( gl_FragCoord.xy * tileSizePx ), zTile);
uint tileIndex = tiles.x +
tileSizes.x * tiles.y +
(tileSizes.x * tileSizes.y) * tiles.z;
tileSizeX * tiles.y +
(tileSizeX * tileSizeY) * tiles.z;

//Solving outgoing reflectance of fragment
vec3 radianceOut = vec3(0.0);
Expand Down Expand Up @@ -210,7 +215,7 @@ void main(){
radianceOut += emissive;

if(slices){
FragColor = vec4(colors[uint(mod(zTile, 8.0))], 1.0);
FragColor = vec4(colors[uint(mod(float(zTile), 8.0))], 1.0);
}
else{
FragColor = vec4(radianceOut, 1.0);
Expand Down Expand Up @@ -319,7 +324,7 @@ float calcPointLightShadows(samplerCube depthMap, vec3 fragToLight, float viewDi
float currentDepth = (length(fragToLight) - bias);

for(int i = 0; i < samples; ++i){
float closestDepth = texture(depthMap, fragToLight + sampleOffsetDirections[i], diskRadius).r;
float closestDepth = texture(depthMap, fragToLight + (sampleOffsetDirections[i] * diskRadius)).r;
closestDepth *= far_plane;
if(currentDepth > closestDepth){
shadow += fraction;
Expand Down
1 change: 0 additions & 1 deletion assets/shaders/PBRClusteredShader.vert
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ out VS_OUT{
vec3 T;
vec3 B;
vec3 N;
mat3 TBN;
} vs_out;

uniform mat4 MVP;
Expand Down
1 change: 0 additions & 1 deletion assets/shaders/screenShader.frag
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ in vec2 TexCoords;

uniform sampler2D screenTexture;
uniform sampler2D bloomBlur;
uniform int offset;
uniform float exposure;

void main(){
Expand Down
2 changes: 1 addition & 1 deletion include/cubeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct CubeMap : public Texture{

//Static constants used in all cubemaps
static Cube cubeMapCube;
static const glm::mat4 captureViews[18];
static const glm::mat4 captureViews[6];
static const unsigned int numSidesInCube;
static const glm::mat4 captureProjection;
static const std::string fileHandleForFaces[6]; //Order from Opengl cubemap enums
Expand Down
13 changes: 9 additions & 4 deletions include/gpuData.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef GPUDATA_H
#define GPUTDATA_H
#define GPUDATA_H

/*
AUTHOR : Angel Ortiz (angelo12 AT vt DOT edu)
Expand All @@ -19,11 +19,16 @@ struct VolumeTileAABB{

struct ScreenToView{
glm::mat4 inverseProjectionMat;
unsigned int tileSizes[4];
unsigned int screenWidth;
unsigned int screenHeight;
unsigned int tileSizeX;
unsigned int tileSizeY;
unsigned int tileSizeZ;
unsigned int padding1;
glm::vec2 tilePixelSize;
glm::vec2 viewPixelSize;
float sliceScalingFactor;
float sliceBiasFactor;
unsigned int padding2;
unsigned int padding3;
}screen2View;

#endif
4 changes: 2 additions & 2 deletions include/renderManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class RenderManager{
//optimizations. In the future, (the magical land where all projects are complete) I plan on
//heavily optimizing this part of the program along the lines of the 2014 talk, "beyond porting"
//But in the mean-time it uses pretty basic an naive openGL.
void render(const unsigned int start);
void render();
private:
//Internal initialization functions
bool initFBOs();
Expand All @@ -53,7 +53,7 @@ class RenderManager{
bool preProcess();

//Functions used to break up the main render function into more manageable parts.
void postProcess(const unsigned int start);
void postProcess();

//Todo:: shaders should belong to a material not the rendermanager
Shader depthPrePassShader, PBRClusteredShader, skyboxShader,
Expand Down
7 changes: 4 additions & 3 deletions src/cubeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ DATE : 2018-09-24

//Initializing all static variables at compile time
const glm::mat4 CubeMap::captureProjection = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 10.0f);
const glm::mat4 CubeMap::captureViews[18] = {
const glm::mat4 CubeMap::captureViews[6] = {
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
Expand Down Expand Up @@ -82,7 +82,6 @@ void CubeMap::generateCubeMap(const int width, const int height, CubeMapType cub
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_REF_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
break;
Expand Down Expand Up @@ -168,7 +167,9 @@ void CubeMap::preFilterCubeMap(const unsigned int environmentMap,
glBindRenderbuffer(GL_RENDERBUFFER, captureRBO);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, mipWidth, mipHeight);
glViewport(0, 0, mipWidth, mipHeight);


filterShader.setFloat("roughness", mip / (float)(maxMipLevels - 1));

for(unsigned int i = 0; i < numSidesInCube; ++i){
filterShader.setMat4("view", captureViews[i]);

Expand Down
2 changes: 1 addition & 1 deletion src/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void Engine::run(){
//Update all models, camera and lighting in the current scene
gSceneManager.update(deltaT);

gRenderManager.render(start);
gRenderManager.render();

//Obtaining deltaT for any
deltaT = SDL_GetTicks() - start;
Expand Down
2 changes: 1 addition & 1 deletion src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void Mesh::draw(const Shader &shader, bool textured){

//Mesh Drawing
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, (GLsizei)indices.size(), GL_UNSIGNED_INT, 0);
glDrawElements(GL_TRIANGLES, (GLsizei)indices.size(), GL_UNSIGNED_INT, NULL);
}

//Sending the data to the GPU and formatting it in memory
Expand Down
3 changes: 2 additions & 1 deletion src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ std::vector<unsigned int> Model::processTextures(const aiMaterial *material){
//If this texture has not been added to the atlas yet we load it
if (textureAtlas.count(fullTexturePath) == 0){
Texture texture;
bool srgb = false;
// Diffuse is sRGB, the rest aren't
bool srgb = tex == aiTextureType_DIFFUSE;
texture.loadTexture(fullTexturePath, srgb);
textureAtlas.insert({fullTexturePath, texture});
}
Expand Down
27 changes: 16 additions & 11 deletions src/renderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ bool RenderManager::startUp(DisplayManager &displayManager, SceneManager &sceneM
}

bool RenderManager::preProcess(){
glDisable(GL_BLEND);

//Initializing the surface that we use to draw screen-space effects
canvas.setup();

Expand Down Expand Up @@ -116,6 +118,7 @@ bool RenderManager::preProcess(){
bool RenderManager::initSSBOs(){
//Setting up tile size on both X and Y
sizeX = (unsigned int)std::ceilf(DisplayManager::SCREEN_WIDTH / (float)gridSizeX);
sizeY = (unsigned int)std::ceilf(DisplayManager::SCREEN_HEIGHT / (float)gridSizeY);

float zFar = sceneCamera->cameraFrustum.farPlane;
float zNear = sceneCamera->cameraFrustum.nearPlane;
Expand All @@ -138,12 +141,13 @@ bool RenderManager::initSSBOs(){

//Setting up contents of buffer
screen2View.inverseProjectionMat = glm::inverse(sceneCamera->projectionMatrix);
screen2View.tileSizes[0] = gridSizeX;
screen2View.tileSizes[1] = gridSizeY;
screen2View.tileSizes[2] = gridSizeZ;
screen2View.tileSizes[3] = sizeX;
screen2View.screenWidth = DisplayManager::SCREEN_WIDTH;
screen2View.screenHeight = DisplayManager::SCREEN_HEIGHT;
screen2View.tileSizeX = gridSizeX;
screen2View.tileSizeY = gridSizeY;
screen2View.tileSizeZ = gridSizeZ;
screen2View.tilePixelSize.x = 1.0f / (float)sizeX;
screen2View.tilePixelSize.y = 1.0f / (float)sizeY;
screen2View.viewPixelSize.x = 1.0f / (float)DisplayManager::SCREEN_WIDTH;
screen2View.viewPixelSize.y = 1.0f / (float)DisplayManager::SCREEN_HEIGHT;
//Basically reduced a log function into a simple multiplication an addition by pre-calculating these
screen2View.sliceScalingFactor = (float)gridSizeZ / std::log2f(zFar / zNear) ;
screen2View.sliceBiasFactor = -((float)gridSizeZ * std::log2f(zNear) / std::log2f(zFar / zNear)) ;
Expand Down Expand Up @@ -324,7 +328,7 @@ Algorithm steps:
5. Shading by reading from the active tiles list :: DONE
6. Post processing and screen space effects :: DONE
*/
void RenderManager::render(const unsigned int start){
void RenderManager::render(){
//Initiating rendering gui
ImGui::Begin("Rendering Controls");
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
Expand All @@ -338,7 +342,8 @@ void RenderManager::render(const unsigned int start){
ImGui::InputFloat3("Camera Pos", (float*)&sceneCamera->position); //Camera controls
ImGui::SliderFloat("Movement speed", &sceneCamera->camSpeed, 0.005f, 1.0f);
}
//Making sure depth testing is enabled

glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(true);

Expand Down Expand Up @@ -367,7 +372,7 @@ void RenderManager::render(const unsigned int start){
multiSampledFBO.blitTo(simpleFBO, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

//6 -postprocessing, includes bloom, exposure mapping
postProcess(start);
postProcess();

//Rendering gui scope ends here cannot be done later because the whole frame
//is reset in the display buffer swap
Expand All @@ -379,7 +384,7 @@ void RenderManager::render(const unsigned int start){
}


void RenderManager::postProcess(const unsigned int start){
void RenderManager::postProcess(){
if(ImGui::CollapsingHeader("Post-processing")){
ImGui::SliderInt("Blur", &sceneCamera->blurAmount, 0, 10);
ImGui::SliderFloat("Exposure", &sceneCamera->exposure, 0.1f, 5.0f);
Expand All @@ -406,6 +411,7 @@ void RenderManager::postProcess(const unsigned int start){

//Vertical pass
glBindFramebuffer(GL_FRAMEBUFFER, pingPongFBO.frameBufferID);
glDrawBuffer(GL_COLOR_ATTACHMENT0);
gaussianBlurShader.setBool("horizontal", false);
canvas.draw(simpleFBO.blurHighEnd);
}
Expand All @@ -416,7 +422,6 @@ void RenderManager::postProcess(const unsigned int start){
//Shader setup for postprocessing
screenSpaceShader.use();

screenSpaceShader.setInt("offset", start);
screenSpaceShader.setFloat("exposure", sceneCamera->exposure);
screenSpaceShader.setInt("screenTexture", 0);
screenSpaceShader.setInt("bloomBlur", 1);
Expand Down
10 changes: 5 additions & 5 deletions src/scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ DATE : 2018-09-12
#include "imgui/imgui.h"

Scene::Scene(const std::string &sceneName){
std::string folderPath = "../assets/scenes/";
std::string folderPath = "../../../assets/scenes/";
std::string fileExtension = ".json";
sceneID = sceneName;

Expand Down Expand Up @@ -252,7 +252,7 @@ PointLight *Scene::getPointLight(unsigned int index){
//Config file parsing, gets all the important
bool Scene::loadContent(){
//Parsing into Json file readable format
std::string folderPath = "../assets/scenes/";
std::string folderPath = "../../../assets/scenes/";
std::string fileExtension = ".json";
std::string sceneConfigFilePath = folderPath + sceneID + fileExtension;
std::ifstream file(sceneConfigFilePath.c_str());
Expand Down Expand Up @@ -394,7 +394,7 @@ void Scene::loadSceneModels(const json &sceneConfigJson ){
for (unsigned int i = 0; i < modelCount; ++i){
//get model mesh and material info
json currentModel = sceneConfigJson["models"][i];
modelMesh = currentModel["mesh"];
modelMesh = currentModel["mesh"].get<std::string>();
IBL = currentModel["IBL"];

modelName = modelMesh.substr(0, modelMesh.find_last_of('.'));
Expand All @@ -415,7 +415,7 @@ void Scene::loadSceneModels(const json &sceneConfigJson ){
initParameters.scaling = glm::vec3((float)scaling[0], (float)scaling[1], (float)scaling[2]);

//attempts to load model with the initparameters it has read
modelMesh = "../assets/models/" + modelName + "/" + modelMesh;
modelMesh = "../../../assets/models/" + modelName + "/" + modelMesh;
if (!FLOAD::checkFileValidity(modelMesh)){
printf("Error! Mesh: %s does not exist.\n", modelMesh.c_str());
}
Expand Down Expand Up @@ -443,7 +443,7 @@ void Scene::generateEnvironmentMaps(){
brdfLUTTexture.width = res;
glGenTextures(1, &brdfLUTTexture.textureID);
glBindTexture(GL_TEXTURE_2D, brdfLUTTexture.textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, res, res, 0, GL_RG, GL_FLOAT, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, res, res, 0, GL_RG, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
Expand Down
2 changes: 1 addition & 1 deletion src/sceneManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ SceneManager::~SceneManager(){}
// the scene could not load any model, or there are none defined it quits early.
bool SceneManager::startUp(){
// currentSceneID = "pbrTest";
currentSceneID = "Sponza";
currentSceneID = "sponza";
if (!loadScene(currentSceneID)){
printf("Could not load default sponza scene. No models succesfully loaded!\n");
return false;
Expand Down
Loading