Improved particles and trajectory rendering #430
|
@ -152,8 +152,8 @@
|
||||||
NumberOfChildren: 0
|
NumberOfChildren: 0
|
||||||
Components:
|
Components:
|
||||||
Transform Component:
|
Transform Component:
|
||||||
Translate: {x: 0, y: 0, z: 0}
|
Translate: {x: 0, y: 0.823412895, z: -4.31447983}
|
||||||
Rotate: {x: 0, y: 0, z: 0}
|
Rotate: {x: -0, y: 0, z: -0}
|
||||||
Scale: {x: 1, y: 1, z: 1}
|
Scale: {x: 1, y: 1, z: 1}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
classSHADE::SHParticleEmitterComponent:
|
classSHADE::SHParticleEmitterComponent:
|
||||||
|
|
|
@ -87,6 +87,11 @@ namespace SHADE
|
||||||
cpuEmitterData.lifeAndSizeRange.w = size;
|
cpuEmitterData.lifeAndSizeRange.w = size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHParticleEmitterComponent::SetCustomShader(Handle<SHVkShaderModule> shaderModule) noexcept
|
||||||
|
{
|
||||||
|
customUpdateShader = shaderModule;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t SHParticleEmitterComponent::GetEmissionCount(void) const noexcept
|
uint32_t SHParticleEmitterComponent::GetEmissionCount(void) const noexcept
|
||||||
{
|
{
|
||||||
return emissionCount;
|
return emissionCount;
|
||||||
|
@ -154,4 +159,9 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Handle<SHVkShaderModule> SHParticleEmitterComponent::GetCustomShader(void) const noexcept
|
||||||
|
{
|
||||||
|
return customUpdateShader;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -11,10 +11,13 @@ namespace SHADE
|
||||||
class SHVkBuffer;
|
class SHVkBuffer;
|
||||||
class SHVkDescriptorSetGroup;
|
class SHVkDescriptorSetGroup;
|
||||||
class SHVkDescriptorSetLayout;
|
class SHVkDescriptorSetLayout;
|
||||||
|
class SHVkShaderModule;
|
||||||
|
class SHVkPipeline;
|
||||||
|
|
||||||
class SHParticleEmitterComponent : public SHComponent
|
class SHParticleEmitterComponent : public SHComponent
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct GPUEmitterStruct
|
struct GPUEmitterStruct
|
||||||
{
|
{
|
||||||
//! Angular ranges of emission
|
//! Angular ranges of emission
|
||||||
|
@ -94,6 +97,12 @@ namespace SHADE
|
||||||
//! will contain 2 bindings that point to 2 buffers (input and output).
|
//! will contain 2 bindings that point to 2 buffers (input and output).
|
||||||
Handle<SHVkDescriptorSetGroup> particleDescriptorSet;
|
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.
|
//! Emitter's data on the CPU side. To be copied to GPU.
|
||||||
GPUEmitterStruct cpuEmitterData;
|
GPUEmitterStruct cpuEmitterData;
|
||||||
|
|
||||||
|
@ -131,6 +140,7 @@ namespace SHADE
|
||||||
void SetTextureAssetID (AssetID id);
|
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;
|
||||||
|
|
||||||
|
|
||||||
uint32_t GetEmissionCount (void) const noexcept;
|
uint32_t GetEmissionCount (void) const noexcept;
|
||||||
|
@ -146,6 +156,8 @@ namespace SHADE
|
||||||
AssetID GetTextureAssetID (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;
|
||||||
|
|
||||||
|
|
||||||
friend class SHParticleSubSystem;
|
friend class SHParticleSubSystem;
|
||||||
|
|
||||||
|
|
|
@ -240,6 +240,34 @@ namespace SHADE
|
||||||
postUpdateBarriers.push_back(drawDataBarrierPostUpdate);
|
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
|
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;
|
descPool = inDescPool;
|
||||||
|
@ -416,13 +444,22 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
/* EMITTING PARTICLES DONE, BEGIN UPDATES.... */
|
/* EMITTING PARTICLES DONE, BEGIN UPDATES.... */
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
// bind the pipeline for updating
|
|
||||||
cmdBuffer->BindPipeline(defaultUpdatePipelineData.pipeline);
|
|
||||||
|
|
||||||
for (auto& emitter : emitters)
|
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)
|
if (emitter.isActive)
|
||||||
UpdateCompoennt(cmdBuffer, emitter, frameIndex);
|
UpdateCompoennt(cmdBuffer, emitter, frameIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,12 @@ namespace SHADE
|
||||||
static constexpr uint32_t DYOFF_INDEX_INDICES_DATA = 3;
|
static constexpr uint32_t DYOFF_INDEX_INDICES_DATA = 3;
|
||||||
static constexpr uint32_t DYOFF_INDEX_DRAW_DATA = 4;
|
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.
|
// To hold data for a pipeline and pipeline layout.
|
||||||
// We want this here because particles require 3 pipeline sets:
|
// We want this here because particles require 3 pipeline sets:
|
||||||
|
@ -76,6 +82,8 @@ namespace SHADE
|
||||||
//! Desc pool for particle component desc set allocation
|
//! Desc pool for particle component desc set allocation
|
||||||
Handle<SHVkDescriptorPool> descPool;
|
Handle<SHVkDescriptorPool> descPool;
|
||||||
|
|
||||||
|
std::unordered_map<Handle<SHVkShaderModule>, CustomPipeline> customUpdatePipelineCache;
|
||||||
|
|
||||||
|
|
||||||
void InitializeComponent (SHParticleEmitterComponent& comp) noexcept;
|
void InitializeComponent (SHParticleEmitterComponent& comp) noexcept;
|
||||||
void EmitComponent (Handle<SHVkCommandBuffer> cmdBuffer, SHParticleEmitterComponent& comp, uint32_t frameIndex) 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;
|
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:
|
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;
|
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;
|
||||||
|
|
||||||
|
|
|
@ -574,7 +574,8 @@ namespace YAML
|
||||||
AssetID id = node[TEXTURE_ASSET_ID_TAG.data()].as<AssetID>();
|
AssetID id = node[TEXTURE_ASSET_ID_TAG.data()].as<AssetID>();
|
||||||
|
|
||||||
Handle<SHTexture> texture = SHResourceManager::LoadOrGet<SHTexture>(id);
|
Handle<SHTexture> texture = SHResourceManager::LoadOrGet<SHTexture>(id);
|
||||||
gfxSystem->BuildTextures();
|
SHResourceManager::FinaliseChanges();
|
||||||
|
//gfxSystem->BuildTextures();
|
||||||
|
|
||||||
rhs.SetTextureIndex(texture->TextureArrayIndex);
|
rhs.SetTextureIndex(texture->TextureArrayIndex);
|
||||||
rhs.SetTextureAssetID(id);
|
rhs.SetTextureAssetID(id);
|
||||||
|
|
Loading…
Reference in New Issue