Compare commits

...

1 Commits

Author SHA1 Message Date
FakeShemp 1b0cc1d80b Add normal map support 2016-01-22 16:41:20 +01:00
5 changed files with 28 additions and 4 deletions
+1 -1
Submodule assets updated: 6ffb46e155...f7e349a316
+1
View File
@@ -27,6 +27,7 @@ private:
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const; void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
Texture* m_WhiteTexture; Texture* m_WhiteTexture;
Texture* m_NeutralNormalMap;
const IRenderer* m_Renderer; const IRenderer* m_Renderer;
const LightCullingPass* m_LightCullingPass; const LightCullingPass* m_LightCullingPass;
+12 -3
View File
@@ -5,7 +5,8 @@ uniform mat4 V;
uniform mat4 P; uniform mat4 P;
uniform vec4 Color; uniform vec4 Color;
uniform vec2 ScreenDimensions; uniform vec2 ScreenDimensions;
uniform sampler2D texture0; layout(binding = 0) uniform sampler2D DiffuseTexture;
layout(binding = 1) uniform sampler2D NormalMapTexture;
#define TILE_SIZE 16 #define TILE_SIZE 16
@@ -44,6 +45,8 @@ layout (std430, binding = 4) buffer LightIndexBuffer
in VertexData{ in VertexData{
vec3 Position; vec3 Position;
vec3 Normal; vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate; vec2 TextureCoordinate;
vec4 DiffuseColor; vec4 DiffuseColor;
}Input; }Input;
@@ -96,12 +99,18 @@ LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensi
return result; return result;
} }
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap)
{
mat3 TBN = mat3(tangent, bitangent, normal);
vec3 NormalMap = texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
return vec4(TBN * normalize(NormalMap), 0.0);
}
void main() void main()
{ {
vec4 texel = texture2D(texture0, Input.TextureCoordinate); vec4 texel = texture2D(DiffuseTexture, Input.TextureCoordinate);
vec4 position = V * M * vec4(Input.Position, 1.0); vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 normal = V * vec4(Input.Normal, 0.0); vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, NormalMapTexture);
vec4 viewVec = normalize(-position); vec4 viewVec = normalize(-position);
vec2 tilePos; vec2 tilePos;
+4
View File
@@ -19,6 +19,8 @@ layout(location = 10) in vec4 BoneWeights2;
out VertexData{ out VertexData{
vec3 Position; vec3 Position;
vec3 Normal; vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate; vec2 TextureCoordinate;
vec4 DiffuseColor; vec4 DiffuseColor;
}Output; }Output;
@@ -30,5 +32,7 @@ void main()
Output.Position = Position; Output.Position = Position;
Output.TextureCoordinate = TextureCoords; Output.TextureCoordinate = TextureCoords;
Output.Normal = vec3(M * vec4(Normal, 0.0)); Output.Normal = vec3(M * vec4(Normal, 0.0));
Output.Tangent = vec3(M * vec4(Tangent, 0.0));
Output.BiTangent = vec3(M * vec4(BiTangent, 0.0));
Output.DiffuseColor = DiffuseVertexColor; Output.DiffuseColor = DiffuseVertexColor;
} }
+10
View File
@@ -11,6 +11,7 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
void DrawFinalPass::InitializeTextures() void DrawFinalPass::InitializeTextures()
{ {
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png"); m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
m_NeutralNormalMap = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
} }
void DrawFinalPass::InitializeShaderPrograms() void DrawFinalPass::InitializeShaderPrograms()
@@ -59,6 +60,15 @@ void DrawFinalPass::Draw(RenderScene& scene)
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
} }
if (modelJob->NormalTexture != nullptr) {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, modelJob->NormalTexture->m_Texture);
}
else {
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalMap->m_Texture);
}
glBindVertexArray(modelJob->Model->VAO); glBindVertexArray(modelJob->Model->VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex); glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);