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/Assets/Shaders/UI_FS.glsl b/Assets/Shaders/UI_FS.glsl index 30b59e48..3c66891b 100644 --- a/Assets/Shaders/UI_FS.glsl +++ b/Assets/Shaders/UI_FS.glsl @@ -37,7 +37,7 @@ layout(location = 1) out uint outEntityID; void main() { fragColor = texture(textures[nonuniformEXT(MatProp.data[In2.materialIndex].textureIndex)], In.uv); - if (fragColor.a < 0.01f) + if (fragColor.a < 0.1f) { discard; } diff --git a/Assets/Shaders/UI_FS.shshaderb b/Assets/Shaders/UI_FS.shshaderb index 92f4ed4e..d734949d 100644 Binary files a/Assets/Shaders/UI_FS.shshaderb and b/Assets/Shaders/UI_FS.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 b571952f..67c44434 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -27,6 +27,7 @@ #include "Physics/Collision/Shapes/SHSphere.h" #include "../SHEditorWindowManager.h" #include "../AssetBrowser/SHAssetBrowser.h" +#include "Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderableComponent.h" #include "Animation/SHAnimationClip.h" namespace SHADE @@ -601,7 +602,7 @@ namespace SHADE component->SetText(val); } ); - + SHEditorWidgets::DragVec3("Text Size", { "X", "Y", "Z" }, [&textComp = component]() {return textComp->GetTextSize();}, [&textComp = component](SHVec3 const& size) {textComp->SetTextSize(size); }); SHEditorWidgets::ColorPicker("Color", [&textComp = component]() {return textComp->GetColor(); }, [&textComp = component](SHVec4 const& newColor) {textComp->SetColor(newColor); }); } else @@ -656,4 +657,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/Images/SHVkImage.cpp b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp index 53703924..28870797 100644 --- a/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp +++ b/SHADE_Engine/src/Graphics/Images/SHVkImage.cpp @@ -262,7 +262,7 @@ namespace SHADE copyRegions[i].imageSubresource.baseArrayLayer = 0; // TODO: Array textures not supported yet copyRegions[i].imageSubresource.layerCount = layerCount; copyRegions[i].imageOffset = vk::Offset3D{ 0,0,0 }; - copyRegions[i].imageExtent = vk::Extent3D{ width >> i, height >> i, 1 }; + copyRegions[i].imageExtent = vk::Extent3D{ std::max (1u, width >> i), std::max (1u, height >> i), 1 }; } cmdBufferHdl->CopyBufferToImage(stagingBuffer, vkImage, copyRegions); 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/TextRendering/SHTextRenderableComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.cpp index 3edf0983..5703a9c1 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.cpp @@ -29,6 +29,8 @@ namespace SHADE // Default white color. color = SHColour::WHITE; + + textSize = SHVec3::One; } void SHTextRenderableComponent::OnDestroy(void) @@ -66,6 +68,11 @@ namespace SHADE color = newColor; } + void SHTextRenderableComponent::SetTextSize(SHVec3 const& size) noexcept + { + textSize = size; + } + /***************************************************************************/ /*! @@ -92,6 +99,11 @@ namespace SHADE return color; } + SHVec3 const& SHTextRenderableComponent::GetTextSize(void) const noexcept + { + return textSize; + } + } namespace rttr diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h index 9d31cdd8..81d3a85f 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h @@ -40,6 +40,9 @@ namespace SHADE //! character position data for each letter in the text Handle charPositionDataBuffer; + //! Text size. Multiplied to TRS. + SHVec3 textSize; + void MakeDirty (void) noexcept; void Clean (void) noexcept; @@ -53,10 +56,12 @@ namespace SHADE void SetText (std::string_view newText) noexcept; void SetFont(Handle font) noexcept; void SetColor(SHColour const& newColor) noexcept; + void SetTextSize (SHVec3 const& size) noexcept; std::string const& GetText (void) const noexcept; Handle GetFont (void) const noexcept; SHColour const& GetColor (void) const noexcept; + SHVec3 const& GetTextSize (void) const noexcept; friend class SHTextRenderingSubSystem; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index 9ab6106d..ff9168c9 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -210,10 +210,13 @@ namespace SHADE cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::CALCULATED_GLYPH_POSITION, comp.charPositionDataBuffer, 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::GLYPH_INDEX, comp.indexingDataBuffer, 0); + auto const& textSize = comp.textSize; + SHMatrix textSizeScale{textSize.x, 0.0f, 0.0f, 0.0f, 0.0f, textSize.y, 0.0f, 0.0f, 0.0f, 0.0f, textSize.z, 0.0f}; + if (auto* uiComp = SHComponentManager::GetComponent_s(comp.GetEID())) - cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", uiComp->GetMatrix(), SH_PIPELINE_TYPE::GRAPHICS); + cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", textSizeScale * uiComp->GetMatrix(), SH_PIPELINE_TYPE::GRAPHICS); else - cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS); + cmdBuffer->SetPushConstantVariable("TestPushConstant.worldTransform", textSizeScale * transform->GetTRS(), SH_PIPELINE_TYPE::GRAPHICS); cmdBuffer->SetPushConstantVariable("TestPushConstant.eid", comp.GetEID(), SH_PIPELINE_TYPE::GRAPHICS); 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 ffb676b0..69b4f409 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 @@ -355,6 +357,7 @@ namespace YAML static constexpr std::string_view TEXT_YAML_TAG = "Text"; static constexpr std::string_view FONT_YAML_TAG = "Font"; static constexpr std::string_view COLOR_YAML_TAG = "Color"; + static constexpr std::string_view TEXT_SIZE_YAML_TAG = "Text Size"; static YAML::Node encode(SHTextRenderableComponent const& rhs) { @@ -370,7 +373,8 @@ namespace YAML { node[FONT_YAML_TAG.data()] = 0; } - node[COLOR_YAML_TAG.data()] = SHVec4 (textColor); + node[COLOR_YAML_TAG.data()] = SHVec4(textColor); + node[TEXT_SIZE_YAML_TAG.data()] = rhs.GetTextSize(); return node; } static bool decode(YAML::Node const& node, SHTextRenderableComponent& rhs) @@ -393,6 +397,10 @@ namespace YAML { rhs.SetColor(node[COLOR_YAML_TAG.data()].as()); } + if (node[TEXT_SIZE_YAML_TAG.data()].IsDefined()) + { + rhs.SetTextSize(node[TEXT_SIZE_YAML_TAG.data()].as()); + } return true; } }; @@ -431,6 +439,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 +448,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 +459,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());