mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-06 06:09:52 +03:00
Bunch of improvements
- Camera preview - Culling, Sampling in materials - Per scene lighting now working properly - Fixed vk validations errors - Viewport can be enabled/disabled - Enabled anisotropy in device features - Scenes now a resource
This commit is contained in:
@@ -3,49 +3,112 @@
|
||||
#include <Nuake/Scene/Components/CameraComponent.h>
|
||||
#include "Nuake/FileSystem/FileSystem.h"
|
||||
|
||||
class CameraPanel {
|
||||
#include "Nuake/Core/Core.h"
|
||||
#include "Nuake/Rendering/Vulkan/SceneViewport.h"
|
||||
|
||||
class CameraPanel
|
||||
{
|
||||
public:
|
||||
static void Draw(Nuake::Entity& entity, entt::meta_any& componentInstance)
|
||||
{
|
||||
using namespace Nuake;
|
||||
|
||||
Nuake::CameraComponent* componentPtr = componentInstance.try_cast<Nuake::CameraComponent>();
|
||||
static Ref<Nuake::Viewport> previewViewport;
|
||||
if (!previewViewport)
|
||||
{
|
||||
auto scene = entity.GetScene();
|
||||
auto& vkRenderer = Nuake::VkRenderer::Get();
|
||||
const UUID viewId = componentPtr->CameraInstance->ID;
|
||||
|
||||
previewViewport = vkRenderer.CreateViewport(viewId, { 200, 200 });
|
||||
vkRenderer.RegisterSceneViewport(scene->Shared(), previewViewport->GetID());
|
||||
}
|
||||
if (componentPtr == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Nuake::CameraComponent& component = *componentPtr;
|
||||
|
||||
BeginComponentTable(CAMERA, Nuake::CameraComponent);
|
||||
|
||||
UIFont* boldFont = new UIFont(Fonts::Bold);
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.f, 0.f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.f, 8.f));
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);
|
||||
bool removed = false;
|
||||
bool headerOpened = ImGui::CollapsingHeader("CAMERA", ImGuiTreeNodeFlags_DefaultOpen);
|
||||
ImGui::PopStyleVar();
|
||||
if (ImGui::BeginPopupContextItem())
|
||||
{
|
||||
{
|
||||
ImGui::Text("FOV");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Fov", &component.CameraInstance->Fov, 0.1f, 0.1f, 360.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.CameraInstance->Fov, 88.0f);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Exposure");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Exposure", &component.CameraInstance->Exposure, 0.1f, 0.1f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.CameraInstance->Fov, 1.0f);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Gamma");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Gamma", &component.CameraInstance->Gamma, 0.1f, 0.1f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.CameraInstance->Fov, 2.2f);
|
||||
}
|
||||
if (ImGui::Selectable("Remove")) { removed = true; }
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
EndComponentTable();
|
||||
if (removed)
|
||||
{
|
||||
entity.RemoveComponent<Nuake::CameraComponent>();
|
||||
ImGui::PopStyleVar();
|
||||
delete boldFont;
|
||||
}
|
||||
else if (headerOpened)
|
||||
{
|
||||
delete boldFont;
|
||||
|
||||
auto size = ImVec2{ ImGui::GetContentRegionAvail().x, 200 };
|
||||
componentPtr->CameraInstance->OnWindowResize(size.x, size.y);
|
||||
previewViewport->QueueResize({ size.x, size.y });
|
||||
ImGui::BeginChild("##CameraPreview", size);
|
||||
{
|
||||
VkDescriptorSet textureDesc = previewViewport->GetRenderTarget()->GetImGuiDescriptorSet();
|
||||
ImGui::Image(textureDesc, ImGui::GetContentRegionAvail(), { 0, 1 }, { 1, 0 });
|
||||
}
|
||||
ImGui::EndChild();
|
||||
|
||||
|
||||
ImGui::PopStyleVar();
|
||||
ImGui::Indent();
|
||||
if (ImGui::BeginTable("Camera", 3, ImGuiTableFlags_SizingStretchProp))
|
||||
{
|
||||
ImGui::TableSetupColumn("name", 0, 0.25f);
|
||||
ImGui::TableSetupColumn("set", 0, 0.65f);
|
||||
ImGui::TableSetupColumn("reset", 0, 0.1f);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
{
|
||||
{
|
||||
ImGui::Text("FOV");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Fov", &component.CameraInstance->Fov, 0.1f, 0.1f, 360.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.CameraInstance->Fov, 88.0f);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Exposure");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Exposure", &component.CameraInstance->Exposure, 0.1f, 0.1f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.CameraInstance->Fov, 1.0f);
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Gamma");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::DragFloat("##Gamma", &component.CameraInstance->Gamma, 0.1f, 0.1f, 10.0f);
|
||||
ImGui::TableNextColumn();
|
||||
ComponentTableReset(component.CameraInstance->Fov, 2.2f);
|
||||
}
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Unindent();
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PopStyleVar();
|
||||
delete boldFont;
|
||||
}
|
||||
ImGui::PopStyleVar();
|
||||
}
|
||||
};
|
||||
@@ -26,6 +26,16 @@ enum class Shapes
|
||||
|
||||
Shapes currentShape = Shapes::Sphere;
|
||||
|
||||
void MaterialEditor::Enable()
|
||||
{
|
||||
SceneViewport->SetActive(true);
|
||||
}
|
||||
|
||||
void MaterialEditor::Disable()
|
||||
{
|
||||
SceneViewport->SetActive(false);
|
||||
}
|
||||
|
||||
MaterialEditor::MaterialEditor()
|
||||
{
|
||||
using namespace Nuake;
|
||||
@@ -37,12 +47,13 @@ MaterialEditor::MaterialEditor()
|
||||
camera.GetComponent<Nuake::TransformComponent>().Translation = Nuake::Vector3(-2, 0, -2);
|
||||
auto& camComponent = camera.AddComponent<Nuake::CameraComponent>();
|
||||
camComponent.CameraInstance->Fov = 44.0f;
|
||||
//auto light = PreviewScene->CreateEntity("Light");
|
||||
//auto& lightC = light.AddComponent<LightComponent>();
|
||||
//lightC.CastShadows = false;
|
||||
//lightC.Type = LightType::Directional;
|
||||
auto light = PreviewScene->CreateEntity("Light");
|
||||
auto& lightC = light.AddComponent<LightComponent>();
|
||||
auto& lightT = light.AddComponent<TransformComponent>();
|
||||
lightC.CastShadows = false;
|
||||
lightC.Type = LightType::Directional;
|
||||
|
||||
glm::vec3 forward = glm::normalize(Vector3(0, 1, 0));
|
||||
glm::vec3 forward = glm::normalize(Vector3(.33, -.33, -.33));
|
||||
glm::vec3 up = glm::vec3(0, 1, 0);
|
||||
|
||||
// Prevent up being colinear with forward
|
||||
@@ -55,7 +66,7 @@ MaterialEditor::MaterialEditor()
|
||||
glm::mat3 rotationMatrix(right, up, forward);
|
||||
|
||||
//auto& lightT = light.GetComponent<TransformComponent>();
|
||||
//lightT.GlobalRotation = glm::quat_cast(rotationMatrix);
|
||||
lightT.GlobalRotation = glm::quat_cast(rotationMatrix);
|
||||
|
||||
auto sphere = PreviewScene->CreateEntity("Sphere");
|
||||
auto& modelComponent = sphere.AddComponent<Nuake::ModelComponent>();
|
||||
@@ -272,7 +283,6 @@ void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
{
|
||||
UIFont boldfont = UIFont(Fonts::SubTitle);
|
||||
ImGui::Text(material->Path.c_str());
|
||||
|
||||
}
|
||||
ImGui::SameLine();
|
||||
{
|
||||
@@ -435,16 +445,43 @@ void MaterialEditor::Draw(Ref<Nuake::Material> material)
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::TableNextColumn();
|
||||
{
|
||||
ImGui::Text("Culling");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
bool unlit = material->data.u_Unlit == 1;
|
||||
ImGui::Checkbox("Unlit", &unlit);
|
||||
material->data.u_Unlit = (int)unlit;
|
||||
ImGui::TableNextColumn();
|
||||
static const char* cullingType[]{ "Back", "Front", "None"};
|
||||
int selectedCulling = static_cast<int>(material->m_CullingType);
|
||||
ImGui::Combo("##Culling", &selectedCulling, cullingType, IM_ARRAYSIZE(cullingType));
|
||||
material->m_CullingType = static_cast<CullingType>(selectedCulling);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Sampling");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
static const char* samplingType[]{ "Nearest", "Linear" };
|
||||
int selectedSampling = static_cast<int>(material->m_SamplingType);
|
||||
ImGui::Combo("##Sampling", &selectedSampling, samplingType, IM_ARRAYSIZE(samplingType));
|
||||
material->m_SamplingType = static_cast<SamplingType>(selectedSampling);
|
||||
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
{
|
||||
ImGui::Text("Unlit");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
bool unlit = material->data.u_Unlit == 1;
|
||||
ImGui::Checkbox("##Unlit", &unlit);
|
||||
material->data.u_Unlit = (int)unlit;
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TableNextColumn();
|
||||
}
|
||||
|
||||
ImGui::Text("Emissive");
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
|
||||
@@ -13,5 +13,7 @@ public:
|
||||
MaterialEditor();
|
||||
~MaterialEditor() = default;
|
||||
|
||||
void Disable();
|
||||
void Enable();
|
||||
void Draw(Ref<Nuake::Material> material);
|
||||
};
|
||||
@@ -233,6 +233,17 @@ void SelectionPropertyWidget::DrawAddComponentMenu(Nuake::Entity entity)
|
||||
void SelectionPropertyWidget::DrawFile(Ref<Nuake::File> file)
|
||||
{
|
||||
using namespace Nuake;
|
||||
auto fileType = file->GetFileType();
|
||||
|
||||
if (fileType != FileType::Material)
|
||||
{
|
||||
matEditor.Disable();
|
||||
}
|
||||
else
|
||||
{
|
||||
matEditor.Enable();
|
||||
}
|
||||
|
||||
switch (file->GetFileType())
|
||||
{
|
||||
case FileType::Material:
|
||||
|
||||
@@ -19,6 +19,7 @@ private:
|
||||
SkinnedMeshPanel skinnedMeshPanel;
|
||||
Ref<Nuake::File> currentFile;
|
||||
Ref<Nuake::Resource> selectedResource;
|
||||
|
||||
AnimatedValue<float> opacity;
|
||||
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user