-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ravbug
committed
Jun 13, 2024
1 parent
9d42e98
commit 90b25c2
Showing
8 changed files
with
136 additions
and
5 deletions.
There are no files selected for viewing
Submodule RavEngine
updated
from 83cb6f to cc26df
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
### Asset attributions | ||
- Helmet model and textures from [KhronosGroup/glTF-Sample-Assets](https://github.com/KhronosGroup/glTF-Sample-Assets) | ||
- smoke particle texture by Freepik: https://www.freepik.com/free-vector/cartoon-smoke-element-animation-frames_13763535.htm | ||
- fire particle texture by macrovector: https://www.freepik.com/free-vector/light-fire-flames-animation-collection_10271988.htm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
struct ParticleData{ | ||
vec3 pos; | ||
vec2 scale; | ||
uint animationFrame; | ||
}; | ||
|
||
float rand(in vec2 ip) { | ||
const float seed = 12345678; | ||
uvec2 p = uvec2(floatBitsToUint(ip.x), floatBitsToUint(ip.y)); | ||
uint s = floatBitsToUint(seed); | ||
s ^= (s ^ ((~p.x << s) + (~p.y << s))); | ||
|
||
p ^= (p << 17U); | ||
p ^= ((p ^ s) >> 13U); | ||
p ^= (p << 5U); | ||
p ^= ((s + (s&(p.x^p.y))) >> 3U); | ||
uint n = (p.x*s+p.y)+((p.x ^ p.y) << ~p.x ^ s) + ((p.x ^ p.y) << ~p.y ^ s); | ||
return float(n*50323U) / float(0xFFFFFFFFU); | ||
} | ||
ParticleData init(ParticleInitData initData) | ||
{ | ||
uint particleID = initData.particleID; | ||
ParticleData data; | ||
data.scale = vec2(0.1,1); | ||
vec4 pos = vec4( | ||
rand(vec2(particleID,particleID)), | ||
rand(vec2(particleID * 2,particleID * 2)), | ||
rand(vec2(particleID / 2,particleID / 2)), | ||
1 | ||
); | ||
pos = initData.emitterModel * pos; | ||
data.pos = pos.xyz; | ||
data.animationFrame = 0; | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"shader": "FireParticleInit.csh", | ||
"type": "particle-init", | ||
"stage": "compute" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "ravengine_shader.glsl" | ||
|
||
layout(push_constant, std430) uniform UniformBufferObject{ | ||
float fpsScale; | ||
} ubo; | ||
|
||
|
||
struct ParticleData{ | ||
vec3 pos; | ||
vec2 scale; | ||
uint animationFrame; | ||
}; | ||
|
||
|
||
float rand(in vec2 ip) { | ||
const float seed = 12345678; | ||
uvec2 p = uvec2(floatBitsToUint(ip.x), floatBitsToUint(ip.y)); | ||
uint s = floatBitsToUint(seed); | ||
s ^= (s ^ ((~p.x << s) + (~p.y << s))); | ||
|
||
p ^= (p << 17U); | ||
p ^= ((p ^ s) >> 13U); | ||
p ^= (p << 5U); | ||
p ^= ((s + (s&(p.x^p.y))) >> 3U); | ||
uint n = (p.x*s+p.y)+((p.x ^ p.y) << ~p.x ^ s) + ((p.x ^ p.y) << ~p.y ^ s); | ||
return float(n*50323U) / float(0xFFFFFFFFU); | ||
} | ||
const float maxLife = 20; | ||
void update(inout ParticleData data, inout float newLife, uint particleID) | ||
{ | ||
data.scale += ubo.fpsScale * 0.05; | ||
data.pos.y += ubo.fpsScale * 0.01; | ||
vec2 movevec = vec2( | ||
rand(vec2(particleID, particleID)) * 2 - 1, | ||
rand(vec2(particleID * 2, particleID * 2)) * 2 - 1 | ||
); | ||
float life = maxLife; | ||
movevec *= 0.02; | ||
data.pos.x += movevec.x; | ||
data.pos.z += movevec.y; | ||
newLife += ubo.fpsScale; | ||
data.animationFrame = uint(remap(newLife,0,life,0,11)); | ||
if (newLife > life){ | ||
// destroy the particle | ||
newLife = 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"shader": "FireParticleUpdate.csh", | ||
"type": "particle-update", | ||
"stage": "compute" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.