From eb4386ef23db26d8a12bd1919e09444fd96a8d67 Mon Sep 17 00:00:00 2001 From: Riku Avelar Date: Wed, 9 Nov 2016 21:10:25 -0500 Subject: [PATCH] The rumour come out, does phong lighting is work? --- src/shaders/basicShader.frag | 6 +++--- src/shaders/basicShader.vert | 2 +- src/shaders/skyboxShader.frag | 2 +- src/viewer/simpleViewer.cpp | 33 ++++++++++++++++----------------- 4 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/shaders/basicShader.frag b/src/shaders/basicShader.frag index 8777e0c..3b7068d 100644 --- a/src/shaders/basicShader.frag +++ b/src/shaders/basicShader.frag @@ -11,9 +11,9 @@ void main() { // Get lighting vectors - vec3 LightDirection = normalize(vec3(0.0)-fPosition); // We assume light is at camera position + vec3 LightDirection = normalize(vec3(-1,-3,0)); // We assume light is at camera position vec3 nfNormal = normalize(fNormal); - vec3 nviewDirection = normalize(vec3(0.0)-fPosition); + vec3 nviewDirection = normalize(fPosition); // Compute diffuse component float diffuse = max(0.0, dot(nfNormal, LightDirection)); @@ -26,5 +26,5 @@ main() vec3 color = ifColor.xyz; // Compute final color - fColor = vec4(color * (diffuse + specular), 1); + fColor = vec4(color * (0.1 + diffuse + specular), 1); } diff --git a/src/shaders/basicShader.vert b/src/shaders/basicShader.vert index a0f2a96..9a9d533 100644 --- a/src/shaders/basicShader.vert +++ b/src/shaders/basicShader.vert @@ -17,7 +17,7 @@ main() { vec4 vEyeCoord = mvMatrix * vPosition; gl_Position = projMatrix * vEyeCoord; - fPosition = vEyeCoord.xyz; + fPosition = -vEyeCoord.xyz; fNormal = normalMatrix * vNormal; ifColor = color; } diff --git a/src/shaders/skyboxShader.frag b/src/shaders/skyboxShader.frag index 3cacd66..9d56e35 100644 --- a/src/shaders/skyboxShader.frag +++ b/src/shaders/skyboxShader.frag @@ -6,6 +6,6 @@ uniform sampler2D skybox; void main() { - //fColor = texture(skybox, texCoords); + //fColor = vec4(1); fColor = texture(skybox, texCoords); } diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index 6673290..0cc1feb 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -142,6 +142,8 @@ void Viewer::draw() projectionMatrix.translate(0, -5, 0); projectionMatrix.rotate(15, 1, 0, 0);//*/ + modelViewMatrix.rotate(30,0,1,0); + m_program->setUniformValue(m_projMatrixLocation, projectionMatrix); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); @@ -394,23 +396,23 @@ void Viewer::initGeometries() }; GLfloat normals[numVerticesCube][3] = { - { 0, 0, 1 }, {0, 0, 1}, {0, 0, 1}, - { 0, 0, 1 }, {0, 0, 1}, {0, 0, 1}, + { 0.0, 0.0, 1.0 }, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, + { 0.0, 0.0, 1.0 }, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, - { 0, 0, -1 }, {0, 0, -1}, {0, 0, -1}, - { 0, 0, -1 }, {0, 0, -1}, {0, 0, -1}, + { 0.0, 0.0, -1.0 }, {0.0, 0.0, -1.0}, {0.0, 0.0, -1.0}, + { 0.0, 0.0, -1.0 }, {0.0, 0.0, -1.0}, {0.0, 0.0, -1.0}, - { 1, 0, 0 }, {1, 0, 0}, {1, 0, 0}, - { 1, 0, 0 }, {1, 0, 0}, {1, 0, 0}, + { 1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, + { 1.0, 0.0, 0.0 }, {1.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, - { -1, 0, 0 }, {-1, 0, 0}, {-1, 0, 0}, - { -1, 0, 0 }, {-1, 0, 0}, {-1, 0, 0}, + { -1.0, 0.0, 0.0 }, {-1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, + { -1.0, 0.0, 0.0 }, {-1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, - { 0, 1, 0 }, {0, 1, 0}, {0, 1, 0}, - { 0, 1, 0 }, {0, 1, 0}, {0, 1, 0}, + { 0.0, 1.0, 0.0 }, {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, + { 0.0, 1.0, 0.0 }, {0.0, 1.0, 0.0}, {0.0, 1.0, 0.0}, - { 0, -1, 0 }, {0, -1, 0}, {0, -1, 0}, - { 0, -1, 0 }, {0, -1, 0}, {0, -1, 0}, + { 0.0, -1.0, 0.0 }, {0.0, -1.0, 0.0}, {0.0, -1.0, 0.0}, + { 0.0, -1.0, 0.0 }, {0.0, -1.0, 0.0}, {0.0, -1.0, 0.0} }; @@ -436,22 +438,19 @@ void Viewer::initGeometries() glEnableVertexAttribArray(s_vUvLocation); glVertexAttribPointer(m_vNormalLocation, 3, GL_FLOAT, - GL_FALSE, 0, BUFFER_OFFSET(sizeof(verticesCube) + sizeof(uvs))); + GL_TRUE, 0, BUFFER_OFFSET(sizeof(verticesCube) + sizeof(uvs))); glEnableVertexAttribArray(m_vNormalLocation); } void Viewer::visit(Cube &s) { QMatrix4x4 modelViewMatrix = modelStack.top() * QMatrix4x4(s.transform); - QMatrix4x4 lookAt; - - camera()->getProjectionMatrix(lookAt); int faces = floor(numVerticesCube/6); for(int i = 0; i < faces; i++){ // 6 vertexes par face glBindVertexArray(m_VAOs[VAO_Cube]); m_program->setUniformValue(m_mvMatrixLocation, modelViewMatrix); - m_program->setUniformValue(m_normalMatrixLoc, lookAt.normalMatrix()); + m_program->setUniformValue(m_normalMatrixLoc, modelViewMatrix.normalMatrix()); m_program->setUniformValue(m_colorLocation, s.getColor()); glDrawArrays(GL_TRIANGLES, i*6, 6);