diff --git a/projects/fire_works/shaders/add.comp b/projects/fire_works/shaders/add.comp index d706c1fcd9517c52eedaa7c15fde86fffbce6940..365919852135ca0cfb2e6803e524a5468b5ba103 100644 --- a/projects/fire_works/shaders/add.comp +++ b/projects/fire_works/shaders/add.comp @@ -16,6 +16,7 @@ layout(set=1, binding=0, std430) readonly buffer randomBuffer { layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in; #include "physics.inc" +#include "smoke.inc" #define NUM_VOXEL_SAMPLES 32 @@ -45,21 +46,22 @@ void main() { randomData[(globalID * NUM_VOXEL_SAMPLES * 2 + i * 2 + 1) % randomData.length()] ); + float noiseF = max(0.0f, 1.0f - length(noise)); + outSamples += texture( sampler2D(voxelTexture, voxelSampler), pos + noise * (NUM_VOXEL_SAMPLES - 1.0f) / size - ) * max(0.0f, 1.0f - length(noise)); + ) * (noiseF * noiseF); } outSamples /= NUM_VOXEL_SAMPLES; - // TODO: add noise to the smoke here! - vec4 result = vec4(0.0f); - result += vec4(outParticles.rgb * outParticles.a, outParticles.a); - result += vec4(outSmoke.rgb * outSmoke.a, outSmoke.a); - result += vec4(outTrails.rgb * outTrails.a, outTrails.a); - result += vec4(outSamples.rgb * outSamples.a, outSamples.a); + + result = smokeBlend(result, outParticles); + result = smokeBlend(result, outTrails); + result = smokeBlend(result, outSmoke); + result = smokeBlend(result, outSamples); result.r = clamp(result.r, 0, 1); result.g = clamp(result.g, 0, 1); diff --git a/projects/fire_works/shaders/physics.inc b/projects/fire_works/shaders/physics.inc index 1f92f1cf06e69978f28307cbc9539022993f6a9b..e14c62e33a6fd42ebfa8d31591394989de68a8d2 100644 --- a/projects/fire_works/shaders/physics.inc +++ b/projects/fire_works/shaders/physics.inc @@ -4,10 +4,10 @@ const float pi = 3.14159f; const float g = 9.81f; -const float friction = 0.001f; +const float friction = 0.004f; const float flowRate = 0.75f; - -const float mediumDensity = 0.0001f; +const float mediumDensity = 0.0002f; +const float trailWidth = 0.25f; #endif // PHYSICS_INC \ No newline at end of file diff --git a/projects/fire_works/shaders/sample.comp b/projects/fire_works/shaders/sample.comp index 12e342d132b072f2791248126fe6cc078bba032d..1eef49df639cfbc9f35c53ace21b1ce50ab62459 100644 --- a/projects/fire_works/shaders/sample.comp +++ b/projects/fire_works/shaders/sample.comp @@ -2,6 +2,7 @@ #extension GL_GOOGLE_include_directive : enable #include "voxel.inc" +#include "smoke.inc" layout(set=0, binding=0, rgba16) restrict readonly uniform image3D voxelImage; layout(set=1, binding=0, rgba16f) restrict writeonly uniform image2D outImage; @@ -26,10 +27,7 @@ void main() { vec4 data = imageLoad(voxelImage, voxelPos); - voxel = vec4( - (voxel.rgb + data.rgb * data.a) * (1.0f - voxel.a), - voxel.a + (data.a) * (1.0f - voxel.a) - ); + voxel = smokeBlend(voxel, data); } voxel.r = clamp(voxel.r, 0, 1); diff --git a/projects/fire_works/shaders/smoke.frag b/projects/fire_works/shaders/smoke.frag index e5549df150c6ca5ac57efc0259602506dbbe6491..8ded98ac5fbae554959a83df5bbf7451d286e832 100644 --- a/projects/fire_works/shaders/smoke.frag +++ b/projects/fire_works/shaders/smoke.frag @@ -3,6 +3,7 @@ #extension GL_GOOGLE_include_directive : enable #include "physics.inc" +#include "smoke.inc" layout(location = 0) in vec3 passPos; layout(location = 1) in vec3 passDir; @@ -40,10 +41,7 @@ void main() { const uint randomIndex = (passSmokeIndex * NUM_SMOKE_SAMPLES + i) % randomData.length(); const float alpha = (1.0f + randomData[randomIndex] * 0.1f) * data.a * fallOff; - result = vec4( - (result.rgb + data.rgb * alpha) * (1.0f - result.a), - result.a + (alpha) * (1.0f - result.a) - ); + result = smokeBlend(result, vec4(data.rgb, alpha)); } result.r = clamp(result.r, 0, 1); diff --git a/projects/fire_works/shaders/smoke.inc b/projects/fire_works/shaders/smoke.inc index 6b1bbbb5aebc49211257241343ae57b136fb9431..87eaa36b135043034c329842f475841e949a2b3a 100644 --- a/projects/fire_works/shaders/smoke.inc +++ b/projects/fire_works/shaders/smoke.inc @@ -18,4 +18,11 @@ float smokeDensity(float size) { } } +vec4 smokeBlend(vec4 dst, vec4 src) { + return vec4( + dst.rgb + src.rgb * src.a * (1.0f - dst.a), + dst.a + src.a * (1.0f - dst.a) + ); +} + #endif // SMOKE_INC \ No newline at end of file diff --git a/projects/fire_works/shaders/trail.comp b/projects/fire_works/shaders/trail.comp index 79d95c912ac0087d17043cc2447f8735a1d3f125..8e811a5251948e979fcacc0d2c1e95e27411fa87 100644 --- a/projects/fire_works/shaders/trail.comp +++ b/projects/fire_works/shaders/trail.comp @@ -74,8 +74,6 @@ void main() { const float scaling = points[y].scaling; - // position = position - velocity * dt; - // velocity = velocity * fading + vec3(0.0f, g, 0.0f) * dt; size = size * fading + scaling * dt; points[x].position = position; @@ -91,7 +89,7 @@ void main() { const float trailFactor = mediumDensity / friction; points[startIndex].position = position * fading; - points[startIndex].size = 0.5f * size * fading; + points[startIndex].size = trailWidth * size * fading; points[startIndex].velocity = velocity * fading; points[startIndex].scaling = trailFactor * length(velocity) * fading;