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

Write basic voxel compute shader (WIP)

parent 309b83da
No related branches found
No related tags found
1 merge request!106Created initial firework project
...@@ -10,4 +10,12 @@ struct smoke_t { ...@@ -10,4 +10,12 @@ struct smoke_t {
uint eventID; uint eventID;
}; };
float smokeDensity(float size) {
if (size > 0.0f) {
return 0.025f / size;
} else {
return 0.0f;
}
}
#endif // SMOKE_INC #endif // SMOKE_INC
\ No newline at end of file
...@@ -30,13 +30,7 @@ void main() { ...@@ -30,13 +30,7 @@ void main() {
passPos = vertexPos; passPos = vertexPos;
passDir = pos - camera; passDir = pos - camera;
passColor = color; passColor = color;
passDensity = smokeDensity(size);
if (size > 0.0f) {
passDensity = 0.025f / size;
} else {
passDensity = 0.0f;
}
passSmokeIndex = gl_InstanceIndex; passSmokeIndex = gl_InstanceIndex;
// transform position into projected view space // transform position into projected view space
......
#ifndef VOXEL_INC
#define VOXEL_INC
struct voxel_t {
vec3 color;
float density;
};
#endif // VOXEL_INC
\ No newline at end of file
#version 450 core
#extension GL_GOOGLE_include_directive : enable
#extension GL_ARB_separate_shader_objects : enable
layout(local_size_x = 256) in;
#include "physics.inc"
#include "particle.inc"
layout(set=0, binding=0, std430) readonly buffer particleBuffer {
particle_t particles [];
};
#include "voxel.inc"
layout(set=1, binding=0, std430) buffer voxelBuffer {
voxel_t voxel [];
};
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= particles.length()) {
return;
}
vec3 position = particles[id].position;
float lifetime = particles[id].lifetime;
if (lifetime <= 0.0f) {
return;
}
vec4 cs_pos = mvp * vec4(position, 1);
if (abs(cs_pos.w) <= 0.0f) {
return;
}
vec3 ndc_pos = cs_pos.xyz / cs_pos.w;
vec3 pos = (ndc_pos + vec3(1, 1, 0)) * vec3(0.5f, 0.5f, 1.0f);
// clipping!
float size = particles[id].size;
vec3 color = particles[id].color;
// write color into voxel at `pos * (resolution-1)` atomically!
}
#version 450 core
#extension GL_GOOGLE_include_directive : enable
#extension GL_ARB_separate_shader_objects : enable
layout(local_size_x = 256) in;
#include "physics.inc"
#include "smoke.inc"
layout(set=0, binding=0, std430) readonly buffer smokeBuffer {
smoke_t smokes [];
};
#include "voxel.inc"
layout(set=1, binding=0, std430) buffer voxelBuffer {
voxel_t voxel [];
};
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= smokes.length()) {
return;
}
vec3 position = smokes[id].position;
float size = smokes[id].size;
const float density = smokeDensity(size);
if (density <= mediumDensity) {
return;
}
vec4 cs_pos = mvp * vec4(position, 1);
if (abs(cs_pos.w) <= 0.0f) {
return;
}
vec3 ndc_pos = cs_pos.xyz / cs_pos.w;
vec3 pos = (ndc_pos + vec3(1, 1, 0)) * vec3(0.5f, 0.5f, 1.0f);
// clipping!
vec3 color = smokes[id].color;
// write (color, density) into voxel at `pos * (resolution-1)` atomically!
}
#version 450 core
#extension GL_GOOGLE_include_directive : enable
#extension GL_ARB_separate_shader_objects : enable
layout(local_size_x = 256) in;
#include "physics.inc"
#include "trail.inc"
layout(set=0, binding=0, std430) coherent buffer trailBuffer {
trail_t trails [];
};
#include "point.inc"
layout(set=0, binding=1, std430) buffer pointBuffer {
point_t points [];
};
#include "voxel.inc"
layout(set=1, binding=0, std430) buffer voxelBuffer {
voxel_t voxel [];
};
#include "smoke.inc"
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= trails.length()) {
return;
}
const uint particleIndex = trails[id].particleIndex;
const uint startIndex = trails[id].startIndex;
uint useCount = trails[id].useCount;
if (useCount <= 0) {
return;
}
vec3 color = trails[id].color;
float lifetime = trails[id].lifetime;
if (lifetime <= 0.0f) {
return;
}
for (uint i = 0; i < useCount; i++) {
const uint x = (startIndex + i) % points.length();
vec3 position = points[x].position;
float size = points[x].size;
const float density = smokeDensity(size);
if (density <= mediumDensity) {
break;
}
vec4 cs_pos = mvp * vec4(position, 1);
if (abs(cs_pos.w) <= 0.0f) {
return;
}
vec3 ndc_pos = cs_pos.xyz / cs_pos.w;
vec3 pos = (ndc_pos + vec3(1, 1, 0)) * vec3(0.5f, 0.5f, 1.0f);
// clipping!
// write (color, density) into voxel at `pos * (resolution-1)` atomically!
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment