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;
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);
/* 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();
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;
in vec3 tangent;
in vec3 bitangent;
in vec2 vTexCoord;
+
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
+
out vec3 defNormal;
out vec2 texCoord;
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;
}