diff --git a/Editor/resources/Shaders/basic.shader b/Editor/resources/Shaders/basic.shader index 6beb329f..bf9b397b 100644 --- a/Editor/resources/Shaders/basic.shader +++ b/Editor/resources/Shaders/basic.shader @@ -109,16 +109,16 @@ uniform sampler2D m_Displacement; layout(std140, binding = 32) uniform u_MaterialUniform { - bool u_HasAlbedo; - vec3 m_AlbedoColor; - bool u_HasMetalness; - float u_MetalnessValue; - bool u_HasRoughness; - float u_RoughnessValue; - bool u_HasAO; - float u_AOValue; - bool u_HasNormal; - bool u_HasDisplacement; + int u_HasAlbedo; + vec3 m_AlbedoColor; // 16 byte + int u_HasMetalness; // 32 byte + float u_MetalnessValue; // 36 byte + int u_HasRoughness; // 40 byte + float u_RoughnessValue; // 44 byte + int u_HasAO; // 48 byte + float u_AOValue; // 52 byte + int u_HasNormal; // 56 byte + int u_HasDisplacement; // 60 byte }; float height_scale = 0.00f; @@ -322,22 +322,27 @@ void main() vec2 finalTexCoords = texCoords; vec3 finalAlbedo = m_AlbedoColor; - if(u_HasAlbedo) + if(u_HasAlbedo == 1) finalAlbedo = texture(m_Albedo, finalTexCoords).rgb; float finalRoughness = u_RoughnessValue; - if (u_HasRoughness ) + if (u_HasRoughness == 1) finalRoughness = texture(m_Roughness, finalTexCoords).r; float finalMetalness = u_MetalnessValue; - if (u_HasMetalness) + if (u_HasMetalness == 1) finalMetalness = texture(m_Metalness, finalTexCoords).r; float finalAO = u_AOValue; - if (u_HasAO) + if (u_HasAO == 1) finalAO = texture(m_AO, finalTexCoords).r; - vec3 finalNormal = texture(m_Normal, finalTexCoords).rgb; + vec3 finalNormal = vec3(0.5, 0.5, 1.0); + if (u_HasNormal == 1) + { + finalNormal = texture(m_Normal, finalTexCoords).rgb; + } + finalNormal = finalNormal * 2.0 - 1.0; finalNormal = v_TBN * normalize(finalNormal); diff --git a/Nuake/src/Rendering/Textures/Material.cpp b/Nuake/src/Rendering/Textures/Material.cpp index 6a79eb0f..282d42ec 100644 --- a/Nuake/src/Rendering/Textures/Material.cpp +++ b/Nuake/src/Rendering/Textures/Material.cpp @@ -57,10 +57,10 @@ Material::Material(const glm::vec3 albedoColor) { glGenBuffers(1, &UBO); glBindBuffer(GL_UNIFORM_BUFFER, UBO); - glBufferData(GL_UNIFORM_BUFFER, sizeof(UBOStructure), NULL, GL_STATIC_DRAW); + glBufferData(GL_UNIFORM_BUFFER, 128, NULL, GL_STATIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); - data.m_AlbedoColor = myVec3{ albedoColor.r, albedoColor.g, albedoColor.b}; + data.m_AlbedoColor = Vector3{ albedoColor.r, albedoColor.g, albedoColor.b}; m_Name = "New material"; @@ -90,7 +90,21 @@ void Material::Bind() MaterialManager::Get()->CurrentlyBoundedMaterial = m_Name; glBindBuffer(GL_UNIFORM_BUFFER, UBO); + glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(UBOStructure), &data); + //glBufferSubData(GL_UNIFORM_BUFFER, 0, 4, &data.u_HasAlbedo); + // + //glBufferSubData(GL_UNIFORM_BUFFER, 16, 12, &data.m_AlbedoColor); + // + //glBufferSubData(GL_UNIFORM_BUFFER, 28, 4, &data.u_HasMetalness); + //glBufferSubData(GL_UNIFORM_BUFFER, 32, 4, &data.u_MetalnessValue); + //glBufferSubData(GL_UNIFORM_BUFFER, 36, 4, &data.u_HasRoughness); + //glBufferSubData(GL_UNIFORM_BUFFER, 40, 4, &data.u_RoughnessValue); + // + //glBufferSubData(GL_UNIFORM_BUFFER, 44, 4, &data.u_HasAO); + //glBufferSubData(GL_UNIFORM_BUFFER, 48, 4, &data.u_AOValue); + //glBufferSubData(GL_UNIFORM_BUFFER, 52, 4, &data.u_HasNormal); + //glBufferSubData(GL_UNIFORM_BUFFER, 56, 4, &data.u_HasDisplacement); glBindBuffer(GL_UNIFORM_BUFFER, 0); glBindBufferBase(GL_UNIFORM_BUFFER, 32, UBO); diff --git a/Nuake/src/Rendering/Textures/Material.h b/Nuake/src/Rendering/Textures/Material.h index 159432cb..fc30b83e 100644 --- a/Nuake/src/Rendering/Textures/Material.h +++ b/Nuake/src/Rendering/Textures/Material.h @@ -10,20 +10,22 @@ struct myVec3 { float r; float g; float b; - float a; }; struct UBOStructure { int u_HasAlbedo; - myVec3 m_AlbedoColor; - uint32_t u_HasMetalness; + float padding; + float padding2; + float padding3; + glm::vec3 m_AlbedoColor; + int u_HasMetalness; float u_MetalnessValue; - uint32_t u_HasRoughness; + int u_HasRoughness; float u_RoughnessValue; - uint32_t u_HasAO; + int u_HasAO; float u_AOValue; - uint32_t u_HasNormal; - uint32_t u_HasDisplacement; + int u_HasNormal; + int u_HasDisplacement; }; class Material @@ -39,10 +41,12 @@ public: Ref m_Normal; Ref m_Displacement; - UBOStructure data{ 0, // has labedo - myVec3{0.f, 0.f, 0.f, 1.0f}, // m_AlbedoColor + 0, // padding + 0, // padding + 0, // padding + glm::vec3{0.f, 0.f, 0.f}, // m_AlbedoColor 0, // u_HasMetalness 0.5f, // u_MetalnessValue 0, // u_HasRoughness