Improved particles and trajectory rendering #430

Merged
Xenosas1337 merged 19 commits from SP3-1-Rendering into main 2023-03-20 16:55:29 +08:00
5 changed files with 88 additions and 10 deletions
Showing only changes of commit 565126c4ba - Show all commits

View File

@ -886,7 +886,7 @@ namespace SHADE
if (AssetID* payload = SHDragDrop::AcceptPayload<AssetID>(SHDragDrop::DRAG_RESOURCE)) if (AssetID* payload = SHDragDrop::AcceptPayload<AssetID>(SHDragDrop::DRAG_RESOURCE))
{ {
Handle<SHTexture> texture = SHResourceManager::LoadOrGet<SHTexture>(*payload); Handle<SHTexture> texture = SHResourceManager::LoadOrGet<SHTexture>(*payload);
gfxSystem->BuildTextures(); gfxSystem->BuildTextures();
if (texture) if (texture)
{ {
@ -901,6 +901,49 @@ namespace SHADE
SHDragDrop::EndTarget(); SHDragDrop::EndTarget();
} }
} }
SHEditorWidgets::InputText("Custom Update Shader",
[comp = component]()
{
auto customShader = comp->GetCustomUpdateShader();
if (customShader)
return customShader->GetName();
else
return std::string{};
},
[comp = component](std::string const& text)
{
}, {}, ImGuiSliderFlags_ReadOnly);
if (SHDragDrop::BeginTarget())
{
if (AssetID* payload = SHDragDrop::AcceptPayload<AssetID>(SHDragDrop::DRAG_RESOURCE))
{
Handle<SHVkShaderModule> shaderModule = SHResourceManager::LoadOrGet<SHVkShaderModule>(*payload);
if (shaderModule)
{
component->SetCustomUpdateShader(shaderModule);
component->SetCustomUpdateShaderAssetID(*payload);
}
else
{
SHLOG_WARNING("[] Attempted to load invalid shader! Custom update shader for particles not set. ");
}
SHDragDrop::EndTarget();
}
}
ImGui::SameLine();
if (ImGui::Button("Reset"))
{
component->SetCustomUpdateShader({});
component->SetCustomUpdateShaderAssetID(INVALID_ASSET_ID);
}
SHEditorWidgets::CheckBox("Is Passive", [comp = component]() {return comp->GetPassive(); }, [comp = component](bool flag) {comp->SetPassive(flag); }); SHEditorWidgets::CheckBox("Is Passive", [comp = component]() {return comp->GetPassive(); }, [comp = component](bool flag) {comp->SetPassive(flag); });

View File

@ -72,11 +72,16 @@ namespace SHADE
cpuEmitterData.textureIndex = index; cpuEmitterData.textureIndex = index;
} }
void SHParticleEmitterComponent::SetTextureAssetID(AssetID id) void SHParticleEmitterComponent::SetTextureAssetID(AssetID id) noexcept
{ {
textureAssetID = id; textureAssetID = id;
} }
void SHParticleEmitterComponent::SetCustomUpdateShaderAssetID(AssetID id) noexcept
{
customUpdateShaderID = id;
}
void SHParticleEmitterComponent::SetMinSize(float size) noexcept void SHParticleEmitterComponent::SetMinSize(float size) noexcept
{ {
cpuEmitterData.lifeAndSizeRange.z = size; cpuEmitterData.lifeAndSizeRange.z = size;
@ -87,7 +92,7 @@ namespace SHADE
cpuEmitterData.lifeAndSizeRange.w = size; cpuEmitterData.lifeAndSizeRange.w = size;
} }
void SHParticleEmitterComponent::SetCustomShader(Handle<SHVkShaderModule> shaderModule) noexcept void SHParticleEmitterComponent::SetCustomUpdateShader(Handle<SHVkShaderModule> shaderModule) noexcept
{ {
customUpdateShader = shaderModule; customUpdateShader = shaderModule;
} }
@ -148,6 +153,11 @@ namespace SHADE
return textureAssetID; return textureAssetID;
} }
AssetID SHParticleEmitterComponent::GetCustomUpdateShaderAssetID(void) const noexcept
{
return customUpdateShaderID;
}
float SHParticleEmitterComponent::GetMinSize(void) const noexcept float SHParticleEmitterComponent::GetMinSize(void) const noexcept
{ {
return cpuEmitterData.lifeAndSizeRange.z; return cpuEmitterData.lifeAndSizeRange.z;
@ -159,7 +169,7 @@ namespace SHADE
} }
Handle<SHVkShaderModule> SHParticleEmitterComponent::GetCustomShader(void) const noexcept Handle<SHVkShaderModule> SHParticleEmitterComponent::GetCustomUpdateShader(void) const noexcept
{ {
return customUpdateShader; return customUpdateShader;
} }

View File

@ -121,6 +121,9 @@ namespace SHADE
//! For the emitter to use to give particles their texture //! For the emitter to use to give particles their texture
AssetID textureAssetID; AssetID textureAssetID;
//! Custom update shaders, similarly with textures, will be identified through their AssetID
AssetID customUpdateShaderID;
public: public:
void OnCreate(void) override final; void OnCreate(void) override final;
void OnDestroy(void) override final; void OnDestroy(void) override final;
@ -137,11 +140,9 @@ namespace SHADE
void SetMaxSpeed (float speed) noexcept; void SetMaxSpeed (float speed) noexcept;
void SetRotationSpeed (float speed) noexcept; void SetRotationSpeed (float speed) noexcept;
void SetTextureIndex (uint32_t index) noexcept; void SetTextureIndex (uint32_t index) noexcept;
void SetTextureAssetID (AssetID id);
void SetMinSize (float size) noexcept; void SetMinSize (float size) noexcept;
void SetMaxSize (float size) noexcept; void SetMaxSize (float size) noexcept;
void SetCustomShader (Handle<SHVkShaderModule> shaderModule) noexcept; void SetCustomUpdateShader (Handle<SHVkShaderModule> shaderModule) noexcept;
uint32_t GetEmissionCount (void) const noexcept; uint32_t GetEmissionCount (void) const noexcept;
bool GetPassive (void) const noexcept; bool GetPassive (void) const noexcept;
@ -153,11 +154,19 @@ namespace SHADE
float GetMaxSpeed (void) const noexcept; float GetMaxSpeed (void) const noexcept;
float GetRotationSpeed (void) const noexcept; float GetRotationSpeed (void) const noexcept;
uint32_t GetTextureIndex (void) const noexcept; uint32_t GetTextureIndex (void) const noexcept;
AssetID GetTextureAssetID (void) const noexcept;
float GetMinSize (void) const noexcept; float GetMinSize (void) const noexcept;
float GetMaxSize (void) const noexcept; float GetMaxSize (void) const noexcept;
Handle<SHVkShaderModule> GetCustomShader (void) const noexcept; Handle<SHVkShaderModule> GetCustomUpdateShader (void) const noexcept;
/*-----------------------------------------------------------------------*/
/* NON-INTERFACE FUNCTIONS */
/*-----------------------------------------------------------------------*/
void SetTextureAssetID(AssetID id) noexcept;
void SetCustomUpdateShaderAssetID(AssetID id) noexcept;
AssetID GetTextureAssetID(void) const noexcept;
AssetID GetCustomUpdateShaderAssetID(void) const noexcept;
friend class SHParticleSubSystem; friend class SHParticleSubSystem;

View File

@ -446,8 +446,10 @@ namespace SHADE
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
for (auto& emitter : emitters) for (auto& emitter : emitters)
{ {
// If custom update shader is a valid handle in the component
if (emitter.customUpdateShader) if (emitter.customUpdateShader)
{ {
// Check if pipeline associated with shader is valid, if not create or get one from the cache
if (!emitter.customUpdatePipeline) if (!emitter.customUpdatePipeline)
emitter.customUpdatePipeline = GetCustomUpdatePipeline(emitter.customUpdateShader); emitter.customUpdatePipeline = GetCustomUpdatePipeline(emitter.customUpdateShader);
@ -456,7 +458,7 @@ namespace SHADE
} }
else else
{ {
// bind the pipeline for updating // bind the default upddate pipeline for updating
cmdBuffer->BindPipeline(defaultUpdatePipelineData.pipeline); cmdBuffer->BindPipeline(defaultUpdatePipelineData.pipeline);
} }

View File

@ -516,6 +516,7 @@ namespace YAML
static constexpr std::string_view MAX_SPEED_TAG = "Maximum Speed"; static constexpr std::string_view MAX_SPEED_TAG = "Maximum Speed";
static constexpr std::string_view ROTATION_SPEED_TAG = "Rotation Speed"; static constexpr std::string_view ROTATION_SPEED_TAG = "Rotation Speed";
static constexpr std::string_view TEXTURE_ASSET_ID_TAG = "Texture Asset ID"; static constexpr std::string_view TEXTURE_ASSET_ID_TAG = "Texture Asset ID";
static constexpr std::string_view CUSTOM_UPDATE_SHADER_ASSET_ID_TAG = "Custom Update Shader Asset ID";
static YAML::Node encode(SHParticleEmitterComponent const& rhs) static YAML::Node encode(SHParticleEmitterComponent const& rhs)
{ {
@ -532,6 +533,7 @@ namespace YAML
node[ANGULAR_RANGES_OFFSET_TAG.data()] = rhs.GetAngularRangesAndOffsets(); node[ANGULAR_RANGES_OFFSET_TAG.data()] = rhs.GetAngularRangesAndOffsets();
node[ROTATION_SPEED_TAG.data()] = rhs.GetRotationSpeed(); node[ROTATION_SPEED_TAG.data()] = rhs.GetRotationSpeed();
node[TEXTURE_ASSET_ID_TAG.data()] = rhs.GetTextureAssetID(); node[TEXTURE_ASSET_ID_TAG.data()] = rhs.GetTextureAssetID();
node[CUSTOM_UPDATE_SHADER_ASSET_ID_TAG.data()] = rhs.GetCustomUpdateShaderAssetID();
return node; return node;
} }
@ -580,6 +582,18 @@ namespace YAML
rhs.SetTextureIndex(texture->TextureArrayIndex); rhs.SetTextureIndex(texture->TextureArrayIndex);
rhs.SetTextureAssetID(id); rhs.SetTextureAssetID(id);
} }
if (node[CUSTOM_UPDATE_SHADER_ASSET_ID_TAG.data()].IsDefined())
{
AssetID id = node[CUSTOM_UPDATE_SHADER_ASSET_ID_TAG.data()].as<AssetID>();
Handle<SHVkShaderModule> shaderModule = SHResourceManager::LoadOrGet<SHVkShaderModule>(id);
SHResourceManager::FinaliseChanges();
//gfxSystem->BuildTextures();
rhs.SetCustomUpdateShader(shaderModule);
rhs.SetTextureAssetID(id);
}
return true; return true;
} }