add scene render system, add proper HDR environments, try load texture from mesh file

This commit is contained in:
2025-11-30 20:12:57 +08:00
parent 4cdd405ba9
commit 0d4024be39
62 changed files with 2302 additions and 1037 deletions

View File

@ -3,9 +3,7 @@
//
#include "EditorLayer.h"
#include "ImGuizmo.h"
#include "Prism/Core/KeyCodes.h"
namespace Prism
{
@ -19,7 +17,6 @@ namespace Prism
ImGui::Text(name.c_str());
ImGui::NextColumn();
ImGui::PushItemWidth(-1);
std::string id = "##" + name;
ImGui::Checkbox(id.c_str(), &value);
@ -88,6 +85,25 @@ namespace Prism
}
void Property(const std::string& name, glm::vec2& value, float min, float max, PropertyFlag flags)
{
ImGui::Text(name.c_str());
ImGui::NextColumn();
ImGui::PushItemWidth(-1);
std::string id = "##" + name;
ImGui::SliderFloat2(id.c_str(), glm::value_ptr(value), min, max);
ImGui::PopItemWidth();
ImGui::NextColumn();
}
void Property(const std::string& name, glm::vec2& value, PropertyFlag flags)
{
Property(name, value, -1.0f, 1.0f, flags);
}
static void ImGuiShowHelpMarker(const char* desc)
{
ImGui::TextDisabled("(?)");
@ -102,8 +118,7 @@ namespace Prism
}
EditorLayer::EditorLayer()
: m_ClearColor{0.1f, 0.1f, 0.1f, 1.0f}, m_Scene(Scene::Model),
m_Camera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 10000.0f))
: m_SceneType(SceneType::Model)
{
}
@ -113,114 +128,83 @@ namespace Prism
void EditorLayer::OnAttach()
{
// RenderPass
FramebufferSpecification geoFramebufferSpec;
geoFramebufferSpec.Width = 1280;
geoFramebufferSpec.Height = 720;
geoFramebufferSpec.Format = FramebufferFormat::RGBA16F;
geoFramebufferSpec.ClearColor = { 0.1f, 0.1f, 0.1f, 1.0f };
auto environment = Environment::Load("assets/env/birchwood_4k.hdr");
RenderPassSpecification geoRenderPassSpec;
geoRenderPassSpec.TargetFramebuffer = FrameBuffer::Create(geoFramebufferSpec);
m_GeoPass = RenderPass::Create(geoRenderPassSpec);
// Model Scene
{
m_Scene = CreateRef<Scene>("Model Scene");
m_Scene->SetCamera(Camera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 10000.0f)));
m_Scene->SetEnvironment(environment);
FramebufferSpecification compFramebufferSpec;
compFramebufferSpec.Width = 1280;
compFramebufferSpec.Height = 720;
compFramebufferSpec.Format = FramebufferFormat::RGBA8;
compFramebufferSpec.ClearColor = { 0.1f, 0.1f, 0.1f, 1.0f };
m_MeshEntity = m_Scene->CreateEntity();
RenderPassSpecification compRenderPassSpec;
compRenderPassSpec.TargetFramebuffer = FrameBuffer::Create(compFramebufferSpec);
m_CompositePass = RenderPass::Create(compRenderPassSpec);
const auto mesh = CreateRef<Mesh>("assets/models/m1911/m1911.fbx");
//auto mesh = CreateRef<Mesh>("assets/meshes/cerberus/CerberusMaterials.fbx");
// auto mesh = CreateRef<Mesh>("assets/models/m1911/M1911Materials.fbx");
m_MeshEntity->SetMesh(mesh);
/*
m_Framebuffer.reset(FrameBuffer::Create(1280, 720, FramebufferFormat::RGBA16F));
m_FinalPresentBuffer.reset(FrameBuffer::Create(1280, 720, FramebufferFormat::RGBA8));
*/
m_MeshMaterial = mesh->GetMaterial();
}
m_QuadShader = Shader::Create("assets/shaders/quad.glsl");
m_HDRShader = Shader::Create("assets/shaders/hdr.glsl");
// Sphere Scene
{
m_SphereScene = CreateRef<Scene>("PBR Sphere Scene");
m_SphereScene->SetCamera(Camera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 10000.0f)));
m_Mesh = CreateRef<Mesh>("assets/models/m1911/m1911.fbx");
m_MeshMaterial = CreateRef<MaterialInstance>(m_Mesh->GetMaterial());
m_SphereScene->SetEnvironment(environment);
m_SphereMesh = CreateRef<Mesh>("assets/models/Sphere1m.fbx");
m_PlaneMesh = CreateRef<Mesh>("assets/models/Plane1m.fbx");
auto sphereMesh = CreateRef<Mesh>("assets/models/Sphere1m.fbx");
m_SphereBaseMaterial = sphereMesh->GetMaterial();
m_GridShader = Shader::Create("assets/shaders/Grid.glsl");
m_GridMaterial = MaterialInstance::Create(Material::Create(m_GridShader));
m_GridMaterial->Set("u_Scale", m_GridScale);
m_GridMaterial->Set("u_Res", m_GridSize);
float x = -4.0f;
float roughness = 0.0f;
for (int i = 0; i < 8; i++)
{
auto sphereEntity = m_SphereScene->CreateEntity();
Ref<MaterialInstance> mi = CreateRef<MaterialInstance>(m_SphereBaseMaterial);
mi->Set("u_Metalness", 1.0f);
mi->Set("u_Roughness", roughness);
x += 1.1f;
roughness += 0.15f;
m_MetalSphereMaterialInstances.push_back(mi);
sphereEntity->SetMesh(sphereMesh);
sphereEntity->SetMaterial(mi);
sphereEntity->Transform() = glm::translate(glm::mat4(1.0f), glm::vec3(x, 0.0f, 0.0f));
}
x = -4.0f;
roughness = 0.0f;
for (int i = 0; i < 8; i++)
{
auto sphereEntity = m_SphereScene->CreateEntity();
Ref<MaterialInstance> mi(new MaterialInstance(m_SphereBaseMaterial));
mi->Set("u_Metalness", 0.0f);
mi->Set("u_Roughness", roughness);
x += 1.1f;
roughness += 0.15f;
m_DielectricSphereMaterialInstances.push_back(mi);
sphereEntity->SetMesh(sphereMesh);
sphereEntity->SetMaterial(mi);
sphereEntity->Transform() = glm::translate(glm::mat4(1.0f), glm::vec3(x, 1.2f, 0.0f));
}
}
m_ActiveScene = m_Scene;
m_SceneHierarchyPanel = CreateScope<SceneHierarchyPanel>(m_ActiveScene);
m_PlaneMesh.reset(new Mesh("assets/models/Plane1m.obj"));
// Editor
m_CheckerboardTex.reset(Texture2D::Create("assets/editor/Checkerboard.tga"));
// Environment
m_EnvironmentCubeMap.reset(
TextureCube::Create("assets/textures/environments/Arches_E_PineTree_Radiance.tga"));
m_EnvironmentIrradiance.reset(
TextureCube::Create("assets/textures/environments/Arches_E_PineTree_Irradiance.tga"));
m_BRDFLUT.reset(Texture2D::Create("assets/textures/BRDF_LUT.tga"));
float x = -4.0f;
float roughness = 0.0f;
for (int i = 0; i < 8; i++)
{
Ref<MaterialInstance> mi = CreateRef<MaterialInstance>(
m_SphereMesh->GetMaterial());
mi->Set("u_Metalness", 1.0f);
mi->Set("u_Roughness", roughness);
mi->Set("u_ModelMatrix", glm::translate(glm::mat4(1.0f), glm::vec3(x, 0.0f, 0.0f)));
x += 1.1f;
roughness += 0.125f;
m_MetalSphereMaterialInstances.push_back(mi);
}
x = -4.0f;
roughness = 0.0f;
for (int i = 0; i < 8; i++)
{
Ref<MaterialInstance> mi = CreateRef<MaterialInstance>(
m_SphereMesh->GetMaterial());
mi->Set("u_Metalness", 0.0f);
mi->Set("u_Roughness", roughness);
mi->Set("u_ModelMatrix", translate(glm::mat4(1.0f), glm::vec3(x, 1.2f, 0.0f)));
x += 1.1f;
roughness += 0.125f;
m_DielectricSphereMaterialInstances.push_back(mi);
}
// Create Quad
static float QuadVertex[] = {
-1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-1.0f, 1.0f, 0.0f, 0.0f, 1.0f
};
static uint32_t QuadIndices[] = {
0, 1, 2, 2, 3, 0
};
m_FullscreenQuadVertexArray = VertexArray::Create();
auto quadVB = VertexBuffer::Create(QuadVertex, sizeof(float) * sizeof(QuadVertex));
quadVB->SetLayout({
{ ShaderDataType::Float3, "a_Position" },
{ ShaderDataType::Float2, "a_TexCoord" }
});
auto quadIB = IndexBuffer::Create(QuadIndices, sizeof(QuadIndices) * sizeof(uint32_t));
m_FullscreenQuadVertexArray->AddVertexBuffer(quadVB);
m_FullscreenQuadVertexArray->SetIndexBuffer(quadIB);
m_CheckerboardTex = Texture2D::Create("assets/editor/Checkerboard.tga");
// lights
m_Light.Direction = {-0.5f, -0.5f, 1.0f};
m_Light.Radiance = {1.0f, 1.0f, 1.0f};
m_Transform = glm::scale(glm::mat4(1.0f), glm::vec3(m_MeshScale));
}
void EditorLayer::OnDetach()
@ -232,62 +216,28 @@ namespace Prism
{
// THINGS TO LOOK AT:
// - BRDF LUT
// - Cubemap mips and filtering
// - Tonemapping and proper HDR pipeline
using namespace Prism;
using namespace glm;
m_Camera.Update(deltaTime);
auto viewProjection = m_Camera.GetProjectionMatrix() * m_Camera.GetViewMatrix();
// m_Framebuffer->Bind();
Renderer::BeginRenderPass(m_GeoPass);
Renderer::Clear(m_ClearColor[0], m_ClearColor[1], m_ClearColor[2], m_ClearColor[3]);
m_QuadShader->Bind();
m_QuadShader->SetMat4("u_InverseVP", inverse(viewProjection));
m_EnvironmentCubeMap->Bind(0);
/*
m_VertexBuffer->Bind();
m_IndexBuffer->Bind();
*/
m_FullscreenQuadVertexArray->Bind();
Renderer::DrawIndexed(m_FullscreenQuadVertexArray->GetIndexBuffer()->GetCount(), false);
m_MeshMaterial->Set("u_AlbedoColor", m_AlbedoInput.Color);
m_MeshMaterial->Set("u_Metalness", m_MetalnessInput.Value);
m_MeshMaterial->Set("u_Roughness", m_RoughnessInput.Value);
m_MeshMaterial->Set("u_ViewProjectionMatrix", viewProjection);
m_MeshMaterial->Set("u_ModelMatrix", scale(mat4(1.0f), vec3(m_MeshScale)));
m_MeshMaterial->Set("lights", m_Light);
m_MeshMaterial->Set("u_CameraPosition", m_Camera.GetPosition());
m_MeshMaterial->Set("u_RadiancePrefilter", m_RadiancePrefilter ? 1.0f : 0.0f);
m_MeshMaterial->Set("u_AlbedoTexToggle", m_AlbedoInput.UseTexture ? 1.0f : 0.0f);
m_MeshMaterial->Set("u_NormalTexToggle", m_NormalInput.UseTexture ? 1.0f : 0.0f);
m_MeshMaterial->Set("u_MetalnessTexToggle", m_MetalnessInput.UseTexture ? 1.0f : 0.0f);
m_MeshMaterial->Set("u_RoughnessTexToggle", m_RoughnessInput.UseTexture ? 1.0f : 0.0f);
m_MeshMaterial->Set("u_EnvMapRotation", m_EnvMapRotation);
m_MeshMaterial->Set("u_EnvRadianceTex", m_EnvironmentCubeMap);
m_MeshMaterial->Set("u_EnvIrradianceTex", m_EnvironmentIrradiance);
m_MeshMaterial->Set("u_BRDFLUTTexture", m_BRDFLUT);
m_SphereMesh->GetMaterial()->Set("u_AlbedoColor", m_AlbedoInput.Color);
m_SphereMesh->GetMaterial()->Set("u_Metalness", m_MetalnessInput.Value);
m_SphereMesh->GetMaterial()->Set("u_Roughness", m_RoughnessInput.Value);
m_SphereMesh->GetMaterial()->Set("u_ViewProjectionMatrix", viewProjection);
m_SphereMesh->GetMaterial()->Set("u_ModelMatrix", scale(mat4(1.0f), vec3(m_MeshScale)));
m_SphereMesh->GetMaterial()->Set("lights", m_Light);
m_SphereMesh->GetMaterial()->Set("u_CameraPosition", m_Camera.GetPosition());
m_SphereMesh->GetMaterial()->Set("u_RadiancePrefilter", m_RadiancePrefilter ? 1.0f : 0.0f);
m_SphereMesh->GetMaterial()->Set("u_AlbedoTexToggle", m_AlbedoInput.UseTexture ? 1.0f : 0.0f);
m_SphereMesh->GetMaterial()->Set("u_NormalTexToggle", m_NormalInput.UseTexture ? 1.0f : 0.0f);
m_SphereMesh->GetMaterial()->Set("u_MetalnessTexToggle", m_MetalnessInput.UseTexture ? 1.0f : 0.0f);
m_SphereMesh->GetMaterial()->Set("u_RoughnessTexToggle", m_RoughnessInput.UseTexture ? 1.0f : 0.0f);
m_SphereMesh->GetMaterial()->Set("u_EnvMapRotation", m_EnvMapRotation);
m_SphereMesh->GetMaterial()->Set("u_EnvRadianceTex", m_EnvironmentCubeMap);
m_SphereMesh->GetMaterial()->Set("u_EnvIrradianceTex", m_EnvironmentIrradiance);
m_SphereMesh->GetMaterial()->Set("u_BRDFLUTTexture", m_BRDFLUT);
m_SphereBaseMaterial->Set("u_AlbedoColor", m_AlbedoInput.Color);
m_SphereBaseMaterial->Set("lights", m_Light);
m_SphereBaseMaterial->Set("u_RadiancePrefilter", m_RadiancePrefilter ? 1.0f : 0.0f);
m_SphereBaseMaterial->Set("u_AlbedoTexToggle", m_AlbedoInput.UseTexture ? 1.0f : 0.0f);
m_SphereBaseMaterial->Set("u_NormalTexToggle", m_NormalInput.UseTexture ? 1.0f : 0.0f);
m_SphereBaseMaterial->Set("u_MetalnessTexToggle", m_MetalnessInput.UseTexture ? 1.0f : 0.0f);
m_SphereBaseMaterial->Set("u_RoughnessTexToggle", m_RoughnessInput.UseTexture ? 1.0f : 0.0f);
m_SphereBaseMaterial->Set("u_EnvMapRotation", m_EnvMapRotation);
if (m_AlbedoInput.TextureMap)
@ -299,56 +249,7 @@ namespace Prism
if (m_RoughnessInput.TextureMap)
m_MeshMaterial->Set("u_RoughnessTexture", m_RoughnessInput.TextureMap);
if (m_Scene == Scene::Spheres)
{
// Metals
for (int i = 0; i < 8; i++)
{
m_SphereMesh->Render(deltaTime, glm::mat4(1.0f), m_MetalSphereMaterialInstances[i]);
/*
m_MetalSphereMaterialInstances[i]->Bind();
m_SphereMesh->Render(deltaTime, m_SimplePBRShader.get());
*/
}
// Dielectrics
for (int i = 0; i < 8; i++)
{
m_SphereMesh->Render(deltaTime, glm::mat4(1.0f), m_DielectricSphereMaterialInstances[i]);
/*
m_DielectricSphereMaterialInstances[i]->Bind();
m_SphereMesh->Render(deltaTime, m_SimplePBRShader.get());
*/
}
}
else if (m_Scene == Scene::Model)
{
if (m_Mesh)
{
m_Mesh->Render(deltaTime, m_Transform, m_MeshMaterial);
}
}
m_GridMaterial->Set("u_MVP", viewProjection * glm::scale(glm::mat4(1.0f), glm::vec3(16.0f)));
m_PlaneMesh->Render(deltaTime, m_GridMaterial);
// m_Framebuffer->Unbind();
Renderer::EndRenderPass();
Renderer::BeginRenderPass(m_CompositePass);
// m_FinalPresentBuffer->Bind();
m_HDRShader->Bind();
m_HDRShader->SetFloat("u_Exposure", m_Exposure);
// m_Framebuffer->BindTexture();
m_GeoPass->GetSpecification().TargetFramebuffer->BindTexture();
/*
m_VertexBuffer->Bind();
m_IndexBuffer->Bind();
*/
m_FullscreenQuadVertexArray->Bind();
Renderer::DrawIndexed(m_FullscreenQuadVertexArray->GetIndexBuffer()->GetCount(), false);
// m_FinalPresentBuffer->Unbind();
Renderer::EndRenderPass();
m_ActiveScene->OnUpdate(deltaTime);
}
}
@ -493,25 +394,39 @@ namespace Prism
ImGui::EndMenuBar();
}
m_SceneHierarchyPanel->OnImGuiRender();
ImGui::End();
#endif
// Editor Panel ------------------------------------------------------------------------------
ImGui::Begin("Model");
ImGui::RadioButton("Spheres", (int*)&m_Scene, (int)Scene::Spheres);
if (ImGui::RadioButton("Spheres", (int*)&m_SceneType, (int)SceneType::Spheres))
m_ActiveScene = m_SphereScene;
ImGui::SameLine();
ImGui::RadioButton("Model", (int*)&m_Scene, (int)Scene::Model);
if (ImGui::RadioButton("Model", (int*)&m_SceneType, (int)SceneType::Model))
m_ActiveScene = m_Scene;
ImGui::Begin("Environment");
if (ImGui::Button("Load Environment Map"))
{
std::string filename = Application::Get().OpenFile("*.hdr");
if (!filename.empty())
m_ActiveScene->SetEnvironment(Environment::Load(filename));
}
ImGui::SliderFloat("Skybox LOD", &m_Scene->GetSkyboxLod(), 0.0f, 11.0f);
ImGui::Columns(2);
ImGui::AlignTextToFramePadding();
Property("Light Direction", m_Light.Direction);
Property("Light Radiance", m_Light.Radiance, PropertyFlag::ColorProperty);
Property("Light Multiplier", m_LightMultiplier, 0.0f, 5.0f);
Property("Exposure", m_Exposure, 0.0f, 5.0f);
Property("Exposure", m_ActiveScene->GetCamera().GetExposure(), 0.0f, 5.0f);
Property("Radiance Prefiltering", m_RadiancePrefilter);
Property("Env Map Rotation", m_EnvMapRotation, -360.0f, 360.0f);
@ -523,16 +438,22 @@ namespace Prism
ImGui::Separator();
{
ImGui::Text("Mesh");
std::string fullpath = m_Mesh ? m_Mesh->GetFilePath() : "None";
size_t found = fullpath.find_last_of("/\\");
std::string path = found != std::string::npos ? fullpath.substr(found + 1) : fullpath;
auto mesh = m_MeshEntity->GetMesh();
std::string fullpath = mesh ? mesh->GetFilePath() : "None";
size_t found = fullpath.find_last_of("/\\");
std::string path = found != std::string::npos ? fullpath.substr(found + 1) : fullpath;
ImGui::Text(path.c_str());
ImGui::SameLine();
if (ImGui::Button("...##Mesh"))
{
std::string filename = Application::Get().OpenFile("");
if (filename != "")
m_Mesh.reset(new Mesh(filename));
if (!filename.empty())
{
auto newMesh = CreateRef<Mesh>(filename);
// m_MeshMaterial.reset(new MaterialInstance(newMesh->GetMaterial()));
// m_MeshEntity->SetMaterial(m_MeshMaterial);
m_MeshEntity->SetMesh(newMesh);
}
}
}
ImGui::Separator();
@ -561,8 +482,8 @@ namespace Prism
if (ImGui::IsItemClicked())
{
std::string filename = Application::Get().OpenFile("");
if (filename != "")
m_AlbedoInput.TextureMap.reset(Texture2D::Create(filename, m_AlbedoInput.SRGB));
if (!filename.empty())
m_AlbedoInput.TextureMap = Texture2D::Create(filename, m_AlbedoInput.SRGB);
}
}
ImGui::SameLine();
@ -571,8 +492,7 @@ namespace Prism
if (ImGui::Checkbox("sRGB##AlbedoMap", &m_AlbedoInput.SRGB))
{
if (m_AlbedoInput.TextureMap)
m_AlbedoInput.TextureMap.reset(
Texture2D::Create(m_AlbedoInput.TextureMap->GetPath(), m_AlbedoInput.SRGB));
m_AlbedoInput.TextureMap = Texture2D::Create(m_AlbedoInput.TextureMap->GetPath(), m_AlbedoInput.SRGB);
}
ImGui::EndGroup();
ImGui::SameLine();
@ -602,8 +522,8 @@ namespace Prism
if (ImGui::IsItemClicked())
{
std::string filename = Application::Get().OpenFile("");
if (filename != "")
m_NormalInput.TextureMap.reset(Texture2D::Create(filename));
if (!filename.empty())
m_NormalInput.TextureMap = Texture2D::Create(filename);
}
}
ImGui::SameLine();
@ -633,8 +553,8 @@ namespace Prism
if (ImGui::IsItemClicked())
{
std::string filename = Application::Get().OpenFile("");
if (filename != "")
m_MetalnessInput.TextureMap.reset(Texture2D::Create(filename));
if (!filename.empty())
m_MetalnessInput.TextureMap = Texture2D::Create(filename);
}
}
ImGui::SameLine();
@ -666,8 +586,8 @@ namespace Prism
if (ImGui::IsItemClicked())
{
std::string filename = Application::Get().OpenFile("");
if (filename != "")
m_RoughnessInput.TextureMap.reset(Texture2D::Create(filename));
if (!filename.empty())
m_RoughnessInput.TextureMap = Texture2D::Create(filename);
}
}
ImGui::SameLine();
@ -701,42 +621,25 @@ namespace Prism
ImGui::Begin("Viewport");
auto viewportSize = ImGui::GetContentRegionAvail();
m_GeoPass->GetSpecification().TargetFramebuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
m_CompositePass->GetSpecification().TargetFramebuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
// m_Framebuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
// m_FinalPresentBuffer->Resize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
m_Camera.SetProjectionMatrix(glm::perspectiveFov(glm::radians(45.0f), viewportSize.x, viewportSize.y, 0.1f, 10000.0f));
// ImGui::Image((ImTextureRef)m_FinalPresentBuffer->GetColorAttachmentRendererID(), viewportSize, {0, 1}, {1, 0});
ImGui::Image((ImTextureRef)m_CompositePass->GetSpecification().TargetFramebuffer->GetColorAttachmentRendererID(), viewportSize, { 0, 1 }, { 1, 0 });
SceneRenderer::SetViewportSize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
m_ActiveScene->GetCamera().SetProjectionMatrix(glm::perspectiveFov(glm::radians(45.0f), viewportSize.x, viewportSize.y, 0.1f, 10000.0f));
m_ActiveScene->GetCamera().SetViewportSize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
ImGui::Image((ImTextureRef)SceneRenderer::GetFinalColorBufferRendererID(), viewportSize, { 0, 1 }, { 1, 0 });
// ImGuizmo
if (m_GizmoType != -1)
{
const float rw = (float)ImGui::GetWindowWidth();
const float rh = (float)ImGui::GetWindowHeight();
const auto rw = (float)ImGui::GetWindowWidth();
const auto rh = (float)ImGui::GetWindowHeight();
ImGuizmo::SetOrthographic(false);
ImGuizmo::SetDrawlist();
ImGuizmo::SetRect(ImGui::GetWindowPos().x, ImGui::GetWindowPos().y, rw, rh);
ImGuizmo::Manipulate(glm::value_ptr(m_Camera.GetViewMatrix()), glm::value_ptr(m_Camera.GetProjectionMatrix()), (ImGuizmo::OPERATION)m_GizmoType, ImGuizmo::LOCAL, glm::value_ptr(m_Transform));
const auto& camera = m_ActiveScene->GetCamera();
ImGuizmo::Manipulate(glm::value_ptr(camera.GetViewMatrix()), glm::value_ptr(camera.GetProjectionMatrix()), (ImGuizmo::OPERATION)m_GizmoType, ImGuizmo::LOCAL, glm::value_ptr(m_MeshEntity->Transform()));
}
ImGui::End();
ImGui::PopStyleVar();
ImGui::Begin("Log");
const auto& cameraPos = m_Camera.GetPosition();
ImGui::Text("cameraPos: (%.2f, %.2f, %.2f)", cameraPos.x, cameraPos.y, cameraPos.z);
const auto& Direct = m_Camera.GetForwardDirection();
ImGui::Text("forward Vec: (%.2f, %.2f, %.2f)", Direct.x, Direct.y, Direct.z);
const auto& distance = m_Camera.GetDistance();
ImGui::Text("distance: %.3f", distance);
ImGui::End();
if (m_Mesh)
m_Mesh->OnImGuiRender();
}

View File

@ -6,120 +6,110 @@
#define EDITORLAYER_H
#include "Prism.h"
#include "Prism/Editor/SceneHierachyPanel.h"
namespace Prism
{
class EditorLayer : public Layer
{
public:
EditorLayer();
virtual ~EditorLayer();
virtual void OnAttach() override;
virtual void OnDetach() override;
virtual void OnUpdate(TimeStep deltaTime) override;
virtual void OnImGuiRender() override;
virtual void OnEvent(Event& e) override;
private:
bool OnKeyPressedEvent(KeyPressedEvent& e);
private:
float m_ClearColor[4];
// Ref<FrameBuffer> m_Framebuffer, m_FinalPresentBuffer;
Ref<RenderPass> m_GeoPass, m_CompositePass;
/*
Ref<VertexBuffer> m_VertexBuffer;
Ref<IndexBuffer> m_IndexBuffer;
*/
Ref<VertexArray> m_FullscreenQuadVertexArray;
Ref<TextureCube> m_EnvironmentCubeMap, m_EnvironmentIrradiance;
Camera m_Camera;
Ref<Shader> m_QuadShader;
Ref<Shader> m_HDRShader;
Ref<Shader> m_GridShader;
Ref<Mesh> m_Mesh;
Ref<Mesh> m_SphereMesh, m_PlaneMesh;
Ref<Texture2D> m_BRDFLUT;
Ref<MaterialInstance> m_MeshMaterial;
Ref<MaterialInstance> m_GridMaterial;
std::vector<Ref<MaterialInstance>> m_MetalSphereMaterialInstances;
std::vector<Ref<MaterialInstance>> m_DielectricSphereMaterialInstances;
float m_GridScale = 16.025f, m_GridSize = 0.025f;
float m_MeshScale = 1.0f;
Ref<Shader> m_Shader;
Ref<Shader> m_PBRShader;
// Imguizmo
int m_GizmoType = -1; // -1 = no gizmo
glm::mat4 m_Transform;
struct AlbedoInput
class EditorLayer : public Layer
{
glm::vec3 Color = { 0.972f, 0.96f, 0.915f }; // Silver, from https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/PhysicallyBased
Ref<Texture2D> TextureMap;
bool SRGB = true;
bool UseTexture = false;
public:
EditorLayer();
virtual ~EditorLayer();
virtual void OnAttach() override;
virtual void OnDetach() override;
virtual void OnUpdate(TimeStep deltaTime) override;
virtual void OnImGuiRender() override;
virtual void OnEvent(Event& e) override;
private:
bool OnKeyPressedEvent(KeyPressedEvent& e);
private:
Scope<SceneHierarchyPanel> m_SceneHierarchyPanel;
Ref<Scene> m_Scene;
Ref<Scene> m_SphereScene;
Ref<Scene> m_ActiveScene;
Entity* m_MeshEntity = nullptr;
Ref<Shader> m_BrushShader;
Ref<Mesh> m_PlaneMesh;
Ref<Material> m_SphereBaseMaterial;
Ref<Material> m_MeshMaterial;
Ref<RenderPass> m_GeoPass, m_CompositePass;
Ref<MaterialInstance> m_GridMaterial;
std::vector<Ref<MaterialInstance>> m_MetalSphereMaterialInstances;
std::vector<Ref<MaterialInstance>> m_DielectricSphereMaterialInstances;
float m_GridScale = 16.025f, m_GridSize = 0.025f;
float m_MeshScale = 1.0f;
// Imguizmo
int m_GizmoType = -1; // -1 = no gizmo
struct AlbedoInput
{
glm::vec3 Color = { 0.972f, 0.96f, 0.915f }; // Silver, from https://docs.unrealengine.com/en-us/Engine/Rendering/Materials/PhysicallyBased
Ref<Texture2D> TextureMap;
bool SRGB = true;
bool UseTexture = false;
};
AlbedoInput m_AlbedoInput;
struct NormalInput
{
Ref<Texture2D> TextureMap;
bool UseTexture = false;
};
NormalInput m_NormalInput;
struct MetalnessInput
{
float Value = 1.0f;
Ref<Texture2D> TextureMap;
bool UseTexture = false;
};
MetalnessInput m_MetalnessInput;
struct RoughnessInput
{
float Value = 0.5f;
Ref<Texture2D> TextureMap;
bool UseTexture = false;
};
RoughnessInput m_RoughnessInput;
struct Light
{
glm::vec3 Direction;
glm::vec3 Radiance;
};
Light m_Light;
float m_LightMultiplier = 0.3f;
// PBR params
bool m_RadiancePrefilter = false;
float m_EnvMapRotation = 0.0f;
enum class SceneType : uint32_t
{
Spheres = 0, Model = 1
};
SceneType m_SceneType;
// Editor resources
Ref<Texture2D> m_CheckerboardTex;
};
AlbedoInput m_AlbedoInput;
struct NormalInput
{
Ref<Texture2D> TextureMap;
bool UseTexture = false;
};
NormalInput m_NormalInput;
struct MetalnessInput
{
float Value = 1.0f;
Ref<Texture2D> TextureMap;
bool UseTexture = false;
};
MetalnessInput m_MetalnessInput;
struct RoughnessInput
{
float Value = 0.5f;
Ref<Texture2D> TextureMap;
bool UseTexture = false;
};
RoughnessInput m_RoughnessInput;
struct Light
{
glm::vec3 Direction;
glm::vec3 Radiance;
};
Light m_Light;
float m_LightMultiplier = 0.3f;
// PBR params
float m_Exposure = 1.0f;
bool m_RadiancePrefilter = false;
float m_EnvMapRotation = 0.0f;
enum class Scene : uint32_t
{
Spheres = 0, Model = 1
};
Scene m_Scene;
// Editor resources
Ref<Texture2D> m_CheckerboardTex;
};
}