Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 119-graphicspipeline-refactoring
  • 129-projekte-und-assets-auslagern
  • 132-denoising-module
  • 143-ar-vr-support-via-openxr
  • 43-multi-threading
  • 91-compute-first-network
  • 95-arm64-raspberry-pi-4-support
  • develop
  • master
  • optimizations
  • 0.1.0
  • 0.2.0
12 results

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Select Git revision
  • 119-graphicspipeline-refactoring
  • 129-projekte-und-assets-auslagern
  • 132-denoising-module
  • 143-ar-vr-support-via-openxr
  • 43-multi-threading
  • 91-compute-first-network
  • 95-arm64-raspberry-pi-4-support
  • develop
  • master
  • optimizations
  • 0.1.0
  • 0.2.0
12 results
Show changes
Showing
with 0 additions and 870 deletions
fire_works
cmake_minimum_required(VERSION 3.16)
project(fire_works)
# setting c++ standard for the project
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# adding source files to the project
add_project(fire_works
src/main.cpp)
# including headers of dependencies and the VkCV framework
target_include_directories(fire_works SYSTEM BEFORE PRIVATE
${vkcv_include}
${vkcv_includes}
${vkcv_camera_include}
${vkcv_gui_include}
${vkcv_shader_compiler_include}
${vkcv_effects_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(fire_works
vkcv
vkcv_camera
vkcv_gui
vkcv_shader_compiler
vkcv_effects)
#version 440
#extension GL_GOOGLE_include_directive : enable
layout(set=0, binding=0) uniform texture2D voxelTexture;
layout(set=0, binding=1) uniform sampler voxelSampler;
layout(set=0, binding=2, rgba16f) restrict readonly uniform image2D inParticles;
layout(set=0, binding=3, rgba16f) restrict readonly uniform image2D inSmoke;
layout(set=0, binding=4, rgba16f) restrict readonly uniform image2D inTrails;
layout(set=0, binding=5, rgba16f) restrict writeonly uniform image2D outImage;
layout(set=1, binding=0, std430) readonly buffer randomBuffer {
float randomData [];
};
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
shared vec2 sc_data [NUM_VOXEL_SAMPLES];
void main() {
const float localRadian = 0.25f * pi * randomData[gl_LocalInvocationIndex % randomData.length()];
sc_data[gl_LocalInvocationIndex % NUM_VOXEL_SAMPLES] = vec2(
sin(localRadian), cos(localRadian)
);
memoryBarrierShared();
barrier();
const ivec2 res = imageSize(outImage);
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, res))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec4 outParticles = imageLoad(inParticles, uv);
vec4 outSmoke = imageLoad(inSmoke, uv);
vec4 outTrails = imageLoad(inTrails, uv);
vec2 pos = (vec2(uv) + vec2(0.5f)) / vec2(res);
vec4 outSamples = texture(sampler2D(voxelTexture, voxelSampler), pos);
vec4 result = vec4(0.0f);
result = smokeBlend(result, outParticles);
result = smokeBlend(result, outTrails);
result = smokeBlend(result, outSmoke);
result = smokeBlend(result, outSamples * 0.1f);
result.r = clamp(result.r, 0, 1);
result.g = clamp(result.g, 0, 1);
result.b = clamp(result.b, 0, 1);
result.a = clamp(result.a, 0, 1);
imageStore(outImage, uv, result);
}
\ No newline at end of file
#version 440
#extension GL_GOOGLE_include_directive : enable
#include "physics.inc"
#include "voxel.inc"
layout(set=0, binding=0, r32ui) restrict writeonly uniform uimage3D voxelRed;
layout(set=0, binding=1, r32ui) restrict writeonly uniform uimage3D voxelGreen;
layout(set=0, binding=2, r32ui) restrict writeonly uniform uimage3D voxelBlue;
layout(set=0, binding=3, r32ui) restrict writeonly uniform uimage3D voxelDensity;
layout(local_size_x = 4, local_size_y = 4, local_size_z = 4) in;
void main() {
if(any(greaterThanEqual(gl_GlobalInvocationID.xyz, imageSize(voxelDensity)))){
return;
}
ivec3 pos = ivec3(gl_GlobalInvocationID.xyz);
voxel_write(voxelRed, pos, 0.0f);
voxel_write(voxelGreen, pos, 0.0f);
voxel_write(voxelBlue, pos, 0.0f);
voxel_write(voxelDensity, pos, mediumDensity);
}
\ No newline at end of file
#ifndef EVENT_INC
#define EVENT_INC
struct event_t {
vec3 direction;
float startTime;
vec3 color;
float velocity;
uint count;
uint index;
uint parent;
uint continuous;
float lifetime;
float mass;
float size;
uint contCount;
};
#endif // EVENT_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 = 4, local_size_y = 4, local_size_z = 4) in;
#include "physics.inc"
#include "voxel.inc"
layout(set=0, binding=0) uniform texture3D voxelTexture;
layout(set=0, binding=1) uniform sampler voxelSampler;
layout(set=0, binding=2, rgba16) restrict writeonly uniform image3D fluidImage;
vec4 getDataFrom(vec3 position, vec3 offset) {
return texture(
sampler3D(
voxelTexture,
voxelSampler
),
position + offset
);
}
shared vec4 cachedData [4][4][4];
void storeCachedData(vec3 position) {
uvec3 localId = gl_LocalInvocationID;
cachedData[localId.x][localId.y][localId.z] = getDataFrom(position, vec3(0));
}
vec4 getCachedData() {
uvec3 localId = gl_LocalInvocationID;
return cachedData[localId.x][localId.y][localId.z];
}
vec4 loadCachedData(vec3 position, ivec3 offset, ivec3 size) {
uvec3 localId = gl_LocalInvocationID;
ivec3 index = ivec3(localId) + offset;
// TOO SPECIAL FOR GPU TO WORK..!
//if ((any(lessThan(index, ivec3(0)))) || (any(greaterThan(index, ivec3(gl_WorkGroupSize))))) {
return getDataFrom(position, vec3(offset) / vec3(size));
//} else {
// return cachedData[index.x][index.y][index.z];
//}
}
void main() {
uvec3 id = gl_GlobalInvocationID;
ivec3 size = imageSize(fluidImage);
if (any(greaterThanEqual(id, size))) {
return;
}
vec3 position = (vec3(id) + vec3(0.5f)) / vec3(size);
storeCachedData(position);
memoryBarrierShared();
barrier();
vec4 extData [6];
extData[0] = loadCachedData(position, ivec3(+1, 0, 0), size);
extData[1] = loadCachedData(position, ivec3(-1, 0, 0), size);
extData[2] = loadCachedData(position, ivec3(0, +1, 0), size);
extData[3] = loadCachedData(position, ivec3(0, -1, 0), size);
extData[4] = loadCachedData(position, ivec3(0, 0, +1), size);
extData[5] = loadCachedData(position, ivec3(0, 0, -1), size);
vec4 data = vec4(0);
for (uint i = 0; i < 6; i++) {
data += extData[i];
}
data = mix(getCachedData(), (data / 6), flowRate);
imageStore(fluidImage, ivec3(id), data);
}
#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) buffer particleBuffer {
particle_t particles [];
};
layout(set=0, binding=1, std430) readonly buffer particleBufferCopy {
particle_t particlesCopy [];
};
layout(set=1, binding=0, std430) readonly buffer randomBuffer {
float randomData [];
};
#include "event.inc"
layout(set=1, binding=1, std430) buffer eventBuffer {
event_t events [];
};
layout(set=1, binding=2, std430) buffer startIndexBuffer {
uint startIndex [];
};
#include "smoke.inc"
layout(set=2, binding=0, std430) writeonly buffer smokeBuffer {
smoke_t smokes [];
};
layout(set=2, binding=1, std430) buffer smokeIndexBuffer {
uint smokeIndex;
uint trailIndex;
uint pointIndex;
};
#include "trail.inc"
layout(set=3, binding=0, std430) writeonly buffer trailBuffer {
trail_t trails [];
};
#include "point.inc"
layout(set=3, binding=1, std430) readonly buffer pointBuffer {
point_t points [];
};
layout( push_constant ) uniform constants{
float t;
float dt;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= particles.length()) {
return;
}
float lifetime = particles[id].lifetime;
if (lifetime > 0.0f) {
return;
}
uint event_id = events.length();
uint index = 0;
for (uint i = 0; i < events.length(); i++) {
const float start = events[i].startTime;
if ((events[i].continuous < 1) && (t < start)) {
continue;
}
index = atomicAdd(events[i].index, 1);
if (events[i].continuous < 1) {
if (events[i].count > index) {
event_id = i;
break;
} else {
atomicAdd(events[i].index, -1);
}
} else {
if (events[i].continuous > index){
event_id = i;
break;
} else {
if (events[i].contCount > 0) {
atomicAdd(events[i].contCount, -1);
events[i].index = 0;
}
atomicAdd(events[i].index, -1);
}
}
}
if (event_id >= events.length()) {
return;
}
lifetime = events[event_id].lifetime * (1.0f + 0.1f * randomData[(id + 1) % randomData.length()]);
vec3 direction;
if (dot(events[event_id].direction, events[event_id].direction) <= 0.0f) {
direction = vec3(
randomData[(id * 3 + 0) % randomData.length()],
randomData[(id * 3 + 1) % randomData.length()],
randomData[(id * 3 + 2) % randomData.length()]
);
} else {
direction = events[event_id].direction;
}
vec3 color = normalize(events[event_id].color);
const float v = events[event_id].velocity;
vec3 velocity = vec3(0.0f);
float size = events[event_id].size;
const uint pid = events[event_id].parent;
if (pid < events.length()) {
const uint spawnCount = events[pid].count;
const uint spawnId = startIndex[pid] + (id % spawnCount);
if (spawnId < particlesCopy.length()) {
particles[id].position = particlesCopy[spawnId].position;
velocity += particlesCopy[spawnId].velocity;
size = particlesCopy[spawnId].size;
}
}
if ((0 == index) && (events[event_id].continuous < 1)) {
const uint sid = atomicAdd(smokeIndex, 1) % smokes.length();
smokes[sid].position = particles[id].position;
smokes[sid].size = size * (1.0f + friction);
smokes[sid].velocity = velocity;
smokes[sid].scaling = v;
smokes[sid].color = mix(color, vec3(1.0f), 0.5f);
smokes[sid].eventID = event_id;
}
velocity += normalize(direction) * v * (1.0f + 0.1f * randomData[(id + 2) % randomData.length()]);;
const float split = pow(1.0f / events[event_id].count, 1.0f / 3.0f);
particles[id].lifetime = lifetime;
particles[id].velocity = velocity;
particles[id].size = size * split;
particles[id].color = color;
particles[id].mass = events[event_id].mass / events[event_id].count;
particles[id].eventId = event_id;
{
const uint tid = atomicAdd(trailIndex, 1) % trails.length();
const uint trailLen = 96 + int(randomData[(tid + id) % randomData.length()] * 32);
const uint startIndex = atomicAdd(pointIndex, trailLen) % points.length();
trails[tid].particleIndex = id;
trails[tid].startIndex = startIndex;
trails[tid].endIndex = (startIndex + trailLen - 1) % points.length();
trails[tid].useCount = 0;
trails[tid].color = mix(color, vec3(1.0f), 0.75f);
trails[tid].lifetime = lifetime + (dt * trailLen) * 0.5f;
}
}
#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) coherent buffer particleBuffer {
particle_t particles [];
};
layout( push_constant ) uniform constants{
float t;
float dt;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= particles.length()) {
return;
}
vec3 position = particles[id].position;
float lifetime = particles[id].lifetime;
vec3 velocity = particles[id].velocity;
if (lifetime > dt) {
lifetime -= dt;
} else {
lifetime = 0.0f;
}
const float fading = 1.0f / (1.0f + friction);
position = position + velocity * dt;
if (particles[id].mass > 0){
velocity = velocity * fading + vec3(0.0f, -g, 0.0f) * dt;
} else {
velocity = velocity * fading;
}
particles[id].position = position;
particles[id].lifetime = lifetime;
particles[id].velocity = velocity;
}
#version 450
layout(location = 0) in vec2 passPos;
layout(location = 1) in flat vec3 passColor;
layout(location = 2) in flat float passLifetime;
layout(location = 0) out vec4 outColor;
void main() {
if (passLifetime <= 0.0f) {
discard;
}
const float value = length(passPos);
if (value < 0.5f) {
outColor = vec4(passColor, 1.0f - max(value * 2.0f, 0.0f));
} else {
discard;
}
}
\ No newline at end of file
#ifndef PARTICLE_INC
#define PARTICLE_INC
struct particle_t {
vec3 position;
float lifetime;
vec3 velocity;
float size;
vec3 color;
float mass;
vec3 pad0;
uint eventId;
};
#endif // PARTICLE_INC
\ No newline at end of file
#version 450
#extension GL_GOOGLE_include_directive : enable
#include "particle.inc"
layout(set=0, binding=0, std430) readonly buffer particleBuffer {
particle_t particles [];
};
layout(location = 0) in vec2 vertexPos;
layout(location = 0) out vec2 passPos;
layout(location = 1) out flat vec3 passColor;
layout(location = 2) out flat float passLifetime;
layout( push_constant ) uniform constants{
mat4 mvp;
uint width;
uint height;
};
void main() {
vec3 position = particles[gl_InstanceIndex].position;
float lifetime = particles[gl_InstanceIndex].lifetime;
float size = particles[gl_InstanceIndex].size;
vec3 color = particles[gl_InstanceIndex].color;
if (width > height) {
passPos = vertexPos * vec2(1.0f * width / height, 1.0f);
} else {
passPos = vertexPos * vec2(1.0f, 1.0f * height / width);
}
passColor = color;
passLifetime = lifetime;
// align particle to face camera
gl_Position = mvp * vec4(position, 1); // transform position into projected view space
gl_Position.xy += vertexPos * size * 2.0f; // move position directly in view space
}
\ No newline at end of file
#ifndef PHYSICS_INC
#define PHYSICS_INC
const float pi = 3.14159f;
const float g = 9.81f;
const float friction = 0.004f;
const float flowRate = 0.75f;
const float mediumDensity = 0.0002f;
const float trailWidth = 0.25f;
#endif // PHYSICS_INC
\ No newline at end of file
#ifndef POINT_INC
#define POINT_INC
struct point_t {
vec3 position;
float size;
vec3 velocity;
float scaling;
};
#endif // POINT_INC
\ No newline at end of file
#version 440
#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;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main() {
const ivec2 res = imageSize(outImage);
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, res))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
const ivec3 voxelRes = imageSize(voxelImage);
vec4 voxel = vec4(0.0f);
for (int i = 0; i < voxelRes.z; i++) {
const ivec3 voxelPos = ivec3(uv, i);
vec4 data = imageLoad(voxelImage, voxelPos);
voxel = smokeBlend(voxel, data);
}
voxel.r = clamp(voxel.r, 0, 1);
voxel.g = clamp(voxel.g, 0, 1);
voxel.b = clamp(voxel.b, 0, 1);
voxel.a = clamp(voxel.a, 0, 1);
imageStore(outImage, uv, voxel);
}
\ 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 "smoke.inc"
layout(set=0, binding=0, std430) buffer smokeBuffer {
smoke_t smokes [];
};
layout( push_constant ) uniform constants{
float t;
float dt;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= smokes.length()) {
return;
}
vec3 position = smokes[id].position;
float size = smokes[id].size;
vec3 velocity = smokes[id].velocity;
const float scaling = smokes[id].scaling;
const float fading = 1.0f / (1.0f + friction);
position = position + velocity * dt;
velocity = velocity * fading + vec3(0.0f, 0.2f, 0.0f) * dt; //smoke is lighter than air right? + vec3(0.0f, -g, 0.0f) * dt;
size = size + scaling * dt;
smokes[id].position = position;
smokes[id].size = size;
smokes[id].velocity = velocity;
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable
#include "physics.inc"
#include "smoke.inc"
layout(location = 0) in vec3 passPos;
layout(location = 1) in vec3 passDir;
layout(location = 2) in vec3 passColor;
layout(location = 3) in float passDensity;
layout(location = 4) in flat int passSmokeIndex;
layout(location = 0) out vec4 outColor;
layout(set=1, binding=0, std430) readonly buffer randomBuffer {
float randomData [];
};
#define NUM_SMOKE_SAMPLES 16
void main() {
if (passDensity <= mediumDensity) {
discard;
}
vec3 start = passPos;
vec3 end = start + normalize(passDir) * 3.5f;
vec4 result = vec4(0);
for (uint i = 0; i < NUM_SMOKE_SAMPLES; i++) {
vec3 position = (
end + (start - end) * i / (NUM_SMOKE_SAMPLES - 1)
);
vec4 data = vec4(passColor, passDensity);
float fallOff = max(1.0f - length(position), 0.0f);
const uint randomIndex = (passSmokeIndex * NUM_SMOKE_SAMPLES + i) % randomData.length();
const float alpha = (1.0f + randomData[randomIndex] * 0.1f) * data.a * fallOff;
result = smokeBlend(result, vec4(data.rgb, alpha));
}
result.r = clamp(result.r, 0, 1);
result.g = clamp(result.g, 0, 1);
result.b = clamp(result.b, 0, 1);
result.a = clamp(result.a, 0, 1);
if (result.a < 1.0f) {
outColor = result;
} else {
discard;
}
}
\ No newline at end of file
#ifndef SMOKE_INC
#define SMOKE_INC
struct smoke_t {
vec3 position;
float size;
vec3 velocity;
float scaling;
vec3 color;
uint eventID;
};
float smokeDensity(float size) {
if (size > 0.0f) {
return 0.025f / size;
} else {
return 0.0f;
}
}
vec4 smokeBlend(vec4 dst, vec4 src) {
const float f = max(1.0f - dst.a, 0.0f);
const float a = clamp(0.0f, 1.0f, src.a);
return vec4(
dst.rgb + src.rgb * a * f,
dst.a + a * f
);
}
#endif // SMOKE_INC
\ No newline at end of file
#version 450
#extension GL_GOOGLE_include_directive : enable
#include "smoke.inc"
layout(set=0, binding=0, std430) readonly buffer smokeBuffer {
smoke_t smokes [];
};
layout(location = 0) in vec3 vertexPos;
layout(location = 0) out vec3 passPos;
layout(location = 1) out vec3 passDir;
layout(location = 2) out vec3 passColor;
layout(location = 3) out float passDensity;
layout(location = 4) out flat int passSmokeIndex;
layout( push_constant ) uniform constants{
mat4 mvp;
vec3 camera;
};
void main() {
vec3 position = smokes[gl_InstanceIndex].position;
float size = smokes[gl_InstanceIndex].size;
vec3 color = smokes[gl_InstanceIndex].color;
vec3 pos = position + vertexPos * size;
passPos = vertexPos;
passDir = pos - camera;
passColor = color;
passDensity = smokeDensity(size);
passSmokeIndex = gl_InstanceIndex;
// transform position into projected view space
gl_Position = mvp * vec4(pos, 1);
}
\ No newline at end of file
#version 440
layout(set=0, binding=0, rgba16f) readonly uniform image2D inImage;
layout(set=0, binding=1, rgba8) writeonly uniform image2D outImage;
layout(local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
void main() {
if(any(greaterThanEqual(gl_GlobalInvocationID.xy, imageSize(inImage)))){
return;
}
ivec2 uv = ivec2(gl_GlobalInvocationID.xy);
vec3 linearColor = imageLoad(inImage, uv).rgb;
vec3 tonemapped = linearColor / (dot(linearColor, vec3(0.21, 0.71, 0.08)) + 1); // reinhard tonemapping
vec3 gammaCorrected = pow(tonemapped, vec3(1.f / 2.2f));
imageStore(outImage, uv, vec4(gammaCorrected, 0.f));
}
\ 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 "trail.inc"
layout(set=1, binding=0, std430) coherent buffer trailBuffer {
trail_t trails [];
};
#include "point.inc"
layout(set=1, binding=1, std430) buffer pointBuffer {
point_t points [];
};
layout( push_constant ) uniform constants{
float t;
float dt;
};
void main() {
uint id = gl_GlobalInvocationID.x;
if (id >= trails.length()) {
return;
}
const uint particleIndex = trails[id].particleIndex;
const uint startIndex = trails[id].startIndex;
const uint endIndex = trails[id].endIndex;
uint useCount = trails[id].useCount;
float lifetime = trails[id].lifetime;
if (lifetime > dt) {
lifetime -= dt;
} else {
lifetime = 0.0f;
}
const uint available = (endIndex - startIndex) % points.length();
float trailLife = dt * available;
float fading = 1.0f / (1.0f + friction);
if (lifetime <= trailLife) {
fading *= (lifetime / trailLife);
if (useCount > 0) {
useCount--;
}
} else
if (available > useCount) {
useCount++;
}
for (uint i = useCount; i > 1; i--) {
const uint x = (startIndex + (i - 1)) % points.length();
const uint y = (startIndex + (i - 2)) % points.length();
vec3 position = points[y].position;
float size = points[y].size;
vec3 velocity = points[y].velocity;
const float scaling = points[y].scaling;
size = size * fading + scaling * dt;
points[x].position = position;
points[x].size = size;
points[x].velocity = velocity;
points[x].scaling = scaling;
}
vec3 position = particles[particleIndex].position;
float size = particles[particleIndex].size;
vec3 velocity = particles[particleIndex].velocity;
const float trailFactor = mediumDensity / friction;
points[startIndex].position = position * fading;
points[startIndex].size = trailWidth * size * fading;
points[startIndex].velocity = velocity * fading;
points[startIndex].scaling = trailFactor * length(velocity) * fading;
trails[id].useCount = useCount;
trails[id].lifetime = lifetime;
}