diff --git a/Assets/Scenes/Level2.shade b/Assets/Scenes/Level2.shade index 7a052425..ada9fb8a 100644 --- a/Assets/Scenes/Level2.shade +++ b/Assets/Scenes/Level2.shade @@ -3128,23 +3128,23 @@ Scale: {x: 1.00000012, y: 1, z: 1.00000012} IsActive: true classSHADE::SHParticleEmitterComponent: - Emission Count: 4 + Emission Count: 2 Is Passive: false Emission Interval: 0 - Min Life: 0 - Max Life: 0.5 + Min Life: 0.100000001 + Max Life: 2 Minimum Speed: 1 Maximum Speed: 1.5 - Minimum Size: 0 - Maximum Size: 0.5 - Size Decay: 0.907999992 - Angular Ranges And Offset: {x: 6.19999981, y: 3.1400001, z: 0, w: 1.70000005} + Minimum Size: 0.100000001 + Maximum Size: 0.100000001 + Size Decay: 0.907000005 + Angular Ranges And Offset: {x: 0.779999971, y: 0, z: -1.57070005, w: 0} Rotation Speed: 0.805999994 Rotation Decay: 0 - Texture Asset ID: 0 - Custom Update Shader Asset ID: 0 + Texture Asset ID: 56224060 + Custom Update Shader Asset ID: 42141152 Color Tint: {x: 1, y: 1, z: 1, w: 1} - Acceleration: {x: 0, y: 0.0500000007, z: 0.100000001} + Acceleration: {x: 0, y: 0, z: 0} IsActive: true Scripts: ~ - EID: 239 diff --git a/Assets/Scripts/Gameplay/Player/PlayerStates/UT_PlayerWalkState.cs b/Assets/Scripts/Gameplay/Player/PlayerStates/UT_PlayerWalkState.cs index ad79b3de..68802e1f 100644 --- a/Assets/Scripts/Gameplay/Player/PlayerStates/UT_PlayerWalkState.cs +++ b/Assets/Scripts/Gameplay/Player/PlayerStates/UT_PlayerWalkState.cs @@ -1,4 +1,4 @@ -using SHADE; +using SHADE; using SHADE_Scripting.Audio; using System; @@ -48,6 +48,12 @@ public class PlayerWalkState : BaseState if (timer > delay) { + + if (machine.GetScript().tranform.LocalEulerAngles.y > 0.0f) + machine.GetScript().smoke.AngularOffsets = new Vector2(machine.GetScript().tranform.LocalEulerAngles.y - (MathF.PI * 1.5f), machine.GetScript().smoke.AngularOffsets.y); + else + machine.GetScript().smoke.AngularOffsets = new Vector2(machine.GetScript().tranform.LocalEulerAngles.y + (MathF.PI * 0.5f), machine.GetScript().smoke.AngularOffsets.y); + AudioHandler.audioClipHandlers["footsteps"].Play(); machine.GetScript().smoke.Emit(); timer = 0; diff --git a/Assets/Shaders/ParticleEmit_CS.glsl b/Assets/Shaders/ParticleEmit_CS.glsl index b2f81a05..96ad1ef4 100644 --- a/Assets/Shaders/ParticleEmit_CS.glsl +++ b/Assets/Shaders/ParticleEmit_CS.glsl @@ -139,19 +139,20 @@ void main() // emit particle from emitter position particle.position = vec4 (emitterPosition.xyz, 1.0f); - vec2 eulerAngles = vec2 (rand(seed) * angularRangesAndOffsets.x + angularRangesAndOffsets.z, - rand(seed) * angularRangesAndOffsets.y + angularRangesAndOffsets.w); + vec2 eulerAngles = vec2 ((rand(seed) - 0.5f) * angularRangesAndOffsets.x + angularRangesAndOffsets.z, + (rand(seed) - 0.5f) * angularRangesAndOffsets.y + angularRangesAndOffsets.w); // Set its velocity // particle.velocity.xyz = vec3 (cos(eulerAngles.x) * cos(eulerAngles.y), // sin(eulerAngles.x) * cos(eulerAngles.y), // sin(eulerAngles.y)); + float heading = eulerAngles.x; float bank = eulerAngles.y; float cb = cos(bank); float sb = sin(bank); - float ch = cos (eulerAngles.x); - float sh = sin (eulerAngles.x); + float ch = cos (heading); + float sh = sin (heading); float cp = cos (0.0f); float sp = sin (0.0f); diff --git a/Assets/Shaders/ParticleEmit_CS.shshaderb b/Assets/Shaders/ParticleEmit_CS.shshaderb index 08972d9d..fb928683 100644 Binary files a/Assets/Shaders/ParticleEmit_CS.shshaderb and b/Assets/Shaders/ParticleEmit_CS.shshaderb differ diff --git a/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.glsl b/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.glsl new file mode 100644 index 00000000..0c9600f5 --- /dev/null +++ b/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.glsl @@ -0,0 +1,173 @@ +#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; + vec4 colorTint; + 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]; + + if (particle.life > 0.0f) + { + + // update position from velocity + particle.position.xyz += particle.velocity.xyz * genericDataBuffer.data.dt; + particle.velocity += particle.acceleration; + particle.life -= genericDataBuffer.data.dt; + particle.orientationSpeedDecay.x += particle.orientationSpeedDecay.y; + // particle.scaleAndDecay.x *= particle.scaleAndDecay.z; + // particle.scaleAndDecay.y *= particle.scaleAndDecay.w; + + if (particle.position.w == 0.0f) + { + particle.scaleAndDecay.x *= particle.scaleAndDecay.z; + particle.scaleAndDecay.y *= particle.scaleAndDecay.w; + if (particle.scaleAndDecay.x < 0.0f) + { + particle.scaleAndDecay.x = 0.0f; + particle.scaleAndDecay.y = 0.0f; + } + } + else + { + particle.scaleAndDecay.x /= particle.scaleAndDecay.z; + particle.scaleAndDecay.y /= particle.scaleAndDecay.w; + if (particle.scaleAndDecay.x > 0.2f) + particle.position.w = 0.0f; + } + + + 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) + { + 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/ParticleUpdateGrowThenShrink_CS.shshaderb b/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.shshaderb new file mode 100644 index 00000000..babded60 Binary files /dev/null and b/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.shshaderb differ diff --git a/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.shshaderb.shmeta b/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.shshaderb.shmeta new file mode 100644 index 00000000..bf67f4ee --- /dev/null +++ b/Assets/Shaders/ParticleUpdateGrowThenShrink_CS.shshaderb.shmeta @@ -0,0 +1,3 @@ +Name: ParticleUpdateGrowThenShrink_CS +ID: 42141152 +Type: 2 diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp index 208134bf..961e321a 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorComponentView.hpp @@ -913,12 +913,6 @@ namespace SHADE { comp->SetTextureAssetID(val); }); - ImGui::SameLine(); - if (ImGui::Button("Reset")) - { - component->SetTextureAssetID(0); - component->SetTextureIndex(0); - } if (SHDragDrop::BeginTarget()) { @@ -940,6 +934,13 @@ namespace SHADE SHDragDrop::EndTarget(); } } + ImGui::SameLine(); + if (ImGui::Button("Reset")) + { + component->SetTextureAssetID(0); + component->SetTextureIndex(0); + } + SHEditorWidgets::InputText("Custom Update Shader", [comp = component]() { diff --git a/SHADE_Engine/src/Serialization/SHYAMLConverters.h b/SHADE_Engine/src/Serialization/SHYAMLConverters.h index 8805ed41..de57e45d 100644 --- a/SHADE_Engine/src/Serialization/SHYAMLConverters.h +++ b/SHADE_Engine/src/Serialization/SHYAMLConverters.h @@ -576,6 +576,9 @@ namespace YAML if (node[MAX_SPEED_TAG.data()].IsDefined()) rhs.SetMaxSpeed (node[MAX_SPEED_TAG.data()].as()); + if (node[MIN_SIZE_TAG.data()].IsDefined()) + rhs.SetMinSize(node[MIN_SIZE_TAG.data()].as()); + if (node[MAX_SIZE_TAG.data()].IsDefined()) rhs.SetMaxSize(node[MAX_SIZE_TAG.data()].as()); @@ -619,7 +622,7 @@ namespace YAML //gfxSystem->BuildTextures(); rhs.SetCustomUpdateShader(shaderModule); - rhs.SetTextureAssetID(id); + rhs.SetCustomUpdateShaderAssetID(id); } return true;