diff --git a/OpenGL/playground/output b/OpenGL/playground/output index e6f5fd5..c09bd68 100755 Binary files a/OpenGL/playground/output and b/OpenGL/playground/output differ diff --git a/OpenGL/playground/resources/shaders/phong.frag b/OpenGL/playground/resources/shaders/phong.frag index 73ac3a9..d861017 100644 --- a/OpenGL/playground/resources/shaders/phong.frag +++ b/OpenGL/playground/resources/shaders/phong.frag @@ -4,6 +4,7 @@ in vec3 Normal; in vec3 FragPos; uniform vec3 lightPos; +vec3 viewPos = vec3(0.0, 0.0, 0.0); out vec4 outColour; @@ -15,11 +16,23 @@ void main() { vec3 ambient = ambientStrength * lightColour; vec3 norm = normalize(Normal); - vec3 lightDir = normalize(lightPos - FragPos); + vec3 lightDir = normalize(lightPos - FragPos); float diff = max(dot(norm, lightDir), 0.0); vec3 diffuse = diff * lightColour; - vec3 result = (ambient + diffuse) * objectColour; + + + float specularStrength = 0.5; + + vec3 viewDir = normalize(viewPos - FragPos); + vec3 reflectDir = reflect(-lightDir, norm); + + float spec = pow(max(dot(viewDir, reflectDir), 0.0), 32); + vec3 specular = specularStrength * spec * lightColour; + + + + vec3 result = (ambient + diffuse + specular) * objectColour; outColour = vec4(result, 1.0); } diff --git a/OpenGL/playground/resources/shaders/phong.vert b/OpenGL/playground/resources/shaders/phong.vert index 1c53af9..a18e40c 100644 --- a/OpenGL/playground/resources/shaders/phong.vert +++ b/OpenGL/playground/resources/shaders/phong.vert @@ -13,5 +13,5 @@ uniform mat4 proj; void main() { gl_Position = proj * view * model * vec4(position, 1.0); FragPos = vec3(model * vec4(position, 1.0)); - Normal = normal; + Normal = mat3(model) * normal; } diff --git a/OpenGL/playground/src/main.cpp b/OpenGL/playground/src/main.cpp index e9977c7..35c9a80 100644 --- a/OpenGL/playground/src/main.cpp +++ b/OpenGL/playground/src/main.cpp @@ -110,9 +110,6 @@ int main(int argc, char** argv) { glEnableVertexAttribArray(normalAttrib); glVertexAttribPointer(normalAttrib, 3, GL_FLOAT, GL_FALSE, 0, (const void*)(vertices.size() * sizeof(glm::vec3))); - glm::vec3 lightPos(2.20, 1.0f, 2.0f); - GLint uniLight = glGetUniformLocation(simpleShader.getProgram(), "lightPos"); - glUniform3fv(uniLight, 1, GL_FALSE, glm::value_ptr(lightPos)); // Model matrice glm::mat4 model = glm::mat4(1.0f); @@ -145,9 +142,9 @@ int main(int argc, char** argv) { // Update tick (60ups) if (UPSTimer()) { - // model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 0.0f, 1.0f)); - // model = glm::rotate(model, glm::radians(0.5f), glm::vec3(1.0f, 0.0f, 0.0f)); - model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 1.0f, 0.0f)); + model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 0.0f, 1.0f)); + model = glm::rotate(model, glm::radians(0.5f), glm::vec3(1.0f, 0.0f, 0.0f)); + // model = glm::rotate(model, glm::radians(0.5f), glm::vec3(0.0f, 1.0f, 0.0f)); glm::vec4 result = model * glm::vec4(1.0f, 0.0f, 0.0f, 1.0f); glUniformMatrix4fv(uniTrans, 1, GL_FALSE, glm::value_ptr(model));