Fixed so that we could use DTX5nm as normal map
This commit is contained in:
+1
-1
Submodule assets updated: e8d98c2dae...1944662a1c
@@ -20,7 +20,9 @@ public:
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
GLuint m_Texture = 0;
|
||||
|
||||
|
||||
enum TextureType : GLint { Invalid = 0, DDS = 1, PNG = 2};
|
||||
TextureType m_Type;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -14,13 +14,7 @@ protected:
|
||||
TextureSprite(std::string path);
|
||||
|
||||
public:
|
||||
~TextureSprite();
|
||||
|
||||
void Bind(GLenum textureUnit = GL_TEXTURE0);
|
||||
|
||||
GLuint m_Texture = 0;
|
||||
unsigned char* Data = nullptr;
|
||||
|
||||
~TextureSprite() {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
#version 430
|
||||
|
||||
#include "Shaders/Util/CommonNormalFunc.glsl"
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
|
||||
uniform mat4 VM;
|
||||
uniform mat4 M;
|
||||
uniform mat4 V;
|
||||
@@ -18,6 +21,7 @@ uniform vec3 CameraPosition;
|
||||
uniform int SSAOQuality;
|
||||
uniform float FarDistance[MAX_SPLITS];
|
||||
|
||||
uniform int NormalTextureType;
|
||||
uniform vec2 DiffuseUVRepeat;
|
||||
uniform vec2 NormalUVRepeat;
|
||||
uniform vec2 SpecularUVRepeat;
|
||||
@@ -140,13 +144,6 @@ 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);
|
||||
}
|
||||
|
||||
// Returns a "random" value.
|
||||
float Random(vec3 seed, int i)
|
||||
{
|
||||
@@ -303,7 +300,7 @@ void main()
|
||||
vec4 glowTexel = texture2D(GlowMapTexture, Input.TextureCoordinate * GlowUVRepeat);
|
||||
vec4 specularTexel = texture2D(SpecularMapTexture, Input.TextureCoordinate * SpecularUVRepeat);
|
||||
vec4 position = VM * vec4(Input.Position, 1.0);
|
||||
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture);
|
||||
vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate * NormalUVRepeat, NormalMapTexture, NormalTextureType);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#version 430
|
||||
|
||||
#include "Shaders/Util/CommonNormalFunc.glsl"
|
||||
|
||||
#define MIN_AMBIENT_LIGHT 0.3
|
||||
#define MAX_SPLITS 4
|
||||
|
||||
@@ -20,6 +22,10 @@ layout (binding = 0) uniform sampler2D AOTexture;
|
||||
layout (binding = 30) uniform sampler2DArrayShadow DepthMap;
|
||||
|
||||
//Get bineded at the same time as the textures
|
||||
uniform int NormalTextureType1;
|
||||
uniform int NormalTextureType2;
|
||||
uniform int NormalTextureType3;
|
||||
|
||||
uniform vec2 DiffuseUVRepeat1;
|
||||
uniform vec2 DiffuseUVRepeat2;
|
||||
uniform vec2 DiffuseUVRepeat3;
|
||||
@@ -182,11 +188,12 @@ vec4 CalcBlendedTexel(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B,
|
||||
}
|
||||
|
||||
vec4 CalcBlendedNormal(vec4 blendValue, sampler2D R, sampler2D G, sampler2D B,
|
||||
vec2 R_TileValues, vec2 G_TileValues, vec2 B_TileValues){
|
||||
vec2 R_TileValues, vec2 G_TileValues, vec2 B_TileValues
|
||||
int R_TextureType, int G_TextureType, int B_TextureType) {
|
||||
mat3 TBN = mat3(Input.Tangent, Input.BiTangent, Input.Normal);
|
||||
vec3 R_Channel = texture(R, Input.TextureCoordinate * R_TileValues).xyz * 2.0 - vec3(1.0);
|
||||
vec3 G_Channel = texture(G, Input.TextureCoordinate * G_TileValues).xyz * 2.0 - vec3(1.0);
|
||||
vec3 B_Channel = texture(B, Input.TextureCoordinate * B_TileValues).xyz * 2.0 - vec3(1.0);
|
||||
vec3 R_Channel = NormalMapValue(Input.TextureCoordinate * R_TileValues, R, R_TextureType);
|
||||
vec3 G_Channel = NormalMapValue(Input.TextureCoordinate * G_TileValues, G, G_TextureType);
|
||||
vec3 B_Channel = NormalMapValue(Input.TextureCoordinate * B_TileValues, B, B_TextureType);
|
||||
|
||||
float total = blendValue.r + blendValue.g + blendValue.b + blendValue.a;
|
||||
float totalDiv = 1 / total;
|
||||
@@ -365,7 +372,8 @@ void main()
|
||||
vec4 position = VM * vec4(Input.Position, 1.0);
|
||||
//vec4 normal = V * CalcNormalMappedValue(Input.Normal, Input.Tangent, Input.BiTangent, Input.TextureCoordinate, SplatMapTexture);
|
||||
vec4 normal = V * CalcBlendedNormal(splatTexel, NormalMapTexture1, NormalMapTexture2, NormalMapTexture3,
|
||||
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3);
|
||||
NormalUVRepeat1, NormalUVRepeat2, NormalUVRepeat3,
|
||||
NormalTextureType1, NormalTextureType2, NormalTextureType3);
|
||||
normal = normalize(normal);
|
||||
//vec4 normal = normalize(V * vec4(Input.Normal, 0.0));
|
||||
vec4 viewVec = normalize(-position);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#define NORMAL_DDS 1
|
||||
#define NORMAL_PNG 2
|
||||
|
||||
vec3 NormalMapValue(vec2 textureCoordinate, sampler2D normalMap, int normalTextureType){
|
||||
if(normalTextureType == NORMAL_DDS){
|
||||
vec3 normal;
|
||||
normal.xy = texture(normalMap, textureCoordinate).wy * 2.0 - vec2(1.0);
|
||||
normal.z = sqrt(1.0 - clamp(dot(normal.xy, normal.xy), 0.0, 1.0));
|
||||
return normal;
|
||||
} else {
|
||||
//should be PNG or anything that doesn't need special support
|
||||
return texture(normalMap, textureCoordinate).xyz * 2.0 - vec3(1.0);
|
||||
}
|
||||
}
|
||||
|
||||
vec4 CalcNormalMappedValue(vec3 normal, vec3 tangent, vec3 bitangent, vec2 textureCoordinate, sampler2D normalMap, int normalTextureType)
|
||||
{
|
||||
mat3 TBN = mat3(tangent, bitangent, normal);
|
||||
vec3 NormalMap = NormalMapValue(textureCoordinate, normalMap, normalTextureType);
|
||||
return vec4(TBN * normalize(NormalMap), 0.0);
|
||||
}
|
||||
@@ -1527,10 +1527,12 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptr<Model
|
||||
if (job->NormalTexture.size() > 0 && job->NormalTexture[0]->Texture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[0]->Texture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, "NormalUVRepeat"), 1, glm::value_ptr(job->NormalTexture[0]->UVRepeat));
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, "NormalTextureType"), job->NormalTexture[0]->Texture->m_Type);
|
||||
}
|
||||
else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, "NormalUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
//glUniform2fv(glGetUniformLocation(shaderHandle, "NormalUVRepeat"), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, "NormalTextureType"), m_NeutralNormalTexture->m_Type);
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
@@ -1562,57 +1564,60 @@ void DrawFinalPass::BindModelTextures(GLuint shaderHandle, std::shared_ptr<Model
|
||||
int texturePosition = GL_TEXTURE2;
|
||||
|
||||
//Bind 5 diffuse textures
|
||||
std::string UniformName = "DiffuseUVRepeat";
|
||||
std::string UVRepeatName = "DiffuseUVRepeat";
|
||||
for (unsigned int i = 0; i < 3; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->DiffuseTexture.size() > i && job->DiffuseTexture[i]->Texture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->DiffuseTexture[i]->Texture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->DiffuseTexture[i]->UVRepeat));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->DiffuseTexture[i]->UVRepeat));
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
|
||||
//Bind 5 Normal textures
|
||||
UniformName = "NormalUVRepeat";
|
||||
std::string textureType = "NormalTextureType";
|
||||
UVRepeatName = "NormalUVRepeat";
|
||||
for (unsigned int i = 0; i < 3; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->NormalTexture.size() > i && job->NormalTexture[i]->Texture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->NormalTexture[i]->Texture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->NormalTexture[i]->UVRepeat));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->NormalTexture[i]->UVRepeat));
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, std::string(textureType + ((char)(i + '1'))).c_str()), job->NormalTexture[i]->Texture->m_Type);
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_NeutralNormalTexture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
glUniform1i(glGetUniformLocation(shaderHandle, std::string(textureType + ((char)(i + '1'))).c_str()), m_NeutralNormalTexture->m_Type);
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
|
||||
//Bind 5 Specular textures
|
||||
UniformName = "SpecularUVRepeat";
|
||||
UVRepeatName = "SpecularUVRepeat";
|
||||
for (unsigned int i = 0; i < 3; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->SpecularTexture.size() > i && job->SpecularTexture[i]->Texture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->SpecularTexture[i]->Texture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->SpecularTexture[i]->UVRepeat));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->SpecularTexture[i]->UVRepeat));
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_GreyTexture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
|
||||
//Bind 5 Incandescence textures
|
||||
UniformName = "GlowUVRepeat";
|
||||
UVRepeatName = "GlowUVRepeat";
|
||||
for (unsigned int i = 0; i < 3; i++) {
|
||||
glActiveTexture(texturePosition);
|
||||
if (job->IncandescenceTexture.size() > i && job->IncandescenceTexture[i]->Texture != nullptr) {
|
||||
glBindTexture(GL_TEXTURE_2D, job->IncandescenceTexture[i]->Texture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->IncandescenceTexture[i]->UVRepeat));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(job->IncandescenceTexture[i]->UVRepeat));
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, m_BlackTexture->m_Texture);
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UniformName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
glUniform2fv(glGetUniformLocation(shaderHandle, std::string(UVRepeatName + ((char)(i + '1'))).c_str()), 1, glm::value_ptr(glm::vec2(1.0f, 1.0f)));
|
||||
}
|
||||
texturePosition++;
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@ Texture::Texture(std::string path)
|
||||
Image* img;
|
||||
if (ext == ".png") {
|
||||
img = ResourceManager::Load<PNG, true>(path);
|
||||
m_Type = TextureType::PNG;
|
||||
} else if (ext == ".dds") {
|
||||
img = ResourceManager::Load<DDS, true>(path);
|
||||
m_Type = TextureType::DDS;
|
||||
} else {
|
||||
m_Type = TextureType::Invalid;
|
||||
throw Resource::FailedLoadingException("Texture extension is not .png nor .dds");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user