Skip to content
Snippets Groups Projects
Unverified Commit 9a29205b authored by TheJackiMonster's avatar TheJackiMonster
Browse files

Adjusted blending

parent 3874a0a3
No related branches found
No related tags found
1 merge request!106Created initial firework project
...@@ -16,6 +16,7 @@ layout(set=1, binding=0, std430) readonly buffer randomBuffer { ...@@ -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; layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
#include "physics.inc" #include "physics.inc"
#include "smoke.inc"
#define NUM_VOXEL_SAMPLES 32 #define NUM_VOXEL_SAMPLES 32
...@@ -45,21 +46,22 @@ void main() { ...@@ -45,21 +46,22 @@ void main() {
randomData[(globalID * NUM_VOXEL_SAMPLES * 2 + i * 2 + 1) % randomData.length()] randomData[(globalID * NUM_VOXEL_SAMPLES * 2 + i * 2 + 1) % randomData.length()]
); );
float noiseF = max(0.0f, 1.0f - length(noise));
outSamples += texture( outSamples += texture(
sampler2D(voxelTexture, voxelSampler), sampler2D(voxelTexture, voxelSampler),
pos + noise * (NUM_VOXEL_SAMPLES - 1.0f) / size pos + noise * (NUM_VOXEL_SAMPLES - 1.0f) / size
) * max(0.0f, 1.0f - length(noise)); ) * (noiseF * noiseF);
} }
outSamples /= NUM_VOXEL_SAMPLES; outSamples /= NUM_VOXEL_SAMPLES;
// TODO: add noise to the smoke here!
vec4 result = vec4(0.0f); vec4 result = vec4(0.0f);
result += vec4(outParticles.rgb * outParticles.a, outParticles.a);
result += vec4(outSmoke.rgb * outSmoke.a, outSmoke.a); result = smokeBlend(result, outParticles);
result += vec4(outTrails.rgb * outTrails.a, outTrails.a); result = smokeBlend(result, outTrails);
result += vec4(outSamples.rgb * outSamples.a, outSamples.a); result = smokeBlend(result, outSmoke);
result = smokeBlend(result, outSamples);
result.r = clamp(result.r, 0, 1); result.r = clamp(result.r, 0, 1);
result.g = clamp(result.g, 0, 1); result.g = clamp(result.g, 0, 1);
......
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
const float pi = 3.14159f; const float pi = 3.14159f;
const float g = 9.81f; const float g = 9.81f;
const float friction = 0.001f; const float friction = 0.004f;
const float flowRate = 0.75f; const float flowRate = 0.75f;
const float mediumDensity = 0.0002f;
const float mediumDensity = 0.0001f; const float trailWidth = 0.25f;
#endif // PHYSICS_INC #endif // PHYSICS_INC
\ No newline at end of file
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#extension GL_GOOGLE_include_directive : enable #extension GL_GOOGLE_include_directive : enable
#include "voxel.inc" #include "voxel.inc"
#include "smoke.inc"
layout(set=0, binding=0, rgba16) restrict readonly uniform image3D voxelImage; layout(set=0, binding=0, rgba16) restrict readonly uniform image3D voxelImage;
layout(set=1, binding=0, rgba16f) restrict writeonly uniform image2D outImage; layout(set=1, binding=0, rgba16f) restrict writeonly uniform image2D outImage;
...@@ -26,10 +27,7 @@ void main() { ...@@ -26,10 +27,7 @@ void main() {
vec4 data = imageLoad(voxelImage, voxelPos); vec4 data = imageLoad(voxelImage, voxelPos);
voxel = vec4( voxel = smokeBlend(voxel, data);
(voxel.rgb + data.rgb * data.a) * (1.0f - voxel.a),
voxel.a + (data.a) * (1.0f - voxel.a)
);
} }
voxel.r = clamp(voxel.r, 0, 1); voxel.r = clamp(voxel.r, 0, 1);
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#extension GL_GOOGLE_include_directive : enable #extension GL_GOOGLE_include_directive : enable
#include "physics.inc" #include "physics.inc"
#include "smoke.inc"
layout(location = 0) in vec3 passPos; layout(location = 0) in vec3 passPos;
layout(location = 1) in vec3 passDir; layout(location = 1) in vec3 passDir;
...@@ -40,10 +41,7 @@ void main() { ...@@ -40,10 +41,7 @@ void main() {
const uint randomIndex = (passSmokeIndex * NUM_SMOKE_SAMPLES + i) % randomData.length(); const uint randomIndex = (passSmokeIndex * NUM_SMOKE_SAMPLES + i) % randomData.length();
const float alpha = (1.0f + randomData[randomIndex] * 0.1f) * data.a * fallOff; const float alpha = (1.0f + randomData[randomIndex] * 0.1f) * data.a * fallOff;
result = vec4( result = smokeBlend(result, vec4(data.rgb, alpha));
(result.rgb + data.rgb * alpha) * (1.0f - result.a),
result.a + (alpha) * (1.0f - result.a)
);
} }
result.r = clamp(result.r, 0, 1); result.r = clamp(result.r, 0, 1);
......
...@@ -18,4 +18,11 @@ float smokeDensity(float size) { ...@@ -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 #endif // SMOKE_INC
\ No newline at end of file
...@@ -74,8 +74,6 @@ void main() { ...@@ -74,8 +74,6 @@ void main() {
const float scaling = points[y].scaling; 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; size = size * fading + scaling * dt;
points[x].position = position; points[x].position = position;
...@@ -91,7 +89,7 @@ void main() { ...@@ -91,7 +89,7 @@ void main() {
const float trailFactor = mediumDensity / friction; const float trailFactor = mediumDensity / friction;
points[startIndex].position = position * fading; 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].velocity = velocity * fading;
points[startIndex].scaling = trailFactor * length(velocity) * fading; points[startIndex].scaling = trailFactor * length(velocity) * fading;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment