Added particle and bug fixes #437
|
@ -3128,23 +3128,23 @@
|
||||||
Scale: {x: 1.00000012, y: 1, z: 1.00000012}
|
Scale: {x: 1.00000012, y: 1, z: 1.00000012}
|
||||||
IsActive: true
|
IsActive: true
|
||||||
classSHADE::SHParticleEmitterComponent:
|
classSHADE::SHParticleEmitterComponent:
|
||||||
Emission Count: 4
|
Emission Count: 2
|
||||||
Is Passive: false
|
Is Passive: false
|
||||||
Emission Interval: 0
|
Emission Interval: 0
|
||||||
Min Life: 0
|
Min Life: 0.100000001
|
||||||
Max Life: 0.5
|
Max Life: 2
|
||||||
Minimum Speed: 1
|
Minimum Speed: 1
|
||||||
Maximum Speed: 1.5
|
Maximum Speed: 1.5
|
||||||
Minimum Size: 0
|
Minimum Size: 0.100000001
|
||||||
Maximum Size: 0.5
|
Maximum Size: 0.100000001
|
||||||
Size Decay: 0.907999992
|
Size Decay: 0.907000005
|
||||||
Angular Ranges And Offset: {x: 6.19999981, y: 3.1400001, z: 0, w: 1.70000005}
|
Angular Ranges And Offset: {x: 0.779999971, y: 0, z: -1.57070005, w: 0}
|
||||||
Rotation Speed: 0.805999994
|
Rotation Speed: 0.805999994
|
||||||
Rotation Decay: 0
|
Rotation Decay: 0
|
||||||
Texture Asset ID: 0
|
Texture Asset ID: 56224060
|
||||||
Custom Update Shader Asset ID: 0
|
Custom Update Shader Asset ID: 42141152
|
||||||
Color Tint: {x: 1, y: 1, z: 1, w: 1}
|
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
|
IsActive: true
|
||||||
Scripts: ~
|
Scripts: ~
|
||||||
- EID: 239
|
- EID: 239
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
using SHADE;
|
using SHADE;
|
||||||
using SHADE_Scripting.Audio;
|
using SHADE_Scripting.Audio;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
@ -48,6 +48,12 @@ public class PlayerWalkState : BaseState
|
||||||
|
|
||||||
if (timer > delay)
|
if (timer > delay)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if (machine.GetScript<PlayerController>().tranform.LocalEulerAngles.y > 0.0f)
|
||||||
|
machine.GetScript<PlayerController>().smoke.AngularOffsets = new Vector2(machine.GetScript<PlayerController>().tranform.LocalEulerAngles.y - (MathF.PI * 1.5f), machine.GetScript<PlayerController>().smoke.AngularOffsets.y);
|
||||||
|
else
|
||||||
|
machine.GetScript<PlayerController>().smoke.AngularOffsets = new Vector2(machine.GetScript<PlayerController>().tranform.LocalEulerAngles.y + (MathF.PI * 0.5f), machine.GetScript<PlayerController>().smoke.AngularOffsets.y);
|
||||||
|
|
||||||
AudioHandler.audioClipHandlers["footsteps"].Play();
|
AudioHandler.audioClipHandlers["footsteps"].Play();
|
||||||
machine.GetScript<PlayerController>().smoke.Emit();
|
machine.GetScript<PlayerController>().smoke.Emit();
|
||||||
timer = 0;
|
timer = 0;
|
||||||
|
|
|
@ -139,19 +139,20 @@ void main()
|
||||||
// emit particle from emitter position
|
// emit particle from emitter position
|
||||||
particle.position = vec4 (emitterPosition.xyz, 1.0f);
|
particle.position = vec4 (emitterPosition.xyz, 1.0f);
|
||||||
|
|
||||||
vec2 eulerAngles = vec2 (rand(seed) * angularRangesAndOffsets.x + angularRangesAndOffsets.z,
|
vec2 eulerAngles = vec2 ((rand(seed) - 0.5f) * angularRangesAndOffsets.x + angularRangesAndOffsets.z,
|
||||||
rand(seed) * angularRangesAndOffsets.y + angularRangesAndOffsets.w);
|
(rand(seed) - 0.5f) * angularRangesAndOffsets.y + angularRangesAndOffsets.w);
|
||||||
|
|
||||||
// Set its velocity
|
// Set its velocity
|
||||||
// particle.velocity.xyz = vec3 (cos(eulerAngles.x) * cos(eulerAngles.y),
|
// particle.velocity.xyz = vec3 (cos(eulerAngles.x) * cos(eulerAngles.y),
|
||||||
// sin(eulerAngles.x) * cos(eulerAngles.y),
|
// sin(eulerAngles.x) * cos(eulerAngles.y),
|
||||||
// sin(eulerAngles.y));
|
// sin(eulerAngles.y));
|
||||||
|
|
||||||
|
float heading = eulerAngles.x;
|
||||||
float bank = eulerAngles.y;
|
float bank = eulerAngles.y;
|
||||||
float cb = cos(bank);
|
float cb = cos(bank);
|
||||||
float sb = sin(bank);
|
float sb = sin(bank);
|
||||||
float ch = cos (eulerAngles.x);
|
float ch = cos (heading);
|
||||||
float sh = sin (eulerAngles.x);
|
float sh = sin (heading);
|
||||||
float cp = cos (0.0f);
|
float cp = cos (0.0f);
|
||||||
float sp = sin (0.0f);
|
float sp = sin (0.0f);
|
||||||
|
|
||||||
|
|
Binary file not shown.
|
@ -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;
|
||||||
|
}
|
Binary file not shown.
|
@ -0,0 +1,3 @@
|
||||||
|
Name: ParticleUpdateGrowThenShrink_CS
|
||||||
|
ID: 42141152
|
||||||
|
Type: 2
|
|
@ -913,12 +913,6 @@ namespace SHADE
|
||||||
{
|
{
|
||||||
comp->SetTextureAssetID(val);
|
comp->SetTextureAssetID(val);
|
||||||
});
|
});
|
||||||
ImGui::SameLine();
|
|
||||||
if (ImGui::Button("Reset"))
|
|
||||||
{
|
|
||||||
component->SetTextureAssetID(0);
|
|
||||||
component->SetTextureIndex(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SHDragDrop::BeginTarget())
|
if (SHDragDrop::BeginTarget())
|
||||||
{
|
{
|
||||||
|
@ -940,6 +934,13 @@ namespace SHADE
|
||||||
SHDragDrop::EndTarget();
|
SHDragDrop::EndTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Reset"))
|
||||||
|
{
|
||||||
|
component->SetTextureAssetID(0);
|
||||||
|
component->SetTextureIndex(0);
|
||||||
|
}
|
||||||
|
|
||||||
SHEditorWidgets::InputText("Custom Update Shader",
|
SHEditorWidgets::InputText("Custom Update Shader",
|
||||||
[comp = component]()
|
[comp = component]()
|
||||||
{
|
{
|
||||||
|
|
|
@ -576,6 +576,9 @@ namespace YAML
|
||||||
if (node[MAX_SPEED_TAG.data()].IsDefined())
|
if (node[MAX_SPEED_TAG.data()].IsDefined())
|
||||||
rhs.SetMaxSpeed (node[MAX_SPEED_TAG.data()].as<float>());
|
rhs.SetMaxSpeed (node[MAX_SPEED_TAG.data()].as<float>());
|
||||||
|
|
||||||
|
if (node[MIN_SIZE_TAG.data()].IsDefined())
|
||||||
|
rhs.SetMinSize(node[MIN_SIZE_TAG.data()].as<float>());
|
||||||
|
|
||||||
if (node[MAX_SIZE_TAG.data()].IsDefined())
|
if (node[MAX_SIZE_TAG.data()].IsDefined())
|
||||||
rhs.SetMaxSize(node[MAX_SIZE_TAG.data()].as<float>());
|
rhs.SetMaxSize(node[MAX_SIZE_TAG.data()].as<float>());
|
||||||
|
|
||||||
|
@ -619,7 +622,7 @@ namespace YAML
|
||||||
//gfxSystem->BuildTextures();
|
//gfxSystem->BuildTextures();
|
||||||
|
|
||||||
rhs.SetCustomUpdateShader(shaderModule);
|
rhs.SetCustomUpdateShader(shaderModule);
|
||||||
rhs.SetTextureAssetID(id);
|
rhs.SetCustomUpdateShaderAssetID(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue