diff --git a/Editor/resources/Scenes/level.scene b/Editor/resources/Scenes/level.scene deleted file mode 100644 index fbddfefa..00000000 --- a/Editor/resources/Scenes/level.scene +++ /dev/null @@ -1,62 +0,0 @@ -{ - "Entities": [ - { - "GetComponent()": { - "Name": "Camera" - }, - "GetComponent()": { - "HasParent": false, - "Type": "ParentComponent" - }, - "GetComponent()": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - } - ], - "Name": "", - "m_Environement": { - "AmbientColor": { - "w": 1.0141871010880041e-38, - "x": 4.489836626909252e+21, - "y": 7.618957098799247e+31, - "z": 1.0141871010880041e-38 - }, - "ProceduralSkybox": { - "AtmosphereRadius": 6380000.0, - "MieScattering": { - "x": 1.9999999494757503e-05, - "y": 1.9999999494757503e-05, - "z": 1.9999999494757503e-05 - }, - "RayleighScattering": { - "x": 5.80000005356851e-06, - "y": 1.3500000022759195e-05, - "z": 3.310000101919286e-05 - }, - "SunDirection": { - "x": 0.20000000298023224, - "y": 0.9591699838638306, - "z": 0.20000000298023224 - }, - "SunIntensity": 100.0, - "SurfaceRadius": 6360000.0 - }, - "VolumetricFog": 0.949999988079071, - "VolumetricStepCount": 100.0 - } -} \ No newline at end of file diff --git a/Editor/resources/Scenes/test.scene b/Editor/resources/Scenes/test.scene deleted file mode 100644 index f731718d..00000000 --- a/Editor/resources/Scenes/test.scene +++ /dev/null @@ -1,389 +0,0 @@ -{ - "Entities": [ - { - "NameComponent": { - "ID": -1986865524, - "Name": "testing" - }, - "ParentComponent": { - "HasParent": true, - "ParentID": -1986867378 - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 1.125, - "y": -2.375, - "z": -6.375 - }, - "Type": "TransformComponent" - } - }, - { - "NameComponent": { - "ID": -1986867378, - "Name": "Brush 2" - }, - "ParentComponent": { - "HasParent": true, - "ParentID": 237443808 - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - }, - { - "NameComponent": { - "ID": -1986874285, - "Name": "TestTrigger" - }, - "ParentComponent": { - "HasParent": true, - "ParentID": -1986876522 - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": -0.25, - "y": -1.25, - "z": 0.875 - }, - "Type": "TransformComponent" - }, - "WrenScriptComponent": { - "Class": "TriggerScript", - "Script": "Scripts/Trigger.wren" - } - }, - { - "NameComponent": { - "ID": -1986876522, - "Name": "Brush 1" - }, - "ParentComponent": { - "HasParent": true, - "ParentID": 237443808 - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - }, - { - "NameComponent": { - "ID": -1990960415, - "Name": "" - }, - "ParentComponent": { - "HasParent": true, - "ParentID": -1990962787 - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.75, - "y": -2.875, - "z": -1.0 - }, - "Type": "TransformComponent" - } - }, - { - "NameComponent": { - "ID": -1990962787, - "Name": "Brush 0" - }, - "ParentComponent": { - "HasParent": true, - "ParentID": 237443808 - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - }, - { - "NameComponent": { - "ID": -1598095916, - "Name": "Model" - }, - "ParentComponent": { - "HasParent": false - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - }, - { - "NameComponent": { - "ID": 237443808, - "Name": "Trenchbroom map" - }, - "ParentComponent": { - "HasParent": false - }, - "QuakeMapComponent": { - "HasCollisions": true, - "Path": "Maps/afgd.map" - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": -0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - }, - { - "LightComponent": { - "CastShadows": true, - "Color": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Direction": { - "x": 0.20000000298023224, - "y": 0.9591699838638306, - "z": 0.20000000298023224 - }, - "IsVolumetric": false, - "Strength": 10.0, - "SyncDirectionWithSky": true, - "Type": 0 - }, - "NameComponent": { - "ID": 3, - "Name": "Light" - }, - "ParentComponent": { - "HasParent": false - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": -0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 17.93589973449707, - "z": 0.0 - }, - "Type": "TransformComponent" - }, - "WrenScriptComponent": { - "Class": "TestScript", - "Script": "Scripts/entityScript.wren" - } - }, - { - "CharacterControllerComponent": { - "Height": 1.2000000476837158, - "Mass": 2500.0, - "Radius": 0.20000000298023224 - }, - "NameComponent": { - "ID": 237171289, - "Name": "Player" - }, - "ParentComponent": { - "HasParent": false - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": -0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 6.100314617156982, - "y": 0.0, - "z": -5.69704008102417 - }, - "Type": "TransformComponent" - }, - "WrenScriptComponent": { - "Class": "PlayerScript", - "Script": "Scripts/Player.wren" - } - }, - { - "CameraComponent": { - "CameraInstance": { - "AspectRatio": 1.9246861934661865, - "Exposure": 1.0, - "Fov": 88.0, - "Speed": 1.0, - "m_Type": 1 - } - }, - "NameComponent": { - "ID": 237481018, - "Name": "Camera" - }, - "ParentComponent": { - "HasParent": false - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": -0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 6.100314617156982, - "y": -49.37096405029297, - "z": -5.69704008102417 - }, - "Type": "TransformComponent" - }, - "WrenScriptComponent": { - "Class": "CamScript", - "Script": "Scripts/Cam.wren" - } - } - ], - "Name": "", - "m_Environement": { - "AmbientColor": { - "w": -431602080.0, - "x": -431602080.0, - "y": -431602080.0, - "z": -431602080.0 - }, - "ProceduralSkybox": { - "AtmosphereRadius": 6380000.0, - "MieScattering": { - "x": 1.9999999494757503e-05, - "y": 1.9999999494757503e-05, - "z": 1.9999999494757503e-05 - }, - "RayleighScattering": { - "x": 5.80000005356851e-06, - "y": 1.3500000022759195e-05, - "z": 3.310000101919286e-05 - }, - "SunDirection": { - "x": 0.20000000298023224, - "y": 0.9591699838638306, - "z": 0.20000000298023224 - }, - "SunIntensity": 100.0, - "SurfaceRadius": 6360000.0 - }, - "VolumetricFog": 0.949999988079071, - "VolumetricStepCount": 100.0 - } -} \ No newline at end of file diff --git a/Editor/resources/Scenes/test.scene.scene b/Editor/resources/Scenes/test.scene.scene deleted file mode 100644 index 0f285f04..00000000 --- a/Editor/resources/Scenes/test.scene.scene +++ /dev/null @@ -1,70 +0,0 @@ -{ - "Entities": [ - { - "CameraComponent": { - "CameraInstance": { - "AspectRatio": 1.7777777910232544, - "Exposure": 1.0, - "Fov": 88.0, - "Speed": 1.0, - "m_Type": 1 - } - }, - "NameComponent": { - "Name": "Camera" - }, - "ParentComponent": { - "HasParent": false - }, - "TransformComponent": { - "Rotation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Scale": { - "x": 1.0, - "y": 1.0, - "z": 1.0 - }, - "Translation": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "Type": "TransformComponent" - } - } - ], - "Name": "", - "m_Environement": { - "AmbientColor": { - "w": 9.275544859982045e-39, - "x": 1.0193902624158886e-38, - "y": 8.449025394560124e-39, - "z": 9.275544859982045e-39 - }, - "ProceduralSkybox": { - "AtmosphereRadius": 6380000.0, - "MieScattering": { - "x": 1.9999999494757503e-05, - "y": 1.9999999494757503e-05, - "z": 1.9999999494757503e-05 - }, - "RayleighScattering": { - "x": 5.80000005356851e-06, - "y": 1.3500000022759195e-05, - "z": 3.310000101919286e-05 - }, - "SunDirection": { - "x": 0.20000000298023224, - "y": 0.9591699838638306, - "z": 0.20000000298023224 - }, - "SunIntensity": 100.0, - "SurfaceRadius": 6360000.0 - }, - "VolumetricFog": 0.949999988079071, - "VolumetricStepCount": 100.0 - } -} \ No newline at end of file diff --git a/Editor/resources/Shaders/deferred.shader b/Editor/resources/Shaders/deferred.shader index 6ad6109e..8f4e6b22 100644 --- a/Editor/resources/Shaders/deferred.shader +++ b/Editor/resources/Shaders/deferred.shader @@ -29,6 +29,7 @@ in vec3 FragPos; in vec2 UV; in mat4 InvProjection; in mat4 InvView; + // Camera uniform float u_Exposure; uniform vec3 u_EyePosition; diff --git a/Editor/resources/Shaders/gbuffer.shader b/Editor/resources/Shaders/gbuffer.shader index 0e487a18..f8a04be8 100644 --- a/Editor/resources/Shaders/gbuffer.shader +++ b/Editor/resources/Shaders/gbuffer.shader @@ -30,30 +30,70 @@ void main() #shader fragment #version 460 core -layout(location = 0) out vec3 gAlbedo; -layout(location = 1) out vec3 gNormal; -layout(location = 2) out vec3 gMaterial; +layout(location = 0) out vec4 gAlbedo; +layout(location = 1) out vec4 gNormal; +layout(location = 2) out vec4 gMaterial; in vec3 FragPos; in vec2 UV; in mat3 TBN; +// Material uniform sampler2D m_Albedo; -uniform sampler2D m_Normal; -uniform sampler2D m_Roughness; uniform sampler2D m_Metalness; +uniform sampler2D m_Roughness; uniform sampler2D m_AO; +uniform sampler2D m_Normal; +uniform sampler2D m_Displacement; + +layout(std140, binding = 32) uniform u_MaterialUniform +{ + 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 + int u_Unlit; +}; void main() { - gAlbedo.rgb = texture(m_Albedo, UV).rgb; + // Normal + vec3 normal = vec3(0.5, 0.5, 1.0); + if (u_HasNormal == 1) + normal = texture(m_Normal, UV).rgb; - vec3 normal = texture(m_Normal, UV).rgb; normal = normal * 2.0 - 1.0; - normal = normalize((TBN * normalize(normal)).xyz); + normal = TBN * normalize(normal); + gNormal = vec4(normal, 1.0); + + // Albedo + gAlbedo = vec4(m_AlbedoColor, 1.0); + if (u_HasAlbedo == 1) + gAlbedo = texture(m_Albedo, UV).rgba; + + gAlbedo.rgba = texture(m_Albedo, UV).rgba; - gNormal = (normal * 0.5 + 0.5); - gMaterial.r = texture(m_Metalness, UV).r; - gMaterial.g = texture(m_AO, UV).r; - gMaterial.b = texture(m_Roughness, UV).r; + // Material + float finalMetalness = u_MetalnessValue; + if (u_HasMetalness == 1) + finalMetalness = texture(m_Metalness, UV).r; + + float finalAO = u_AOValue; + if (u_HasAO == 1) + finalAO = texture(m_AO, UV).r; + + float finalRoughness = u_RoughnessValue; + if (u_HasRoughness == 1) + finalRoughness = texture(m_Roughness, UV).r; + + gMaterial = vec4(0, 0, 0, 1); + gMaterial.r = finalMetalness; + gMaterial.g = finalAO; + gMaterial.b = finalRoughness; } \ No newline at end of file diff --git a/Editor/src/EditorInterface.cpp b/Editor/src/EditorInterface.cpp index fcac85b3..74f29360 100644 --- a/Editor/src/EditorInterface.cpp +++ b/Editor/src/EditorInterface.cpp @@ -131,17 +131,42 @@ namespace Nuake { if (m_IsEntitySelected) { - //if (ImGui::Begin("CSM")) - //{ - // if (m_SelectedEntity.HasComponent()) - // { - // ImVec2 regionAvail = ImGui::GetContentRegionAvail(); - // glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y); - // Ref texture = m_SelectedEntity.GetComponent().m_Framebuffers[0]->GetTexture(GL_DEPTH_ATTACHMENT); - // ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); - // } - //} - //ImGui::End(); + if (ImGui::Begin("GBUFFER")) + { + ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y); + Ref texture = Engine::GetCurrentWindow()->GetGBuffer()->GetTexture(GL_DEPTH_ATTACHMENT); + ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); + + } + ImGui::End(); + if (ImGui::Begin("GBUFFER2")) + { + ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y); + Ref texture = Engine::GetCurrentWindow()->GetGBuffer()->GetTexture(GL_COLOR_ATTACHMENT0); + ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); + + } + ImGui::End(); + if (ImGui::Begin("GBUFFER3")) + { + ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y); + Ref texture = Engine::GetCurrentWindow()->GetGBuffer()->GetTexture(GL_COLOR_ATTACHMENT1); + ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); + + } + ImGui::End(); + if (ImGui::Begin("GBUFFER4")) + { + ImVec2 regionAvail = ImGui::GetContentRegionAvail(); + glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y); + Ref texture = Engine::GetCurrentWindow()->GetGBuffer()->GetTexture(GL_COLOR_ATTACHMENT2); + ImGui::Image((void*)texture->GetID(), regionAvail, ImVec2(0, 1), ImVec2(1, 0)); + + } + ImGui::End(); // //if (ImGui::Begin("CSM 2")) //{ diff --git a/Nuake/src/Rendering/Buffers/Framebuffer.cpp b/Nuake/src/Rendering/Buffers/Framebuffer.cpp index 77aacf07..cbfa61f6 100644 --- a/Nuake/src/Rendering/Buffers/Framebuffer.cpp +++ b/Nuake/src/Rendering/Buffers/Framebuffer.cpp @@ -45,13 +45,13 @@ namespace Nuake // Surely, this can be optimized. int size = 0; std::vector keys = std::vector(); - for (auto s : m_Textures) + for (auto& s : m_Textures) { - if (s.first != GL_DEPTH_ATTACHMENT) - { - keys.push_back(s.first); - size += 1; - } + if (s.first == GL_DEPTH_ATTACHMENT) + continue; + + keys.push_back(s.first); + size += 1; } if (size > 0) diff --git a/Nuake/src/Rendering/Mesh/Mesh.cpp b/Nuake/src/Rendering/Mesh/Mesh.cpp index 31726417..4c4c41f6 100644 --- a/Nuake/src/Rendering/Mesh/Mesh.cpp +++ b/Nuake/src/Rendering/Mesh/Mesh.cpp @@ -55,10 +55,10 @@ namespace Nuake m_VertexArray->Unbind(); } - void Mesh::Draw(bool drawMaterial) + void Mesh::Draw(Ref shader, bool bindMaterial) { - if (drawMaterial) - m_Material->Bind(); + if (bindMaterial) + m_Material->Bind(shader); m_VertexArray->Bind(); RenderCommand::DrawElements(RendererEnum::TRIANGLES, m_Indices.size(), RendererEnum::UINT, 0); @@ -68,6 +68,7 @@ namespace Nuake { Renderer::m_DebugShader->Bind(); Renderer::m_DebugShader->SetUniform4f("u_Color", 1.0f, 0.0f, 0.0f, 1.f); + m_VertexArray->Bind(); RenderCommand::DrawElements(RendererEnum::TRIANGLES, m_Indices.size(), RendererEnum::UINT, 0); } diff --git a/Nuake/src/Rendering/Mesh/Mesh.h b/Nuake/src/Rendering/Mesh/Mesh.h index 0e3a4e60..c6bbeb69 100644 --- a/Nuake/src/Rendering/Mesh/Mesh.h +++ b/Nuake/src/Rendering/Mesh/Mesh.h @@ -1,7 +1,7 @@ #pragma once #include "src/Core/Core.h" #include "src/Core/Maths.h" - +#include "src/Rendering/Shaders/Shader.h" #include "src/Rendering/Textures/Material.h" #include "src/Rendering/Vertex.h" @@ -9,6 +9,7 @@ #include "src/Rendering/Buffers/VertexArray.h" #include "src/Rendering/Buffers/VertexBufferLayout.h" #include "src/Rendering/AABB.h" + namespace Nuake { class Mesh @@ -20,7 +21,7 @@ namespace Nuake Mesh(std::vector vertices, std::vector indices, Ref material); - void Draw(bool bindMaterial = true); + void Draw(Ref shader, bool bindMaterial = true); void DebugDraw(); inline AABB GetAABB() const { return m_AABB; } diff --git a/Nuake/src/Rendering/RenderList.h b/Nuake/src/Rendering/RenderList.h index c1b467b1..0bf33b2a 100644 --- a/Nuake/src/Rendering/RenderList.h +++ b/Nuake/src/Rendering/RenderList.h @@ -36,12 +36,12 @@ namespace Nuake for (auto& i : m_RenderList) { if(!depthOnly) - i.first->Bind(); + i.first->Bind(shader); for (auto& m : i.second) { shader->SetUniformMat4f("u_Model", m.transform); - m.Mesh->Draw(false); + m.Mesh->Draw(shader, false); } } diff --git a/Nuake/src/Rendering/Shaders/Shader.cpp b/Nuake/src/Rendering/Shaders/Shader.cpp index 2907e898..a529d617 100644 --- a/Nuake/src/Rendering/Shaders/Shader.cpp +++ b/Nuake/src/Rendering/Shaders/Shader.cpp @@ -113,11 +113,11 @@ namespace Nuake // m alloc. casted as a pointer. char* message = (char*)malloc(length * sizeof(char)); - //glGetShaderInfoLog(id, length, &length, message); + glGetShaderInfoLog(id, length, &length, message); std::cout << "Failed to compile " << (type == GL_VERTEX_SHADER ? "vertex" : "Fragment") << " shader!" << std::endl; - std::cout << std::string(message) << std::endl; + std::cout << message << std::endl; // Delete invalid shader glDeleteShader(id); diff --git a/Nuake/src/Rendering/Textures/Material.cpp b/Nuake/src/Rendering/Textures/Material.cpp index 27ccf2ef..71f4e2ee 100644 --- a/Nuake/src/Rendering/Textures/Material.cpp +++ b/Nuake/src/Rendering/Textures/Material.cpp @@ -84,7 +84,7 @@ namespace Nuake Material::~Material() {} - void Material::Bind() + void Material::Bind(Ref shader) { if (MaterialManager::Get()->CurrentlyBoundedMaterial == m_Name) return; @@ -101,35 +101,35 @@ namespace Nuake m_Albedo->Bind(4); else m_DefaultAlbedo->Bind(4); - Renderer::m_Shader->SetUniform1i("m_Albedo", 4); + shader->SetUniform1i("m_Albedo", 4); // AO if (m_AO != nullptr) m_AO->Bind(5); else m_DefaultAO->Bind(5); - Renderer::m_Shader->SetUniform1i("m_AO", 5); + shader->SetUniform1i("m_AO", 5); // Metallic if (m_Metalness != nullptr) m_Metalness->Bind(6); else m_DefaultMetalness->Bind(6); - Renderer::m_Shader->SetUniform1i("m_Metalness", 6); + shader->SetUniform1i("m_Metalness", 6); // Roughness if (m_Roughness != nullptr) m_Roughness->Bind(7); else m_DefaultRoughness->Bind(7); - Renderer::m_Shader->SetUniform1i("m_Roughness", 7); + shader->SetUniform1i("m_Roughness", 7); // Normal if (m_Normal != nullptr) m_Normal->Bind(8); else m_DefaultNormal->Bind(8); - Renderer::m_Shader->SetUniform1i("m_Normal", 8); + shader->SetUniform1i("m_Normal", 8); // Displacement if (m_Displacement != nullptr) diff --git a/Nuake/src/Rendering/Textures/Material.h b/Nuake/src/Rendering/Textures/Material.h index fca869e9..96f7e2c4 100644 --- a/Nuake/src/Rendering/Textures/Material.h +++ b/Nuake/src/Rendering/Textures/Material.h @@ -1,9 +1,11 @@ #pragma once +#include "src/Core/Core.h" +#include "src/Core/Maths.h" + +#include "src/Rendering/Shaders/Shader.h" #include "src/Rendering/Textures/TextureManager.h" #include "Texture.h" -#include "src/Core/Core.h" -#include "src/Core/Maths.h" namespace Nuake { @@ -68,7 +70,7 @@ namespace Nuake ~Material(); - void Bind(); + void Bind(Ref shader); void SetupUniformBuffer(); diff --git a/Nuake/src/Scene/Components/MeshComponent.cpp b/Nuake/src/Scene/Components/MeshComponent.cpp index 99d3d1ab..99842540 100644 --- a/Nuake/src/Scene/Components/MeshComponent.cpp +++ b/Nuake/src/Scene/Components/MeshComponent.cpp @@ -5,12 +5,6 @@ #include namespace Nuake { - void MeshComponent::Draw() - { - for (auto m : meshes) - m->Draw(); - } - void MeshComponent::LoadModel() { this->meshes.clear(); diff --git a/Nuake/src/Scene/Components/QuakeMap.cpp b/Nuake/src/Scene/Components/QuakeMap.cpp index 1a8212dc..13e323fb 100644 --- a/Nuake/src/Scene/Components/QuakeMap.cpp +++ b/Nuake/src/Scene/Components/QuakeMap.cpp @@ -1,12 +1,6 @@ #include "QuakeMap.h" namespace Nuake { - void QuakeMapComponent::Draw() - { - for (auto m : m_Meshes) - m->Draw(); - } - void QuakeMapComponent::Load(std::string path, bool collisions) { if (Path == path) diff --git a/Nuake/src/Scene/Scene.cpp b/Nuake/src/Scene/Scene.cpp index 5c65f87c..3f989a25 100644 --- a/Nuake/src/Scene/Scene.cpp +++ b/Nuake/src/Scene/Scene.cpp @@ -278,25 +278,26 @@ namespace Nuake { pbrShader->SetUniform1i("u_ShowNormal", 0); - if (!cam) + if (cam) { - return; pbrShader->SetUniform1f("u_Exposure", cam->Exposure); pbrShader->SetUniformMat4f("u_View", cam->GetTransform()); pbrShader->SetUniformMat4f("u_Projection", cam->GetPerspective()); auto view = m_Registry.view(); - for (auto e : view) + for (auto e : view) { auto [transform, model, parent] = view.get(e); for (auto& m : model.meshes) Renderer::SubmitMesh(m, transform.GetTransform()); } + glCullFace(GL_BACK); Renderer::Flush(pbrShader); glCullFace(GL_FRONT); + auto quakeView = m_Registry.view(); - for (auto e : quakeView) + for (auto e : quakeView) { auto [transform, model, parent] = quakeView.get(e); if (model.IsTransparent) @@ -304,10 +305,7 @@ namespace Nuake { for (auto& b : model.Meshes) { - AABB aabb = b->GetAABB(); - aabb.Transform(transform.GetTransform()); - if(cam->BoxFrustumCheck(aabb)) - Renderer::SubmitMesh(b, transform.GetTransform()); + Renderer::SubmitMesh(b, transform.GetTransform()); } } @@ -425,10 +423,34 @@ namespace Nuake { } } - Renderer::Flush(flatShader); + Renderer::Flush(flatShader, true); } } + void Scene::EditorDrawDeferred() + { + glEnable(GL_DEPTH_TEST); + + Ref gBufferShader = ShaderManager::GetShader("resources/Shaders/gbuffer.shader"); + gBufferShader->Bind(); + gBufferShader->SetUniformMat4f("u_Projection", m_EditorCamera->GetPerspective()); + gBufferShader->SetUniformMat4f("u_View", m_EditorCamera->GetTransform()); + + auto quakeView = m_Registry.view(); + for (auto e : quakeView) + { + auto [transform, model, parent] = quakeView.get(e); + + if (model.IsTransparent) + continue; + + for (auto& b : model.Meshes) + Renderer::SubmitMesh(b, transform.GetTransform()); + } + + Renderer::Flush(gBufferShader, false); + } + std::vector Scene::GetAllEntities() { std::vector allEntities; @@ -461,7 +483,8 @@ namespace Nuake { { std::vector allEntities; auto view = m_Registry.view(); - for (auto e : view) { + for (auto e : view) + { auto [transform, namec] = view.get(e); if (namec.Name == name) return Entity{ e, this }; @@ -489,11 +512,14 @@ namespace Nuake { { ParentComponent& parentC = entity.GetComponent(); std::vector copyChildrens = parentC.Children; + if (parentC.HasParent) { // Remove self from parents children lists. ParentComponent& parent = parentC.Parent.GetComponent(); parent.RemoveChildren(entity); } - for (auto& c : copyChildrens) { + + for (auto& c : copyChildrens) + { Logger::Log("Deleting... entity" + std::to_string(c.GetHandle())); DestroyEntity(c); } @@ -517,6 +543,7 @@ namespace Nuake { break; } } + if (!cam) cam = m_EditorCamera; return cam; diff --git a/Nuake/src/Scene/Scene.h b/Nuake/src/Scene/Scene.h index 06640040..8b5b9f9e 100644 --- a/Nuake/src/Scene/Scene.h +++ b/Nuake/src/Scene/Scene.h @@ -57,6 +57,7 @@ namespace Nuake { void DrawShadows(); void DrawInterface(Vector2 screensize); void Draw(); + void EditorDrawDeferred(); void EditorDraw(); std::vector GetAllEntities(); diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index c6e789e9..20325d9b 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -78,6 +78,11 @@ namespace Nuake { return m_Framebuffer; } + Ref Window::GetGBuffer() const + { + return m_GBuffer; + } + Vector2 Window::GetSize() { int w, h = 0; @@ -135,6 +140,12 @@ namespace Nuake { m_Framebuffer = CreateRef(true, glm::vec2(1920, 1080)); m_Framebuffer->SetTexture(CreateRef(glm::vec2(1920, 1080), GL_RGB)); + m_GBuffer = CreateRef(false, Vector2(1920, 1080)); + m_GBuffer->SetTexture(CreateRef(Vector2(1920, 1080), GL_DEPTH_COMPONENT), GL_DEPTH_ATTACHMENT); + m_GBuffer->SetTexture(CreateRef(Vector2(1920, 1080), GL_RGB), GL_COLOR_ATTACHMENT0); + m_GBuffer->SetTexture(CreateRef(Vector2(1920, 1080), GL_RGB), GL_COLOR_ATTACHMENT1); + m_GBuffer->SetTexture(CreateRef(Vector2(1920, 1080), GL_RGB), GL_COLOR_ATTACHMENT2); + // Temporary quad vbo for deferred. glGenVertexArrays(1, &vao); glBindVertexArray(vao); @@ -258,6 +269,15 @@ namespace Nuake { } m_Framebuffer->Unbind(); + m_GBuffer->Bind(); + m_GBuffer->Clear(); + { + m_Scene->EditorDrawDeferred(); + } + + m_GBuffer->Unbind(); + + Renderer::EndDraw(); } diff --git a/Nuake/src/Window.h b/Nuake/src/Window.h index 2756bc7f..f834bae2 100644 --- a/Nuake/src/Window.h +++ b/Nuake/src/Window.h @@ -19,6 +19,7 @@ namespace Nuake GLFWwindow* m_Window; Ref m_Framebuffer; + Ref m_GBuffer; Ref m_Scene; Vector2 m_FramebufferOffset; @@ -39,6 +40,7 @@ namespace Nuake void EndDraw(); Ref GetFrameBuffer() const; + Ref GetGBuffer() const; Vector2 GetSize();