add directional light component and skylight component, add PCSS and hard shadow
This commit is contained in:
@ -161,7 +161,7 @@ namespace Prism
|
||||
}
|
||||
|
||||
EditorLayer::EditorLayer()
|
||||
: m_SceneType(SceneType::Model), m_EditorCamera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 10000.0f))
|
||||
: m_SceneType(SceneType::Model), m_EditorCamera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 1000.0f))
|
||||
{
|
||||
}
|
||||
|
||||
@ -175,12 +175,12 @@ namespace Prism
|
||||
m_CheckerboardTex = Texture2D::Create("assets/editor/Checkerboard.tga");
|
||||
m_PlayButtonTex = Texture2D::Create("assets/editor/PlayButton.png");
|
||||
|
||||
m_EditorScene = Ref<Scene>::Create("untitled Scene", true);
|
||||
ScriptEngine::SetSceneContext(m_EditorScene);
|
||||
m_SceneHierarchyPanel = CreateScope<SceneHierarchyPanel>(m_EditorScene);
|
||||
m_SceneHierarchyPanel->SetSelectionChangedCallback(std::bind(&EditorLayer::SelectEntity, this, std::placeholders::_1));
|
||||
m_SceneHierarchyPanel->SetEntityDeletedCallback(std::bind(&EditorLayer::OnEntityDeleted, this, std::placeholders::_1));
|
||||
UpdateWindowTitle("untitled Scene");
|
||||
|
||||
OpenScene("assets/scenes/FPSDemo.scene");
|
||||
}
|
||||
|
||||
void EditorLayer::OnDetach()
|
||||
@ -190,6 +190,10 @@ namespace Prism
|
||||
|
||||
void EditorLayer::OnUpdate(const TimeStep deltaTime)
|
||||
{
|
||||
auto [x, y] = GetMouseViewportSpace();
|
||||
|
||||
SceneRenderer::SetFocusPoint({ x * 0.5f + 0.5f, y * 0.5f + 0.5f });
|
||||
|
||||
switch (m_SceneState)
|
||||
{
|
||||
case SceneState::Edit:
|
||||
@ -330,9 +334,11 @@ namespace Prism
|
||||
{
|
||||
if (ImGui::BeginMenu("file"))
|
||||
{
|
||||
if (ImGui::MenuItem("New Scene"))
|
||||
if (ImGui::MenuItem("New Scene", "Ctrl+N"))
|
||||
{
|
||||
NewScene();
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Open Scene...", "Ctrl+O"))
|
||||
{
|
||||
OpenScene();
|
||||
@ -390,6 +396,8 @@ namespace Prism
|
||||
|
||||
m_SceneHierarchyPanel->OnImGuiRender();
|
||||
PhysicsSettingsWindow::OnImGuiRender(m_ShowPhysicsSettings);
|
||||
SceneRenderer::OnImGuiRender();
|
||||
// m_EditorCamera.OnImGuiRender();
|
||||
|
||||
ImGui::Begin("Materials");
|
||||
|
||||
@ -475,6 +483,7 @@ namespace Prism
|
||||
}
|
||||
{
|
||||
// Normals
|
||||
|
||||
if (ImGui::CollapsingHeader("Normals", nullptr, ImGuiTreeNodeFlags_DefaultOpen))
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10, 10));
|
||||
@ -606,13 +615,6 @@ namespace Prism
|
||||
ImGui::Begin("Model");
|
||||
ImGui::Begin("Environment");
|
||||
|
||||
if (ImGui::Button("Load Environment Map"))
|
||||
{
|
||||
std::string filename = Application::Get().OpenFile("*.hdr");
|
||||
if (!filename.empty())
|
||||
m_EditorScene->SetEnvironment(Environment::Load(filename));
|
||||
}
|
||||
|
||||
ImGui::SliderFloat("Skybox LOD", &m_EditorScene->GetSkyboxLod(), 0.0f, 11.0f);
|
||||
|
||||
|
||||
@ -623,7 +625,6 @@ namespace Prism
|
||||
Property("Light Direction", light.Direction, PropertyFlag::SliderProperty);
|
||||
Property("Light Radiance", light.Radiance, PropertyFlag::ColorProperty);
|
||||
Property("Light Multiplier", light.Multiplier, 0.0f, 5.0f, PropertyFlag::SliderProperty);
|
||||
Property("Exposure", m_EditorCamera.GetExposure(), 0.0f, 5.0f, PropertyFlag::SliderProperty);
|
||||
|
||||
Property("Radiance Prefiltering", m_RadiancePrefilter);
|
||||
Property("Env Map Rotation", m_EnvMapRotation, -360.0f, 360.0f, PropertyFlag::SliderProperty);
|
||||
@ -758,7 +759,7 @@ namespace Prism
|
||||
m_EditorScene->SetViewportSize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
||||
if (m_RuntimeScene)
|
||||
m_RuntimeScene->SetViewportSize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
||||
m_EditorCamera.SetProjectionMatrix(glm::perspectiveFov(glm::radians(45.0f), viewportSize.x, viewportSize.y, 0.1f, 10000.0f));
|
||||
m_EditorCamera.SetProjectionMatrix(glm::perspectiveFov(glm::radians(45.0f), viewportSize.x, viewportSize.y, 0.1f, 1000.0f));
|
||||
m_EditorCamera.SetViewportSize((uint32_t)viewportSize.x, (uint32_t)viewportSize.y);
|
||||
ImGui::Image((ImTextureRef)SceneRenderer::GetFinalColorBufferRendererID(), viewportSize, { 0, 1 }, { 1, 0 });
|
||||
|
||||
@ -846,7 +847,7 @@ namespace Prism
|
||||
|
||||
bool EditorLayer::OnKeyPressedEvent(KeyPressedEvent& e)
|
||||
{
|
||||
if (m_ViewportPanelFocused)
|
||||
if (m_ViewportPanelHovered)
|
||||
{
|
||||
switch (e.GetKeyCode())
|
||||
{
|
||||
@ -862,19 +863,23 @@ namespace Prism
|
||||
case KeyCode::R:
|
||||
m_GizmoType = ImGuizmo::OPERATION::SCALE;
|
||||
break;
|
||||
case KeyCode::DELETE:
|
||||
if (m_SelectionContext.size())
|
||||
{
|
||||
const Entity selectedEntity = m_SelectionContext[0].Entity;
|
||||
m_EditorScene->DestroyEntity(selectedEntity);
|
||||
m_SelectionContext.clear();
|
||||
m_EditorScene->SetSelectedEntity({});
|
||||
m_SceneHierarchyPanel->SetSelected({});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (e.GetKeyCode())
|
||||
{
|
||||
case KeyCode::DELETE:
|
||||
if (m_SelectionContext.size())
|
||||
{
|
||||
const Entity selectedEntity = m_SelectionContext[0].Entity;
|
||||
m_EditorScene->DestroyEntity(selectedEntity);
|
||||
m_SelectionContext.clear();
|
||||
m_EditorScene->SetSelectedEntity({});
|
||||
m_SceneHierarchyPanel->SetSelected({});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (Input::IsKeyPressed(KeyCode::LEFT_CONTROL))
|
||||
{
|
||||
const bool IsShiftPressed = Input::IsKeyPressed(KeyCode::LEFT_SHIFT);
|
||||
@ -888,7 +893,9 @@ namespace Prism
|
||||
case KeyCode::S:
|
||||
SaveScene();
|
||||
break;
|
||||
|
||||
case KeyCode::N:
|
||||
NewScene();
|
||||
break;
|
||||
case KeyCode::B:
|
||||
// Toggle bounding boxes
|
||||
m_UIShowBoundingBoxes = !m_UIShowBoundingBoxes;
|
||||
@ -998,10 +1005,8 @@ namespace Prism
|
||||
SelectedSubmesh selection;
|
||||
if (entity.HasComponent<MeshComponent>())
|
||||
{
|
||||
if (auto& meshComp = entity.GetComponent<MeshComponent>(); meshComp.Mesh)
|
||||
{
|
||||
selection.Mesh = &meshComp.Mesh->GetSubmeshes()[0];
|
||||
}
|
||||
if (auto mesh = entity.GetComponent<MeshComponent>().Mesh)
|
||||
selection.Mesh = &mesh->GetSubmeshes()[0];
|
||||
}
|
||||
selection.Entity = entity;
|
||||
m_SelectionContext.clear();
|
||||
@ -1068,33 +1073,56 @@ namespace Prism
|
||||
return Ray::Zero();
|
||||
}
|
||||
|
||||
void EditorLayer::NewScene()
|
||||
{
|
||||
m_EditorScene = Ref<Scene>::Create("Untitled Scene", true);
|
||||
m_SceneHierarchyPanel->SetContext(m_EditorScene);
|
||||
ScriptEngine::SetSceneContext(m_EditorScene);
|
||||
UpdateWindowTitle("Untitled Scene");
|
||||
m_SceneFilePath = std::string();
|
||||
|
||||
m_EditorCamera = EditorCamera(glm::perspectiveFov(glm::radians(45.0f), 1280.0f, 720.0f, 0.1f, 1000.0f));
|
||||
m_SelectionContext.clear();
|
||||
}
|
||||
|
||||
void EditorLayer::OpenScene()
|
||||
{
|
||||
const auto& app = Application::Get();
|
||||
const std::string filepath = app.OpenFile("Prism Scene (*.hsc)\0*.hsc\0");
|
||||
const std::string filepath = app.OpenFile("Hazel Scene (*.hsc)\0*.hsc\0");
|
||||
if (!filepath.empty())
|
||||
{
|
||||
const Ref<Scene> newScene = Ref<Scene>::Create("EditorScene", true);
|
||||
SceneSerializer serializer(newScene);
|
||||
serializer.Deserialize(filepath);
|
||||
m_EditorScene = newScene;
|
||||
const std::filesystem::path path = filepath;
|
||||
UpdateWindowTitle(path.filename().string());
|
||||
m_SceneHierarchyPanel->SetContext(m_EditorScene);
|
||||
ScriptEngine::SetSceneContext(m_EditorScene);
|
||||
OpenScene(filepath);
|
||||
}
|
||||
|
||||
m_EditorScene->SetSelectedEntity({});
|
||||
m_SelectionContext.clear();
|
||||
void EditorLayer::OpenScene(const std::string& filepath)
|
||||
{
|
||||
const std::string fileName = std::filesystem::path(filepath).filename().string();
|
||||
UpdateWindowTitle(fileName);
|
||||
|
||||
m_SceneFilePath = filepath;
|
||||
}
|
||||
const Ref<Scene> newScene = Ref<Scene>::Create(fileName, true);
|
||||
SceneSerializer serializer(newScene);
|
||||
serializer.Deserialize(filepath);
|
||||
m_EditorScene = newScene;
|
||||
m_SceneFilePath = filepath;
|
||||
|
||||
m_SceneHierarchyPanel->SetContext(m_EditorScene);
|
||||
ScriptEngine::SetSceneContext(m_EditorScene);
|
||||
|
||||
m_EditorScene->SetSelectedEntity({});
|
||||
m_SelectionContext.clear();
|
||||
}
|
||||
|
||||
void EditorLayer::SaveScene()
|
||||
{
|
||||
PM_CLIENT_INFO("Saving scene to: {0}", m_SceneFilePath);
|
||||
SceneSerializer serializer(m_EditorScene);
|
||||
serializer.Serialize(m_SceneFilePath);
|
||||
if (!m_SceneFilePath.empty())
|
||||
{
|
||||
PM_CLIENT_INFO("Saving scene to: {0}", m_SceneFilePath);
|
||||
SceneSerializer serializer(m_EditorScene);
|
||||
serializer.Serialize(m_SceneFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveSceneAs();
|
||||
}
|
||||
}
|
||||
|
||||
void EditorLayer::SaveSceneAs()
|
||||
@ -1110,6 +1138,9 @@ namespace Prism
|
||||
std::filesystem::path path = filepath;
|
||||
UpdateWindowTitle(path.filename().string());
|
||||
m_SceneFilePath = filepath;
|
||||
}else
|
||||
{
|
||||
PM_CLIENT_INFO("cancelled");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1140,8 +1171,6 @@ namespace Prism
|
||||
m_SelectionContext.clear();
|
||||
ScriptEngine::SetSceneContext(m_EditorScene);
|
||||
m_SceneHierarchyPanel->SetContext(m_EditorScene);
|
||||
|
||||
Input::SetCursorMode(CursorMode::Normal);
|
||||
}
|
||||
|
||||
float EditorLayer::GetSnapValue()
|
||||
|
||||
Reference in New Issue
Block a user