Normal map support

This commit is contained in:
Tleety
2016-01-27 13:52:27 +01:00
parent 8102f3a2ea
commit a954cbbf50
6 changed files with 30 additions and 21 deletions
+1
View File
@@ -40,6 +40,7 @@ private:
Texture* m_WhiteTexture; Texture* m_WhiteTexture;
Texture* m_BlackTexture; Texture* m_BlackTexture;
Texture* m_NeutralNormalTexture;
FrameBuffer m_FinalPassFrameBuffer; FrameBuffer m_FinalPassFrameBuffer;
GLuint m_BloomTexture; GLuint m_BloomTexture;
+13 -18
View File
@@ -9,7 +9,8 @@ uniform vec2 ScreenDimensions;
uniform vec4 FillColor; uniform vec4 FillColor;
uniform float FillPercentage; uniform float FillPercentage;
layout (binding = 0) uniform sampler2D DiffuseTexture; layout (binding = 0) uniform sampler2D DiffuseTexture;
layout (binding = 1) uniform sampler2D GlowMap; layout (binding = 1) uniform sampler2D NormalMapTexture;
layout (binding = 2) uniform sampler2D GlowMapTexture;
#define TILE_SIZE 16 #define TILE_SIZE 16
@@ -49,6 +50,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 ExplosionColor; vec4 ExplosionColor;
}Input; }Input;
@@ -102,13 +105,20 @@ 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 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate); vec4 diffuseTexel = texture2D(DiffuseTexture, Input.TextureCoordinate);
vec4 glowTexel = texture2D(GlowMap, Input.TextureCoordinate); vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate);
vec4 position = V * M * vec4(Input.Position, 1.0); vec4 position = V * M * vec4(Input.Position, 1.0);
vec4 normal = normalize(V * vec4(Input.Normal, 0.0)); vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, NormalMapTexture);
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
vec4 viewVec = normalize(-position); vec4 viewVec = normalize(-position);
vec2 tilePos; vec2 tilePos;
@@ -147,25 +157,10 @@ void main()
if(pos <= FillPercentage) { if(pos <= FillPercentage) {
color_result += FillColor; color_result += FillColor;
} }
//bloomColor = vec4(0.3, 0.8, 0.6, 1.0);
sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1)); sceneColor = vec4(color_result.xyz, clamp(color_result.a, 0, 1));
//These if statements should be removed if they are slow.
color_result += glowTexel; color_result += glowTexel;
bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0); bloomColor = vec4(clamp(color_result.xyz - 1.0, 0, 100), 1.0);
/*
if(color_result.x > 1 || color_result.y > 1 || color_result.z > 1) {
bloomColor = vec4(color_result.xyz, 1.0);
} else {
bloomColor = vec4(0.0, 0.0, 0.0, 1.0);
} */
//Tiled Debug Code //Tiled Debug Code
/* /*
+4
View File
@@ -16,6 +16,8 @@ layout(location = 6) in vec4 BoneWeights;
out VertexData{ out VertexData{
vec3 Position; vec3 Position;
vec3 Normal; vec3 Normal;
vec3 Tangent;
vec3 BiTangent;
vec2 TextureCoordinate; vec2 TextureCoordinate;
vec4 ExplosionColor; vec4 ExplosionColor;
}Output; }Output;
@@ -37,5 +39,7 @@ void main()
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz; Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
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.ExplosionColor = vec4(0.0); Output.ExplosionColor = vec4(0.0);
} }
+1 -1
View File
@@ -13,7 +13,7 @@ DrawBloomPass::DrawBloomPass(IRenderer* renderer)
void DrawBloomPass::InitializeTextures() void DrawBloomPass::InitializeTextures()
{ {
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png"); m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
} }
void DrawBloomPass::InitializeShaderPrograms() void DrawBloomPass::InitializeShaderPrograms()
+10 -1
View File
@@ -11,8 +11,9 @@ 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/White.png");
m_BlackTexture = ResourceManager::Load<Texture>("Textures/Core/Black.png"); m_BlackTexture = ResourceManager::Load<Texture>("Textures/Core/Black.png");
m_NeutralNormalTexture = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
} }
void DrawFinalPass::InitializeFrameBuffers() void DrawFinalPass::InitializeFrameBuffers()
@@ -230,7 +231,15 @@ void DrawFinalPass::BindModelTextures(std::shared_ptr<ModelJob>& job)
} else { } else {
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
} }
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
if (job->NormalTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->NormalTexture->m_Texture);
} else {
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
}
glActiveTexture(GL_TEXTURE2);
if (job->IncandescenceTexture != nullptr) { if (job->IncandescenceTexture != nullptr) {
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture); glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture->m_Texture);
} else { } else {
+1 -1
View File
@@ -143,7 +143,7 @@ PickData Renderer::Pick(glm::vec2 screenCoord)
void Renderer::InitializeTextures() void Renderer::InitializeTextures()
{ {
m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png"); m_ErrorTexture = ResourceManager::Load<Texture>("Textures/Core/ErrorTexture.png");
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png"); m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/White.png");
} }