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
6 changed files with 92 additions and 22 deletions
Showing only changes of commit f787f2b782 - Show all commits

View File

@ -152,8 +152,8 @@
NumberOfChildren: 0
Components:
Transform Component:
Translate: {x: 0, y: 0, z: 0}
Rotate: {x: 0, y: 0, z: 0}
Translate: {x: 0, y: 0.823412895, z: -4.31447983}
Rotate: {x: -0, y: 0, z: -0}
Scale: {x: 1, y: 1, z: 1}
IsActive: true
classSHADE::SHParticleEmitterComponent:

View File

@ -87,6 +87,11 @@ namespace SHADE
cpuEmitterData.lifeAndSizeRange.w = size;
}
void SHParticleEmitterComponent::SetCustomShader(Handle<SHVkShaderModule> shaderModule) noexcept
{
customUpdateShader = shaderModule;
}
uint32_t SHParticleEmitterComponent::GetEmissionCount(void) const noexcept
{
return emissionCount;
@ -154,4 +159,9 @@ namespace SHADE
}
Handle<SHVkShaderModule> SHParticleEmitterComponent::GetCustomShader(void) const noexcept
{
return customUpdateShader;
}
}

View File

@ -11,10 +11,13 @@ namespace SHADE
class SHVkBuffer;
class SHVkDescriptorSetGroup;
class SHVkDescriptorSetLayout;
class SHVkShaderModule;
class SHVkPipeline;
class SHParticleEmitterComponent : public SHComponent
{
private:
struct GPUEmitterStruct
{
//! Angular ranges of emission
@ -94,6 +97,12 @@ namespace SHADE
//! will contain 2 bindings that point to 2 buffers (input and output).
Handle<SHVkDescriptorSetGroup> particleDescriptorSet;
//! Custom update shader for the particles in this component
Handle<SHVkShaderModule> customUpdateShader;
//! Internally the system will bind this pipeline when it detects that this is not a null handle
Handle<SHVkPipeline> customUpdatePipeline;
//! Emitter's data on the CPU side. To be copied to GPU.
GPUEmitterStruct cpuEmitterData;
@ -131,21 +140,24 @@ namespace SHADE
void SetTextureAssetID (AssetID id);
void SetMinSize (float size) noexcept;
void SetMaxSize (float size) noexcept;
void SetCustomShader (Handle<SHVkShaderModule> shaderModule) noexcept;
uint32_t GetEmissionCount (void) const noexcept;
bool GetPassive (void) const noexcept;
float GetEmissionInterval (void) const noexcept;
float GetMinLife (void) const noexcept;
float GetMaxLife (void) const noexcept;
SHVec4 const& GetAngularRangesAndOffsets (void) const noexcept;
float GetMinSpeed (void) const noexcept;
float GetMaxSpeed (void) const noexcept;
float GetRotationSpeed (void) const noexcept;
uint32_t GetTextureIndex (void) const noexcept;
AssetID GetTextureAssetID (void) const noexcept;
float GetMinSize (void) const noexcept;
float GetMaxSize (void) const noexcept;
uint32_t GetEmissionCount (void) const noexcept;
bool GetPassive (void) const noexcept;
float GetEmissionInterval (void) const noexcept;
float GetMinLife (void) const noexcept;
float GetMaxLife (void) const noexcept;
SHVec4 const& GetAngularRangesAndOffsets (void) const noexcept;
float GetMinSpeed (void) const noexcept;
float GetMaxSpeed (void) const noexcept;
float GetRotationSpeed (void) const noexcept;
uint32_t GetTextureIndex (void) const noexcept;
AssetID GetTextureAssetID (void) const noexcept;
float GetMinSize (void) const noexcept;
float GetMaxSize (void) const noexcept;
Handle<SHVkShaderModule> GetCustomShader (void) const noexcept;
friend class SHParticleSubSystem;

View File

@ -240,6 +240,34 @@ namespace SHADE
postUpdateBarriers.push_back(drawDataBarrierPostUpdate);
}
Handle<SHVkPipeline> SHParticleSubSystem::GetCustomUpdatePipeline(Handle<SHVkShaderModule> customUpdateShader) noexcept
{
if (!customUpdateShader)
return {};
if (!customUpdatePipelineCache.contains(customUpdateShader))
{
SHPipelineLayoutParams plParams
{
.shaderModules = {customUpdateShader},
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::PARTICLE_RENEDERING).descSetLayouts
};
auto pipelineLayout = logicalDevice->CreatePipelineLayout(plParams);
auto newPipeline = logicalDevice->CreateComputePipeline(pipelineLayout);
newPipeline->ConstructPipeline();
if (!newPipeline)
return {};
auto customUpdateShaderData = CustomPipeline{ newPipeline, pipelineLayout };
customUpdatePipelineCache.emplace (customUpdateShader, customUpdateShaderData);
}
return customUpdatePipelineCache.at (customUpdateShader).customPipeline;
}
void SHParticleSubSystem::Init(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> inDescPool, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkShaderModule> VS, Handle<SHVkShaderModule> FS, Handle<SHVkShaderModule> emitCS, Handle<SHVkShaderModule> defaultUpdateCS) noexcept
{
descPool = inDescPool;
@ -416,13 +444,22 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* EMITTING PARTICLES DONE, BEGIN UPDATES.... */
/*-----------------------------------------------------------------------*/
// bind the pipeline for updating
cmdBuffer->BindPipeline(defaultUpdatePipelineData.pipeline);
for (auto& emitter : emitters)
{
if (emitter.customUpdateShader)
{
if (!emitter.customUpdatePipeline)
emitter.customUpdatePipeline = GetCustomUpdatePipeline(emitter.customUpdateShader);
// bind the custom pipeline for updating
cmdBuffer->BindPipeline(emitter.customUpdatePipeline);
}
else
{
// bind the pipeline for updating
cmdBuffer->BindPipeline(defaultUpdatePipelineData.pipeline);
}
if (emitter.isActive)
UpdateCompoennt(cmdBuffer, emitter, frameIndex);
}

View File

@ -34,6 +34,12 @@ namespace SHADE
static constexpr uint32_t DYOFF_INDEX_INDICES_DATA = 3;
static constexpr uint32_t DYOFF_INDEX_DRAW_DATA = 4;
struct CustomPipeline
{
Handle<SHVkPipeline> customPipeline;
Handle<SHVkPipelineLayout> customPipelineLayout;
};
// To hold data for a pipeline and pipeline layout.
// We want this here because particles require 3 pipeline sets:
@ -76,6 +82,8 @@ namespace SHADE
//! Desc pool for particle component desc set allocation
Handle<SHVkDescriptorPool> descPool;
std::unordered_map<Handle<SHVkShaderModule>, CustomPipeline> customUpdatePipelineCache;
void InitializeComponent (SHParticleEmitterComponent& comp) noexcept;
void EmitComponent (Handle<SHVkCommandBuffer> cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) noexcept;
@ -84,6 +92,8 @@ namespace SHADE
void PreparePrePostUpdateBarriers (std::vector<vk::BufferMemoryBarrier>& preUpdateBarriers, std::vector<vk::BufferMemoryBarrier>& postUpdateBarriers, SHParticleEmitterComponent const& emitter, uint32_t const EMITTER_INDEX, uint32_t const FRAME_INDEX) noexcept;
Handle<SHVkPipeline> GetCustomUpdatePipeline (Handle<SHVkShaderModule> customUpdateShader) noexcept;
public:
void Init(Handle<SHVkLogicalDevice> device, Handle<SHVkDescriptorPool> inDescPool, Handle<SHVkRenderpass> compatibleRenderpass, Handle<SHSubpass> subpass, Handle<SHVkShaderModule> VS, Handle<SHVkShaderModule> FS, Handle<SHVkShaderModule> emitCS, Handle<SHVkShaderModule> defaultUpdateCS) noexcept;

View File

@ -574,12 +574,13 @@ namespace YAML
AssetID id = node[TEXTURE_ASSET_ID_TAG.data()].as<AssetID>();
Handle<SHTexture> texture = SHResourceManager::LoadOrGet<SHTexture>(id);
gfxSystem->BuildTextures();
SHResourceManager::FinaliseChanges();
//gfxSystem->BuildTextures();
rhs.SetTextureIndex(texture->TextureArrayIndex);
rhs.SetTextureAssetID(id);
}
return true;
}
};