From c2176098904169f1b19903a1d31a50285810dc5a Mon Sep 17 00:00:00 2001 From: stfx Date: Sun, 26 Nov 2017 20:03:44 +0100 Subject: [PATCH 1/4] Fix rare graphical error showing a black box This may happen at certain hard to replicate viewing angles. Theoretically clamp 0,1 should also be faster since SAT (saturate) is a free operation on output however since saturate only exists on HLSL we are at the mercy of the GLSL compiler to replace clamp 0,1 with SAT. Source: http://www.humus.name/Articles/Persson_LowLevelThinking.pdf#page=22 --- src/6.pbr/1.1.lighting/1.1.pbr.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/6.pbr/1.1.lighting/1.1.pbr.fs b/src/6.pbr/1.1.lighting/1.1.pbr.fs index 61e5d1a..3f08859 100644 --- a/src/6.pbr/1.1.lighting/1.1.pbr.fs +++ b/src/6.pbr/1.1.lighting/1.1.pbr.fs @@ -82,7 +82,7 @@ void main() // Cook-Torrance BRDF float NDF = DistributionGGX(N, H, roughness); float G = GeometrySmith(N, V, L, roughness); - vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0); + vec3 F = fresnelSchlick(clamp(dot(H, V), 0.0, 1.0), F0); vec3 nominator = NDF * G * F; float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // 0.001 to prevent divide by zero. @@ -118,4 +118,4 @@ void main() color = pow(color, vec3(1.0/2.2)); FragColor = vec4(color, 1.0); -} \ No newline at end of file +} From b4982b4611b4be70341f88ddb10946700f5ed360 Mon Sep 17 00:00:00 2001 From: stfx Date: Sun, 26 Nov 2017 22:10:59 +0100 Subject: [PATCH 2/4] Fix another graphical error showing a black box Is needed in addition to #92 to fix all graphical errors. Happens due to divide by 0 when `roughness = 0.0` and `NdotH = 1.0`. Also use max to clamp similar fix for specular calculation instead of addition to fix the formula in normal cases --- src/6.pbr/1.1.lighting/1.1.pbr.fs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/6.pbr/1.1.lighting/1.1.pbr.fs b/src/6.pbr/1.1.lighting/1.1.pbr.fs index 61e5d1a..d807474 100644 --- a/src/6.pbr/1.1.lighting/1.1.pbr.fs +++ b/src/6.pbr/1.1.lighting/1.1.pbr.fs @@ -29,7 +29,7 @@ float DistributionGGX(vec3 N, vec3 H, float roughness) float denom = (NdotH2 * (a2 - 1.0) + 1.0); denom = PI * denom * denom; - return nom / denom; + return nom / max(denom, 0.001); // prevent divide by zero for roughness=0.0 and NdotH=1.0 } // ---------------------------------------------------------------------------- float GeometrySchlickGGX(float NdotV, float roughness) @@ -85,8 +85,8 @@ void main() vec3 F = fresnelSchlick(max(dot(H, V), 0.0), F0); vec3 nominator = NDF * G * F; - float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0) + 0.001; // 0.001 to prevent divide by zero. - vec3 specular = nominator / denominator; + float denominator = 4 * max(dot(N, V), 0.0) * max(dot(N, L), 0.0); + vec3 specular = nominator / max(denominator, 0.001); // prevent divide by zero for NdotV=0.0 or NdotL=0.0 // kS is equal to Fresnel vec3 kS = F; @@ -118,4 +118,4 @@ void main() color = pow(color, vec3(1.0/2.2)); FragColor = vec4(color, 1.0); -} \ No newline at end of file +} From 217877642375374d756079a5cd122c35b0056f4f Mon Sep 17 00:00:00 2001 From: Galfatron Date: Mon, 27 Nov 2017 20:16:05 -0800 Subject: [PATCH 3/4] decoupled assimp from mesh.h --- includes/learnopengl/mesh.h | 4 +--- includes/learnopengl/model.h | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/learnopengl/mesh.h b/includes/learnopengl/mesh.h index 4d2aea7..d6f7ee9 100644 --- a/includes/learnopengl/mesh.h +++ b/includes/learnopengl/mesh.h @@ -3,8 +3,6 @@ #include // holds all OpenGL type declarations -#include - #include #include @@ -33,7 +31,7 @@ struct Vertex { struct Texture { unsigned int id; string type; - aiString path; + string path; }; class Mesh { diff --git a/includes/learnopengl/model.h b/includes/learnopengl/model.h index cc12c84..fab1151 100644 --- a/includes/learnopengl/model.h +++ b/includes/learnopengl/model.h @@ -179,7 +179,7 @@ private: bool skip = false; for(unsigned int j = 0; j < textures_loaded.size(); j++) { - if(std::strcmp(textures_loaded[j].path.C_Str(), str.C_Str()) == 0) + if(std::strcmp(textures_loaded[j].path.data(), str.C_Str()) == 0) { textures.push_back(textures_loaded[j]); skip = true; // a texture with the same filepath has already been loaded, continue to next one. (optimization) @@ -191,7 +191,7 @@ private: Texture texture; texture.id = TextureFromFile(str.C_Str(), this->directory); texture.type = typeName; - texture.path = str; + texture.path = str.C_Str(); textures.push_back(texture); textures_loaded.push_back(texture); // store it as texture loaded for entire model, to ensure we won't unnecesery load duplicate textures. } From 036315579c680719eb681460655b9494f0c67fa5 Mon Sep 17 00:00:00 2001 From: sallyx Date: Wed, 6 Dec 2017 18:50:33 +0100 Subject: [PATCH 4/4] Added required Linux dev packages I needed to install these packages, otherwise my build end with linkage error (-lXi misssing etc.) --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 517a8ec..70165aa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ Keep in mind the supplied libraries were generated with a specific compiler vers ## Linux building First make sure you have CMake, Git, and GCC by typing as root (sudo) `apt-get install g++ cmake git` and then get the required packages: -Using root (sudo) and type `apt-get install libsoil-dev libglm-dev libassimp-dev libglew-dev libglfw3-dev` . Next, run CMake (preferably CMake-gui). The source directory is LearnOpenGL and specify the build directory as LearnOpenGL/build. Creating the build directory within LearnOpenGL is important for linking to the resource files (it also will be ignored by Git). Hit configure and specify your compiler files (Unix Makefiles are recommended), resolve any missing directories or libraries, and then hit generate. Navigate to the build directory (`cd LearnOpenGL/build`) and type `make` in the terminal. This should generate the executables in the respective chapter folders. +Using root (sudo) and type `apt-get install libsoil-dev libglm-dev libassimp-dev libglew-dev libglfw3-dev libxinerama-dev libxcursor-dev libxi-dev` . +Next, run CMake (preferably CMake-gui). The source directory is LearnOpenGL and specify the build directory as LearnOpenGL/build. Creating the build directory within LearnOpenGL is important for linking to the resource files (it also will be ignored by Git). Hit configure and specify your compiler files (Unix Makefiles are recommended), resolve any missing directories or libraries, and then hit generate. Navigate to the build directory (`cd LearnOpenGL/build`) and type `make` in the terminal. This should generate the executables in the respective chapter folders. Note that CodeBlocks or other IDEs may have issues running the programs due to problems finding the shader and resource files, however it should still be able to generate the exectuables. To work around this problem it is possible to set an environment variable to tell the tutorials where the resource files can be found. The environment variable is named LOGL_ROOT_PATH and may be set to the path to the root of the LearnOpenGL directory tree. For example: