From 1043b5b05e00f830da26624eee8b25fb4dc4e4fc Mon Sep 17 00:00:00 2001 From: Luke Lau Date: Fri, 2 Nov 2018 11:48:24 +0000 Subject: [PATCH] Tidy up --- main.cpp | 18 +++++++++--------- texturefrag.glsl | 1 - texturevertex.glsl | 29 ++++------------------------- 3 files changed, 13 insertions(+), 35 deletions(-) diff --git a/main.cpp b/main.cpp index f7b2f85..3104645 100644 --- a/main.cpp +++ b/main.cpp @@ -29,7 +29,7 @@ glm::vec3 camUp = glm::vec3(0.0f, 1.0f, 0.0f); float yaw = 1.57, pitch = 0; bool doScale, doRotate, doTranslate; Model *monkeyHead, *chest; -glm::vec3 chestPos(0); +glm::vec3 lightPos(0); const int WIDTH = 800, HEIGHT = 600; const float ASPECT = (float)WIDTH / (float)HEIGHT; @@ -157,7 +157,7 @@ void display() { float d = (float)glutGet(GLUT_ELAPSED_TIME) * 0.001f; /* glm::vec3 lightPos = glm::vec3(sin(d / 10.f) * 10, 0, cos(d / 10.f) * 10); */ - glm::vec3 lightPos = chestPos; + glm::vec3 lightPos = lightPos; glm::vec4 lightColor(1, 1, 1, 1); drawLight(d, lightPos, lightColor); @@ -182,7 +182,7 @@ void display() { /* Model::Node *key = chest->find("key"); */ /* key->model = glm::translate(glm::mat4(1), glm::vec3(0, 0, sin(d))); */ - /* chest->getRoot()->model = glm::translate(glm::mat4(1), chestPos); */ + /* chest->getRoot()->model = glm::translate(glm::mat4(1), lightPos); */ chest->draw(); glutSwapBuffers(); @@ -523,12 +523,12 @@ void timer(int _) { if (keyStates['e']) ySpeed = -0.1f; - if (keyStates['j']) chestPos.z += 0.1f; - if (keyStates['k']) chestPos.z -= 0.1f; - if (keyStates['h']) chestPos.x -= 0.1f; - if (keyStates['l']) chestPos.x += 0.1f; - if (keyStates['m']) chestPos.y -= 0.1f; - if (keyStates['n']) chestPos.y += 0.1f; + if (keyStates['j']) lightPos.z += 0.1f; + if (keyStates['k']) lightPos.z -= 0.1f; + if (keyStates['h']) lightPos.x -= 0.1f; + if (keyStates['l']) lightPos.x += 0.1f; + if (keyStates['m']) lightPos.y -= 0.1f; + if (keyStates['n']) lightPos.y += 0.1f; camPos.x += xSpeed * sin(yaw) + zSpeed * cos(yaw); camPos.y += ySpeed; diff --git a/texturefrag.glsl b/texturefrag.glsl index 83cce42..35ef1ec 100644 --- a/texturefrag.glsl +++ b/texturefrag.glsl @@ -51,7 +51,6 @@ void main() { vec3 viewDir = normalize(viewPos - fragPos); vec3 reflectDir = reflect(-lightDir, normal); - vec4 specTex; if (material.hasSpecularMap) specTex = texture(material.specularMap, texCoord); diff --git a/texturevertex.glsl b/texturevertex.glsl index d8c97f4..684b9b9 100644 --- a/texturevertex.glsl +++ b/texturevertex.glsl @@ -5,9 +5,11 @@ in vec3 vNormal; in vec3 tangent; in vec3 bitangent; in vec2 vTexCoord; + uniform mat4 model; uniform mat4 view; uniform mat4 projection; + out vec3 defNormal; out vec2 texCoord; @@ -18,44 +20,21 @@ out vec3 lightPos; out vec3 viewPos; out vec3 fragPos; -struct Material { - vec3 ambient; - vec3 diffuse; - sampler2D diffuseMap; - vec3 specular; - sampler2D specularMap; - float shininess; - - bool hasTexture; - bool hasSpecularMap; - - sampler2D normalMap; - bool hasNormalMap; -}; - -uniform Material material; - - void main() { vec4 pos = model * vec4(vPosition, 1.f); - defNormal = mat3(transpose(inverse(model))) * vNormal; texCoord = vTexCoord; //tangent space stuff - if (material.hasNormalMap) { vec3 T = normalize(vec3(model * vec4(tangent, 0.0))); vec3 B = normalize(vec3(model * vec4(bitangent, 0.0))); vec3 N = normalize(vec3(model * vec4(vNormal, 0.0))); // convert TBN to world->tangent space mat3 TBN = transpose(mat3(T, B, N)); + lightPos = TBN * vLightPos; viewPos = TBN * vViewPos; fragPos = TBN * vec3(pos); - } else { - lightPos = vLightPos; - viewPos = vViewPos; - fragPos = vec3(pos); - } + defNormal = TBN * mat3(transpose(inverse(model))) * vNormal; gl_Position = projection * view * pos; } -- 2.30.2