Skip to content
Snippets Groups Projects
Commit 467e5c75 authored by Alexander Gauggel's avatar Alexander Gauggel
Browse files

[#82] Add simple sky

parent 7ceebe33
No related branches found
No related tags found
1 merge request!70Resolve "Voxel cone tracing"
Pipeline #26004 failed
#version 450
#extension GL_ARB_separate_shader_objects : enable
layout(location = 0) out vec3 outColor;
layout( push_constant ) uniform constants{
vec3 skyColor;
float skyStrength;
};
void main() {
outColor = skyColor * skyStrength;
}
\ No newline at end of file
#version 450
#extension GL_ARB_separate_shader_objects : enable
const vec2 positions[3] = {
vec2(-1, -1),
vec2(-1, 4),
vec2(4, -1)
};
void main() {
gl_Position = vec4(positions[gl_VertexIndex], 1, 1);
}
\ No newline at end of file
......@@ -286,6 +286,52 @@ int main(int argc, const char** argv) {
return EXIT_FAILURE;
}
// sky
struct SkySettings {
glm::vec3 color;
float strength;
};
SkySettings skySettings;
skySettings.color = glm::vec3(0.15, 0.65, 1);
skySettings.strength = 5;
const vkcv::AttachmentDescription skyColorAttachment(
vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::LOAD,
colorBufferFormat);
const vkcv::AttachmentDescription skyDepthAttachments(
vkcv::AttachmentOperation::STORE,
vkcv::AttachmentOperation::LOAD,
depthBufferFormat);
vkcv::PassConfig skyPassConfig({ skyColorAttachment, skyDepthAttachments }, msaa);
vkcv::PassHandle skyPass = core.createPass(skyPassConfig);
vkcv::ShaderProgram skyShader;
compiler.compile(vkcv::ShaderStage::VERTEX, std::filesystem::path("resources/shaders/sky.vert"),
[&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
skyShader.addShader(shaderStage, path);
});
compiler.compile(vkcv::ShaderStage::FRAGMENT, std::filesystem::path("resources/shaders/sky.frag"),
[&](vkcv::ShaderStage shaderStage, const std::filesystem::path& path) {
skyShader.addShader(shaderStage, path);
});
vkcv::PipelineConfig skyPipeConfig;
skyPipeConfig.m_ShaderProgram = skyShader;
skyPipeConfig.m_Width = windowWidth;
skyPipeConfig.m_Height = windowHeight;
skyPipeConfig.m_PassHandle = skyPass;
skyPipeConfig.m_VertexLayout = vkcv::VertexLayout({});
skyPipeConfig.m_DescriptorLayouts = {};
skyPipeConfig.m_UseDynamicViewport = true;
skyPipeConfig.m_multisampling = msaa;
skyPipeConfig.m_depthWrite = false;
vkcv::PipelineHandle skyPipe = core.createGraphicsPipeline(skyPipeConfig);
// render targets
vkcv::ImageHandle depthBuffer = core.createImage(depthBufferFormat, windowWidth, windowHeight, 1, false, false, false, msaa).getHandle();
const bool colorBufferRequiresStorage = !usingMsaa;
......@@ -526,6 +572,15 @@ int main(int argc, const char** argv) {
voxelization.renderVoxelVisualisation(cmdStream, viewProjectionCamera, renderTargets, voxelVisualisationMip);
}
// sky
core.recordDrawcallsToCmdStream(
cmdStream,
skyPass,
skyPipe,
vkcv::PushConstantData((void*)&skySettings, sizeof(skySettings)),
{ vkcv::DrawcallInfo(vkcv::Mesh({}, nullptr, 3), {}) },
renderTargets);
const uint32_t fullscreenLocalGroupSize = 8;
const uint32_t fulsscreenDispatchCount[3] = {
static_cast<uint32_t>(glm::ceil(windowWidth / static_cast<float>(fullscreenLocalGroupSize))),
......@@ -581,6 +636,9 @@ int main(int argc, const char** argv) {
ImGui::DragFloat("Max shadow distance", &maxShadowDistance);
maxShadowDistance = std::max(maxShadowDistance, 1.f);
ImGui::ColorEdit3("Sky color", &skySettings.color.x);
ImGui::DragFloat("Sky strength", &skySettings.strength, 0.1);
ImGui::Checkbox("Draw voxel visualisation", &renderVoxelVis);
ImGui::SliderInt("Visualisation mip", &voxelVisualisationMip, 0, 7);
ImGui::DragFloat("Voxelization extent", &voxelizationExtent, 1.f, 0.f);
......
......@@ -27,12 +27,14 @@ namespace vkcv {
// char* cast because void* does not support pointer arithmetic
const void* drawcallPushConstantData = drawcallPushConstantOffset + (char*)pushConstantData.data;
cmdBuffer.pushConstants(
pipelineLayout,
vk::ShaderStageFlagBits::eAll,
0,
pushConstantData.sizePerDrawcall,
drawcallPushConstantData);
if (pushConstantData.data && pushConstantData.sizePerDrawcall > 0) {
cmdBuffer.pushConstants(
pipelineLayout,
vk::ShaderStageFlagBits::eAll,
0,
pushConstantData.sizePerDrawcall,
drawcallPushConstantData);
}
if (drawcall.mesh.indexBuffer) {
cmdBuffer.bindIndexBuffer(drawcall.mesh.indexBuffer, 0, vk::IndexType::eUint16); //FIXME: choose proper size
......
......@@ -221,14 +221,18 @@ namespace vkcv
{ 1.f,1.f,1.f,1.f }
);
const size_t matrixPushConstantSize = config.m_ShaderProgram.getPushConstantSize();
const vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eAll, 0, matrixPushConstantSize);
const size_t pushConstantSize = config.m_ShaderProgram.getPushConstantSize();
const vk::PushConstantRange pushConstantRange(vk::ShaderStageFlagBits::eAll, 0, pushConstantSize);
// pipeline layout
vk::PipelineLayoutCreateInfo pipelineLayoutCreateInfo(
{},
(config.m_DescriptorLayouts),
(pushConstantRange));
if (pushConstantSize == 0) {
pipelineLayoutCreateInfo.pushConstantRangeCount = 0;
}
vk::PipelineLayout vkPipelineLayout{};
if (m_Device.createPipelineLayout(&pipelineLayoutCreateInfo, nullptr, &vkPipelineLayout) != vk::Result::eSuccess)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment