Irradiance works
This commit is contained in:
@@ -14,6 +14,20 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic
|
||||
.offset = {0, 0},
|
||||
},
|
||||
});
|
||||
convolutionViewport = graphics->createViewport(nullptr, ViewportCreateInfo{
|
||||
.dimensions =
|
||||
{
|
||||
.size = {32, 32},
|
||||
.offset = {0, 0},
|
||||
},
|
||||
});
|
||||
cubeSampler = graphics->createSampler({
|
||||
.magFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.minFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
});
|
||||
|
||||
cubeRenderLayout = graphics->createDescriptorLayout("pViewParams");
|
||||
cubeRenderLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
@@ -32,6 +46,10 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic
|
||||
.name = "sampler",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
cubeRenderLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "cubeMap",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
cubeRenderLayout->create();
|
||||
|
||||
cubePipelineLayout = graphics->createPipelineLayout("CubeRenderLayout");
|
||||
@@ -43,7 +61,8 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic
|
||||
.entryPoints =
|
||||
{
|
||||
{"vertMain", "EnvironmentMapping"},
|
||||
{"fragMain", "EnvironmentMapping"},
|
||||
{"computeCubemap", "EnvironmentMapping"},
|
||||
{"convolveCubemap", "EnvironmentMapping"},
|
||||
},
|
||||
.rootSignature = cubePipelineLayout,
|
||||
});
|
||||
@@ -51,14 +70,7 @@ EnvironmentLoader::EnvironmentLoader(Gfx::PGraphics graphics) : graphics(graphic
|
||||
|
||||
cubeRenderVertex = graphics->createVertexShader({0});
|
||||
cubeRenderFrag = graphics->createFragmentShader({1});
|
||||
|
||||
cubeSampler = graphics->createSampler({
|
||||
.magFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.minFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
});
|
||||
convolutionFrag = graphics->createFragmentShader({2});
|
||||
}
|
||||
|
||||
EnvironmentLoader::~EnvironmentLoader() {}
|
||||
@@ -93,12 +105,12 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
|
||||
});
|
||||
Matrix4 captureProjection = glm::perspective(glm::radians(90.0f), 1.0f, 0.1f, 10.0f);
|
||||
Matrix4 captureViews[] = {
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(-1.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f), Vector(0.0f, 0.0f, 1.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, -1.0f, 0.0f), Vector(0.0f, 0.0f, -1.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, 1.0f), Vector(0.0f, 1.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 0.0f, -1.0f), Vector(0.0f, 1.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, -1.0f, 0.0f), Vector(1.0f, 0.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f), Vector(1.0f, 0.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(-1.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f)),
|
||||
glm::lookAt(Vector(0.0f, 0.0f, 0.0f), Vector(1.0f, 0.0f, 0.0f), Vector(0.0f, 1.0f, 0.0f)),
|
||||
};
|
||||
Gfx::PDescriptorSet set = cubeRenderLayout->allocateDescriptorSet();
|
||||
set->updateConstants("view", 0, captureViews);
|
||||
@@ -110,9 +122,9 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = 1024,
|
||||
.height = 1024,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
|
||||
});
|
||||
cubeRenderPass = graphics->createRenderPass(
|
||||
Gfx::ORenderPass cubeRenderPass = graphics->createRenderPass(
|
||||
Gfx::RenderTargetLayout{
|
||||
.colorAttachments = {Gfx::RenderTargetAttachment(cubeMap, Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
|
||||
Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
@@ -139,9 +151,57 @@ void EnvironmentLoader::import(EnvironmentImportArgs args, PEnvironmentMapAsset
|
||||
renderCommand->bindPipeline(cubeRenderPipeline);
|
||||
renderCommand->bindDescriptor({set});
|
||||
renderCommand->setViewport(cubeRenderViewport);
|
||||
renderCommand->draw(6, 1, 0, 0);
|
||||
renderCommand->draw(36, 1, 0, 0);
|
||||
graphics->executeCommands(std::move(renderCommand));
|
||||
graphics->endRenderPass();
|
||||
|
||||
Gfx::OTextureCube convolutedMap = graphics->createTextureCube(TextureCreateInfo{
|
||||
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
|
||||
.width = 32,
|
||||
.height = 32,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
|
||||
});
|
||||
Gfx::ORenderPass convolutionPass = graphics->createRenderPass(
|
||||
Gfx::RenderTargetLayout{
|
||||
.colorAttachments = {Gfx::RenderTargetAttachment(convolutedMap, Gfx::SE_IMAGE_LAYOUT_UNDEFINED,
|
||||
Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE)},
|
||||
},
|
||||
{},
|
||||
URect{
|
||||
.size = {32, 32},
|
||||
.offset = {0, 0},
|
||||
},
|
||||
"EnvironmentRenderPass", {0b111111}, {0b111111});
|
||||
convolutionPipeline = graphics->createGraphicsPipeline(Gfx::LegacyPipelineCreateInfo{
|
||||
.vertexShader = cubeRenderVertex,
|
||||
.fragmentShader = convolutionFrag,
|
||||
.renderPass = convolutionPass,
|
||||
.pipelineLayout = cubePipelineLayout,
|
||||
.colorBlend =
|
||||
{
|
||||
.attachmentCount = 1,
|
||||
},
|
||||
});
|
||||
|
||||
set = cubeRenderLayout->allocateDescriptorSet();
|
||||
set->updateConstants("view", 0, captureViews);
|
||||
set->updateConstants("projection", 0, &captureProjection);
|
||||
set->updateSampler("sampler", 0, cubeSampler);
|
||||
set->updateTexture("cubeMap", 0, Gfx::PTextureCube(cubeMap));
|
||||
set->writeChanges();
|
||||
|
||||
graphics->beginRenderPass(convolutionPass);
|
||||
Gfx::ORenderCommand cmd = graphics->createRenderCommand("ConvolutionPass");
|
||||
cmd->bindPipeline(convolutionPipeline);
|
||||
cmd->bindDescriptor({set});
|
||||
cmd->setViewport(convolutionViewport);
|
||||
cmd->draw(36, 1, 0, 0);
|
||||
graphics->executeCommands(std::move(cmd));
|
||||
graphics->endRenderPass();
|
||||
|
||||
asset->skybox = std::move(cubeMap);
|
||||
asset->irradianceMap = std::move(convolutedMap);
|
||||
asset->specularMap = std::move(cubeMap);
|
||||
graphics->waitDeviceIdle();
|
||||
asset->diffuseMap = std::move(cubeMap);
|
||||
}
|
||||
|
||||
@@ -25,8 +25,10 @@ class EnvironmentLoader {
|
||||
Gfx::ODescriptorLayout cubeRenderLayout;
|
||||
Gfx::OPipelineLayout cubePipelineLayout;
|
||||
Gfx::PGraphicsPipeline cubeRenderPipeline;
|
||||
Gfx::ORenderPass cubeRenderPass;
|
||||
Gfx::OFragmentShader convolutionFrag;
|
||||
Gfx::PGraphicsPipeline convolutionPipeline;
|
||||
Gfx::OViewport cubeRenderViewport;
|
||||
Gfx::OViewport convolutionViewport;
|
||||
Gfx::OSampler cubeSampler;
|
||||
};
|
||||
}
|
||||
+4
-1
@@ -100,8 +100,11 @@ int main() {
|
||||
.filePath = sourcePath / "import/textures/skybox.jpg",
|
||||
.type = TextureImportType::TEXTURE_CUBEMAP,
|
||||
});
|
||||
//AssetImporter::importEnvironmentMap(EnvironmentImportArgs{
|
||||
// .filePath = sourcePath / "import/models/main1_sponza/textures/kloppenheim_05_4k.hdr",
|
||||
//});
|
||||
AssetImporter::importEnvironmentMap(EnvironmentImportArgs{
|
||||
.filePath = sourcePath / "import/models/main1_sponza/textures/kloppenheim_05_4k.hdr",
|
||||
.filePath = sourcePath / "import/textures/newport_loft.hdr",
|
||||
});
|
||||
// AssetImporter::importMesh(MeshImportArgs{
|
||||
// .filePath = sourcePath / "import/models/ship.fbx",
|
||||
|
||||
@@ -11,8 +11,12 @@ class EnvironmentMapAsset : public Asset {
|
||||
virtual ~EnvironmentMapAsset();
|
||||
virtual void save(ArchiveBuffer& buffer) const override;
|
||||
virtual void load(ArchiveBuffer& buffer) override;
|
||||
Gfx::PTextureCube getSkybox() const { return skybox; }
|
||||
Gfx::PTextureCube getIrradianceMap() const { return irradianceMap; }
|
||||
Gfx::PTextureCube getSpecularMap() const { return specularMap; }
|
||||
private:
|
||||
Gfx::OTextureCube diffuseMap;
|
||||
Gfx::OTextureCube skybox;
|
||||
Gfx::OTextureCube irradianceMap;
|
||||
Gfx::OTextureCube specularMap;
|
||||
friend class EnvironmentLoader;
|
||||
};
|
||||
|
||||
@@ -45,7 +45,6 @@ void TextureAsset::load(ArchiveBuffer& buffer) {
|
||||
.width = ktxHandle->baseWidth,
|
||||
.height = ktxHandle->baseHeight,
|
||||
.depth = ktxHandle->baseDepth,
|
||||
.layers = ktxHandle->numFaces,
|
||||
.elements = ktxHandle->numLayers,
|
||||
.useMip = true,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_SAMPLED_BIT,
|
||||
|
||||
@@ -56,7 +56,7 @@ class Graphics {
|
||||
virtual OViewport createViewport(PWindow owner, const ViewportCreateInfo& createInfo) = 0;
|
||||
|
||||
virtual ORenderPass createRenderPass(RenderTargetLayout layout, Array<SubPassDependency> dependencies, URect renderArea,
|
||||
std::string name = "", Array<uint32> viewMasks = {}, Array<uint32> correlationMasks = {}) = 0;
|
||||
std::string name = "", Array<uint32> viewMasks = {0}, Array<uint32> correlationMasks = {}) = 0;
|
||||
virtual void beginRenderPass(PRenderPass renderPass) = 0;
|
||||
virtual void endRenderPass() = 0;
|
||||
virtual void waitDeviceIdle() = 0;
|
||||
|
||||
@@ -49,7 +49,6 @@ struct TextureCreateInfo {
|
||||
uint32 width = 1;
|
||||
uint32 height = 1;
|
||||
uint32 depth = 1;
|
||||
uint32 layers = 1;
|
||||
uint32 elements = 1;
|
||||
uint32 samples = 1;
|
||||
bool useMip = false;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "BasePass.h"
|
||||
#include "Actor/CameraActor.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/EnvironmentMapAsset.h"
|
||||
#include "Component/Camera.h"
|
||||
#include "Component/Mesh.h"
|
||||
#include "Component/WaterTile.h"
|
||||
@@ -78,8 +79,8 @@ BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics)
|
||||
});
|
||||
}
|
||||
skybox = Seele::Component::Skybox{
|
||||
.day = AssetRegistry::findTexture("", "skybox")->getTexture().cast<Gfx::TextureCube>(),
|
||||
.night = AssetRegistry::findTexture("", "skybox")->getTexture().cast<Gfx::TextureCube>(),
|
||||
.day = scene->getLightEnvironment()->getEnvironmentMap()->getIrradianceMap(),
|
||||
.night = scene->getLightEnvironment()->getEnvironmentMap()->getIrradianceMap(),
|
||||
.fogColor = Vector(0.1, 0.1, 0.8),
|
||||
.blendFactor = 0,
|
||||
};
|
||||
|
||||
@@ -108,7 +108,6 @@ class RenderPass {
|
||||
RenderPass(RenderPass&&) = default;
|
||||
RenderPass& operator=(RenderPass&&) = default;
|
||||
const RenderTargetLayout& getLayout() const { return layout; }
|
||||
void updateColorAttachment(uint32 index, Gfx::PTextureCube attachment) { layout.colorAttachments[index].setTexture(attachment); }
|
||||
|
||||
protected:
|
||||
RenderTargetLayout layout;
|
||||
|
||||
@@ -16,12 +16,14 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
Array<VkImageView> attachments;
|
||||
uint32 width = 0;
|
||||
uint32 height = 0;
|
||||
uint32 layers = 0;
|
||||
for (auto inputAttachment : layout.inputAttachments) {
|
||||
PTextureBase vkInputAttachment = inputAttachment.getTexture().cast<TextureBase>();
|
||||
attachments.add(vkInputAttachment->getView());
|
||||
description.inputAttachments[description.numInputAttachments++] = vkInputAttachment->getView();
|
||||
width = std::max(width, vkInputAttachment->getWidth());
|
||||
height = std::max(height, vkInputAttachment->getHeight());
|
||||
layers = std::max(layers, vkInputAttachment->getNumLayers());
|
||||
}
|
||||
for (auto colorAttachment : layout.colorAttachments) {
|
||||
PTextureBase vkColorAttachment = colorAttachment.getTexture().cast<TextureBase>();
|
||||
@@ -29,6 +31,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
description.colorAttachments[description.numColorAttachments++] = vkColorAttachment->getView();
|
||||
width = std::max(width, vkColorAttachment->getWidth());
|
||||
height = std::max(height, vkColorAttachment->getHeight());
|
||||
layers = std::max(layers, vkColorAttachment->getNumLayers());
|
||||
}
|
||||
for (auto resolveAttachment : layout.resolveAttachments) {
|
||||
PTextureBase vkResolveAttachment = resolveAttachment.getTexture().cast<TextureBase>();
|
||||
@@ -36,6 +39,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
description.resolveAttachments[description.numResolveAttachments++] = vkResolveAttachment->getView();
|
||||
width = std::max(width, vkResolveAttachment->getWidth());
|
||||
height = std::max(height, vkResolveAttachment->getHeight());
|
||||
layers = std::max(layers, vkResolveAttachment->getNumLayers());
|
||||
}
|
||||
if (layout.depthAttachment.getTexture() != nullptr) {
|
||||
PTextureBase vkDepthAttachment = layout.depthAttachment.getTexture().cast<TextureBase>();
|
||||
@@ -43,6 +47,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
description.depthAttachment = vkDepthAttachment->getView();
|
||||
width = std::max(width, vkDepthAttachment->getWidth());
|
||||
height = std::max(height, vkDepthAttachment->getHeight());
|
||||
layers = std::max(layers, vkDepthAttachment->getNumLayers());
|
||||
}
|
||||
if (layout.depthResolveAttachment.getTexture() != nullptr) {
|
||||
PTextureBase vkDepthAttachment = layout.depthResolveAttachment.getTexture().cast<TextureBase>();
|
||||
@@ -50,6 +55,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render
|
||||
description.depthResolveAttachment = vkDepthAttachment->getView();
|
||||
width = std::max(width, vkDepthAttachment->getWidth());
|
||||
height = std::max(height, vkDepthAttachment->getHeight());
|
||||
layers = std::max(layers, vkDepthAttachment->getNumLayers());
|
||||
}
|
||||
VkFramebufferCreateInfo createInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO,
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array<Gfx::SubPassDependency> _dependencies,
|
||||
URect viewport, std::string name, Array<uint32> viewMasks, Array<uint32> correlationMasks)
|
||||
RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array<Gfx::SubPassDependency> _dependencies, URect viewport,
|
||||
std::string name, Array<uint32> viewMasks, Array<uint32> correlationMasks)
|
||||
: Gfx::RenderPass(std::move(_layout), std::move(_dependencies)), graphics(graphics) {
|
||||
renderArea.extent.width = viewport.size.x;
|
||||
renderArea.extent.height = viewport.size.y;
|
||||
@@ -166,6 +166,7 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
|
||||
.pNext = layout.depthResolveAttachment.getTexture() != nullptr ? &depthResolve : nullptr,
|
||||
.flags = 0,
|
||||
.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS,
|
||||
.viewMask = viewMasks[0],
|
||||
.inputAttachmentCount = (uint32)inputRefs.size(),
|
||||
.pInputAttachments = inputRefs.data(),
|
||||
.colorAttachmentCount = (uint32)colorRefs.size(),
|
||||
@@ -196,19 +197,9 @@ RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Arra
|
||||
.pSubpasses = &subPassDesc,
|
||||
.dependencyCount = (uint32)dep.size(),
|
||||
.pDependencies = dep.data(),
|
||||
.correlatedViewMaskCount = (uint32)correlationMasks.size(),
|
||||
.pCorrelatedViewMasks = correlationMasks.data(),
|
||||
};
|
||||
VkRenderPassMultiviewCreateInfo multiViewInfo;
|
||||
if (!viewMasks.empty()) {
|
||||
multiViewInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_MULTIVIEW_CREATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.subpassCount = 1,
|
||||
.pViewMasks = viewMasks.data(),
|
||||
.correlationMaskCount = (uint32)correlationMasks.size(),
|
||||
.pCorrelationMasks = correlationMasks.data(),
|
||||
};
|
||||
info.pNext = &multiViewInfo;
|
||||
}
|
||||
VK_CHECK(vkCreateRenderPass2(graphics->getDevice(), &info, nullptr, &renderPass));
|
||||
VkDebugUtilsObjectNameInfoEXT nameInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_DEBUG_UTILS_OBJECT_NAME_INFO_EXT,
|
||||
|
||||
@@ -31,7 +31,7 @@ VkImageAspectFlags getAspectFromFormat(Gfx::SeFormat format) {
|
||||
TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const TextureCreateInfo& createInfo, VkImage existingImage)
|
||||
: CommandBoundResource(graphics, createInfo.name), image(existingImage), imageView(VK_NULL_HANDLE), allocation(nullptr),
|
||||
owner(createInfo.sourceData.owner), width(createInfo.width), height(createInfo.height), depth(createInfo.depth),
|
||||
arrayCount(createInfo.elements), layerCount(createInfo.layers), mipLevels(1), samples(createInfo.samples), format(createInfo.format),
|
||||
layerCount(createInfo.elements), mipLevels(1), samples(createInfo.samples), format(createInfo.format),
|
||||
usage(createInfo.usage), layout(Gfx::SE_IMAGE_LAYOUT_UNDEFINED), aspect(getAspectFromFormat(createInfo.format)), ownsImage(false) {
|
||||
if (createInfo.useMip) {
|
||||
mipLevels = static_cast<uint32_t>(std::floor(std::log2(std::max(width, height)))) + 1;
|
||||
@@ -55,7 +55,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
case VK_IMAGE_VIEW_TYPE_CUBE_ARRAY:
|
||||
type = VK_IMAGE_TYPE_2D;
|
||||
flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
|
||||
layerCount = 6 * arrayCount;
|
||||
layerCount = 6 * layerCount;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -76,7 +76,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
.depth = depth,
|
||||
},
|
||||
.mipLevels = mipLevels,
|
||||
.arrayLayers = arrayCount * layerCount,
|
||||
.arrayLayers = layerCount,
|
||||
.samples = (VkSampleCountFlagBits)samples,
|
||||
.tiling = VK_IMAGE_TILING_OPTIMAL,
|
||||
.usage = usage,
|
||||
@@ -129,7 +129,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||
.mipLevel = 0,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = arrayCount * layerCount,
|
||||
.layerCount = layerCount,
|
||||
},
|
||||
.imageOffset =
|
||||
{
|
||||
@@ -163,7 +163,7 @@ TextureHandle::TextureHandle(PGraphics graphics, VkImageViewType viewType, const
|
||||
{
|
||||
.aspectMask = aspect,
|
||||
.levelCount = mipLevels,
|
||||
.layerCount = layerCount * arrayCount,
|
||||
.layerCount = layerCount,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -195,7 +195,7 @@ void TextureHandle::pipelineBarrier(VkAccessFlags srcAccess, VkPipelineStageFlag
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = mipLevels,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = layerCount * arrayCount,
|
||||
.layerCount = layerCount,
|
||||
},
|
||||
};
|
||||
PCommand command = graphics->getQueueCommands(owner)->getCommands();
|
||||
@@ -223,7 +223,7 @@ void TextureHandle::transferOwnership(Gfx::QueueType newOwner) {
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = mipLevels,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = arrayCount,
|
||||
.layerCount = layerCount,
|
||||
},
|
||||
};
|
||||
PCommandPool sourcePool = graphics->getQueueCommands(owner);
|
||||
|
||||
@@ -25,7 +25,6 @@ class TextureHandle : public CommandBoundResource {
|
||||
uint32 width;
|
||||
uint32 height;
|
||||
uint32 depth;
|
||||
uint32 arrayCount;
|
||||
uint32 layerCount;
|
||||
uint32 mipLevels;
|
||||
uint32 samples;
|
||||
@@ -48,6 +47,7 @@ class TextureBase {
|
||||
uint32 getWidth() const { return handle->width; }
|
||||
uint32 getHeight() const { return handle->height; }
|
||||
uint32 getDepth() const { return handle->depth; }
|
||||
uint32 getNumLayers() const { return handle->layerCount; }
|
||||
PTextureHandle getHandle() const { return handle; }
|
||||
VkImage getImage() const { return handle->image; };
|
||||
VkImageView getView() const { return handle->imageView; };
|
||||
|
||||
@@ -276,7 +276,6 @@ void Window::createSwapChain() {
|
||||
.width = extent.width,
|
||||
.height = extent.height,
|
||||
.depth = 1,
|
||||
.layers = 1,
|
||||
.elements = 1,
|
||||
.samples = 1,
|
||||
.usage = Gfx::SE_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | Gfx::SE_IMAGE_USAGE_TRANSFER_DST_BIT,
|
||||
|
||||
@@ -9,7 +9,12 @@ Window::~Window() {}
|
||||
|
||||
Viewport::Viewport(PWindow owner, const ViewportCreateInfo& viewportInfo)
|
||||
: sizeX(viewportInfo.dimensions.size.x), sizeY(viewportInfo.dimensions.size.y), offsetX(viewportInfo.dimensions.offset.x),
|
||||
offsetY(viewportInfo.dimensions.offset.y), fieldOfView(viewportInfo.fieldOfView), owner(owner) {}
|
||||
offsetY(viewportInfo.dimensions.offset.y), fieldOfView(viewportInfo.fieldOfView), owner(owner) {
|
||||
if (owner != nullptr) {
|
||||
sizeX = std::min(owner->getFramebufferWidth(), sizeX);
|
||||
sizeY = std::min(owner->getFramebufferHeight(), sizeY);
|
||||
}
|
||||
}
|
||||
|
||||
Viewport::~Viewport() {}
|
||||
|
||||
|
||||
@@ -158,8 +158,8 @@ void Material::load(ArchiveBuffer& buffer) {
|
||||
|
||||
void Material::compile() {
|
||||
std::ofstream codeStream("./shaders/generated/" + materialName + ".slang");
|
||||
codeStream << "import BRDF;\n";
|
||||
codeStream << "import MaterialParameter;\n";
|
||||
codeStream << "import LightEnv;\n";
|
||||
codeStream << "import Material;\n";
|
||||
codeStream << "struct Material{\n";
|
||||
codeStream << "\ttypedef " << brdf.profile << " BRDF;\n";
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
#include "LightEnvironment.h"
|
||||
#include "Asset/EnvironmentMapAsset.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics) {
|
||||
LightEnvironment::LightEnvironment(Gfx::PGraphics graphics)
|
||||
: graphics(graphics), environment(AssetRegistry::findEnvironmentMap("", "newport_loft")) {
|
||||
layout = graphics->createDescriptorLayout("pLightEnv");
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "directionalLights",
|
||||
@@ -21,6 +24,10 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics)
|
||||
.name = "numPointLights",
|
||||
.uniformLength = sizeof(uint32),
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "irradianceMap",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
layout->create();
|
||||
|
||||
directionalLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
@@ -29,6 +36,13 @@ LightEnvironment::LightEnvironment(Gfx::PGraphics graphics) : graphics(graphics)
|
||||
pointLights = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.name = "PointLights",
|
||||
});
|
||||
environmentSampler = graphics->createSampler({
|
||||
.magFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.minFilter = Gfx::SE_FILTER_LINEAR,
|
||||
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
|
||||
});
|
||||
}
|
||||
|
||||
LightEnvironment::~LightEnvironment() {}
|
||||
@@ -63,6 +77,7 @@ void LightEnvironment::commit() {
|
||||
set->updateBuffer("pointLights", 0, pointLights);
|
||||
set->updateConstants("numDirectionalLights", 0, &numDirectionalLights);
|
||||
set->updateBuffer("directionalLights", 0, directionalLights);
|
||||
set->updateTexture("irradianceMap", 0, environment->getIrradianceMap());
|
||||
set->writeChanges();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include "Graphics/Buffer.h"
|
||||
#include "Graphics/Descriptor.h"
|
||||
|
||||
|
||||
namespace Seele {
|
||||
DECLARE_REF(EnvironmentMapAsset)
|
||||
class LightEnvironment {
|
||||
public:
|
||||
LightEnvironment(Gfx::PGraphics graphics);
|
||||
@@ -16,12 +16,15 @@ class LightEnvironment {
|
||||
void commit();
|
||||
const Gfx::PDescriptorLayout getDescriptorLayout() const;
|
||||
Gfx::PDescriptorSet getDescriptorSet();
|
||||
PEnvironmentMapAsset getEnvironmentMap() { return environment; }
|
||||
|
||||
private:
|
||||
Gfx::OShaderBuffer directionalLights;
|
||||
Gfx::OShaderBuffer pointLights;
|
||||
Array<Component::DirectionalLight> dirs;
|
||||
Array<Component::PointLight> points;
|
||||
PEnvironmentMapAsset environment;
|
||||
Gfx::OSampler environmentSampler;
|
||||
Gfx::ODescriptorLayout layout;
|
||||
Gfx::PDescriptorSet set;
|
||||
Gfx::PGraphics graphics;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "Scene.h"
|
||||
#include "Actor/PointLightActor.h"
|
||||
#include "Asset/AssetRegistry.h"
|
||||
#include "Asset/MaterialAsset.h"
|
||||
#include "Asset/TextureAsset.h"
|
||||
#include "Component/DirectionalLight.h"
|
||||
@@ -13,7 +12,8 @@
|
||||
|
||||
using namespace Seele;
|
||||
|
||||
Scene::Scene(Gfx::PGraphics graphics) : graphics(graphics), lightEnv(new LightEnvironment(graphics)), physics(registry) {}
|
||||
Scene::Scene(Gfx::PGraphics graphics)
|
||||
: graphics(graphics), lightEnv(new LightEnvironment(graphics)), physics(registry) {}
|
||||
|
||||
Scene::~Scene() {}
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
#include "MinimalEngine.h"
|
||||
#include "Component/Skybox.h"
|
||||
#include "Graphics/Graphics.h"
|
||||
#include "LightEnvironment.h"
|
||||
#include "MinimalEngine.h"
|
||||
#include "Physics/PhysicsSystem.h"
|
||||
#include <entt/entt.hpp>
|
||||
#include <iostream>
|
||||
|
||||
Reference in New Issue
Block a user