Normal mapping code

Normal mapping code for normal mapping tutorial (+ few extra's for next
tutorial)
This commit is contained in:
Joey de Vries
2015-05-26 22:00:13 +02:00
parent e1e307f3de
commit 2a0a415c8f
20 changed files with 13805 additions and 158 deletions

View File

@@ -19,6 +19,10 @@ struct Vertex {
glm::vec3 Normal;
// TexCoords
glm::vec2 TexCoords;
// Tangent
glm::vec3 Tangent;
// Bitangent
glm::vec3 Bitangent;
};
struct Texture {
@@ -53,6 +57,7 @@ public:
// Bind appropriate textures
GLuint diffuseNr = 1;
GLuint specularNr = 1;
GLuint normalNr = 1;
for(GLuint i = 0; i < this->textures.size(); i++)
{
glActiveTexture(GL_TEXTURE0 + i); // Active proper texture unit before binding
@@ -64,9 +69,11 @@ public:
ss << diffuseNr++; // Transfer GLuint to stream
else if(name == "texture_specular")
ss << specularNr++; // Transfer GLuint to stream
else if(name == "texture_normal")
ss << normalNr++; // Transfer GLuint to stream
number = ss.str();
// Now set the sampler to the correct texture unit
glUniform1f(glGetUniformLocation(shader.Program, (name + number).c_str()), i);
glUniform1i(glGetUniformLocation(shader.Program, (name + number).c_str()), i);
// And finally bind the texture
glBindTexture(GL_TEXTURE_2D, this->textures[i].id);
}
@@ -118,6 +125,12 @@ private:
// Vertex Texture Coords
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, TexCoords));
// Vertex Tangent
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Tangent));
// Vertex Bitangent
glEnableVertexAttribArray(4);
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)offsetof(Vertex, Bitangent));
glBindVertexArray(0);
}