Skip to content
Snippets Groups Projects
Commit 40b590ac authored by Lars Hoerttrich's avatar Lars Hoerttrich
Browse files

[#57] Creation of default-textures

parent 459dc325
No related branches found
No related tags found
1 merge request!44Resolve "Material (Modul)"
Pipeline #25886 failed
...@@ -222,6 +222,11 @@ namespace vkcv ...@@ -222,6 +222,11 @@ namespace vkcv
[[nodiscard]] [[nodiscard]]
Image createImage(vk::Format format, uint32_t width, uint32_t height, uint32_t depth = 1); Image createImage(vk::Format format, uint32_t width, uint32_t height, uint32_t depth = 1);
[[nodiscard]]
const uint32_t getImageWidth(ImageHandle imageHandle);
[[nodiscard]]
const uint32_t getImageHeight(ImageHandle imageHandle);
/** TODO: /** TODO:
* @param setDescriptions * @param setDescriptions
* @return * @return
......
# Add new modules here: # Add new modules here:
add_subdirectory(asset_loader) add_subdirectory(asset_loader)
add_subdirectory(material)
add_subdirectory(camera) add_subdirectory(camera)
add_subdirectory(gui) add_subdirectory(gui)
add_subdirectory(shader_compiler) add_subdirectory(shader_compiler)
......
...@@ -40,16 +40,41 @@ namespace vkcv::material ...@@ -40,16 +40,41 @@ namespace vkcv::material
SamplerHandle& metRoughSmp) SamplerHandle& metRoughSmp)
{ {
//Test if Images and samplers valid, if not use default //Test if Images and samplers valid, if not use default
if (colorImg) { uint32_t width = core->getImageWidth(colorImg); //use colorImg size as default
//TODO uint32_t height = core->getImageHeight(colorImg);
uint32_t n = width * height;
struct vec3 {
float x, y, z;
};
struct vec4 {
float x, y, z, a;
};
if (!colorImg) {
width = core->getImageWidth(metRoughImg); // if colorImg has no size
height = core->getImageHeight(metRoughImg);
n = width * height;
vkcv::Image defaultColor = core->createImage(vk::Format::eR8G8B8A8Srgb, width, height);
std::vector<vec4> colorData(n);
std::fill(colorData.begin(), colorData.end(), vec4{ 228, 51 , 255, 1 });
defaultColor.fill(colorData.data());
colorImg = defaultColor.getHandle();
} }
if (normalImg) { if (!normalImg || (core->getImageWidth(normalImg)!=width)|| (core->getImageHeight(normalImg) != height)) {
//TODO vkcv::Image defaultNormal = core->createImage(vk::Format::eR8G8B8A8Srgb, width, height);
std::vector<vec4> normalData(n);
std::fill(normalData.begin(), normalData.end(), vec4{ 228, 51 , 255, 1 });
defaultNormal.fill(normalData.data());
normalImg = defaultNormal.getHandle();
} }
if (metRoughImg) { if (!metRoughImg || (core->getImageWidth(metRoughImg) != width) || (core->getImageHeight(metRoughImg) != height)) {
//TODO vkcv::Image defaultRough = core->createImage(vk::Format::eR8G8B8A8Srgb, width, height);
std::vector<vec4> roughData(n);
std::fill(roughData.begin(), roughData.end(), vec4{ 228, 51 , 255, 1 });
defaultRough.fill(roughData.data());
metRoughImg = defaultRough.getHandle();
} }
if (colorSmp) { if (!colorSmp) {
colorSmp = core->createSampler( colorSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
...@@ -57,7 +82,7 @@ namespace vkcv::material ...@@ -57,7 +82,7 @@ namespace vkcv::material
vkcv::SamplerAddressMode::REPEAT vkcv::SamplerAddressMode::REPEAT
); );
} }
if (normalSmp) { if (!normalSmp) {
normalSmp = core->createSampler( normalSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
...@@ -65,7 +90,7 @@ namespace vkcv::material ...@@ -65,7 +90,7 @@ namespace vkcv::material
vkcv::SamplerAddressMode::REPEAT vkcv::SamplerAddressMode::REPEAT
); );
} }
if (metRoughSmp) { if (!metRoughSmp) {
metRoughSmp = core->createSampler( metRoughSmp = core->createSampler(
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
vkcv::SamplerFilterType::LINEAR, vkcv::SamplerFilterType::LINEAR,
...@@ -87,7 +112,7 @@ namespace vkcv::material ...@@ -87,7 +112,7 @@ namespace vkcv::material
vkcv::SamplerDescriptorWrite(1, colorSmp), vkcv::SamplerDescriptorWrite(1, colorSmp),
vkcv::SamplerDescriptorWrite(3, normalSmp), vkcv::SamplerDescriptorWrite(3, normalSmp),
vkcv::SamplerDescriptorWrite(5, metRoughSmp) }; vkcv::SamplerDescriptorWrite(5, metRoughSmp) };
core->writeResourceDescription(descriptorSetHandle, 0, setWrites); core->writeDescriptorSet(descriptorSetHandle, setWrites);
return PBRMaterial(colorImg, colorSmp, normalImg, normalSmp, metRoughImg, metRoughSmp, descriptorSetHandle); return PBRMaterial(colorImg, colorSmp, normalImg, normalSmp, metRoughImg, metRoughSmp, descriptorSetHandle);
} }
......
...@@ -456,6 +456,16 @@ namespace vkcv ...@@ -456,6 +456,16 @@ namespace vkcv
return Image::create(m_ImageManager.get(), format, width, height, depth); return Image::create(m_ImageManager.get(), format, width, height, depth);
} }
const uint32_t Core::getImageWidth(ImageHandle imageHandle)
{
return m_ImageManager->getImageWidth(imageHandle);
}
const uint32_t Core::getImageHeight(ImageHandle imageHandle)
{
return m_ImageManager->getImageHeight(imageHandle);
}
DescriptorSetHandle Core::createDescriptorSet(const std::vector<DescriptorBinding>& bindings) DescriptorSetHandle Core::createDescriptorSet(const std::vector<DescriptorBinding>& bindings)
{ {
return m_DescriptorManager->createDescriptorSet(bindings); return m_DescriptorManager->createDescriptorSet(bindings);
......
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