Skip to content
Snippets Groups Projects
Verified Commit 2e4b1b45 authored by Tobias Frisch's avatar Tobias Frisch
Browse files

Merge branch 'develop' into 69-partikelsystem

parents ee976b56 87f98dec
No related branches found
No related tags found
1 merge request!56Resolve "Partikelsystem"
Pipeline #26184 passed
Showing
with 472 additions and 42 deletions
......@@ -80,4 +80,7 @@ set(vkcv_sources
${vkcv_source}/vkcv/CommandStreamManager.cpp
${vkcv_include}/vkcv/CommandRecordingFunctionTypes.hpp
${vkcv_include}/vkcv/ImageConfig.hpp
${vkcv_source}/vkcv/ImageConfig.cpp
)
......@@ -78,8 +78,6 @@ namespace vkcv
event_handle<int,int> e_resizeHandle;
static std::vector<vk::ImageView> createSwapchainImageViews( Context &context, Swapchain& swapChain);
public:
/**
* Destructor of #Core destroys the Vulkan objects contained in the core's context.
......@@ -215,13 +213,19 @@ namespace vkcv
*/
[[nodiscard]]
Image createImage(
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth = 1,
bool createMipChain = false,
bool supportStorage = false,
bool supportColorAttachment = false);
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth = 1,
bool createMipChain = false,
bool supportStorage = false,
bool supportColorAttachment = false,
Multisampling multisampling = Multisampling::None);
[[nodiscard]]
const uint32_t getImageWidth(ImageHandle imageHandle);
[[nodiscard]]
const uint32_t getImageHeight(ImageHandle imageHandle);
/** TODO:
* @param setDescriptions
......@@ -285,7 +289,8 @@ namespace vkcv
void prepareImageForStorage(const CommandStreamHandle cmdStream, const ImageHandle image);
void recordImageMemoryBarrier(const CommandStreamHandle cmdStream, const ImageHandle image);
void recordBufferMemoryBarrier(const CommandStreamHandle cmdStream, const BufferHandle buffer);
void resolveMSAAImage(CommandStreamHandle cmdStream, ImageHandle src, ImageHandle dst);
vk::ImageView getSwapchainImageView() const;
};
......
......@@ -7,11 +7,11 @@
#include "vulkan/vulkan.hpp"
#include "Handles.hpp"
#include "vkcv/ImageConfig.hpp"
namespace vkcv {
// forward declares
class ImageManager;
class ImageManager;
bool isDepthFormat(const vk::Format format);
......@@ -50,15 +50,16 @@ namespace vkcv {
Image(ImageManager* manager, const ImageHandle& handle);
static Image create(
ImageManager* manager,
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipCount,
bool supportStorage,
bool supportColorAttachment);
ImageManager* manager,
vk::Format format,
uint32_t width,
uint32_t height,
uint32_t depth,
uint32_t mipCount,
bool supportStorage,
bool supportColorAttachment,
Multisampling msaa);
};
}
#pragma once
#include <vulkan/vulkan.hpp>
namespace vkcv {
enum class Multisampling { None, MSAA2X, MSAA4X, MSAA8X };
vk::SampleCountFlagBits msaaToVkSampleCountFlag(Multisampling msaa);
uint32_t msaaToSampleCount(Multisampling msaa);
}
......@@ -2,6 +2,7 @@
#include <vector>
#include <vulkan/vulkan.hpp>
#include "ImageConfig.hpp"
namespace vkcv
{
......@@ -45,7 +46,8 @@ namespace vkcv
struct PassConfig
{
explicit PassConfig(std::vector<AttachmentDescription> attachments) noexcept;
explicit PassConfig(std::vector<AttachmentDescription> attachments, Multisampling msaa = Multisampling::None) noexcept;
std::vector<AttachmentDescription> attachments{};
Multisampling msaa;
};
}
\ No newline at end of file
......@@ -10,26 +10,35 @@
#include "Handles.hpp"
#include "ShaderProgram.hpp"
#include "VertexLayout.hpp"
#include "ImageConfig.hpp"
namespace vkcv {
enum class PrimitiveTopology{PointList, LineList, TriangleList };
enum class CullMode{ None, Front, Back };
enum class DepthTest { None, Less, LessEqual, Greater, GreatherEqual, Equal };
// add more as needed
// alternatively we could expose the blend factors directly
enum class BlendMode{ None, Additive };
struct PipelineConfig {
ShaderProgram m_ShaderProgram;
uint32_t m_Width;
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
BlendMode m_blendMode = BlendMode::None;
ShaderProgram m_ShaderProgram;
uint32_t m_Width;
uint32_t m_Height;
PassHandle m_PassHandle;
VertexLayout m_VertexLayout;
std::vector<vk::DescriptorSetLayout> m_DescriptorLayouts;
bool m_UseDynamicViewport;
bool m_UseConservativeRasterization = false;
PrimitiveTopology m_PrimitiveTopology = PrimitiveTopology::TriangleList;
BlendMode m_blendMode = BlendMode::None;
bool m_EnableDepthClamping = false;
Multisampling m_multisampling = Multisampling::None;
CullMode m_culling = CullMode::None;
DepthTest m_depthTest = DepthTest::LessEqual;
bool m_depthWrite = true;
bool m_alphaToCoverage = false;
};
}
\ No newline at end of file
......@@ -7,6 +7,9 @@
namespace vkcv
{
const uint32_t MIN_SWAPCHAIN_SIZE = 2;
class Swapchain final {
private:
friend class Core;
......@@ -119,4 +122,5 @@ namespace vkcv
const vk::Extent2D& getExtent() const;
};
}
......@@ -157,6 +157,13 @@ namespace vkcv {
* Destructor of #Window, terminates GLFW
*/
virtual ~Window();
/**
* gets the windows framebuffer size
* @param width
* @param height
*/
void getFramebufferSize(int& width, int& height) const;
};
}
# Add new modules here:
add_subdirectory(asset_loader)
add_subdirectory(material)
add_subdirectory(camera)
add_subdirectory(gui)
add_subdirectory(shader_compiler)
......
......@@ -9,6 +9,7 @@
#include <vector>
#include <array>
#include <cstdint>
#include <filesystem>
/** These macros define limits of the following structs. Implementations can
* test against these limits when performing sanity checks. The main constraint
......@@ -114,7 +115,8 @@ enum class PrimitiveType : uint32_t {
POSITION = 1,
NORMAL = 2,
TEXCOORD_0 = 3,
TEXCOORD_1 = 4
TEXCOORD_1 = 4,
TANGENT = 5
};
/** These integer values are used the same way in OpenGL, Vulkan and glTF. This
......@@ -189,5 +191,12 @@ typedef struct {
* */
int loadScene(const std::string &path, Scene &scene);
struct TextureData {
int width;
int height;
int componentCount;
std::vector<char*> data;
};
TextureData loadTexture(const std::filesystem::path& path);
}
......@@ -63,8 +63,7 @@ enum IndexType getIndexType(const enum fx::gltf::Accessor::ComponentType &t)
case fx::gltf::Accessor::ComponentType::UnsignedInt:
return IndexType::UINT32;
default:
std::cerr << "ERROR: Index type not supported: " <<
static_cast<uint16_t>(t) << std::endl;
vkcv_log(LogLevel::ERROR, "Index type not supported: %u", static_cast<uint16_t>(t));
return IndexType::UNDEFINED;
}
}
......@@ -174,8 +173,11 @@ int loadScene(const std::string &path, Scene &scene){
attribute.type = PrimitiveType::NORMAL;
} else if (attrib.first == "TEXCOORD_0") {
attribute.type = PrimitiveType::TEXCOORD_0;
} else if (attrib.first == "TEXCOORD_1") {
}
else if (attrib.first == "TEXCOORD_1") {
attribute.type = PrimitiveType::TEXCOORD_1;
} else if (attrib.first == "TANGENT") {
attribute.type = PrimitiveType::TANGENT;
} else {
return 0;
}
......@@ -363,4 +365,23 @@ int loadScene(const std::string &path, Scene &scene){
return 1;
}
TextureData loadTexture(const std::filesystem::path& path) {
TextureData texture;
uint8_t* data = stbi_load(path.string().c_str(), &texture.width, &texture.height, &texture.componentCount, 4);
if (!data) {
vkcv_log(LogLevel::ERROR, "Texture could not be loaded from '%s'", path.c_str());
texture.width = 0;
texture.height = 0;
texture.componentCount = 0;
return texture;
}
texture.data.resize(texture.width * texture.height * 4);
memcpy(texture.data.data(), data, texture.data.size());
return texture;
}
}
cmake_minimum_required(VERSION 3.16)
project(vkcv_material)
# setting c++ standard for the module
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(vkcv_material_source ${PROJECT_SOURCE_DIR}/src)
set(vkcv_material_include ${PROJECT_SOURCE_DIR}/include)
# Add source and header files to the module
set(vkcv_material_sources
${vkcv_material_include}/vkcv/material/Material.hpp
${vkcv_material_source}/vkcv/material/Material.cpp
${vkcv_material_include}/vkcv/material/PBRMaterial.hpp
${vkcv_material_source}/vkcv/material/PBRMaterial.cpp
)
# adding source files to the module
add_library(vkcv_material STATIC ${vkcv_material_sources})
# link the required libraries to the module
target_link_libraries(vkcv_material vkcv ${vkcv_libraries})
# including headers of dependencies and the VkCV framework
target_include_directories(vkcv_material SYSTEM BEFORE PRIVATE ${vkcv_include} ${vkcv_includes})
# add the own include directory for public headers
target_include_directories(vkcv_material BEFORE PUBLIC ${vkcv_material_include})
#pragma once
#include <vkcv/Handles.hpp>
namespace vkcv::material {
class Material {
private:
public:
const DescriptorSetHandle m_DescriptorSetHandle;
protected:
Material(const DescriptorSetHandle& setHandle);
};
}
#pragma once
#include <vector>
#include <vkcv/DescriptorConfig.hpp>
#include <vkcv/Core.hpp>
#include "Material.hpp"
namespace vkcv::material
{
class PBRMaterial : Material
{
private:
struct vec3 {
float x, y, z;
};
struct vec4 {
float x, y, z, a;
};
PBRMaterial(const ImageHandle& colorImg,
const SamplerHandle& colorSmp,
const ImageHandle& normalImg,
const SamplerHandle& normalSmp,
const ImageHandle& metRoughImg,
const SamplerHandle& metRoughSmp,
const ImageHandle& occlusionImg,
const SamplerHandle& occlusionSmp,
const ImageHandle& emissiveImg,
const SamplerHandle& emissiveSmp,
const DescriptorSetHandle& setHandle,
vec4 baseColorFactor,
float metallicFactor,
float roughnessFactor,
float normalScale,
float occlusionStrength,
vec3 emissiveFactor) noexcept;
public:
PBRMaterial() = delete;
const ImageHandle m_ColorTexture;
const SamplerHandle m_ColorSampler;
const ImageHandle m_NormalTexture;
const SamplerHandle m_NormalSampler;
const ImageHandle m_MetRoughTexture;
const SamplerHandle m_MetRoughSampler;
const ImageHandle m_OcclusionTexture;
const SamplerHandle m_OcclusionSampler;
const ImageHandle m_EmissiveTexture;
const SamplerHandle m_EmissiveSampler;
//
const vec4 m_BaseColorFactor;
const float m_MetallicFactor;
const float m_RoughnessFactor;
const float m_NormalScale;
const float m_OcclusionStrength;
const vec3 m_EmissiveFactor;
/*
* Returns the material's necessary descriptor bindings which serves as its descriptor layout
* The binding is in the following order:
* 0 - diffuse texture
* 1 - diffuse sampler
* 2 - normal texture
* 3 - normal sampler
* 4 - metallic roughness texture
* 5 - metallic roughness sampler
* 6 - occlusion texture
* 7 - occlusion sampler
* 8 - emissive texture
* 9 - emissive sampler
*/
static std::vector<DescriptorBinding> getDescriptorBindings() noexcept;
static PBRMaterial create(
vkcv::Core* core,
ImageHandle &colorImg,
SamplerHandle &colorSmp,
ImageHandle &normalImg,
SamplerHandle &normalSmp,
ImageHandle &metRoughImg,
SamplerHandle &metRoughSmp,
ImageHandle &occlusionImg,
SamplerHandle &occlusionSmp,
ImageHandle &emissiveImg,
SamplerHandle &emissiveSmp,
vec4 baseColorFactor,
float metallicFactor,
float roughnessFactor,
float normalScale,
float occlusionStrength,
vec3 emissiveFactor);
};
}
\ No newline at end of file
#include "vkcv/material/Material.hpp"
namespace vkcv::material {
//TODO
Material::Material(const DescriptorSetHandle& setHandle) : m_DescriptorSetHandle(setHandle)
{
}
}
#include "vkcv/material/PBRMaterial.hpp"
namespace vkcv::material
{
PBRMaterial::PBRMaterial(
const ImageHandle& colorImg,
const SamplerHandle& colorSmp,
const ImageHandle& normalImg,
const SamplerHandle& normalSmp,
const ImageHandle& metRoughImg,
const SamplerHandle& metRoughSmp,
const ImageHandle& occlusionImg,
const SamplerHandle& occlusionSmp,
const ImageHandle& emissiveImg,
const SamplerHandle& emissiveSmp,
const DescriptorSetHandle& setHandle,
vec4 baseColorFactor,
float metallicFactor,
float roughnessFactor,
float normalScale,
float occlusionStrength,
vec3 emissiveFactor) noexcept :
m_ColorTexture(colorImg),
m_ColorSampler(colorSmp),
m_NormalTexture(normalImg),
m_NormalSampler(normalSmp),
m_MetRoughTexture(metRoughImg),
m_MetRoughSampler(metRoughSmp),
m_OcclusionTexture(occlusionImg),
m_OcclusionSampler(occlusionSmp),
m_EmissiveTexture(emissiveImg),
m_EmissiveSampler(emissiveSmp),
Material(setHandle),
m_BaseColorFactor(baseColorFactor),
m_MetallicFactor(metallicFactor),
m_RoughnessFactor(roughnessFactor),
m_NormalScale(normalScale),
m_OcclusionStrength(occlusionStrength),
m_EmissiveFactor(emissiveFactor)
{
}
std::vector<DescriptorBinding> PBRMaterial::getDescriptorBindings() noexcept
{
static std::vector<DescriptorBinding> bindings;
if (bindings.empty()) {
bindings.emplace_back(0, DescriptorType::IMAGE_SAMPLED, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(1, DescriptorType::SAMPLER, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(2, DescriptorType::IMAGE_SAMPLED, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(3, DescriptorType::SAMPLER, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(4, DescriptorType::IMAGE_SAMPLED, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(5, DescriptorType::SAMPLER, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(6, DescriptorType::IMAGE_SAMPLED, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(7, DescriptorType::SAMPLER, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(8, DescriptorType::IMAGE_SAMPLED, 1, ShaderStage::FRAGMENT);
bindings.emplace_back(9, DescriptorType::SAMPLER, 1, ShaderStage::FRAGMENT);
}
return bindings;
}
PBRMaterial PBRMaterial::create(
vkcv::Core* core,
ImageHandle& colorImg,
SamplerHandle& colorSmp,
ImageHandle& normalImg,
SamplerHandle& normalSmp,
ImageHandle& metRoughImg,
SamplerHandle& metRoughSmp,
ImageHandle& occlusionImg,
SamplerHandle& occlusionSmp,
ImageHandle& emissiveImg,
SamplerHandle& emissiveSmp,
vec4 baseColorFactor,
float metallicFactor,
float roughnessFactor,
float normalScale,
float occlusionStrength,
vec3 emissiveFactor)
{
//Test if Images and samplers valid, if not use default
if (!colorImg) {
vkcv::Image defaultColor = core->createImage(vk::Format::eR8G8B8A8Srgb, 1, 1);
vec4 colorData{ 228, 51, 255,1 };
defaultColor.fill(&colorData);
colorImg = defaultColor.getHandle();
}
if (!normalImg) {
vkcv::Image defaultNormal = core->createImage(vk::Format::eR8G8B8A8Srgb, 1, 1);
vec4 normalData{ 0, 0, 1,0 };
defaultNormal.fill(&normalData);
normalImg = defaultNormal.getHandle();
}
if (!metRoughImg) {
vkcv::Image defaultRough = core->createImage(vk::Format::eR8G8B8A8Srgb, 1, 1);
vec4 roughData{ 228, 51, 255,1 };
defaultRough.fill(&roughData);
metRoughImg = defaultRough.getHandle();
}
if (!occlusionImg) {
vkcv::Image defaultOcclusion = core->createImage(vk::Format::eR8G8B8A8Srgb, 1, 1);
vec4 occlusionData{ 228, 51, 255,1 };
defaultOcclusion.fill(&occlusionData);
occlusionImg = defaultOcclusion.getHandle();
}
if (!emissiveImg) {
vkcv::Image defaultEmissive = core->createImage(vk::Format::eR8G8B8A8Srgb, 1, 1);
vec4 emissiveData{ 0, 0, 0,1 };
defaultEmissive.fill(&emissiveData);
emissiveImg = defaultEmissive.getHandle();
}
if (!colorSmp) {
colorSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerMipmapMode::LINEAR,
vkcv::SamplerAddressMode::REPEAT
);
}
if (!normalSmp) {
normalSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerMipmapMode::LINEAR,
vkcv::SamplerAddressMode::REPEAT
);
}
if (!metRoughSmp) {
metRoughSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerMipmapMode::LINEAR,
vkcv::SamplerAddressMode::REPEAT
);
}
if (!occlusionSmp) {
occlusionSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerMipmapMode::LINEAR,
vkcv::SamplerAddressMode::REPEAT
);
}
if (!emissiveSmp) {
emissiveSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerMipmapMode::LINEAR,
vkcv::SamplerAddressMode::REPEAT
);
}
//create descriptorset
vkcv::DescriptorSetHandle descriptorSetHandle = core->createDescriptorSet(getDescriptorBindings());
//writes
vkcv::DescriptorWrites setWrites;
setWrites.sampledImageWrites = {
vkcv::SampledImageDescriptorWrite(0, colorImg),
vkcv::SampledImageDescriptorWrite(2, normalImg),
vkcv::SampledImageDescriptorWrite(4, metRoughImg),
vkcv::SampledImageDescriptorWrite(6, occlusionImg),
vkcv::SampledImageDescriptorWrite(8, emissiveImg) };
setWrites.samplerWrites = {
vkcv::SamplerDescriptorWrite(1, colorSmp),
vkcv::SamplerDescriptorWrite(3, normalSmp),
vkcv::SamplerDescriptorWrite(5, metRoughSmp),
vkcv::SamplerDescriptorWrite(7, occlusionSmp),
vkcv::SamplerDescriptorWrite(9, emissiveSmp) };
core->writeDescriptorSet(descriptorSetHandle, setWrites);
return PBRMaterial(
colorImg,
colorSmp,
normalImg,
normalSmp,
metRoughImg,
metRoughSmp,
occlusionImg,
occlusionSmp,
emissiveImg,
emissiveSmp,
descriptorSetHandle,
baseColorFactor,
metallicFactor,
roughnessFactor,
normalScale,
occlusionStrength,
emissiveFactor);
}
}
\ No newline at end of file
......@@ -13,7 +13,11 @@ add_executable(voxelization src/main.cpp)
target_sources(voxelization PRIVATE
src/Voxelization.hpp
src/Voxelization.cpp)
src/Voxelization.cpp
src/ShadowMapping.hpp
src/ShadowMapping.cpp
src/BloomAndFlares.hpp
src/BloomAndFlares.cpp)
# this should fix the execution path to load local files from the project (for MSVC)
if(MSVC)
......
projects/voxelization/resources/Sponza/sponza_thorn_diff.png

131 B | W: | H:

projects/voxelization/resources/RadialLUT.png

128 B | W: | H:

projects/voxelization/resources/Sponza/sponza_thorn_diff.png
projects/voxelization/resources/RadialLUT.png
projects/voxelization/resources/Sponza/sponza_thorn_diff.png
projects/voxelization/resources/RadialLUT.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
Source diff could not be displayed: it is stored in LFS. Options to address this: view the blob.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment