Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -4,8 +4,8 @@ using namespace Seele;
|
||||
|
||||
DirectionalLightActor::DirectionalLightActor(PScene scene) : Actor(scene) { attachComponent<Component::DirectionalLight>(); }
|
||||
|
||||
DirectionalLightActor::DirectionalLightActor(PScene scene, Vector color, Vector direction) : Actor(scene) {
|
||||
attachComponent<Component::DirectionalLight>(Vector4(color, 0), Vector4(direction, 0));
|
||||
DirectionalLightActor::DirectionalLightActor(PScene scene, Vector color, float intensity, Vector direction) : Actor(scene) {
|
||||
attachComponent<Component::DirectionalLight>(Vector4(color, intensity), Vector4(direction, 0));
|
||||
}
|
||||
|
||||
DirectionalLightActor::~DirectionalLightActor() {}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Seele {
|
||||
class DirectionalLightActor : public Actor {
|
||||
public:
|
||||
DirectionalLightActor(PScene scene);
|
||||
DirectionalLightActor(PScene scene, Vector color, Vector direction);
|
||||
DirectionalLightActor(PScene scene, Vector color, float intensity, Vector direction);
|
||||
virtual ~DirectionalLightActor();
|
||||
Component::DirectionalLight& getDirectionalLightComponent();
|
||||
const Component::DirectionalLight& getDirectionalLightComponent() const;
|
||||
|
||||
@@ -4,8 +4,8 @@ using namespace Seele;
|
||||
|
||||
PointLightActor::PointLightActor(PScene scene) : Actor(scene) { attachComponent<Component::PointLight>(); }
|
||||
|
||||
PointLightActor::PointLightActor(PScene scene, Vector position, Vector color, float attenuation) : Actor(scene) {
|
||||
attachComponent<Component::PointLight>(Vector4(position, 1), Vector4(color, attenuation));
|
||||
PointLightActor::PointLightActor(PScene scene, Vector position, float intensity, Vector color, float attenuation) : Actor(scene) {
|
||||
attachComponent<Component::PointLight>(Vector4(position, intensity), Vector4(color, attenuation));
|
||||
}
|
||||
|
||||
PointLightActor::~PointLightActor() {}
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace Seele {
|
||||
class PointLightActor : public Actor {
|
||||
public:
|
||||
PointLightActor(PScene scene);
|
||||
PointLightActor(PScene scene, Vector position, Vector color, float attenuation);
|
||||
PointLightActor(PScene scene, Vector position, float intensity, Vector color, float attenuation);
|
||||
virtual ~PointLightActor();
|
||||
Component::PointLight& getPointLightComponent();
|
||||
const Component::PointLight& getPointLightComponent() const;
|
||||
|
||||
@@ -34,7 +34,7 @@ class Asset {
|
||||
std::string name;
|
||||
std::string assetId;
|
||||
Status status;
|
||||
uint64 byteSize;
|
||||
uint64 byteSize = 0;
|
||||
};
|
||||
DEFINE_REF(Asset)
|
||||
} // namespace Seele
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace Seele {
|
||||
namespace Component {
|
||||
struct DirectionalLight {
|
||||
Vector4 color;
|
||||
Vector4 colorIntensity;
|
||||
Vector4 direction;
|
||||
};
|
||||
} // namespace Component
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Seele {
|
||||
namespace Component {
|
||||
struct PointLight {
|
||||
// give the lights a radius so that they are not actual points
|
||||
Vector4 positionWSRadius;
|
||||
Vector4 positionWS;
|
||||
Vector4 colorRange;
|
||||
};
|
||||
} // namespace Component
|
||||
|
||||
@@ -3,43 +3,121 @@
|
||||
using namespace Seele;
|
||||
|
||||
ToneMappingPass::ToneMappingPass(Gfx::PGraphics graphics) : RenderPass(graphics) {
|
||||
layout = graphics->createDescriptorLayout("ToneMappingDescriptor");
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
tonemappingLayout = graphics->createDescriptorLayout("ToneMappingDescriptor");
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "offset",
|
||||
.uniformLength = sizeof(Vector4),
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "slope",
|
||||
.uniformLength = sizeof(Vector4),
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "power",
|
||||
.uniformLength = sizeof(Vector4),
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "sat",
|
||||
.uniformLength = sizeof(float),
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "hdrInputTexture",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
layout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "hdrSampler",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
|
||||
});
|
||||
layout->create();
|
||||
pipelineLayout = graphics->createPipelineLayout("ToneMappingLayout");
|
||||
pipelineLayout->addDescriptorLayout(layout);
|
||||
tonemappingLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "averageLuminance",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
tonemappingLayout->create();
|
||||
tonemappingPipelineLayout = graphics->createPipelineLayout("ToneMappingLayout");
|
||||
tonemappingPipelineLayout->addDescriptorLayout(tonemappingLayout);
|
||||
|
||||
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
||||
.name = "ToneMapping",
|
||||
.modules = {"FullScreenQuad", "ToneMapping"},
|
||||
.entryPoints = {{"quadMain", "FullScreenQuad"}, {"toneMapping", "ToneMapping"}},
|
||||
.rootSignature = pipelineLayout,
|
||||
.entryPoints =
|
||||
{
|
||||
{"quadMain", "FullScreenQuad"},
|
||||
{"toneMapping", "ToneMapping"},
|
||||
},
|
||||
.rootSignature = tonemappingPipelineLayout,
|
||||
});
|
||||
pipelineLayout->create();
|
||||
tonemappingPipelineLayout->create();
|
||||
vert = graphics->createVertexShader({0});
|
||||
frag = graphics->createFragmentShader({1});
|
||||
|
||||
histogramLayout = graphics->createDescriptorLayout("pHistogramParams");
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "minLogLum",
|
||||
.uniformLength = sizeof(float),
|
||||
});
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "inverseLogLumRange",
|
||||
.uniformLength = sizeof(float),
|
||||
});
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "timeCoeff",
|
||||
.uniformLength = sizeof(float),
|
||||
});
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "numPixels",
|
||||
.uniformLength = sizeof(uint32),
|
||||
});
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "hdrImage",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
|
||||
});
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "histogram",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
histogramLayout->addDescriptorBinding(Gfx::DescriptorBinding{
|
||||
.name = "averageLuminance",
|
||||
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
|
||||
});
|
||||
histogramLayout->create();
|
||||
histogramPipelineLayout = graphics->createPipelineLayout("HistogramPipelineLayout");
|
||||
histogramPipelineLayout->addDescriptorLayout(histogramLayout);
|
||||
|
||||
graphics->beginShaderCompilation(ShaderCompilationInfo{
|
||||
.name = "Exposure",
|
||||
.modules = {"Exposure"},
|
||||
.entryPoints =
|
||||
{
|
||||
{"histogram", "Exposure"},
|
||||
{"exposure", "Exposure"},
|
||||
},
|
||||
.rootSignature = histogramPipelineLayout,
|
||||
});
|
||||
histogramPipelineLayout->create();
|
||||
histogramShader = graphics->createComputeShader({0});
|
||||
histogramPipeline = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = histogramShader,
|
||||
.pipelineLayout = histogramPipelineLayout,
|
||||
});
|
||||
exposureShader = graphics->createComputeShader({1});
|
||||
exposurePipeline = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
|
||||
.computeShader = exposureShader,
|
||||
.pipelineLayout = histogramPipelineLayout,
|
||||
});
|
||||
histogramBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = sizeof(uint32) * 256,
|
||||
},
|
||||
.name = "HistogramBuffer",
|
||||
});
|
||||
luminanceBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||
.sourceData =
|
||||
{
|
||||
.size = sizeof(uint32),
|
||||
},
|
||||
.name = "LuminanceBuffer",
|
||||
});
|
||||
sampler = graphics->createSampler({});
|
||||
}
|
||||
|
||||
@@ -50,18 +128,56 @@ void ToneMappingPass::beginFrame(const Component::Camera& cam) { RenderPass::beg
|
||||
void ToneMappingPass::render() {
|
||||
hdrInputTexture.getTexture()->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
|
||||
layout->reset();
|
||||
set = layout->allocateDescriptorSet();
|
||||
set->updateTexture("hdrInputTexture", 0, hdrInputTexture.getTexture());
|
||||
set->updateSampler("hdrSampler", 0, sampler);
|
||||
set->writeChanges();
|
||||
histogramLayout->reset();
|
||||
Gfx::PDescriptorSet histogramSet = histogramLayout->allocateDescriptorSet();
|
||||
histogramSet->updateConstants("minLogLum", 0, &minLogLum);
|
||||
histogramSet->updateConstants("inverseLogLumRange", 0, &inverseLogLumRange);
|
||||
histogramSet->updateConstants("timeCoeff", 0, &timeCoeff);
|
||||
histogramSet->updateConstants("numPixels", 0, &numPixels);
|
||||
histogramSet->updateTexture("hdrImage", 0, hdrInputTexture.getTexture());
|
||||
histogramSet->updateBuffer("histogram", 0, histogramBuffer);
|
||||
histogramSet->updateBuffer("averageLuminance", 0, luminanceBuffer);
|
||||
histogramSet->writeChanges();
|
||||
|
||||
{
|
||||
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("HistogramCommand");
|
||||
computeCommand->bindPipeline(histogramPipeline);
|
||||
computeCommand->bindDescriptor({histogramSet});
|
||||
computeCommand->dispatch(threadGroups.x, threadGroups.y, 1);
|
||||
graphics->executeCommands(std::move(computeCommand));
|
||||
}
|
||||
histogramBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||
{
|
||||
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("ExposureCommand");
|
||||
computeCommand->bindPipeline(exposurePipeline);
|
||||
computeCommand->bindDescriptor({histogramSet});
|
||||
computeCommand->dispatch(1, 1, 1);
|
||||
graphics->executeCommands(std::move(computeCommand));
|
||||
}
|
||||
luminanceBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
|
||||
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
||||
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
|
||||
|
||||
tonemappingLayout->reset();
|
||||
Gfx::PDescriptorSet tonemappingSet = tonemappingLayout->allocateDescriptorSet();
|
||||
tonemappingSet->updateConstants("offset", 0, &offset);
|
||||
tonemappingSet->updateConstants("slope", 0, &slope);
|
||||
tonemappingSet->updateConstants("power", 0, &power);
|
||||
tonemappingSet->updateConstants("sat", 0, &sat);
|
||||
tonemappingSet->updateTexture("hdrInputTexture", 0, hdrInputTexture.getTexture());
|
||||
tonemappingSet->updateSampler("hdrSampler", 0, sampler);
|
||||
tonemappingSet->updateBuffer("averageLuminance", 0, luminanceBuffer);
|
||||
tonemappingSet->writeChanges();
|
||||
graphics->beginRenderPass(renderPass);
|
||||
Gfx::ORenderCommand command = graphics->createRenderCommand("ToneMapping");
|
||||
command->setViewport(viewport);
|
||||
command->bindPipeline(pipeline);
|
||||
command->bindDescriptor({set});
|
||||
command->bindDescriptor({tonemappingSet});
|
||||
command->draw(3, 1, 0, 0);
|
||||
graphics->executeCommands(std::move(command));
|
||||
graphics->endRenderPass();
|
||||
@@ -70,6 +186,8 @@ void ToneMappingPass::render() {
|
||||
void ToneMappingPass::endFrame() {}
|
||||
|
||||
void ToneMappingPass::publishOutputs() {
|
||||
numPixels = viewport->getWidth() * viewport->getHeight();
|
||||
threadGroups = UVector2((viewport->getWidth() + 15) / 16, (viewport->getHeight() + 15) / 16);
|
||||
colorAttachment = Gfx::RenderTargetAttachment(viewport, Gfx::SE_IMAGE_LAYOUT_UNDEFINED, Gfx::SE_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
|
||||
Gfx::SE_ATTACHMENT_LOAD_OP_DONT_CARE, Gfx::SE_ATTACHMENT_STORE_OP_STORE);
|
||||
resources->registerRenderPassOutput("TONEMAPPING_COLOR", colorAttachment);
|
||||
@@ -103,7 +221,7 @@ void ToneMappingPass::createRenderPass() {
|
||||
.vertexShader = vert,
|
||||
.fragmentShader = frag,
|
||||
.renderPass = renderPass,
|
||||
.pipelineLayout = pipelineLayout,
|
||||
.pipelineLayout = tonemappingPipelineLayout,
|
||||
.colorBlend =
|
||||
{
|
||||
.attachmentCount = 1,
|
||||
|
||||
@@ -19,13 +19,31 @@ class ToneMappingPass : public RenderPass {
|
||||
private:
|
||||
// non-hdr swapchain output
|
||||
Gfx::RenderTargetAttachment colorAttachment;
|
||||
Gfx::OShaderBuffer histogramBuffer;
|
||||
Gfx::OShaderBuffer luminanceBuffer;
|
||||
|
||||
float minLogLum = 1;
|
||||
float inverseLogLumRange = 1;
|
||||
float timeCoeff = 1;
|
||||
uint32 numPixels;
|
||||
UVector2 threadGroups;
|
||||
Gfx::ODescriptorLayout histogramLayout;
|
||||
Gfx::PDescriptorSet histogramSet;
|
||||
Gfx::OPipelineLayout histogramPipelineLayout;
|
||||
Gfx::OComputeShader histogramShader;
|
||||
Gfx::PComputePipeline histogramPipeline;
|
||||
Gfx::OComputeShader exposureShader;
|
||||
Gfx::PComputePipeline exposurePipeline;
|
||||
|
||||
Gfx::RenderTargetAttachment hdrInputTexture;
|
||||
Gfx::OSampler sampler;
|
||||
|
||||
Gfx::ODescriptorLayout layout;
|
||||
Gfx::PDescriptorSet set;
|
||||
Gfx::OPipelineLayout pipelineLayout;
|
||||
Vector4 offset = Vector4(0.0);
|
||||
Vector4 slope = Vector4(1.0);
|
||||
Vector4 power = Vector4(1.0);
|
||||
float sat = 1.0;
|
||||
Gfx::ODescriptorLayout tonemappingLayout;
|
||||
Gfx::OPipelineLayout tonemappingPipelineLayout;
|
||||
Gfx::OVertexShader vert;
|
||||
Gfx::OFragmentShader frag;
|
||||
Gfx::PGraphicsPipeline pipeline;
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
#include <fmt/format.h>
|
||||
#include <vma/vk_mem_alloc.h>
|
||||
|
||||
uint64 bufferSize = 0;
|
||||
|
||||
uint64 getBufferSize() { return bufferSize; }
|
||||
|
||||
using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
@@ -26,9 +22,6 @@ BufferAllocation::BufferAllocation(PGraphics graphics, const std::string& name,
|
||||
.pObjectName = name.c_str(),
|
||||
};
|
||||
vkSetDebugUtilsObjectNameEXT(graphics->getDevice(), &nameInfo);
|
||||
if (!(properties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
||||
bufferSize += size;
|
||||
}
|
||||
if (bufferInfo.usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT) {
|
||||
VkBufferDeviceAddressInfo addrInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_BUFFER_DEVICE_ADDRESS_INFO_KHR,
|
||||
@@ -41,9 +34,6 @@ BufferAllocation::BufferAllocation(PGraphics graphics, const std::string& name,
|
||||
|
||||
BufferAllocation::~BufferAllocation() {
|
||||
if (buffer != VK_NULL_HANDLE) {
|
||||
if (!(properties & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
||||
bufferSize -= size;
|
||||
}
|
||||
vmaDestroyBuffer(graphics->getAllocator(), buffer, allocation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@
|
||||
#include "Graphics/Enums.h"
|
||||
#include "Resources.h"
|
||||
|
||||
uint64 getBufferSize();
|
||||
|
||||
namespace Seele {
|
||||
namespace Vulkan {
|
||||
DECLARE_REF(Command)
|
||||
|
||||
Reference in New Issue
Block a user