Fixed trajectory rendering, added text size and solved vulkan errors #382

Merged
Xenosas1337 merged 4 commits from SP3-1-Rendering into main 2023-03-02 16:32:37 +08:00
9 changed files with 136 additions and 13 deletions
Showing only changes of commit e2ef32f130 - Show all commits

View File

@ -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);
}

View File

@ -14,3 +14,4 @@
#include "Physics/Interface/SHColliderComponent.h"
#include "Graphics/MiddleEnd/TextRendering/SHTextRenderableComponent.h"
#include "AudioSystem/SHAudioListenerComponent.h"
#include "Graphics/MiddleEnd/TrajectoryRendering/SHTrajectoryRenderableComponent.h"

View File

@ -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<typename T>
@ -679,4 +681,95 @@ namespace SHADE
ImGui::PopID();
}
template<>
static void DrawComponent(SHTrajectoryRenderableComponent* component)
{
if (!component)
return;
ImGui::PushID(SHFamilyID<SHComponent>::GetID<SHTrajectoryRenderableComponent>());
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<SHMesh> const& mesh = component->GetMesh();
const auto MESH_NAME = SHResourceManager::GetAssetName<SHMesh>(mesh).value_or("");
SHEditorWidgets::DragDropReadOnlyField<AssetID>("Mesh", MESH_NAME, [component]()
{
Handle<SHMesh> const& mesh = component->GetMesh();
return SHResourceManager::GetAssetID<SHMesh>(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<SHMesh>(id));
SHResourceManager::FinaliseChanges();
}, SHDragDrop::DRAG_RESOURCE);
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left))
{
if (Handle<SHMesh> const& mesh = component->GetMesh())
{
AssetID assetID = SHResourceManager::GetAssetID<SHMesh>(mesh).value_or(0);
SHEditorWindowManager::GetEditorWindow<SHAssetBrowser>()->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();
}
}

View File

@ -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;

View File

@ -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<SHVkCommandBuffer> cmdBuffer, Handle<SHRenderer> renderer, uint32_t frameIndex)
@ -485,8 +485,8 @@ namespace SHADE
trajectoryRenderingSubSystem = resourceManager.Create<SHTrajectoryRenderingSubSystem>();
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);

View File

@ -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<SHTrajectoryRenderableComponent>();
for (auto& comp : comps)
{
comp.SetPositions(std::vector
{
SHVec3 {},
SHVec3 {}
});
//std::vector<SHVec3> 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());

View File

@ -247,6 +247,7 @@ namespace SHADE
AddComponentToComponentNode<SHAnimatorComponent>(components, eid);
AddComponentToComponentNode<SHUIComponent>(components, eid);
AddComponentToComponentNode<SHAudioListenerComponent>(components, eid);
AddComponentToComponentNode<SHTrajectoryRenderableComponent>(components, eid);
node[ComponentsNode] = components;
@ -308,6 +309,7 @@ namespace SHADE
AddComponentID<SHAnimatorComponent>(componentIDList, componentsNode);
AddComponentID<SHUIComponent>(componentIDList, componentsNode);
AddComponentID<SHAudioListenerComponent>(componentIDList, componentsNode);
AddComponentID<SHTrajectoryRenderableComponent>(componentIDList, componentsNode);
return componentIDList;
}
@ -395,5 +397,6 @@ namespace SHADE
SHSerializationHelper::InitializeComponentFromNode<SHAnimatorComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHUIComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHAudioListenerComponent>(componentsNode, eid);
SHSerializationHelper::InitializeComponentFromNode<SHTrajectoryRenderableComponent>(componentsNode, eid);
}
}

View File

@ -32,6 +32,8 @@ namespace YAML
struct HasYAMLConv<SHTextRenderableComponent> : std::true_type {};
template<>
struct HasYAMLConv<SHAnimatorComponent> : std::true_type {};
template<>
struct HasYAMLConv<SHTrajectoryRenderableComponent> : std::true_type {};
template<>
struct convert<SHVec4>
@ -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<SHMesh>(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<SHMesh>(node[MESH_YAML_TAG.data()].as<AssetID>()));
if (node[START_COLOR_YAML_TAG.data()].IsDefined())
rhs.SetStartColor(node[START_COLOR_YAML_TAG.data()].as<SHVec3>());
if (node[START_ALPHA_YAML_TAG.data()].IsDefined())
rhs.SetStartAlpha(node[START_ALPHA_YAML_TAG.data()].as<float>());
if (node[END_COLOR_YAML_TAG.data()].IsDefined())
rhs.SetEndColor(node[END_COLOR_YAML_TAG.data()].as<SHVec3>());
if (node[END_ALPHA_YAML_TAG.data()].IsDefined())
rhs.SetEndAlpha(node[END_ALPHA_YAML_TAG.data()].as<float>());
if (node[COLOR_EVAL_RATE_YAML_TAG.data()].IsDefined())
rhs.SetColorEvolveRate(node[COLOR_EVAL_RATE_YAML_TAG.data()].as<float>());