New features added #383

Merged
glencelow merged 8 commits from PlayerController into main 2023-03-02 18:31:38 +08:00
16 changed files with 169 additions and 20 deletions
Showing only changes of commit 97db3b1021 - 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

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

Binary file not shown.

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>
@ -599,7 +601,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
@ -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

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

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

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

View File

@ -40,6 +40,9 @@ namespace SHADE
//! character position data for each letter in the text
Handle<SHVkBuffer> 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<SHFont> font) noexcept;
void SetColor(SHColour const& newColor) noexcept;
void SetTextSize (SHVec3 const& size) noexcept;
std::string const& GetText (void) const noexcept;
Handle<SHFont> GetFont (void) const noexcept;
SHColour const& GetColor (void) const noexcept;
SHVec3 const& GetTextSize (void) const noexcept;
friend class SHTextRenderingSubSystem;

View File

@ -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<SHUIComponent>(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);

View File

@ -71,7 +71,7 @@ namespace SHADE
//! of the texture library would mean the recreation of the desc set that also
//! involves the generic data, which is bad bad bad. Solution is to separate the
//! 2 desc sets.
static constexpr uint32_t DEFAULT_MAX_TEXTURES = 2000;
static constexpr uint32_t DEFAULT_MAX_TEXTURES = 1000;
/*-----------------------------------------------------------------------------*/
/* Usage Functions */

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>
@ -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<SHVec4>());
}
if (node[TEXT_SIZE_YAML_TAG.data()].IsDefined())
{
rhs.SetTextSize(node[TEXT_SIZE_YAML_TAG.data()].as<SHVec3>());
}
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<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 +459,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>());