Skip to content
Snippets Groups Projects
Commit 87a0b5b2 authored by Vanessa Karolek's avatar Vanessa Karolek
Browse files

[#92] update rtx base project

parent 9806cc12
Branches
Tags
1 merge request!75Resolve "RTX-Module"
Showing
with 225 additions and 0 deletions
projects/rtx/resources/Sponza/sponza_flagpole_diff.png

132 B

projects/rtx/resources/Sponza/sponza_floor_a_diff.png

132 B

projects/rtx/resources/Sponza/sponza_roof_diff.png

132 B

projects/rtx/resources/Sponza/sponza_thorn_diff.png

131 B

projects/rtx/resources/Sponza/vase_dif.png

132 B

projects/rtx/resources/Sponza/vase_hanging.png

132 B

projects/rtx/resources/Sponza/vase_plant.png

131 B

projects/rtx/resources/Sponza/vase_round.png

132 B

File added
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
projects/rtx/resources/Szene/boards2_vcyc.jpg

132 B

projects/rtx/resources/Szene/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;
//outColor = passNormal * 0.5 + 0.5;
}
\ 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 <GLFW/glfw3.h>
#include <vkcv/camera/CameraManager.hpp>
#include <chrono>
#include <vkcv/asset/asset_loader.hpp>
#include <vkcv/shader/GLSLCompiler.hpp>
#include <vkcv/scene/Scene.hpp>
int main(int argc, const char** argv) {
const char* applicationName = "First Scene";
uint32_t windowWidth = 800;
uint32_t windowHeight = 600;
vkcv::Window window = vkcv::Window::create(
applicationName,
windowWidth,
windowHeight,
true
);
vkcv::camera::CameraManager cameraManager(window);
uint32_t camIndex0 = cameraManager.addCamera(vkcv::camera::ControllerType::PILOT);
uint32_t camIndex1 = cameraManager.addCamera(vkcv::camera::ControllerType::TRACKBALL);
cameraManager.getCamera(camIndex0).setPosition(glm::vec3(-8, 1, -0.5));
cameraManager.getCamera(camIndex0).setNearFar(0.1f, 30.0f);
cameraManager.getCamera(camIndex1).setNearFar(0.1f, 30.0f);
vkcv::Core core = vkcv::Core::create(
window,
applicationName,
VK_MAKE_VERSION(0, 0, 1),
{ vk::QueueFlagBits::eGraphics ,vk::QueueFlagBits::eCompute , vk::QueueFlagBits::eTransfer },
{},
{ "VK_KHR_swapchain" }
);
vkcv::scene::Scene scene = vkcv::scene::Scene::load(core, std::filesystem::path(
argc > 1 ? argv[1] : "resources/Sponza/Sponza.gltf"
));
const vkcv::AttachmentDescription present_color_attachment(
vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::CLEAR,
core.getSwapchain().getFormat()
);
const vkcv::AttachmentDescription depth_attachment(
vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::CLEAR,
vk::Format::eD32Sfloat
);
vkcv::PassConfig scenePassDefinition({ present_color_attachment, depth_attachment });
vkcv::PassHandle scenePass = core.createPass(scenePassDefinition);
if (!scenePass) {
std::cout << "Error. Could not create renderpass. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::ShaderProgram sceneShaderProgram;
vkcv::shader::GLSLCompiler compiler;
compiler.compile(vkcv::ShaderStage::VERTEX, std::filesystem::path("resources/shaders/shader.vert"),
[&sceneShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
sceneShaderProgram.addShader(shaderStage, path);
});
compiler.compile(vkcv::ShaderStage::FRAGMENT, std::filesystem::path("resources/shaders/shader.frag"),
[&sceneShaderProgram](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
sceneShaderProgram.addShader(shaderStage, path);
});
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::VertexBinding(i, { vertexAttachments[i] }));
}
const vkcv::VertexLayout sceneLayout(bindings);
const auto& material0 = scene.getMaterial(0);
const vkcv::PipelineConfig scenePipelineDefsinition{
sceneShaderProgram,
UINT32_MAX,
UINT32_MAX,
scenePass,
{sceneLayout},
{ core.getDescriptorSet(material0.getDescriptorSet()).layout },
true };
vkcv::PipelineHandle scenePipeline = core.createGraphicsPipeline(scenePipelineDefsinition);
if (!scenePipeline) {
std::cout << "Error. Could not create graphics pipeline. Exiting." << std::endl;
return EXIT_FAILURE;
}
vkcv::ImageHandle depthBuffer = core.createImage(vk::Format::eD32Sfloat, windowWidth, windowHeight).getHandle();
const vkcv::ImageHandle swapchainInput = vkcv::ImageHandle::createSwapchainImageHandle();
auto start = std::chrono::system_clock::now();
while (window.isWindowOpen()) {
vkcv::Window::pollEvents();
if(window.getHeight() == 0 || window.getWidth() == 0)
continue;
uint32_t swapchainWidth, swapchainHeight;
if (!core.beginFrame(swapchainWidth, swapchainHeight)) {
continue;
}
if ((swapchainWidth != windowWidth) || ((swapchainHeight != windowHeight))) {
depthBuffer = core.createImage(vk::Format::eD32Sfloat, swapchainWidth, swapchainHeight).getHandle();
windowWidth = swapchainWidth;
windowHeight = swapchainHeight;
}
auto end = std::chrono::system_clock::now();
auto deltatime = std::chrono::duration_cast<std::chrono::microseconds>(end - start);
start = end;
cameraManager.update(0.000001 * static_cast<double>(deltatime.count()));
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::DrawcallInfo& drawcallInfo) {
pushConstants.appendDrawcall(MVP);
};
scene.recordDrawcalls(cmdStream,
cameraManager.getActiveCamera(),
scenePass,
scenePipeline,
sizeof(glm::mat4),
recordMesh,
renderTargets);
core.prepareSwapchainImageForPresent(cmdStream);
core.submitCommandStream(cmdStream);
core.endFrame();
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment