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 2039 deletions
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable
#define INSTANCE_LEN (16)
layout(points) in;
layout (triangle_strip, max_vertices = (INSTANCE_LEN * 2)) out;
layout(invocations = 8) in;
#include "physics.inc"
#include "point.inc"
layout(set=0, binding=1, std430) readonly buffer pointBuffer {
point_t points [];
};
layout(location = 0) in vec3 geomColor [1];
layout(location = 1) in uint geomTrailIndex [1];
layout(location = 2) in vec3 geomTrailColor [1];
layout(location = 3) in uint geomStartIndex [1];
layout(location = 4) in uint geomUseCount [1];
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() {
const vec3 color = geomColor[0];
const uint id = geomTrailIndex[0];
const vec3 trailColor = geomTrailColor[0];
const uint startIndex = geomStartIndex[0];
const uint useCount = geomUseCount[0];
const uint indexOffset = (gl_InvocationID * (INSTANCE_LEN - 1));
const uint instanceIndex = startIndex + indexOffset;
uint count = min(INSTANCE_LEN, useCount);
if ((indexOffset >= useCount) && (indexOffset + INSTANCE_LEN > useCount)) {
count = indexOffset - useCount;
}
if (count <= 1) {
return;
}
const float trailFactor = mediumDensity / friction;
for (uint i = 0; i < count; i++) {
const float u = float(indexOffset + i + 1) / float(useCount);
const uint index = (instanceIndex + i) % points.length();
const vec3 position = points[index].position;
const float size = points[index].size;
const vec3 velocity = points[index].velocity;
const vec3 dir = normalize(cross(abs(velocity), position - camera));
vec3 offset = dir * size;
float density = trailFactor * (1.0f - u * u) / size;
const vec3 p0 = position - offset;
const vec3 p1 = position + offset;
passPos = vec3(u, -1.0f, -1.0f);
passDir = vec3(-0.1f * u, +0.2f, 2.0f);
passColor = mix(color, trailColor, u);
passDensity = density;
passSmokeIndex = int(id);
gl_Position = mvp * vec4(p0, 1);
EmitVertex();
passPos = vec3(u, +1.0f, -1.0f);
passDir = vec3(-0.1f * u, -0.2f, 2.0f);
passColor = mix(color, trailColor, u);
passDensity = density;
passSmokeIndex = int(id);
gl_Position = mvp * vec4(p1, 1);
EmitVertex();
}
EndPrimitive();
}
\ No newline at end of file
#ifndef TRAIL_INC
#define TRAIL_INC
struct trail_t {
uint particleIndex;
uint startIndex;
uint endIndex;
uint useCount;
vec3 color;
float lifetime;
};
#endif // TRAIL_INC
\ No newline at end of file
#version 450
#extension GL_GOOGLE_include_directive : enable
#include "trail.inc"
layout(set=0, binding=0, std430) readonly buffer trailBuffer {
trail_t trails [];
};
#include "particle.inc"
layout(set=2, binding=0, std430) readonly buffer particleBuffer {
particle_t particles [];
};
layout(location = 0) out vec3 geomColor;
layout(location = 1) out uint geomTrailIndex;
layout(location = 2) out vec3 geomTrailColor;
layout(location = 3) out uint geomStartIndex;
layout(location = 4) out uint geomUseCount;
void main() {
const uint particleIndex = trails[gl_InstanceIndex].particleIndex;
const float lifetime = trails[gl_InstanceIndex].lifetime;
geomColor = particles[particleIndex].color;
geomTrailIndex = gl_InstanceIndex;
geomTrailColor = trails[gl_InstanceIndex].color;
geomStartIndex = trails[gl_InstanceIndex].startIndex;
const uint useCount = trails[gl_InstanceIndex].useCount;
if (lifetime > 0.0f) {
geomUseCount = useCount;
} else {
geomUseCount = 0;
}
gl_Position = vec4(gl_InstanceIndex, lifetime, useCount, 0.0f);
}
\ 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, r32ui) restrict readonly uniform uimage3D voxelRed;
layout(set=0, binding=1, r32ui) restrict readonly uniform uimage3D voxelGreen;
layout(set=0, binding=2, r32ui) restrict readonly uniform uimage3D voxelBlue;
layout(set=0, binding=3, r32ui) restrict readonly uniform uimage3D voxelDensity;
layout(set=1, binding=0, rgba16) restrict writeonly uniform image3D voxelImage;
void main() {
ivec3 pos = ivec3(gl_GlobalInvocationID);
ivec3 size = imageSize(voxelImage);
if (any(greaterThanEqual(pos, size))) {
return;
}
const float red = voxel_read(voxelRed, pos);
const float green = voxel_read(voxelGreen, pos);
const float blue = voxel_read(voxelBlue, pos);
const float density = voxel_read(voxelDensity, pos);
imageStore(voxelImage, pos, vec4(
red,
green,
blue,
density
));
}
#ifndef VOXEL_INC
#define VOXEL_INC
#define VOXEL_NORM_VALUE 0xFF
#define voxel_add(img, pos, value) imageAtomicAdd(img, ivec3((imageSize(img) - ivec3(1)) * pos), uint(VOXEL_NORM_VALUE * value))
#define voxel_write(img, pos, value) imageStore(img, pos, uvec4(VOXEL_NORM_VALUE * value));
#define voxel_read(img, pos) imageLoad(img, pos).r / float(VOXEL_NORM_VALUE);
// https://stackoverflow.com/questions/51108596/linearize-depth
float linearize_depth(float d,float zNear,float zFar) {
return zNear * zFar / (zFar + d * (zNear - zFar));
}
#define voxel_pos(pos) vec3((pos.xy + vec2(1.0f)) * 0.5f, linearize_depth(pos.y, 0.1f, 50.0f))
#endif // VOXEL_INC
\ No newline at end of file
#version 450
#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, r32ui) uniform uimage3D voxelRed;
layout(set=1, binding=1, r32ui) uniform uimage3D voxelGreen;
layout(set=1, binding=2, r32ui) uniform uimage3D voxelBlue;
layout(set=1, binding=3, r32ui) uniform uimage3D voxelDensity;
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 = voxel_pos(ndc_pos);
if ((any(greaterThanEqual(pos, vec3(1.5f)))) || (any(lessThanEqual(pos, vec3(-0.5f))))) {
return;
}
float size = particles[id].size;
vec3 color = particles[id].color;
voxel_add(voxelRed, pos, color.r);
voxel_add(voxelGreen, pos, color.g);
voxel_add(voxelBlue, pos, color.b);
voxel_add(voxelDensity, pos, 1.0f);
}
#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, r32ui) uniform uimage3D voxelRed;
layout(set=1, binding=1, r32ui) uniform uimage3D voxelGreen;
layout(set=1, binding=2, r32ui) uniform uimage3D voxelBlue;
layout(set=1, binding=3, r32ui) uniform uimage3D voxelDensity;
layout( push_constant ) uniform constants{
mat4 mvp;
};
#define NUM_SMOKE_SAMPLES 4
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;
}
vec3 offset = vec3(-size);
for (;offset.x <= size; offset.x += size / NUM_SMOKE_SAMPLES) {
for (;offset.y <= size; offset.y += size / NUM_SMOKE_SAMPLES) {
for (;offset.z <= size; offset.z += size / NUM_SMOKE_SAMPLES) {
vec4 cs_pos = mvp * vec4(position + offset, 1);
if (abs(cs_pos.w) <= 0.0f) {
return;
}
vec3 ndc_pos = cs_pos.xyz / cs_pos.w;
vec3 pos = voxel_pos(ndc_pos);
if ((any(greaterThanEqual(pos, vec3(1.5f)))) || (any(lessThanEqual(pos, vec3(-0.5f))))) {
return;
}
vec3 color = smokes[id].color;
float local_density = density * max(1.0f - length(offset / size), 0.0f);
voxel_add(voxelRed, pos, color.r);
voxel_add(voxelGreen, pos, color.g);
voxel_add(voxelBlue, pos, color.b);
voxel_add(voxelDensity, pos, local_density);
}
}
}
}
#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, r32ui) uniform uimage3D voxelRed;
layout(set=1, binding=1, r32ui) uniform uimage3D voxelGreen;
layout(set=1, binding=2, r32ui) uniform uimage3D voxelBlue;
layout(set=1, binding=3, r32ui) uniform uimage3D voxelDensity;
#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 = voxel_pos(ndc_pos);
if ((any(greaterThanEqual(pos, vec3(1.5f)))) || (any(lessThanEqual(pos, vec3(-0.5f))))) {
continue;
}
voxel_add(voxelRed, pos, color.r);
voxel_add(voxelGreen, pos, color.g);
voxel_add(voxelBlue, pos, color.b);
voxel_add(voxelDensity, pos, density);
}
}
This diff is collapsed.
first_mesh
\ No newline at end of file
cmake_minimum_required(VERSION 3.16)
project(first_mesh)
# 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(first_mesh src/main.cpp)
# including headers of dependencies and the VkCV framework
target_include_directories(first_mesh SYSTEM BEFORE PRIVATE
${vkcv_include}
${vkcv_includes}
${vkcv_asset_loader_include}
${vkcv_geometry_include}
${vkcv_camera_include}
${vkcv_shader_compiler_include}
)
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(first_mesh
vkcv
${vkcv_libraries}
vkcv_asset_loader
vkcv_geometry
vkcv_camera
vkcv_shader_compiler
)
projects/first_mesh/assets/cube/boards2_vcyc_jpg.jpg

132 B

#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 passNormal;
layout(location = 1) in vec2 passUV;
layout(location = 0) out vec3 outColor;
layout(set=0, binding=0) uniform texture2D meshTexture;
layout(set=0, binding=1) uniform sampler textureSampler;
void main() {
outColor = texture(sampler2D(meshTexture, textureSampler), passUV).rgb;
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 2) in vec2 inUV;
layout(location = 0) out vec3 passNormal;
layout(location = 1) out vec2 passUV;
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() {
gl_Position = mvp * vec4(inPosition, 1.0);
passNormal = inNormal;
passUV = inUV;
}
\ No newline at end of file
#include <iostream>
#include <vkcv/Buffer.hpp>
#include <vkcv/Core.hpp>
#include <vkcv/Image.hpp>
#include <vkcv/Pass.hpp>
#include <vkcv/Sampler.hpp>
#include <vkcv/camera/CameraManager.hpp>
#include <vkcv/asset/asset_loader.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/geometry/Cuboid.hpp>
int main(int argc, const char** argv) {
const std::string applicationName = "First Mesh";
vkcv::Core core = vkcv::Core::create(
applicationName,
VK_MAKE_VERSION(0, 0, 1),
{ vk::QueueFlagBits::eGraphics ,vk::QueueFlagBits::eCompute , vk::QueueFlagBits::eTransfer },
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME }
);
vkcv::WindowHandle windowHandle = core.createWindow(applicationName, 800, 600, true);
vkcv::Window& window = core.getWindow(windowHandle);
vkcv::PassHandle firstMeshPass = vkcv::passSwapchain(
core,
window.getSwapchain(),
{ vk::Format::eUndefined, vk::Format::eD32Sfloat }
);
if (!firstMeshPass) {
std::cerr << "Error. Could not create renderpass. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::ShaderProgram firstMeshProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compileProgram(firstMeshProgram, {
{ vkcv::ShaderStage::VERTEX, "assets/shaders/shader.vert" },
{ vkcv::ShaderStage::FRAGMENT, "assets/shaders/shader.frag" }
}, nullptr);
std::vector<vkcv::VertexBinding> bindings = vkcv::createVertexBindings(
firstMeshProgram.getVertexAttachments()
);
const vkcv::VertexLayout firstMeshLayout { bindings };
// since we only use one descriptor set (namely, desc set 0), directly address it
// recreate copies of the bindings and the handles (to check whether they are properly reused instead of actually recreated)
const vkcv::DescriptorBindings& set0Bindings = firstMeshProgram.getReflectedDescriptors().at(0);
auto set0BindingsExplicitCopy = set0Bindings;
vkcv::DescriptorSetLayoutHandle setLayoutHandle = core.createDescriptorSetLayout(set0Bindings);
vkcv::DescriptorSetLayoutHandle setLayoutHandleCopy = core.createDescriptorSetLayout(set0BindingsExplicitCopy);
vkcv::DescriptorSetHandle descriptorSet = core.createDescriptorSet(setLayoutHandle);
vkcv::GraphicsPipelineHandle firstMeshPipeline = core.createGraphicsPipeline(
vkcv::GraphicsPipelineConfig(
firstMeshProgram,
firstMeshPass,
{ firstMeshLayout },
{ setLayoutHandle }
)
);
if (!firstMeshPipeline) {
std::cerr << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::asset::Texture tex = vkcv::asset::loadTexture("assets/cube/boards2_vcyc_jpg.jpg");
if (tex.data.empty()) {
std::cerr << "Error. No texture found. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::Image texture = vkcv::image(core, vk::Format::eR8G8B8A8Srgb, tex.w, tex.h);
texture.fill(tex.data.data());
{
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
texture.recordMipChainGeneration(cmdStream, core.getDownsampler());
core.submitCommandStream(cmdStream, false);
}
vkcv::SamplerHandle sampler = vkcv::samplerLinear(core);
vkcv::DescriptorWrites setWrites;
setWrites.writeSampledImage(0, texture.getHandle());
setWrites.writeSampler(1, sampler);
core.writeDescriptorSet(descriptorSet, setWrites);
vkcv::ImageHandle depthBuffer;
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
vkcv::geometry::Cuboid cube (glm::vec3(0), 1.0f);
vkcv::InstanceDrawcall drawcall (cube.generateVertexData(core));
drawcall.useDescriptorSet(0, descriptorSet);
vkcv::camera::CameraManager cameraManager(window);
auto camHandle = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
cameraManager.getCamera(camHandle).setPosition(glm::vec3(0, 0, -3));
core.run([&](const vkcv::WindowHandle &windowHandle, double t, double dt,
uint32_t swapchainWidth, uint32_t swapchainHeight) {
if ((!depthBuffer) ||
(swapchainWidth != core.getImageWidth(depthBuffer)) ||
(swapchainHeight != core.getImageHeight(depthBuffer))) {
depthBuffer = core.createImage(
vk::Format::eD32Sfloat,
swapchainWidth,
swapchainHeight
);
}
cameraManager.update(dt);
glm::mat4 mvp = cameraManager.getActiveCamera().getMVP();
vkcv::PushConstants pushConstants = vkcv::pushConstants<glm::mat4>();
pushConstants.appendDrawcall(mvp);
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.recordDrawcallsToCmdStream(
cmdStream,
firstMeshPipeline,
pushConstants,
{ drawcall },
renderTargets,
windowHandle
);
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
});
return 0;
}
first_scene
cmake_minimum_required(VERSION 3.16)
project(first_scene)
# 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(first_scene src/main.cpp)
# including headers of dependencies and the VkCV framework
target_include_directories(first_scene SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_asset_loader_include} ${vkcv_camera_include} ${vkcv_scene_include} ${vkcv_shader_compiler_include} ${vkcv_gui_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(first_scene vkcv ${vkcv_libraries} vkcv_asset_loader ${vkcv_asset_loader_libraries} vkcv_camera vkcv_scene vkcv_shader_compiler vkcv_gui)
File deleted
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
File deleted