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 496 deletions
projects/first_scene/assets/Sponza/sponza_thorn_diff.png

131 B

projects/first_scene/assets/Sponza/vase_dif.png

132 B

projects/first_scene/assets/Sponza/vase_hanging.png

132 B

projects/first_scene/assets/Sponza/vase_plant.png

131 B

projects/first_scene/assets/Sponza/vase_round.png

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 vec4 outColor;
layout(set=0, binding=0) uniform texture2D meshTexture;
layout(set=0, binding=1) uniform sampler textureSampler;
void main() {
vec3 lightDirection = normalize(vec3(0.1f, -0.9f, 0.1f));
float ambient = 0.35f;
float diffuse = max(0.0f, -dot(passNormal, lightDirection));
float specular = pow(diffuse, 6.0f);
float brightness = sqrt(
(ambient + diffuse + specular) /
(2.0f + ambient)
);
vec4 color = texture(sampler2D(meshTexture, textureSampler), passUV);
if (color.a <= 0.0f) {
discard;
}
outColor = vec4(color.rgb * brightness, color.a);
}
\ 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/Core.hpp>
#include <vkcv/Pass.hpp>
#include <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <vkcv/gui/GUI.hpp>
#include <vkcv/asset/asset_loader.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/scene/Scene.hpp>
#include <vkcv/Features.hpp>
int main(int argc, const char** argv) {
const std::string applicationName = "First Scene";
uint32_t windowWidth = 800;
uint32_t windowHeight = 600;
vkcv::Features features;
features.requireExtension(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
vkcv::Core core = vkcv::Core::create(
applicationName,
VK_MAKE_VERSION(0, 0, 1),
{vk::QueueFlagBits::eTransfer, vk::QueueFlagBits::eGraphics, vk::QueueFlagBits::eCompute},
features
);
vkcv::WindowHandle windowHandle = core.createWindow(applicationName, windowWidth, windowHeight, true);
vkcv::Window& window = core.getWindow(windowHandle);
vkcv::camera::CameraManager cameraManager(window);
vkcv::gui::GUI gui (core, windowHandle);
auto camHandle0 = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
auto camHandle1 = cameraManager.addCamera(vkcv::camera::ControllerType::TRACKBALL);
cameraManager.getCamera(camHandle0).setPosition(glm::vec3(-8, 1, -0.5));
cameraManager.getCamera(camHandle0).setNearFar(0.1f, 30.0f);
cameraManager.getCamera(camHandle1).setNearFar(0.1f, 30.0f);
vkcv::scene::Scene scene = vkcv::scene::Scene::load(
core,
std::filesystem::path(argc > 1 ? argv[1] : "assets/Sponza/Sponza.gltf"),
{
vkcv::asset::PrimitiveType::POSITION,
vkcv::asset::PrimitiveType::NORMAL,
vkcv::asset::PrimitiveType::TEXCOORD_0
}
);
vkcv::PassHandle scenePass = vkcv::passSwapchain(
core,
window.getSwapchain(),
{ vk::Format::eUndefined, vk::Format::eD32Sfloat }
);
if (!scenePass) {
std::cout << "Error. Could not create renderpass. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::ShaderProgram sceneShaderProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compileProgram(sceneShaderProgram, {
{ vkcv::ShaderStage::VERTEX, "assets/shaders/shader.vert" },
{ vkcv::ShaderStage::FRAGMENT, "assets/shaders/shader.frag" }
}, nullptr);
const std::vector<vkcv::VertexAttachment> vertexAttachments = sceneShaderProgram.getVertexAttachments();
std::vector<vkcv::VertexBinding> bindings;
for (size_t i = 0; i < vertexAttachments.size(); i++) {
bindings.push_back(vkcv::createVertexBinding(i, { vertexAttachments[i] }));
}
const vkcv::VertexLayout sceneLayout { bindings };
const auto& material0 = scene.getMaterial(0);
vkcv::GraphicsPipelineHandle scenePipeline = core.createGraphicsPipeline(
vkcv::GraphicsPipelineConfig(
sceneShaderProgram,
scenePass,
{ sceneLayout },
{ material0.getDescriptorSetLayout() }
)
);
if (!scenePipeline) {
std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::ImageHandle depthBuffer;
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
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);
const std::vector<vkcv::ImageHandle> renderTargets = { swapchainInput, depthBuffer };
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
auto recordMesh = [](const glm::mat4& MVP, const glm::mat4& M,
vkcv::PushConstants &pushConstants,
vkcv::Drawcall& drawcall) {
pushConstants.appendDrawcall(MVP);
};
scene.recordDrawcalls(
cmdStream,
cameraManager.getActiveCamera(),
scenePass,
scenePipeline,
sizeof(glm::mat4),
recordMesh,
renderTargets,
windowHandle
);
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
gui.beginGUI();
ImGui::Begin("Settings");
ImGui::Text("Deltatime %fms, %f", dt * 1000, 1/dt);
ImGui::End();
gui.endGUI();
});
return 0;
}
first_triangle
\ No newline at end of file
cmake_minimum_required(VERSION 3.16)
project(first_triangle)
# 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_triangle src/main.cpp)
# including headers of dependencies and the VkCV framework
target_include_directories(first_triangle SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes} ${vkcv_testing_include} ${vkcv_camera_include} ${vkcv_shader_compiler_include} ${vkcv_gui_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(first_triangle vkcv vkcv_testing vkcv_camera vkcv_shader_compiler vkcv_gui)
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
void main() {
outColor = vec4(fragColor, 1.0);
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) out vec3 fragColor;
layout( push_constant ) uniform constants{
mat4 mvp;
};
void main() {
vec3 positions[3] = {
vec3(-0.5, 0.5, -1),
vec3( 0.5, 0.5, -1),
vec3(0, -0.5, -1)
};
vec3 colors[3] = {
vec3(1, 0, 0),
vec3(0, 1, 0),
vec3(0, 0, 1)
};
gl_Position = mvp * vec4(positions[gl_VertexIndex], 1.0);
fragColor = colors[gl_VertexIndex];
}
\ No newline at end of file
#include <iostream>
#include <vkcv/Core.hpp>
#include <vkcv/Pass.hpp>
#include <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
int main(int argc, const char** argv) {
const std::string applicationName = "First Triangle";
const int windowWidth = 800;
const int windowHeight = 600;
vkcv::Core core = vkcv::Core::create(
applicationName,
VK_MAKE_VERSION(0, 0, 1),
{ vk::QueueFlagBits::eGraphics },
{ VK_KHR_SWAPCHAIN_EXTENSION_NAME }
);
vkcv::WindowHandle windowHandle = core.createWindow(applicationName, windowWidth, windowHeight, true);
vkcv::Window& window = core.getWindow(windowHandle);
vkcv::PassHandle trianglePass = vkcv::passSwapchain(
core,
window.getSwapchain(),
{ vk::Format::eUndefined }
);
if (!trianglePass) {
std::cout << "Error. Could not create renderpass. Exiting." << std::endl;
return EXIT_FAILURE;
}
core.setDebugLabel(trianglePass, "Triangle Pass");
vkcv::ShaderProgram triangleShaderProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compileProgram(triangleShaderProgram, {
{vkcv::ShaderStage::VERTEX, "shaders/shader.vert"},
{ vkcv::ShaderStage::FRAGMENT, "shaders/shader.frag" }
}, nullptr);
vkcv::GraphicsPipelineHandle trianglePipeline = core.createGraphicsPipeline(
vkcv::GraphicsPipelineConfig(
triangleShaderProgram,
trianglePass,
{},
{}
)
);
if (!trianglePipeline) {
std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
core.setDebugLabel(trianglePipeline, "Triangle Pipeline");
vkcv::VertexData vertexData;
vertexData.setCount(3);
vkcv::InstanceDrawcall drawcall (vertexData);
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
vkcv::camera::CameraManager cameraManager(window);
auto camHandle = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
cameraManager.getCamera(camHandle).setPosition(glm::vec3(0, 0, -2));
core.run([&](const vkcv::WindowHandle &windowHandle, double t, double dt,
uint32_t swapchainWidth, uint32_t swapchainHeight) {
cameraManager.update(dt);
glm::mat4 mvp = cameraManager.getActiveCamera().getMVP();
auto cmdStream = core.createCommandStream(vkcv::QueueType::Graphics);
core.setDebugLabel(cmdStream, "Render Commands");
core.recordDrawcallsToCmdStream(
cmdStream,
trianglePipeline,
vkcv::pushConstants<glm::mat4>(mvp),
{ drawcall },
{ swapchainInput },
windowHandle
);
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
});
return 0;
}
head_demo
\ No newline at end of file
cmake_minimum_required(VERSION 3.16)
project(head_demo)
# 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(head_demo src/main.cpp)
# including headers of dependencies and the VkCV framework
target_include_directories(head_demo SYSTEM BEFORE PRIVATE
${vkcv_include}
${vkcv_includes}
${vkcv_asset_loader_include}
${vkcv_camera_include}
${vkcv_scene_include}
${vkcv_shader_compiler_include}
${vkcv_gui_include}
${vkcv_effects_include}
${vkcv_upscaling_include})
# linking with libraries from all dependencies and the VkCV framework
target_link_libraries(head_demo
vkcv
${vkcv_libraries}
vkcv_asset_loader
${vkcv_asset_loader_libraries}
vkcv_camera vkcv_scene
vkcv_shader_compiler
vkcv_gui
vkcv_effects
vkcv_upscaling)
#define CLIP_SCALE 10000.0f
vec4 clipPosition(vec4 pos) {
return vec4(
max(clipX, pos.x),
max(clipY, pos.y),
max(clipZ, pos.z),
1.0f / CLIP_SCALE
);
}
vec4 clipByLimit(vec4 pos) {
if (pos.x / pos.w < clipLimit) {
return vec4(pos.xyz / pos.w, 1.0f);
} else {
return vec4(clipLimit, pos.y / pos.w, pos.z / pos.w, 1.0f);
}
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 passNormal;
layout(location = 1) in vec3 passEdge;
layout(location = 0) out vec3 outColor;
void main() {
outColor = (0.1f + max(dot(passNormal, vec3(1.0f, -1.0f, 0.5f)), 0.0f) * 0.9f) * (passEdge + 0.5f);
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 passNormal;
layout(location = 0) out vec3 outColor;
void main() {
outColor = (vec3(0.3f) + max(dot(passNormal, vec3(1.0f, -1.0f, 0.5f)), 0.0f) * vec3(0.7f));
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_GOOGLE_include_directive : enable
layout(triangles) in;
layout(triangle_strip, max_vertices = 3) out;
layout(location = 0) in vec3 geomNormal[];
layout(location = 0) out vec3 passNormal;
layout(set=1, binding=0) uniform clipBuffer {
float clipLimit;
float clipX;
float clipY;
float clipZ;
};
layout( push_constant ) uniform constants{
mat4 mvp;
};
#include "clip.inc"
void main() {
vec4 v0 = gl_in[0].gl_Position;
vec4 v1 = gl_in[1].gl_Position;
vec4 v2 = gl_in[2].gl_Position;
v0 = clipPosition(v0 / CLIP_SCALE);
v1 = clipPosition(v1 / CLIP_SCALE);
v2 = clipPosition(v2 / CLIP_SCALE);
float dx = abs(v0.x - clipX) + abs(v1.x - clipX) + abs(v2.x - clipX);
float dy = abs(v0.y - clipY) + abs(v1.y - clipY) + abs(v2.y - clipY);
float dz = abs(v0.z - clipZ) + abs(v1.z - clipZ) + abs(v2.z - clipZ);
if (dx * dy * dz > 0.0f) {
gl_Position = mvp * (v0 * CLIP_SCALE);
passNormal = geomNormal[0];
EmitVertex();
gl_Position = mvp * (v1 * CLIP_SCALE);
passNormal = geomNormal[1];
EmitVertex();
gl_Position = mvp * (v2 * CLIP_SCALE);
passNormal = geomNormal[2];
EmitVertex();
EndPrimitive();
}
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) in vec3 inPosition;
layout(location = 1) in vec3 inNormal;
layout(location = 0) out vec3 geomNormal;
void main() {
gl_Position = vec4(inPosition, 1.0);
geomNormal = inNormal;
}
\ No newline at end of file