diff --git a/Assets/Scenes/Scene2.shade b/Assets/Scenes/Scene2.shade index e14f32cb..11078394 100644 --- a/Assets/Scenes/Scene2.shade +++ b/Assets/Scenes/Scene2.shade @@ -157,7 +157,7 @@ Scale: {x: 1, y: 1, z: 1} IsActive: true classSHADE::SHParticleEmitterComponent: - Emission Count: 7 + Emission Count: 15 Is Passive: true Emission Interval: 0.0939999968 Min Life: 2 @@ -166,8 +166,11 @@ Maximum Speed: 6 Minimum Size: 0 Maximum Size: 0.5 + Size Decay: 0.990999997 Angular Ranges And Offset: {x: 6.19999981, y: 1.10000002, z: 0, w: 0.100000001} - Rotation Speed: 0 - Texture Asset ID: 63456868 + Rotation Speed: 0.0309999995 + Rotation Decay: 0.0199999996 + Texture Asset ID: 0 + Custom Update Shader Asset ID: 0 IsActive: true Scripts: ~ \ No newline at end of file diff --git a/Assets/Shaders/ParticleEmit_CS.glsl b/Assets/Shaders/ParticleEmit_CS.glsl index 444af6db..45cea313 100644 --- a/Assets/Shaders/ParticleEmit_CS.glsl +++ b/Assets/Shaders/ParticleEmit_CS.glsl @@ -10,8 +10,11 @@ struct EmitterParameters float minSpeed; float maxSpeed; float rotationSpeed; - uint textureIndex; + float rotationDecay; vec4 lifeAndSizeRange; // min life, max life, min size, max size + float sizeDecay; + uint textureIndex; + float padding[2]; }; struct ParticleData @@ -165,14 +168,16 @@ void main() // Set size of particle particle.scaleAndDecay.x = particleSize; - particle.scaleAndDecay.z = particleSize; + particle.scaleAndDecay.y = particleSize; + particle.scaleAndDecay.z = emitterParams.data.sizeDecay; + particle.scaleAndDecay.w = emitterParams.data.sizeDecay; // Set the texture for the particle particle.textureIndex = emitterParams.data.textureIndex; // Set orientation and rotation speed if (emitterParams.data.rotationSpeed != 0.0f) - particle.orientationSpeedDecay = vec4 (rand(seed) * PI, emitterParams.data.rotationSpeed, 0.0f, 0.0f); + particle.orientationSpeedDecay = vec4 (rand(seed) * PI, emitterParams.data.rotationSpeed, emitterParams.data.rotationDecay, 0.0f); else particle.orientationSpeedDecay = vec4 (0.0f); diff --git a/Assets/Shaders/ParticleEmit_CS.shshaderb b/Assets/Shaders/ParticleEmit_CS.shshaderb index f0d78240..b003ba77 100644 Binary files a/Assets/Shaders/ParticleEmit_CS.shshaderb and b/Assets/Shaders/ParticleEmit_CS.shshaderb differ diff --git a/Assets/Shaders/ParticleUpdate_CS.glsl b/Assets/Shaders/ParticleUpdate_CS.glsl index 5882a561..43d4893d 100644 --- a/Assets/Shaders/ParticleUpdate_CS.glsl +++ b/Assets/Shaders/ParticleUpdate_CS.glsl @@ -123,7 +123,15 @@ void main() particle.velocity += particle.acceleration; particle.life -= genericDataBuffer.data.dt; particle.orientationSpeedDecay.x += particle.orientationSpeedDecay.y; - particle.orientationSpeedDecay.y -= particle.orientationSpeedDecay.z * genericDataBuffer.data.dt; + particle.scaleAndDecay.x *= particle.scaleAndDecay.z; + particle.scaleAndDecay.y *= particle.scaleAndDecay.w; + + if (particle.orientationSpeedDecay.y > 0.0f) + { + particle.orientationSpeedDecay.y -= particle.orientationSpeedDecay.z * genericDataBuffer.data.dt; + if (particle.orientationSpeedDecay.y < 0.0f) + particle.orientationSpeedDecay.y = 0.0f; + } if (particle.life < 0.0f || particle.scaleAndDecay.x < 0.0f || particle.scaleAndDecay.y < 0.0f) { diff --git a/Assets/Shaders/ParticleUpdate_CS.shshaderb b/Assets/Shaders/ParticleUpdate_CS.shshaderb index 963f2ec9..63a79d5a 100644 Binary files a/Assets/Shaders/ParticleUpdate_CS.shshaderb and b/Assets/Shaders/ParticleUpdate_CS.shshaderb differ diff --git a/Assets/Shaders/Particle_VS.glsl b/Assets/Shaders/Particle_VS.glsl index 02830753..5004cea1 100644 --- a/Assets/Shaders/Particle_VS.glsl +++ b/Assets/Shaders/Particle_VS.glsl @@ -81,7 +81,7 @@ void main() vec3 normalized = normalize (particle.velocity.xyz); float angle = particle.orientationSpeedDecay.x; // float angle = atan (normalized.y, normalized.x); - vec2 particleScaleData = particle.scaleAndDecay.xz; // x and y + vec2 particleScaleData = particle.scaleAndDecay.xy; // x and y mat3 rotate = mat3 (1.0f); rotate[0][0] = cos(angle); diff --git a/Assets/Shaders/Particle_VS.shshaderb b/Assets/Shaders/Particle_VS.shshaderb index 58000df2..0a9be96d 100644 Binary files a/Assets/Shaders/Particle_VS.shshaderb and b/Assets/Shaders/Particle_VS.shshaderb differ diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 0fc66afb..2edadbbc 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -830,6 +830,7 @@ namespace SHADE SHEditorWidgets::DragFloat("Max Life", [comp = component]() {return comp->GetMaxLife(); }, [comp = component](float val) {comp->SetMaxLife(val); }); SHEditorWidgets::DragFloat("Min Size", [comp = component]() {return comp->GetMinSize(); }, [comp = component](float val) {comp->SetMinSize(val); }); SHEditorWidgets::DragFloat("Max Size", [comp = component]() {return comp->GetMaxSize(); }, [comp = component](float val) {comp->SetMaxSize(val); }); + SHEditorWidgets::DragFloat("Size Decay", [comp = component]() {return comp->GetSizeDecayMult(); }, [comp = component](float val) {comp->SetSizeDecayMult(val); }, {}, 0.0001f); SHEditorWidgets::DragVec4("Angles and Offsets", {"yaw", "bank", "yaw off", "bank off"}, [comp = component]() @@ -872,6 +873,16 @@ namespace SHADE comp->SetRotationSpeed(val); }); + SHEditorWidgets::DragFloat("Rotation Decay", + [comp = component]() + { + return comp->GetRotationDecay(); + }, + [comp = component](float val) + { + comp->SetRotationDecay(val); + }); + SHEditorWidgets::DragInt("Texture Index", [comp = component]() { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp index 8293604c..5454cf31 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.cpp @@ -67,6 +67,11 @@ namespace SHADE cpuEmitterData.rotationSpeed = speed; } + void SHParticleEmitterComponent::SetRotationDecay(float decay) noexcept + { + cpuEmitterData.rotationDecay = decay; + } + void SHParticleEmitterComponent::SetTextureIndex(uint32_t index) noexcept { cpuEmitterData.textureIndex = index; @@ -92,6 +97,11 @@ namespace SHADE cpuEmitterData.lifeAndSizeRange.w = size; } + void SHParticleEmitterComponent::SetSizeDecayMult(float decay) noexcept + { + cpuEmitterData.sizeDecayMult = decay; + } + void SHParticleEmitterComponent::SetCustomUpdateShader(Handle shaderModule) noexcept { customUpdateShader = shaderModule; @@ -143,6 +153,11 @@ namespace SHADE return cpuEmitterData.rotationSpeed; } + float SHParticleEmitterComponent::GetRotationDecay(void) const noexcept + { + return cpuEmitterData.rotationDecay; + } + uint32_t SHParticleEmitterComponent::GetTextureIndex(void) const noexcept { return cpuEmitterData.textureIndex; @@ -169,6 +184,11 @@ namespace SHADE } + float SHParticleEmitterComponent::GetSizeDecayMult(void) const noexcept + { + return cpuEmitterData.sizeDecayMult; + } + Handle SHParticleEmitterComponent::GetCustomUpdateShader(void) const noexcept { return customUpdateShader; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.h b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.h index 616410cd..d9c26666 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Particles/SHParticleEmitterComponent.h @@ -1,6 +1,7 @@ #pragma once #include "Resource/SHHandle.h" +#include "Math/Vector/SHVec2.h" #include "Math/Vector/SHVec4.h" #include "ECS_Base/Components/SHComponent.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" @@ -32,11 +33,21 @@ namespace SHADE //! Rotational speed of the quad float rotationSpeed; - //! Texture used by the particle - uint32_t textureIndex; + //! Rotation decay rate + float rotationDecay; //! Spawn lifetime and size range (min and max) SHVec4 lifeAndSizeRange; + + //! Size decay for particles + float sizeDecayMult; + + //! Texture used by the particle + uint32_t textureIndex; + + //! Padding for the shader struct + float padding[2]; + }; struct GPUParticleStruct @@ -139,9 +150,11 @@ namespace SHADE void SetMinSpeed (float speed) noexcept; void SetMaxSpeed (float speed) noexcept; void SetRotationSpeed (float speed) noexcept; + void SetRotationDecay (float decay) noexcept; void SetTextureIndex (uint32_t index) noexcept; void SetMinSize (float size) noexcept; void SetMaxSize (float size) noexcept; + void SetSizeDecayMult (float decay) noexcept; void SetCustomUpdateShader (Handle shaderModule) noexcept; uint32_t GetEmissionCount (void) const noexcept; @@ -153,9 +166,11 @@ namespace SHADE float GetMinSpeed (void) const noexcept; float GetMaxSpeed (void) const noexcept; float GetRotationSpeed (void) const noexcept; + float GetRotationDecay (void) const noexcept; uint32_t GetTextureIndex (void) const noexcept; float GetMinSize (void) const noexcept; float GetMaxSize (void) const noexcept; + float GetSizeDecayMult (void) const noexcept; Handle GetCustomUpdateShader (void) const noexcept; /*-----------------------------------------------------------------------*/ diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index c1fa8548..44ed0888 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -512,9 +512,11 @@ namespace YAML static constexpr std::string_view ANGULAR_RANGES_OFFSET_TAG = "Angular Ranges And Offset"; static constexpr std::string_view MIN_SIZE_TAG = "Minimum Size"; static constexpr std::string_view MAX_SIZE_TAG = "Maximum Size"; + static constexpr std::string_view SIZE_DECAY_TAG = "Size Decay"; static constexpr std::string_view MIN_SPEED_TAG = "Minimum 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_DECAY_TAG = "Rotation Decay"; 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"; @@ -530,8 +532,10 @@ namespace YAML node[MAX_SPEED_TAG.data()] = rhs.GetMaxSpeed(); node[MIN_SIZE_TAG.data()] = rhs.GetMinSize(); node[MAX_SIZE_TAG.data()] = rhs.GetMaxSize(); + node[SIZE_DECAY_TAG.data()] = rhs.GetSizeDecayMult(); node[ANGULAR_RANGES_OFFSET_TAG.data()] = rhs.GetAngularRangesAndOffsets(); node[ROTATION_SPEED_TAG.data()] = rhs.GetRotationSpeed(); + node[ROTATION_DECAY_TAG.data()] = rhs.GetRotationDecay(); node[TEXTURE_ASSET_ID_TAG.data()] = rhs.GetTextureAssetID(); node[CUSTOM_UPDATE_SHADER_ASSET_ID_TAG.data()] = rhs.GetCustomUpdateShaderAssetID(); @@ -556,6 +560,9 @@ namespace YAML if (node[MAX_LIFE_TAG.data()].IsDefined()) rhs.SetMaxLife(node[MAX_LIFE_TAG.data()].as()); + if (node[SIZE_DECAY_TAG.data()].IsDefined()) + rhs.SetSizeDecayMult(node[SIZE_DECAY_TAG.data()].as()); + if (node[ANGULAR_RANGES_OFFSET_TAG.data()].IsDefined()) rhs.SetAngularRangesAndOffsets(node[ANGULAR_RANGES_OFFSET_TAG.data()].as()); @@ -571,6 +578,10 @@ namespace YAML if (node[ROTATION_SPEED_TAG.data()].IsDefined()) rhs.SetRotationSpeed(node[ROTATION_SPEED_TAG.data()].as()); + if (node[ROTATION_DECAY_TAG.data()].IsDefined()) + rhs.SetRotationDecay(node[ROTATION_DECAY_TAG.data()].as()); + + if (node[TEXTURE_ASSET_ID_TAG.data()].IsDefined()) { AssetID id = node[TEXTURE_ASSET_ID_TAG.data()].as();