diff --git a/Assets/Shaders/ParticleUpdateRandomAcc_CS.glsl b/Assets/Shaders/ParticleUpdateRandomAcc_CS.glsl new file mode 100644 index 00000000..bf500255 --- /dev/null +++ b/Assets/Shaders/ParticleUpdateRandomAcc_CS.glsl @@ -0,0 +1,146 @@ +#version 450 + +layout(local_size_x = 128) in; + +struct DrawArraysIndirectArgs +{ + uint count; + uint instanceCount; + uint first; + uint baseInstance; +}; + +struct ParticleData +{ + vec4 position; + vec4 orientationSpeedDecay; + vec4 velocity; + vec4 acceleration; + vec4 scaleAndDecay; + float life; + uint textureIndex; +}; + +struct GenericData +{ + //! Delta time + float dt; + + //! Elapsed time of the application + float elapsedTime; + + //! Viewport width of the scene (excluding imgui, that means smaller than window) + uint viewportWidth; + + //! Ditto but for height + uint viewportHeight; +}; + +layout(set = 1, binding = 0) uniform CameraData +{ + vec4 position; + mat4 vpMat; + mat4 viewMat; + mat4 projMat; +} cameraData; + + +layout (set = 0, binding = 0) uniform GenericDataBuffer +{ + GenericData data; +} genericDataBuffer; + +layout (std430, set = 2, binding = 1) coherent restrict readonly buffer ParticlesInputBuffer +{ + ParticleData data[]; +} inputParticles; + +// output buffer not needed +layout (std430, set = 2, binding = 2) coherent restrict buffer ParticlesOutputBuffer +{ + ParticleData data[]; +} outputParticles; + +layout (std430, set = 2, binding = 3) coherent restrict buffer ParticlesFreelistBuffer +{ + int freeCount; + int freeIndices[]; + +} freelist; + +layout (std430, set = 2, binding = 4) coherent restrict buffer IndicesData +{ + uint indices[]; +}; + +layout (std140, set = 2, binding = 5) coherent restrict buffer IndirectDrawArgs +{ + DrawArraysIndirectArgs indirectArgs; +}; + +// push constants +layout(std140, push_constant) uniform EmitterPushConstant +{ + vec4 emitterPosition; + uint emissionCount; + +} emitterPushConstant; + +uint pcg_hash(uint seed) +{ + uint state = seed * 747796405u + 2891336453u; + uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u; + return (word >> 22u) ^ word; +} + +// Used to advance the PCG state. +uint rand_pcg(inout uint rng_state) +{ + uint state = rng_state; + rng_state = rng_state * 747796405u + 2891336453u; + uint word = ((state >> ((state >> 28u) + 4u)) ^ state) * 277803737u; + return (word >> 22u) ^ word; +} + +// Advances the prng state and returns the corresponding random float. +float rand(inout uint state) +{ + uint x = rand_pcg(state); + state = x; + return float(x)*uintBitsToFloat(0x2f800004u); +} + +void main() +{ + uint index = gl_GlobalInvocationID.x; + + ParticleData particle = inputParticles.data[index]; + + // Get seed for randomization + uint pixel_index = uint (particle.position.x + particle.position.y + floatBitsToUint(genericDataBuffer.data.elapsedTime) * (gl_GlobalInvocationID.x + 1)); + uint seed = pcg_hash (pixel_index); + + if (particle.life > 0.0f) + { + // update position from velocity + particle.position += particle.velocity * genericDataBuffer.data.dt; + particle.velocity += vec4 (rand(seed) * particle.acceleration.x, rand(seed) * particle.acceleration.y, rand(seed) * particle.acceleration.z, 1.0f); + particle.life -= genericDataBuffer.data.dt; + + if (particle.life < 0.0f || particle.scaleAndDecay.x < 0.0f || particle.scaleAndDecay.y < 0.0f) + { + particle.life = 0.0f; + particle.position.x = 9999.0f; + + outputParticles.data[index] = particle; + freelist.freeIndices[atomicAdd(freelist.freeCount, 1)] = int (index); + return; + } + + uint drawIndex = atomicAdd (indirectArgs.instanceCount, 1); + indices[drawIndex] = index; + + } + + outputParticles.data[index] = particle; +} \ No newline at end of file diff --git a/Assets/Shaders/ParticleUpdateRandomAcc_CS.shshaderb b/Assets/Shaders/ParticleUpdateRandomAcc_CS.shshaderb new file mode 100644 index 00000000..370f9965 Binary files /dev/null and b/Assets/Shaders/ParticleUpdateRandomAcc_CS.shshaderb differ diff --git a/Assets/Shaders/ParticleUpdateRandomAcc_CS.shshaderb.shmeta b/Assets/Shaders/ParticleUpdateRandomAcc_CS.shshaderb.shmeta new file mode 100644 index 00000000..ede00748 --- /dev/null +++ b/Assets/Shaders/ParticleUpdateRandomAcc_CS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ParticleUpdateRandomAcc_CS +ID: 35838633 +Type: 2 diff --git a/Assets/Shaders/ParticleUpdate_CS.glsl b/Assets/Shaders/ParticleUpdate_CS.glsl index 59b126c2..5882a561 100644 --- a/Assets/Shaders/ParticleUpdate_CS.glsl +++ b/Assets/Shaders/ParticleUpdate_CS.glsl @@ -122,6 +122,8 @@ void main() particle.position += particle.velocity * genericDataBuffer.data.dt; particle.velocity += particle.acceleration; particle.life -= genericDataBuffer.data.dt; + particle.orientationSpeedDecay.x += particle.orientationSpeedDecay.y; + particle.orientationSpeedDecay.y -= particle.orientationSpeedDecay.z * genericDataBuffer.data.dt; 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 d9fd3754..963f2ec9 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 211bb4de..02830753 100644 --- a/Assets/Shaders/Particle_VS.glsl +++ b/Assets/Shaders/Particle_VS.glsl @@ -79,7 +79,7 @@ void main() ParticleData particle = outputParticles.data[indices[gl_InstanceIndex]]; vec3 normalized = normalize (particle.velocity.xyz); - float angle = 1.1f; + float angle = particle.orientationSpeedDecay.x; // float angle = atan (normalized.y, normalized.x); vec2 particleScaleData = particle.scaleAndDecay.xz; // x and y diff --git a/Assets/Shaders/Particle_VS.shshaderb b/Assets/Shaders/Particle_VS.shshaderb index 492a926c..58000df2 100644 Binary files a/Assets/Shaders/Particle_VS.shshaderb and b/Assets/Shaders/Particle_VS.shshaderb differ diff --git a/Assets/Shaders/ShinyHighlight_VS.shshaderb b/Assets/Shaders/ShinyHighlight_VS.shshaderb index 95eac304..3b7e8d72 100644 Binary files a/Assets/Shaders/ShinyHighlight_VS.shshaderb and b/Assets/Shaders/ShinyHighlight_VS.shshaderb differ diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 4aa03a4b..0fc66afb 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -865,11 +865,11 @@ namespace SHADE SHEditorWidgets::DragFloat("Rotation Speed", [comp = component]() { - return comp->GetMaxSpeed(); + return comp->GetRotationSpeed(); }, [comp = component](float val) { - comp->SetMaxSpeed(val); + comp->SetRotationSpeed(val); }); SHEditorWidgets::DragInt("Texture Index", diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp index 38944882..f2f8db7a 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp +++ b/SHADE_Engine/src/Graphics/Pipeline/SHVkPipeline.cpp @@ -299,6 +299,8 @@ namespace SHADE , created{ false } { + if (pipelineLayout) + pipelineLayout->AddCallback([this]() {ConstructPipeline(); }); } diff --git a/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.cpp b/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.cpp index 49188181..8f41d24a 100644 --- a/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.cpp +++ b/SHADE_Engine/src/Graphics/Shaders/SHVkShaderModule.cpp @@ -94,8 +94,8 @@ namespace SHADE Recompile(); - //for (auto& callback : onChangeCallbacks) - // callback(); + for (auto& callback : onChangeCallbacks) + callback(); } void SHVkShaderModule::AddCallback(ChangeCallback&& callback) noexcept