Added GBuffer

This commit is contained in:
antopilo
2021-08-31 23:27:19 -04:00
parent 1b916993e0
commit 54a138c044
19 changed files with 178 additions and 591 deletions

View File

@@ -1,62 +0,0 @@
{
"Entities": [
{
"GetComponent<NameComponent>()": {
"Name": "Camera"
},
"GetComponent<ParentComponent>()": {
"HasParent": false,
"Type": "ParentComponent"
},
"GetComponent<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": 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
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -131,17 +131,42 @@ namespace Nuake {
if (m_IsEntitySelected)
{
//if (ImGui::Begin("CSM"))
//{
// if (m_SelectedEntity.HasComponent<LightComponent>())
// {
// ImVec2 regionAvail = ImGui::GetContentRegionAvail();
// glm::vec2 viewportPanelSize = glm::vec2(regionAvail.x, regionAvail.y);
// Ref<Texture> texture = m_SelectedEntity.GetComponent<LightComponent>().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> 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> 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> 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> 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"))
//{

View File

@@ -45,13 +45,13 @@ namespace Nuake
// Surely, this can be optimized.
int size = 0;
std::vector<unsigned int> keys = std::vector<unsigned int>();
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)

View File

@@ -55,10 +55,10 @@ namespace Nuake
m_VertexArray->Unbind();
}
void Mesh::Draw(bool drawMaterial)
void Mesh::Draw(Ref<Shader> 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);
}

View File

@@ -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<Vertex> vertices, std::vector<unsigned int> indices, Ref<Material> material);
void Draw(bool bindMaterial = true);
void Draw(Ref<Shader> shader, bool bindMaterial = true);
void DebugDraw();
inline AABB GetAABB() const { return m_AABB; }

View File

@@ -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);
}
}

View File

@@ -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);

View File

@@ -84,7 +84,7 @@ namespace Nuake
Material::~Material() {}
void Material::Bind()
void Material::Bind(Ref<Shader> 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)

View File

@@ -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> shader);
void SetupUniformBuffer();

View File

@@ -5,12 +5,6 @@
#include <src/Rendering/Textures/MaterialManager.h>
namespace Nuake {
void MeshComponent::Draw()
{
for (auto m : meshes)
m->Draw();
}
void MeshComponent::LoadModel()
{
this->meshes.clear();

View File

@@ -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)

View File

@@ -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<TransformComponent, MeshComponent, ParentComponent>();
for (auto e : view)
for (auto e : view)
{
auto [transform, model, parent] = view.get<TransformComponent, MeshComponent, ParentComponent>(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<TransformComponent, BSPBrushComponent, ParentComponent>();
for (auto e : quakeView)
for (auto e : quakeView)
{
auto [transform, model, parent] = quakeView.get<TransformComponent, BSPBrushComponent, ParentComponent>(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<Shader> 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<TransformComponent, BSPBrushComponent, ParentComponent>();
for (auto e : quakeView)
{
auto [transform, model, parent] = quakeView.get<TransformComponent, BSPBrushComponent, ParentComponent>(e);
if (model.IsTransparent)
continue;
for (auto& b : model.Meshes)
Renderer::SubmitMesh(b, transform.GetTransform());
}
Renderer::Flush(gBufferShader, false);
}
std::vector<Entity> Scene::GetAllEntities()
{
std::vector<Entity> allEntities;
@@ -461,7 +483,8 @@ namespace Nuake {
{
std::vector<Entity> allEntities;
auto view = m_Registry.view<TransformComponent, NameComponent>();
for (auto e : view) {
for (auto e : view)
{
auto [transform, namec] = view.get<TransformComponent, NameComponent>(e);
if (namec.Name == name)
return Entity{ e, this };
@@ -489,11 +512,14 @@ namespace Nuake {
{
ParentComponent& parentC = entity.GetComponent<ParentComponent>();
std::vector<Entity> copyChildrens = parentC.Children;
if (parentC.HasParent) { // Remove self from parents children lists.
ParentComponent& parent = parentC.Parent.GetComponent<ParentComponent>();
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;

View File

@@ -57,6 +57,7 @@ namespace Nuake {
void DrawShadows();
void DrawInterface(Vector2 screensize);
void Draw();
void EditorDrawDeferred();
void EditorDraw();
std::vector<Entity> GetAllEntities();

View File

@@ -78,6 +78,11 @@ namespace Nuake {
return m_Framebuffer;
}
Ref<FrameBuffer> Window::GetGBuffer() const
{
return m_GBuffer;
}
Vector2 Window::GetSize()
{
int w, h = 0;
@@ -135,6 +140,12 @@ namespace Nuake {
m_Framebuffer = CreateRef<FrameBuffer>(true, glm::vec2(1920, 1080));
m_Framebuffer->SetTexture(CreateRef<Texture>(glm::vec2(1920, 1080), GL_RGB));
m_GBuffer = CreateRef<FrameBuffer>(false, Vector2(1920, 1080));
m_GBuffer->SetTexture(CreateRef<Texture>(Vector2(1920, 1080), GL_DEPTH_COMPONENT), GL_DEPTH_ATTACHMENT);
m_GBuffer->SetTexture(CreateRef<Texture>(Vector2(1920, 1080), GL_RGB), GL_COLOR_ATTACHMENT0);
m_GBuffer->SetTexture(CreateRef<Texture>(Vector2(1920, 1080), GL_RGB), GL_COLOR_ATTACHMENT1);
m_GBuffer->SetTexture(CreateRef<Texture>(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();
}

View File

@@ -19,6 +19,7 @@ namespace Nuake
GLFWwindow* m_Window;
Ref<FrameBuffer> m_Framebuffer;
Ref<FrameBuffer> m_GBuffer;
Ref<Scene> m_Scene;
Vector2 m_FramebufferOffset;
@@ -39,6 +40,7 @@ namespace Nuake
void EndDraw();
Ref<FrameBuffer> GetFrameBuffer() const;
Ref<FrameBuffer> GetGBuffer() const;
Vector2 GetSize();