Compare commits
1 Commits
DDS
...
NormalMaps
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b0cc1d80b |
+1
-1
Submodule assets updated: 6ffb46e155...f7e349a316
@@ -27,6 +27,7 @@ private:
|
||||
void GenerateTexture(GLuint* texture, GLenum wrapping, GLenum filtering, glm::vec2 dimensions, GLint internalFormat, GLint format, GLenum type) const;
|
||||
|
||||
Texture* m_WhiteTexture;
|
||||
Texture* m_NeutralNormalMap;
|
||||
|
||||
const IRenderer* m_Renderer;
|
||||
const LightCullingPass* m_LightCullingPass;
|
||||
|
||||
@@ -5,7 +5,8 @@ uniform mat4 V;
|
||||
uniform mat4 P;
|
||||
uniform vec4 Color;
|
||||
uniform vec2 ScreenDimensions;
|
||||
uniform sampler2D texture0;
|
||||
layout(binding = 0) uniform sampler2D DiffuseTexture;
|
||||
layout(binding = 1) uniform sampler2D NormalMapTexture;
|
||||
|
||||
#define TILE_SIZE 16
|
||||
|
||||
@@ -44,6 +45,8 @@ layout (std430, binding = 4) buffer LightIndexBuffer
|
||||
in VertexData{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoordinate;
|
||||
vec4 DiffuseColor;
|
||||
}Input;
|
||||
@@ -96,12 +99,18 @@ LightResult CalcDirectionalLightSource(vec4 direction, vec4 color, float intensi
|
||||
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()
|
||||
{
|
||||
vec4 texel = texture2D(texture0, Input.TextureCoordinate);
|
||||
vec4 texel = texture2D(DiffuseTexture, Input.TextureCoordinate);
|
||||
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);
|
||||
|
||||
vec2 tilePos;
|
||||
|
||||
@@ -19,6 +19,8 @@ layout(location = 10) in vec4 BoneWeights2;
|
||||
out VertexData{
|
||||
vec3 Position;
|
||||
vec3 Normal;
|
||||
vec3 Tangent;
|
||||
vec3 BiTangent;
|
||||
vec2 TextureCoordinate;
|
||||
vec4 DiffuseColor;
|
||||
}Output;
|
||||
@@ -30,5 +32,7 @@ void main()
|
||||
Output.Position = Position;
|
||||
Output.TextureCoordinate = TextureCoords;
|
||||
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;
|
||||
}
|
||||
@@ -11,6 +11,7 @@ DrawFinalPass::DrawFinalPass(IRenderer* renderer, LightCullingPass* lightCulling
|
||||
void DrawFinalPass::InitializeTextures()
|
||||
{
|
||||
m_WhiteTexture = ResourceManager::Load<Texture>("Textures/Core/Blank.png");
|
||||
m_NeutralNormalMap = ResourceManager::Load<Texture>("Textures/Core/NeutralNormalMap.png");
|
||||
}
|
||||
|
||||
void DrawFinalPass::InitializeShaderPrograms()
|
||||
@@ -59,6 +60,15 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
||||
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);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||
glDrawElementsBaseVertex(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, 0, modelJob->StartIndex);
|
||||
|
||||
Reference in New Issue
Block a user