Skip to content

Commit

Permalink
[ADD] : add Dilation node
Browse files Browse the repository at this point in the history
  • Loading branch information
aiekick committed Nov 18, 2023
1 parent dc0eae1 commit 2b574e8
Show file tree
Hide file tree
Showing 13 changed files with 1,198 additions and 81 deletions.
21 changes: 19 additions & 2 deletions Plugins/CodeGenerator/src/Editor/UBOEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,27 @@ std::string UBOItem::Get_Glsl_Item_Header() {
auto _input_name = m_InputName.GetText();
ct::replaceString(_input_name, " ", "_");

std::string default_values;
if (inputIdx == 0) {
default_values = m_InputValue_x.GetText();
} else if (inputIdx == 1) {
default_values = m_InputValue_x.GetText();
default_values += ", " + m_InputValue_y.GetText();
} else if (inputIdx == 2) {
default_values = m_InputValue_x.GetText();
default_values += ", " + m_InputValue_y.GetText();
default_values += ", " + m_InputValue_z.GetText();
} else if (inputIdx == 3) {
default_values = m_InputValue_x.GetText();
default_values += ", " + m_InputValue_y.GetText();
default_values += ", " + m_InputValue_z.GetText();
default_values += ", " + m_InputValue_w.GetText();
}

res += ct::toStr(
u8R"(
%s u_%s;)",
type.c_str(), _input_name.c_str());
%s u_%s; // default is %s)",
type.c_str(), _input_name.c_str(), default_values.c_str());

return res;
}
Expand Down
4 changes: 2 additions & 2 deletions Plugins/CodeGenerator/src/Headers/CodeGeneratorBuild.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define CodeGenerator_Prefix "CodeGenerator"
#define CodeGenerator_BuildNumber 605
#define CodeGenerator_BuildNumber 606
#define CodeGenerator_MinorNumber 0
#define CodeGenerator_MajorNumber 0
#define CodeGenerator_BuildId "0.0.605"
#define CodeGenerator_BuildId "0.0.606"
2 changes: 1 addition & 1 deletion Plugins/CodeGenerator/src/Modules/GeneratorNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ std::string GeneratorNode::GetGlslHeader(const std::string& vStage, const bool&
}
res += "\n";
if (vStage == "Comp" && m_RendererType == RENDERER_TYPE_COMPUTE_2D) {
res += ct::toStr("layout(binding = %u, rgba32f) uniform image2D colorBuffer; // output\n", bindingStartIndex++);
res += ct::toStr("layout(binding = %u, rgba32f) uniform image2D outColor; // output\n", bindingStartIndex++);
}
return res;
}
Expand Down
4 changes: 2 additions & 2 deletions Plugins/PostProcessing/src/Headers/PostProcessingBuild.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define PostProcessing_Prefix "PostProcessing"
#define PostProcessing_BuildNumber 509
#define PostProcessing_BuildNumber 522
#define PostProcessing_MinorNumber 1
#define PostProcessing_MajorNumber 0
#define PostProcessing_BuildId "0.1.509"
#define PostProcessing_BuildId "0.1.522"
249 changes: 249 additions & 0 deletions Plugins/PostProcessing/src/Modules/PostPro/Effects/DilationModule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
/*
Copyright 2022 - 2022 Stephane Cuillerdier(aka aiekick)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http:://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissionsand
limitations under the License.
*/

// This is an independent project of an individual developer. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com

#include "DilationModule.h"

#include <cinttypes>
#include <functional>
#include <ctools/Logger.h>
#include <ctools/FileHelper.h>
#include <LumoBackend/Graph/Base/BaseNode.h>
#include <ImGuiPack.h>
#include <LumoBackend/Systems/CommonSystem.h>
#include <Gaia/Core/VulkanCore.h>
#include <Gaia/Shader/VulkanShader.h>
#include <Gaia/Core/VulkanSubmitter.h>
#include <LumoBackend/Utils/Mesh/VertexStruct.h>
#include <Gaia/Buffer/FrameBuffer.h>

#include <Modules/PostPro/Effects/Pass/DilationModule_Comp_2D_Pass.h>

using namespace GaiApi;

#ifdef PROFILER_INCLUDE
#include PROFILER_INCLUDE
#endif
#ifndef ZoneScoped
#define ZoneScoped
#endif

//////////////////////////////////////////////////////////////
//// STATIC //////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

std::shared_ptr<DilationModule> DilationModule::Create(GaiApi::VulkanCorePtr vVulkanCorePtr, BaseNodeWeak vParentNode) {
ZoneScoped;

if (!vVulkanCorePtr)
return nullptr;
auto res = std::make_shared<DilationModule>(vVulkanCorePtr);
res->SetParentNode(vParentNode);
res->m_This = res;
if (!res->Init()) {
res.reset();
}

return res;
}

//////////////////////////////////////////////////////////////
//// CTOR / DTOR /////////////////////////////////////////////
//////////////////////////////////////////////////////////////

DilationModule::DilationModule(GaiApi::VulkanCorePtr vVulkanCorePtr) : BaseRenderer(vVulkanCorePtr) {
ZoneScoped;
}

DilationModule::~DilationModule() {
ZoneScoped;

Unit();
}

//////////////////////////////////////////////////////////////
//// INIT / UNIT /////////////////////////////////////////////
//////////////////////////////////////////////////////////////

bool DilationModule::Init() {
ZoneScoped;

m_Loaded = false;

ct::uvec2 map_size = 512;
if (BaseRenderer::InitCompute2D(map_size)) {
// SetExecutionWhenNeededOnly(true);
m_DilationModule_Comp_2D_Pass_Ptr = DilationModule_Comp_2D_Pass::Create(map_size, m_VulkanCorePtr);
if (m_DilationModule_Comp_2D_Pass_Ptr) {
// by default but can be changed via widget
m_DilationModule_Comp_2D_Pass_Ptr->AllowResizeOnResizeEvents(true);
m_DilationModule_Comp_2D_Pass_Ptr->AllowResizeByHandOrByInputs(false);
AddGenericPass(m_DilationModule_Comp_2D_Pass_Ptr);
m_Loaded = true;
}
}

return m_Loaded;
}

//////////////////////////////////////////////////////////////
//// OVERRIDES ///////////////////////////////////////////////
//////////////////////////////////////////////////////////////

bool DilationModule::ExecuteAllTime(const uint32_t& vCurrentFrame, vk::CommandBuffer* vCmd, BaseNodeState* vBaseNodeState) {
ZoneScoped;
BaseRenderer::Render("Dilation", vCmd);
return true;
}

bool DilationModule::ExecuteWhenNeeded(const uint32_t& vCurrentFrame, vk::CommandBuffer* vCmd, BaseNodeState* vBaseNodeState) {
ZoneScoped;
BaseRenderer::Render("Dilation", vCmd);
return true;
}

//////////////////////////////////////////////////////////////////////////////////////////////
//// DRAW WIDGETS ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

bool DilationModule::DrawWidgets(const uint32_t& vCurrentFrame, ImGuiContext* vContextPtr, const std::string& vUserDatas) {
ZoneScoped;

assert(vContextPtr);
ImGui::SetCurrentContext(vContextPtr);

if (m_LastExecutedFrame == vCurrentFrame) {
if (m_DilationModule_Comp_2D_Pass_Ptr) {
return m_DilationModule_Comp_2D_Pass_Ptr->DrawWidgets(vCurrentFrame, vContextPtr, vUserDatas);
}
}

return false;
}

bool DilationModule::DrawOverlays(const uint32_t& vCurrentFrame, const ImRect& vRect, ImGuiContext* vContextPtr, const std::string& vUserDatas) {
ZoneScoped;

assert(vContextPtr);
ImGui::SetCurrentContext(vContextPtr);
if (m_LastExecutedFrame == vCurrentFrame) {
if (m_DilationModule_Comp_2D_Pass_Ptr) {
return m_DilationModule_Comp_2D_Pass_Ptr->DrawOverlays(vCurrentFrame, vRect, vContextPtr, vUserDatas);
}
}

return false;
}

bool DilationModule::DrawDialogsAndPopups(
const uint32_t& vCurrentFrame, const ImVec2& vMaxSize, ImGuiContext* vContextPtr, const std::string& vUserDatas) {
ZoneScoped;

assert(vContextPtr);
ImGui::SetCurrentContext(vContextPtr);
if (m_LastExecutedFrame == vCurrentFrame) {
if (m_DilationModule_Comp_2D_Pass_Ptr) {
return m_DilationModule_Comp_2D_Pass_Ptr->DrawDialogsAndPopups(vCurrentFrame, vMaxSize, vContextPtr, vUserDatas);
}
}

return false;
}

void DilationModule::NeedResizeByResizeEvent(ct::ivec2* vNewSize, const uint32_t* vCountColorBuffers) {
ZoneScoped;

// do some code

BaseRenderer::NeedResizeByResizeEvent(vNewSize, vCountColorBuffers);
}

//////////////////////////////////////////////////////////////////////////////////////////////
//// TEXTURE SLOT INPUT //////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

void DilationModule::SetTexture(const uint32_t& vBindingPoint, vk::DescriptorImageInfo* vImageInfo, ct::fvec2* vTextureSize) {
ZoneScoped;

if (m_DilationModule_Comp_2D_Pass_Ptr) {
m_DilationModule_Comp_2D_Pass_Ptr->SetTexture(vBindingPoint, vImageInfo, vTextureSize);
}
}

//////////////////////////////////////////////////////////////////////////////////////////////
//// TEXTURE SLOT OUTPUT /////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////

vk::DescriptorImageInfo* DilationModule::GetDescriptorImageInfo(const uint32_t& vBindingPoint, ct::fvec2* vOutSize) {
ZoneScoped;

if (m_DilationModule_Comp_2D_Pass_Ptr) {
return m_DilationModule_Comp_2D_Pass_Ptr->GetDescriptorImageInfo(vBindingPoint, vOutSize);
}

return nullptr;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// CONFIGURATION /////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////

std::string DilationModule::getXml(const std::string& vOffset, const std::string& vUserDatas) {
ZoneScoped;
std::string str;
str += vOffset + "<dilation_module>\n";
str += vOffset + "\t<can_we_render>" + (m_CanWeRender ? "true" : "false") + "</can_we_render>\n";
if (m_DilationModule_Comp_2D_Pass_Ptr) {
str += m_DilationModule_Comp_2D_Pass_Ptr->getXml(vOffset + "\t", vUserDatas);
}
str += vOffset + "</dilation_module>\n";
return str;
}

bool DilationModule::setFromXml(tinyxml2::XMLElement* vElem, tinyxml2::XMLElement* vParent, const std::string& vUserDatas) {
ZoneScoped;

// The value of this child identifies the name of this element
std::string strName;
std::string strValue;
std::string strParentName;

strName = vElem->Value();
if (vElem->GetText())
strValue = vElem->GetText();
if (vParent != nullptr)
strParentName = vParent->Value();

if (strParentName == "dilation_module") {
if (strName == "can_we_render") {
m_CanWeRender = ct::ivariant(strValue).GetB();
}
}
if (m_DilationModule_Comp_2D_Pass_Ptr) {
m_DilationModule_Comp_2D_Pass_Ptr->setFromXml(vElem, vParent, vUserDatas);
}

return true;
}

void DilationModule::AfterNodeXmlLoading() {
ZoneScoped;
if (m_DilationModule_Comp_2D_Pass_Ptr) {
m_DilationModule_Comp_2D_Pass_Ptr->AfterNodeXmlLoading();
}
}
Loading

0 comments on commit 2b574e8

Please sign in to comment.