diff --git a/Assets/Shaders/Trajectory_VS.glsl b/Assets/Shaders/Trajectory_VS.glsl index 86be6b7e..1b4de7f7 100644 --- a/Assets/Shaders/Trajectory_VS.glsl +++ b/Assets/Shaders/Trajectory_VS.glsl @@ -32,5 +32,5 @@ void main() Out.uv = aUV; Out.color = aColor; - gl_Position = cameraData.projMat * aTransform * vec4(aPos, 1.0f); + gl_Position = cameraData.vpMat * aTransform * vec4(aPos, 1.0f); } \ No newline at end of file diff --git a/Assets/Shaders/Trajectory_VS.shshaderb b/Assets/Shaders/Trajectory_VS.shshaderb index 6f509f5c..b7a0f9fb 100644 Binary files a/Assets/Shaders/Trajectory_VS.shshaderb and b/Assets/Shaders/Trajectory_VS.shshaderb differ diff --git a/SHADE_Engine/src/Common/SHAllComponents.h b/SHADE_Engine/src/Common/SHAllComponents.h index 36b74853..ee900736 100644 --- a/SHADE_Engine/src/Common/SHAllComponents.h +++ b/SHADE_Engine/src/Common/SHAllComponents.h @@ -13,4 +13,5 @@ #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Physics/Interface/SHColliderComponent.h" #include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h" -#include "AudioSystem/SHAudioListenerComponent.h" \ No newline at end of file +#include "AudioSystem/SHAudioListenerComponent.h" +#include "Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderableComponent.h" diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index af03ffa6..17b9a229 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -27,6 +27,8 @@ #include "Physics/Collision/Shapes/SHSphere.h" #include "../SHEditorWindowManager.h" #include "../AssetBrowser/SHAssetBrowser.h" +#include "Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderableComponent.h" + namespace SHADE { template @@ -679,4 +681,95 @@ namespace SHADE ImGui::PopID(); } + template<> + static void DrawComponent(SHTrajectoryRenderableComponent* component) + { + if (!component) + return; + + ImGui::PushID(SHFamilyID::GetID()); + + const auto componentType = rttr::type::get(*component); + + SHEditorWidgets::CheckBox("##IsActive", [component]() {return component->isActive; }, [component](bool const& active) {component->isActive = active; }, "Is Component Active"); + + ImGui::SameLine(); + if (ImGui::CollapsingHeader(componentType.get_name().data(), ImGuiTreeNodeFlags_DefaultOpen)) + { + DrawContextMenu(component); + Handle const& mesh = component->GetMesh(); + const auto MESH_NAME = SHResourceManager::GetAssetName(mesh).value_or(""); + SHEditorWidgets::DragDropReadOnlyField("Mesh", MESH_NAME, [component]() + { + Handle const& mesh = component->GetMesh(); + return SHResourceManager::GetAssetID(mesh).value_or(0); + }, + [component](AssetID const& id) + { + if (SHAssetManager::GetType(id) != AssetType::MESH) + { + SHLOG_WARNING("Attempted to assign non mesh asset to Renderable Mesh property!") + return; + } + component->SetMesh(SHResourceManager::LoadOrGet(id)); + SHResourceManager::FinaliseChanges(); + }, SHDragDrop::DRAG_RESOURCE); + + if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) + { + if (Handle const& mesh = component->GetMesh()) + { + AssetID assetID = SHResourceManager::GetAssetID(mesh).value_or(0); + SHEditorWindowManager::GetEditorWindow()->SetScrollTo(assetID); + } + } + + SHEditorWidgets::ColorPicker("Start Color", + [comp = component]() + { + SHVec4 newColor(comp->GetStartColor()); + newColor.w = comp->GetStartAlpha(); + return newColor; + }, + [comp = component](SHVec4 vec) + { + SHVec3 temp{vec.x, vec.y, vec.z}; + float a = vec.w; + comp->SetStartColor(temp); + comp->SetStartAlpha(a); + }); + + SHEditorWidgets::ColorPicker("End Color", + [comp = component]() + { + SHVec4 newColor(comp->GetEndColor()); + newColor.w = comp->GetEndAlpha(); + return newColor; + }, + [comp = component](SHVec4 vec) + { + SHVec3 temp{ vec.x, vec.y, vec.z }; + float a = vec.w; + comp->SetEndColor(temp); + comp->SetEndAlpha(a); + }); + + SHEditorWidgets::DragFloat("Color Evolve Rate", + [comp = component]() + { + return comp->GetColorEvolveRate(); + }, + [comp = component](float rate) + { + return comp->SetColorEvolveRate(rate); + }); + + } + else + { + DrawContextMenu(component); + } + ImGui::PopID(); + } + } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index 468cc0c7..d2fcb77e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -130,7 +130,7 @@ namespace SHADE static constexpr std::string_view GBUFFER_WRITE_VFX_SUBPASS = "G-Buffer Write With VFX"; static constexpr std::string_view UI_SUBPASS = "UI"; static constexpr std::string_view UI_TRANSLUCENT_SUBPASS = "UI Translucent"; - static constexpr std::string_view VFX_SUBPASS = "VFX"; + static constexpr std::string_view VFX_SUBPASS = "VFX Subpass"; static constexpr std::string_view OBJ_VFX_SUBPASS = "Object VFX Subpass No Depth"; static constexpr std::array USABLE_SUBPASSES = @@ -362,6 +362,7 @@ namespace SHADE */ /***************************************************************************/ static constexpr uint32_t TRAJECTORY_COLOR = 2; + static constexpr uint32_t TRAJECTORY_TRANSFORM = 3; static constexpr uint32_t CALCULATED_GLYPH_POSITION = 0; static constexpr uint32_t GLYPH_INDEX = 1; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 4681c4ae..e7f1ae68 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -337,7 +337,7 @@ namespace SHADE /* VFX PASS */ /*-----------------------------------------------------------------------*/ auto vfxPass = renderGraph->AddNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data(), { "Scene", "Depth Buffer" }, { SHGraphicsConstants::RenderGraphEntityNames::GBUFFER_PASS.data(), SHGraphicsConstants::RenderGraphEntityNames::DEFERRED_COMPOSITE_PASS.data() }); - auto vfxSubpass = vfxPass->AddSubpass("Vfx Subpass", worldViewport, worldRenderer); + auto vfxSubpass = vfxPass->AddSubpass(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS.data(), worldViewport, worldRenderer); vfxSubpass->AddColorOutput("Scene"); vfxSubpass->AddDepthOutput("Depth Buffer"); vfxSubpass->AddExteriorDrawCalls([=](Handle cmdBuffer, Handle renderer, uint32_t frameIndex) @@ -485,8 +485,8 @@ namespace SHADE trajectoryRenderingSubSystem = resourceManager.Create(); - auto vfxNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::SCREEN_SPACE_PASS.data()); - trajectoryRenderingSubSystem->Init(device, vfxNode->GetRenderpass(), vfxNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::UI_SUBPASS), trajectoryVS, trajectoryFS); + auto vfxNode = renderGraph->GetNode(SHGraphicsConstants::RenderGraphEntityNames::VFX_PASS.data()); + trajectoryRenderingSubSystem->Init(device, vfxNode->GetRenderpass(), vfxNode->GetSubpass(SHGraphicsConstants::RenderGraphEntityNames::VFX_SUBPASS), trajectoryVS, trajectoryFS); SHGlobalDescriptorSets::SetLightingSubSystem(lightingSubSystem); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderingSubSystem.cpp index 61631925..cbf593d4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderingSubSystem.cpp @@ -68,6 +68,8 @@ namespace SHADE } pipeline->GetPipelineState().SetColorBlenState(colorBlendState); + + pipeline->ConstructPipeline(); } void SHTrajectoryRenderingSubSystem::Run(uint32_t frameIndex) noexcept @@ -75,12 +77,16 @@ namespace SHADE auto& comps = SHComponentManager::GetDense(); for (auto& comp : comps) { - comp.SetPositions(std::vector - { - SHVec3 {}, - SHVec3 {} - }); + //std::vector test{}; + //test.resize(10); + //float x = 0.0f; + //for (auto& vec : test) + //{ + // vec = SHVec3(x, 5.0f, 0.0f); + // x += 0.5f; + //} + //comp.SetPositions (test); // If has positions, feed data to buffer. if (comp.HasPositions()) { @@ -122,12 +128,13 @@ namespace SHADE transformData.push_back(trs); colorData.push_back(currentColor); + // evolve lerp value and clamp to 1 + lerpValue = std::min (1.0f, lerpValue + colorEvolveRate); + // evolve color currentColor = SHVec3::Lerp(startColor, endColor, lerpValue); currentColor.w = SHMath::Lerp (comp.GetStartAlpha(), comp.GetEndAlpha(), lerpValue); - // evolve lerp value and clamp to 1 - lerpValue = std::max (1.0f, lerpValue + colorEvolveRate); } // add draw data for this trajectory @@ -178,6 +185,9 @@ namespace SHADE // Bind color vertex buffer cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRAJECTORY_COLOR, colorBuffer, 0); + // Bind transform data + cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRAJECTORY_TRANSFORM, transformBuffer, 0); + // call draw call cmdBuffer->DrawMultiIndirect(drawDataBuffer, drawData.size()); diff --git a/SHADE_Engine/src/Serialization/SHSerialization.cpp b/SHADE_Engine/src/Serialization/SHSerialization.cpp index 13f5e36e..b6455935 100644 --- a/SHADE_Engine/src/Serialization/SHSerialization.cpp +++ b/SHADE_Engine/src/Serialization/SHSerialization.cpp @@ -247,6 +247,7 @@ namespace SHADE AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); AddComponentToComponentNode(components, eid); + AddComponentToComponentNode(components, eid); node[ComponentsNode] = components; @@ -308,6 +309,7 @@ namespace SHADE AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); AddComponentID(componentIDList, componentsNode); + AddComponentID(componentIDList, componentsNode); return componentIDList; } @@ -395,5 +397,6 @@ namespace SHADE SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); + SHSerializationHelper::InitializeComponentFromNode(componentsNode, eid); } } diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index 2c212e5f..ca0c0185 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -32,6 +32,8 @@ namespace YAML struct HasYAMLConv : std::true_type {}; template<> struct HasYAMLConv : std::true_type {}; + template<> + struct HasYAMLConv : std::true_type {}; template<> struct convert @@ -431,6 +433,8 @@ namespace YAML static constexpr std::string_view MESH_YAML_TAG = "Mesh"; static constexpr std::string_view START_COLOR_YAML_TAG = "Start Color"; static constexpr std::string_view END_COLOR_YAML_TAG = "End Color"; + static constexpr std::string_view START_ALPHA_YAML_TAG = "Start Alpha"; + static constexpr std::string_view END_ALPHA_YAML_TAG = "End Alpha"; static constexpr std::string_view COLOR_EVAL_RATE_YAML_TAG = "Color Eval Rate "; static YAML::Node encode(SHTrajectoryRenderableComponent const& rhs) @@ -438,7 +442,9 @@ namespace YAML YAML::Node node; node[MESH_YAML_TAG.data()] = SHResourceManager::GetAssetID(rhs.GetMesh()).value_or(0); node[START_COLOR_YAML_TAG.data()] = SHVec3(rhs.GetStartColor()); + node[START_ALPHA_YAML_TAG.data()] = rhs.GetStartAlpha(); node[END_COLOR_YAML_TAG.data()] = SHVec3(rhs.GetEndColor()); + node[END_ALPHA_YAML_TAG.data()] = rhs.GetEndAlpha(); node[COLOR_EVAL_RATE_YAML_TAG.data()] = rhs.GetColorEvolveRate(); return node; @@ -447,10 +453,19 @@ namespace YAML { if (node[MESH_YAML_TAG.data()].IsDefined()) rhs.SetMesh(SHResourceManager::LoadOrGet(node[MESH_YAML_TAG.data()].as())); + if (node[START_COLOR_YAML_TAG.data()].IsDefined()) rhs.SetStartColor(node[START_COLOR_YAML_TAG.data()].as()); + + if (node[START_ALPHA_YAML_TAG.data()].IsDefined()) + rhs.SetStartAlpha(node[START_ALPHA_YAML_TAG.data()].as()); + if (node[END_COLOR_YAML_TAG.data()].IsDefined()) rhs.SetEndColor(node[END_COLOR_YAML_TAG.data()].as()); + + if (node[END_ALPHA_YAML_TAG.data()].IsDefined()) + rhs.SetEndAlpha(node[END_ALPHA_YAML_TAG.data()].as()); + if (node[COLOR_EVAL_RATE_YAML_TAG.data()].IsDefined()) rhs.SetColorEvolveRate(node[COLOR_EVAL_RATE_YAML_TAG.data()].as());