Tidy up
authorLuke Lau <luke_lau@icloud.com>
Fri, 2 Nov 2018 11:48:24 +0000 (11:48 +0000)
committerLuke Lau <luke_lau@icloud.com>
Fri, 2 Nov 2018 11:48:24 +0000 (11:48 +0000)
main.cpp
texturefrag.glsl
texturevertex.glsl

index f7b2f85a4644f12ba6df69a5f02363926686afe7..31046454ca325d37a6815dff6c654639ac843900 100644 (file)
--- 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;
 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;
 
 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); */
        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);
        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))); */
        
        /* 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();
        chest->draw();
 
        glutSwapBuffers();
@@ -523,12 +523,12 @@ void timer(int _) {
        if (keyStates['e'])
                ySpeed = -0.1f;
 
        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;
 
        camPos.x += xSpeed * sin(yaw) + zSpeed * cos(yaw);
        camPos.y += ySpeed;
index 83cce42cc72a6d42d97fbbda5d1e6761c0f80d57..35ef1ec6fcfa97c89415607490cc328b553d68ae 100644 (file)
@@ -51,7 +51,6 @@ void main() {
        vec3 viewDir = normalize(viewPos - fragPos);
        vec3 reflectDir = reflect(-lightDir, normal);
 
        vec3 viewDir = normalize(viewPos - fragPos);
        vec3 reflectDir = reflect(-lightDir, normal);
 
-
        vec4 specTex;
        if (material.hasSpecularMap)
                specTex = texture(material.specularMap, texCoord);
        vec4 specTex;
        if (material.hasSpecularMap)
                specTex = texture(material.specularMap, texCoord);
index d8c97f4df3c9a73169770d7dcca7a512782a70fe..684b9b94ed98c2117496381ea1071fc53236a39f 100644 (file)
@@ -5,9 +5,11 @@ in vec3 vNormal;
 in vec3 tangent;
 in vec3 bitangent;
 in vec2 vTexCoord;
 in vec3 tangent;
 in vec3 bitangent;
 in vec2 vTexCoord;
+
 uniform mat4 model;
 uniform mat4 view;
 uniform mat4 projection;
 uniform mat4 model;
 uniform mat4 view;
 uniform mat4 projection;
+
 out vec3 defNormal;
 out vec2 texCoord;
 
 out vec3 defNormal;
 out vec2 texCoord;
 
@@ -18,44 +20,21 @@ out vec3 lightPos;
 out vec3 viewPos;
 out vec3 fragPos;
 
 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);
 void main() {
        vec4 pos = model * vec4(vPosition, 1.f);
-       defNormal = mat3(transpose(inverse(model))) * vNormal;
        texCoord = vTexCoord;
 
        //tangent space stuff
        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));
        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);
        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;
 }
        
        gl_Position = projection * view * pos;
 }