mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-30 12:03:22 +08:00
Merge branch 'master' of https://github.com/JoeyDeVries/LearnOpenGL
This commit is contained in:
@@ -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:
|
||||
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
|
||||
#include <glad/glad.h> // holds all OpenGL type declarations
|
||||
|
||||
#include <assimp/Importer.hpp>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
|
||||
@@ -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)
|
||||
@@ -82,11 +82,11 @@ 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.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user