Trying to add water

This commit is contained in:
Dynamitos
2024-08-13 22:44:04 +02:00
parent 97244e87c1
commit 252a241208
43 changed files with 1408 additions and 219 deletions
+56 -41
View File
@@ -3,6 +3,7 @@
#include "Asset/AssetRegistry.h"
#include "Component/Camera.h"
#include "Component/Mesh.h"
#include "Component/WaterTile.h"
#include "Graphics/Command.h"
#include "Graphics/Descriptor.h"
#include "Graphics/Enums.h"
@@ -25,6 +26,7 @@ void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); }
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
waterRenderer = new WaterRenderer(graphics, scene, viewParamsLayout);
basePassLayout = graphics->createPipelineLayout("BasePassLayout");
basePassLayout->addDescriptorLayout(viewParamsLayout);
@@ -96,37 +98,42 @@ void BasePass::beginFrame(const Component::Camera& cam) {
opaqueCulling = lightCullingLayout->allocateDescriptorSet();
transparentCulling = lightCullingLayout->allocateDescriptorSet();
// Debug vertices
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData =
{
.size = sizeof(DebugVertex) * gDebugVertices.size(),
.data = (uint8*)gDebugVertices.data(),
},
.vertexSize = sizeof(DebugVertex),
.numVertices = (uint32)gDebugVertices.size(),
.name = "DebugVertices",
};
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
debugVertices->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT);
waterRenderer->beginFrame();
// Debug vertices
{
VertexBufferCreateInfo vertexBufferInfo = {
.sourceData =
{
.size = sizeof(DebugVertex) * gDebugVertices.size(),
.data = (uint8*)gDebugVertices.data(),
},
.vertexSize = sizeof(DebugVertex),
.numVertices = (uint32)gDebugVertices.size(),
.name = "DebugVertices",
};
debugVertices = graphics->createVertexBuffer(vertexBufferInfo);
debugVertices->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_VERTEX_ATTRIBUTE_READ_BIT, Gfx::SE_PIPELINE_STAGE_VERTEX_INPUT_BIT);
}
// Skybox
skyboxDataLayout->reset();
textureLayout->reset();
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
skyboxBuffer->rotateBuffer(sizeof(SkyboxData));
skyboxBuffer->updateContents(0, sizeof(SkyboxData), &skyboxData);
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, skyboxBuffer);
skyboxDataSet->writeChanges();
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, skybox.day);
textureSet->updateTexture(1, skybox.night);
textureSet->updateSampler(2, skyboxSampler);
textureSet->writeChanges();
{
skyboxDataLayout->reset();
textureLayout->reset();
skyboxData.transformMatrix = glm::rotate(skyboxData.transformMatrix, (float)(Gfx::getCurrentFrameDelta()), Vector(0, 1, 0));
skyboxBuffer->rotateBuffer(sizeof(SkyboxData));
skyboxBuffer->updateContents(0, sizeof(SkyboxData), &skyboxData);
skyboxBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
skyboxDataSet = skyboxDataLayout->allocateDescriptorSet();
skyboxDataSet->updateBuffer(0, skyboxBuffer);
skyboxDataSet->writeChanges();
textureSet = textureLayout->allocateDescriptorSet();
textureSet->updateTexture(0, skybox.day);
textureSet->updateTexture(1, skybox.night);
textureSet->updateSampler(2, skyboxSampler);
textureSet->writeChanges();
}
}
void BasePass::render() {
@@ -138,13 +145,15 @@ void BasePass::render() {
transparentCulling->writeChanges();
query->beginQuery();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "BASEPASS");
timestamps->begin();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "BaseBegin");
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("BasePass");
permutation.setDepthCulling(true); // always use the culling info
permutation.setPositionOnly(false);
Array<VertexData::TransparentDraw> transparentData;
// Base Rendering
for (VertexData* vertexData : VertexData::getList()) {
transparentData.addAll(vertexData->getTransparentData());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
@@ -238,14 +247,18 @@ void BasePass::render() {
commands.add(std::move(command));
}
}
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
skyboxCommand->setViewport(viewport);
skyboxCommand->bindPipeline(pipeline);
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
skyboxCommand->draw(36, 1, 0, 0);
commands.add(std::move(skyboxCommand));
commands.add(waterRenderer->render(viewParamsSet));
// Skybox
{
Gfx::ORenderCommand skyboxCommand = graphics->createRenderCommand("SkyboxRender");
skyboxCommand->setViewport(viewport);
skyboxCommand->bindPipeline(pipeline);
skyboxCommand->bindDescriptor({viewParamsSet, skyboxDataSet, textureSet});
skyboxCommand->draw(36, 1, 0, 0);
commands.add(std::move(skyboxCommand));
}
// Transparent rendering
{
permutation.setDepthCulling(false); // ignore visibility infos for transparency
@@ -360,7 +373,7 @@ void BasePass::render() {
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
query->endQuery();
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "END");
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "BaseEnd");
timestamps->end();
gDebugVertices.clear();
}
@@ -412,12 +425,13 @@ void BasePass::publishOutputs() {
resources->registerRenderPassOutput("BASEPASS_COLOR", colorAttachment);
resources->registerRenderPassOutput("BASEPASS_DEPTH", depthAttachment);
timestamps = graphics->createTimestampQuery(2, "BaseTS");
resources->registerTimestampQueryOutput("BASE_TS", timestamps);
query = graphics->createPipelineStatisticsQuery("BasePassPipelineStatistics");
resources->registerQueryOutput("BASEPASS_QUERY", query);
}
void BasePass::createRenderPass() {
timestamps = resources->requestTimestampQuery("TIMESTAMP");
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{
@@ -458,6 +472,8 @@ void BasePass::createRenderPass() {
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
waterRenderer->setViewport(viewport, renderPass);
// Debug rendering
{
debugPipelineLayout = graphics->createPipelineLayout("DebugPassLayout");
@@ -527,7 +543,6 @@ void BasePass::createRenderPass() {
};
debugPipeline = graphics->createGraphicsPipeline(std::move(gfxInfo));
}
// Skybox
{
skyboxDataLayout = graphics->createDescriptorLayout("pSkyboxData");
+4 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "MinimalEngine.h"
#include "RenderPass.h"
#include "WaterRenderer.h"
namespace Seele {
DECLARE_REF(CameraActor)
@@ -44,10 +45,12 @@ class BasePass : public RenderPass {
Gfx::ODescriptorLayout lightCullingLayout;
Gfx::OPipelineStatisticsQuery query;
Gfx::PTimestampQuery timestamps;
Gfx::OTimestampQuery timestamps;
Gfx::PShaderBuffer cullingBuffer;
OWaterRenderer waterRenderer;
// Debug rendering
Gfx::OVertexInput debugVertexInput;
Gfx::OVertexBuffer debugVertices;
@@ -20,7 +20,9 @@ target_sources(Engine
UIPass.h
UIPass.cpp
VisibilityPass.h
VisibilityPass.cpp)
VisibilityPass.cpp
WaterRenderer.h
WaterRenderer.cpp)
target_sources(Engine
PUBLIC FILE_SET HEADERS
@@ -47,13 +47,13 @@ void CachedDepthPass::beginFrame(const Component::Camera& cam) {
void CachedDepthPass::render() {
query->beginQuery();
timestamps->begin();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CACHED");
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CachedBegin");
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
Gfx::ShaderPermutation permutation = graphics->getShaderCompiler()->getTemplate("CachedDepthPass");
permutation.setPositionOnly(getGlobals().usePositionOnly);
permutation.setDepthCulling(getGlobals().useDepthCulling);
permutation.setDepthCulling(true);
for (VertexData* vertexData : VertexData::getList()) {
permutation.setVertexData(vertexData->getTypeName());
vertexData->getInstanceDataSet()->updateBuffer(6, cullingBuffer);
@@ -127,6 +127,8 @@ void CachedDepthPass::render() {
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CachedEnd");
timestamps->end();
query->endQuery();
}
@@ -161,8 +163,8 @@ void CachedDepthPass::publishOutputs() {
query = graphics->createPipelineStatisticsQuery("CachedPipelineStatistics");
resources->registerQueryOutput("CACHED_QUERY", query);
timestamps = graphics->createTimestampQuery(7, "Timestamps");
resources->registerTimestampQueryOutput("TIMESTAMP", timestamps);
timestamps = graphics->createTimestampQuery(2, "CachedTS");
resources->registerTimestampQueryOutput("CACHED_TS", timestamps);
}
void CachedDepthPass::createRenderPass() {
@@ -78,7 +78,8 @@ void DepthCullingPass::render() {
set->updateBuffer(1, depthMipBuffer);
set->writeChanges();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "DEPTHMIP");
timestamps->begin();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "MipBegin");
Gfx::OComputeCommand computeCommand = graphics->createComputeCommand("DepthMipGenCommand");
computeCommand->bindPipeline(depthInitialReduce);
computeCommand->bindDescriptor({viewParamsSet, set});
@@ -115,7 +116,7 @@ void DepthCullingPass::render() {
Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | Gfx::SE_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT);
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "DEPTHCULL");
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "CullingBegin");
graphics->beginRenderPass(renderPass);
Array<Gfx::ORenderCommand> commands;
@@ -194,6 +195,8 @@ void DepthCullingPass::render() {
graphics->executeCommands(std::move(commands));
graphics->endRenderPass();
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "CullingEnd");
timestamps->end();
query->endQuery();
// Sync depth read/write with compute read
depthAttachment.getTexture()->pipelineBarrier(
@@ -251,12 +254,13 @@ void DepthCullingPass::publishOutputs() {
depthMipGen = graphics->createComputePipeline(pipelineCreateInfo);
timestamps = graphics->createTimestampQuery(3, "CullingTS");
resources->registerTimestampQueryOutput("DEPTH_TS", timestamps);
query = graphics->createPipelineStatisticsQuery("DepthPipelineStatistics");
resources->registerQueryOutput("DEPTH_QUERY", query);
}
void DepthCullingPass::createRenderPass() {
timestamps = resources->requestTimestampQuery("TIMESTAMP");
cullingBuffer = resources->requestBuffer("CULLINGBUFFER");
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH");
@@ -33,7 +33,7 @@ class DepthCullingPass : public RenderPass {
Gfx::ODescriptorLayout depthAttachmentLayout;
Gfx::OPipelineLayout depthCullingLayout;
Gfx::OPipelineStatisticsQuery query;
Gfx::PTimestampQuery timestamps;
Gfx::OTimestampQuery timestamps;
Gfx::OPipelineLayout depthComputeLayout;
Gfx::OComputeShader depthInitialReduceShader;
@@ -37,7 +37,8 @@ void LightCullingPass::beginFrame(const Component::Camera& cam) {
void LightCullingPass::render() {
query->beginQuery();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "LIGHTCULL");
timestamps->begin();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "LightCullBegin");
oLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
tLightGrid->pipelineBarrier(Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
@@ -62,6 +63,8 @@ void LightCullingPass::render() {
commands.add(std::move(computeCommand));
// std::cout << "Execute" << std::endl;
graphics->executeCommands(std::move(commands));
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "LightCullEnd");
timestamps->end();
query->endQuery();
oLightIndexList->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
@@ -224,13 +227,14 @@ void LightCullingPass::publishOutputs() {
resources->registerTextureOutput("LIGHTCULLING_OLIGHTGRID", Gfx::PTexture2D(oLightGrid));
resources->registerTextureOutput("LIGHTCULLING_TLIGHTGRID", Gfx::PTexture2D(tLightGrid));
timestamps = graphics->createTimestampQuery(2, "LightCullTS");
resources->registerTimestampQueryOutput("LIGHTCULL_TS", timestamps);
query = graphics->createPipelineStatisticsQuery("LightCullPipelineStatistics");
resources->registerQueryOutput("LIGHTCULL_QUERY", query);
}
void LightCullingPass::createRenderPass() {
depthAttachment = resources->requestRenderTarget("DEPTHPREPASS_DEPTH").getTexture();
timestamps = resources->requestTimestampQuery("TIMESTAMP");
}
void LightCullingPass::setupFrustums() {
@@ -64,7 +64,7 @@ class LightCullingPass : public RenderPass {
Gfx::PComputePipeline cullingPipeline;
Gfx::PComputePipeline cullingEnabledPipeline;
Gfx::OPipelineStatisticsQuery query;
Gfx::PTimestampQuery timestamps;
Gfx::OTimestampQuery timestamps;
};
DEFINE_REF(LightCullingPass)
} // namespace Seele
@@ -26,7 +26,8 @@ void VisibilityPass::render() {
visibilitySet->writeChanges();
query->beginQuery();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "VISIBILITY");
timestamps->begin();
timestamps->write(Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT, "VisibilityBegin");
Gfx::OComputeCommand command = graphics->createComputeCommand("VisibilityCommand");
command->bindPipeline(visibilityPipeline);
command->bindDescriptor({viewParamsSet, visibilitySet});
@@ -34,6 +35,8 @@ void VisibilityPass::render() {
Array<Gfx::OComputeCommand> commands;
commands.add(std::move(command));
graphics->executeCommands(std::move(commands));
timestamps->write(Gfx::SE_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT, "VisibilityEnd");
timestamps->end();
query->endQuery();
cullingBuffer->pipelineBarrier(Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT,
@@ -85,8 +88,10 @@ void VisibilityPass::publishOutputs() {
});
resources->registerBufferOutput("CULLINGBUFFER", cullingBuffer);
timestamps = graphics->createTimestampQuery(2, "VisibilityTS");
resources->registerTimestampQueryOutput("VISIBILITY_TS", timestamps);
query = graphics->createPipelineStatisticsQuery("VisibilityPipelineStatistics");
timestamps = resources->requestTimestampQuery("TIMESTAMP");
resources->registerQueryOutput("VISIBILITY_QUERY", query);
}
@@ -24,7 +24,7 @@ class VisibilityPass : public RenderPass {
Gfx::OComputeShader visibilityShader;
Gfx::PComputePipeline visibilityPipeline;
Gfx::OPipelineStatisticsQuery query;
Gfx::PTimestampQuery timestamps;
Gfx::OTimestampQuery timestamps;
// Holds culling information for every meshlet for each instance
Gfx::OShaderBuffer cullingBuffer;
@@ -0,0 +1,474 @@
#include "WaterRenderer.h"
#include "Asset/AssetRegistry.h"
#include "Component/WaterTile.h"
#include "Graphics/Graphics.h"
#include "Graphics/Shader.h"
using namespace Seele;
WaterRenderer::WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescriptorLayout viewParamsLayout)
: graphics(graphics), scene(scene) {
skyBox = AssetRegistry::findTexture("", "skyboxsun5deg_tn")->getTexture().cast<Gfx::TextureCube>();
logN = (int)log2(params.N);
threadGroupsX = ceil(params.N / 8.0f);
threadGroupsY = ceil(params.N / 8.0f);
materialUniforms = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData =
{
.size = sizeof(MaterialParams),
.data = (uint8*)&materialParams,
},
.dynamic = true,
.name = "WaterMaterialParams",
});
materialUniforms->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT,
Gfx::SE_ACCESS_UNIFORM_READ_BIT,
Gfx::SE_PIPELINE_STAGE_MESH_SHADER_BIT_EXT | Gfx::SE_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
paramsBuffer = graphics->createUniformBuffer(UniformBufferCreateInfo{
.sourceData =
{
.size = sizeof(ComputeParams),
},
.dynamic = true,
.name = "WaterComputeParams",
});
paramsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
initialSpectrumTextures = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
.width = params.N,
.height = params.N,
.elements = 4,
.useMip = true,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
.name = "InitialSpectrumTextures",
});
initialSpectrumTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
boyancyData = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R16_SFLOAT,
.width = params.N,
.height = params.N,
.useMip = false,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
.name = "Bouyancy",
});
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
displacementTextures = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
.width = params.N,
.height = params.N,
.elements = 4,
.useMip = true,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
.name = "DisplacementTexture",
});
displacementTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
slopeTextures = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32G32_SFLOAT,
.width = params.N,
.height = params.N,
.elements = 4,
.useMip = true,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
.name = "SlopeTextures",
});
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
spectrumTextures = graphics->createTexture2D(TextureCreateInfo{
.format = Gfx::SE_FORMAT_R32G32B32A32_SFLOAT,
.width = params.N,
.height = params.N,
.elements = 8,
.useMip = true,
.usage = Gfx::SE_IMAGE_USAGE_STORAGE_BIT,
.name = "SpectrumTextures",
});
spectrumTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_NONE, Gfx::SE_PIPELINE_STAGE_TOP_OF_PIPE_BIT,
Gfx::SE_ACCESS_SHADER_READ_BIT | Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
spectrumBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData =
{
.size = spectrums.size() * sizeof(SpectrumParameters),
.data = (uint8*)spectrums.data(),
},
.numElements = 8,
.dynamic = true,
.name = "Spectrums",
});
spectrumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
linearRepeatSampler = graphics->createSampler(SamplerCreateInfo{
.magFilter = Gfx::SE_FILTER_LINEAR,
.minFilter = Gfx::SE_FILTER_LINEAR,
.addressModeU = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT,
.addressModeV = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT,
.addressModeW = Gfx::SE_SAMPLER_ADDRESS_MODE_REPEAT,
.anisotropyEnable = true,
.maxAnisotropy = 16,
});
computeLayout = graphics->createDescriptorLayout("pParams");
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 4,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_IMAGE,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 6,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
computeLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 7,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
computeLayout->create();
pipelineLayout = graphics->createPipelineLayout("WaterComputeLayout");
pipelineLayout->addDescriptorLayout(computeLayout);
ShaderCompilationInfo info = {
.name = "WaterCompute",
.modules = {"WaterCompute"},
.entryPoints =
{
{"CS_InitializeSpectrum", "WaterCompute"},
{"CS_PackSpectrumConjugate", "WaterCompute"},
{"CS_UpdateSpectrumForFFT", "WaterCompute"},
{"CS_HorizontalFFT", "WaterCompute"},
{"CS_VerticalFFT", "WaterCompute"},
{"CS_AssembleMaps", "WaterCompute"},
},
.rootSignature = pipelineLayout,
.dumpIntermediate = true,
};
graphics->beginShaderCompilation(info);
initSpectrumCS = graphics->createComputeShader({0});
packSpectrumConjugateCS = graphics->createComputeShader({1});
updateSpectrumForFFTCS = graphics->createComputeShader({2});
horizontalFFTCS = graphics->createComputeShader({3});
verticalFFTCS = graphics->createComputeShader({4});
assembleMapsCS = graphics->createComputeShader({5});
pipelineLayout->create();
initSpectrum = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
.computeShader = initSpectrumCS,
.pipelineLayout = pipelineLayout,
});
packSpectrumConjugate = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
.computeShader = packSpectrumConjugateCS,
.pipelineLayout = pipelineLayout,
});
updateSpectrumForFFT = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
.computeShader = updateSpectrumForFFTCS,
.pipelineLayout = pipelineLayout,
});
horizontalFFT = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
.computeShader = horizontalFFTCS,
.pipelineLayout = pipelineLayout,
});
verticalFFT = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
.computeShader = verticalFFTCS,
.pipelineLayout = pipelineLayout,
});
assembleMaps = graphics->createComputePipeline(Gfx::ComputePipelineCreateInfo{
.computeShader = assembleMapsCS,
.pipelineLayout = pipelineLayout,
});
materialLayout = graphics->createDescriptorLayout("pWaterMaterial");
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 0,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
});
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 1,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 2,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 3,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
});
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 4,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_SAMPLER,
});
materialLayout->addDescriptorBinding(Gfx::DescriptorBinding{
.binding = 5,
.descriptorType = Gfx::SE_DESCRIPTOR_TYPE_STORAGE_BUFFER,
});
materialLayout->create();
waterLayout = graphics->createPipelineLayout("WaterLayout");
waterLayout->addDescriptorLayout(viewParamsLayout);
waterLayout->addDescriptorLayout(materialLayout);
ShaderCompilationInfo createInfo = {
.name = "WaterTiles",
.modules = {"WaterTask", "WaterMesh", "WaterPass"},
.entryPoints =
{
{"taskMain", "WaterTask"},
{"meshMain", "WaterMesh"},
{"main", "WaterPass"},
},
.rootSignature = waterLayout,
};
graphics->beginShaderCompilation(createInfo);
waterTask = graphics->createTaskShader({0});
waterMesh = graphics->createMeshShader({1});
waterFragment = graphics->createFragmentShader({2});
waterLayout->create();
}
WaterRenderer::~WaterRenderer() {}
void WaterRenderer::beginFrame() {
std::cout << "Test" << std::endl;
updateFFTDescriptor();
struct WaterPayload {
Vector2 offset;
float extent;
float height;
};
Array<WaterPayload> payloads;
scene->view<Component::WaterTile>([&](Component::WaterTile& tile) {
payloads.add(WaterPayload{
.offset = Vector2(tile.location) * Component::WaterTile::DIMENSIONS,
.extent = Component::WaterTile::DIMENSIONS,
.height = tile.height,
});
});
waterTiles = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData =
{
.size = payloads.size() * sizeof(WaterPayload),
.data = (uint8*)payloads.data(),
},
.numElements = payloads.size(),
.name = "WaterTiles",
});
waterTiles->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_TASK_SHADER_BIT_EXT);
displacementTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_GENERAL, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT,
Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
Gfx::OComputeCommand updateCommand = graphics->createComputeCommand("WaterUpdate");
updateCommand->bindPipeline(updateSpectrumForFFT);
updateCommand->bindDescriptor(computeSet);
updateCommand->dispatch(threadGroupsX, threadGroupsY, 1);
graphics->executeCommands(std::move(updateCommand));
spectrumTextures->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 horizontalCommand = graphics->createComputeCommand("HorizontalFFT");
horizontalCommand->bindPipeline(horizontalFFT);
horizontalCommand->bindDescriptor(computeSet);
horizontalCommand->dispatch(1, params.N, 1);
graphics->executeCommands(std::move(horizontalCommand));
spectrumTextures->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::OComputeCommand verticalCommand = graphics->createComputeCommand("VerticalFFT");
verticalCommand->bindPipeline(verticalFFT);
verticalCommand->bindDescriptor(computeSet);
verticalCommand->dispatch(1, params.N, 1);
graphics->executeCommands(std::move(verticalCommand));
spectrumTextures->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::OComputeCommand assembleCommand = graphics->createComputeCommand("AssembleCommand");
assembleCommand->bindPipeline(assembleMaps);
assembleCommand->bindDescriptor(computeSet);
assembleCommand->dispatch(threadGroupsX, threadGroupsY, 1);
graphics->executeCommands(std::move(assembleCommand));
// transition for mipmap gen
displacementTextures->changeLayout(
Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_TRANSFER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT,
Gfx::SE_ACCESS_TRANSFER_READ_BIT | Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT);
displacementTextures->generateMipmaps();
slopeTextures->generateMipmaps();
displacementTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
slopeTextures->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_TRANSFER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
updateMaterialDescriptor();
graphics->waitDeviceIdle();
}
Gfx::ORenderCommand WaterRenderer::render(Gfx::PDescriptorSet viewParamsSet) {
Gfx::ORenderCommand waterCommand = graphics->createRenderCommand("WaterRender");
waterCommand->setViewport(viewport);
waterCommand->bindPipeline(waterPipeline);
waterCommand->bindDescriptor({viewParamsSet, materialSet});
waterCommand->drawMesh(waterTiles->getNumElements(), 1, 1);
return waterCommand;
}
void WaterRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass renderPass) {
viewport = _viewport;
updateFFTDescriptor();
Gfx::MeshPipelineCreateInfo pipelineInfo = {
.taskShader = waterTask,
.meshShader = waterMesh,
.fragmentShader = waterFragment,
.renderPass = renderPass,
.pipelineLayout = waterLayout,
.multisampleState =
{
.samples = viewport->getSamples(),
},
.rasterizationState =
{
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
},
.colorBlend =
{
.attachmentCount = 1,
.blendAttachments =
{
Gfx::ColorBlendState::BlendAttachment{
.blendEnable = true,
},
},
},
};
waterPipeline = graphics->createGraphicsPipeline(std::move(pipelineInfo));
Gfx::OComputeCommand initCmd = graphics->createComputeCommand("InitialSpectrumCompute");
initCmd->bindPipeline(initSpectrum);
initCmd->bindDescriptor(computeSet);
initCmd->dispatch(threadGroupsX, threadGroupsY, 1);
graphics->executeCommands(std::move(initCmd));
initialSpectrumTextures->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 packCmd = graphics->createComputeCommand("PackConjugate");
packCmd->bindPipeline(packSpectrumConjugate);
packCmd->bindDescriptor(computeSet);
packCmd->dispatch(threadGroupsX, threadGroupsY, 1);
graphics->executeCommands(std::move(packCmd));
initialSpectrumTextures->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);
}
float WaterRenderer::jonswapAlpha(float fetch, float windSpeed) const {
return 0.076f * pow(params.gravity * fetch / windSpeed / windSpeed, -0.22f);
}
float WaterRenderer::jonswapPeakFrequency(float fetch, float windSpeed) const {
return 22 * pow(windSpeed * fetch / params.gravity / params.gravity, -0.33f);
}
void WaterRenderer::updateFFTDescriptor() {
for (uint32 i = 0; i < displaySpectrums.size(); ++i) {
spectrums[i] = {
.scale = displaySpectrums[i].scale,
.angle = displaySpectrums[i].windDirection / 180 * 3.1415f,
.spreadBlend = displaySpectrums[i].spreadBlend,
.swell = std::clamp(displaySpectrums[i].swell, 0.01f, 1.0f),
.alpha = jonswapAlpha(displaySpectrums[i].fetch, displaySpectrums[i].windSpeed),
.peakOmega = jonswapPeakFrequency(displaySpectrums[i].fetch, displaySpectrums[i].windSpeed),
.gamma = displaySpectrums[i].peakEnhancement,
.shortWavesFade = displaySpectrums[i].shortWavesFade,
};
}
spectrumBuffer->updateContents(0, sizeof(SpectrumParameters) * spectrums.size(), spectrums.data());
spectrumBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
params.deltaTime = Gfx::getCurrentFrameDelta();
params.frameTime = Gfx::getCurrentFrameTime();
paramsBuffer->updateContents(0, sizeof(ComputeParams), &params);
paramsBuffer->pipelineBarrier(Gfx::SE_ACCESS_TRANSFER_WRITE_BIT, Gfx::SE_PIPELINE_STAGE_TRANSFER_BIT, Gfx::SE_ACCESS_UNIFORM_READ_BIT,
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
computeLayout->reset();
computeSet = computeLayout->allocateDescriptorSet();
computeSet->updateBuffer(0, paramsBuffer);
computeSet->updateTexture(1, 0, Gfx::PTexture2D(spectrumTextures));
computeSet->updateTexture(2, 0, Gfx::PTexture2D(initialSpectrumTextures));
computeSet->updateTexture(3, 0, Gfx::PTexture2D(displacementTextures));
computeSet->updateTexture(4, 0, Gfx::PTexture2D(slopeTextures));
computeSet->updateTexture(5, 0, Gfx::PTexture2D(boyancyData));
computeSet->updateBuffer(6, 0, spectrumBuffer);
computeSet->updateSampler(7, 0, linearRepeatSampler);
computeSet->writeChanges();
}
void WaterRenderer::updateMaterialDescriptor() {
materialLayout->reset();
materialSet = materialLayout->allocateDescriptorSet();
materialSet->updateBuffer(0, materialUniforms);
materialSet->updateTexture(1, Gfx::PTexture2D(displacementTextures));
materialSet->updateTexture(2, Gfx::PTexture2D(slopeTextures));
materialSet->updateTexture(3, Gfx::PTextureCube(skyBox));
materialSet->updateSampler(4, linearRepeatSampler);
materialSet->updateBuffer(5, waterTiles);
materialSet->writeChanges();
}
@@ -0,0 +1,136 @@
#pragma once
#include "RenderPass.h"
namespace Seele {
class WaterRenderer {
public:
WaterRenderer(Gfx::PGraphics graphics, PScene scene, Gfx::PDescriptorLayout viewParamsLayout);
~WaterRenderer();
void beginFrame();
Gfx::ORenderCommand render(Gfx::PDescriptorSet viewParamsSet);
void setViewport(Gfx::PViewport viewport, Gfx::PRenderPass renderPass);
private:
float jonswapAlpha(float fetch, float windSpeed) const;
float jonswapPeakFrequency(float fetch, float windSpeed) const;
void updateFFTDescriptor();
void updateMaterialDescriptor();
Gfx::PGraphics graphics;
PScene scene;
Gfx::ODescriptorLayout computeLayout;
Gfx::PDescriptorSet computeSet;
Gfx::OPipelineLayout pipelineLayout;
Gfx::OComputeShader initSpectrumCS;
Gfx::PComputePipeline initSpectrum;
Gfx::OComputeShader packSpectrumConjugateCS;
Gfx::PComputePipeline packSpectrumConjugate;
Gfx::OComputeShader updateSpectrumForFFTCS;
Gfx::PComputePipeline updateSpectrumForFFT;
Gfx::OComputeShader horizontalFFTCS;
Gfx::PComputePipeline horizontalFFT;
Gfx::OComputeShader verticalFFTCS;
Gfx::PComputePipeline verticalFFT;
Gfx::OComputeShader assembleMapsCS;
Gfx::PComputePipeline assembleMaps;
struct SpectrumParameters {
float scale;
float angle;
float spreadBlend;
float swell;
float alpha;
float peakOmega;
float gamma;
float shortWavesFade;
};
StaticArray<SpectrumParameters, 8> spectrums;
struct DisplaySpectrumSettings {
float scale = 1;
float windSpeed = 1;
float windDirection = 0;
float fetch = 1;
float spreadBlend = 1;
float swell = 1;
float peakEnhancement = 1;
float shortWavesFade = 1;
};
StaticArray<DisplaySpectrumSettings, 8> displaySpectrums;
struct ComputeParams {
float frameTime;
float deltaTime;
float gravity = 9.81f;
float repeatTime = 200.0f;
float depth = 20.0f;
float lowCutoff = 0.0001f;
float highCutoff = 9000.0f;
int seed = 0;
Vector2 lambda = Vector2(1, 1);
uint32 N = 1024;
uint32 lengthScale0 = 256;
uint32 lengthScale1 = 256;
uint32 lengthScale2 = 256;
uint32 lengthScale3 = 256;
float foamBias = -0.5f;
float foamDecayRate = 0.05f;
float foamAdd = 0.5f;
float foamThreshold = 0.0f;
} params;
float speed = 1.0f;
float displacementDepthFalloff = 1.0f;
uint32 logN;
uint32 threadGroupsX;
uint32 threadGroupsY;
Gfx::OUniformBuffer paramsBuffer;
Gfx::OTexture2D spectrumTextures, initialSpectrumTextures, displacementTextures;
Gfx::OTexture2D slopeTextures;
Gfx::OTexture2D boyancyData;
Gfx::OShaderBuffer spectrumBuffer;
Gfx::OSampler linearRepeatSampler;
struct MaterialParams {
Vector sunDirection = Vector(0, -1, 0);
float displacementDepthAttenuation = 1;
float foamSubtract0 = 0;
float foamSubtract1 = 0;
float foamSubtract2 = 0;
float foamSubtract3 = 0;
float normalStrength = 1;
float foamDepthAttenuation = 1;
float normalDepthAttenuation = 1;
float roughness = 0.1f;
Vector sunIrradiance = Vector(1, 1, 1);
float foamRoughnessModifier = 1;
Vector scatterColor = Vector(1, 1, 1);
float environmentLightStrength = 1;
Vector bubbleColor = Vector(1, 1, 1);
float heightModifier = 1;
float bubbleDensity = 1;
float wavePeakScatterStrength = 1;
float scatterStrength = 1;
float scatterShadowStrength = 1;
Vector foamColor = Vector(1, 1, 1);
} materialParams;
// Water
Gfx::OUniformBuffer materialUniforms;
Gfx::PTextureCube skyBox;
Gfx::OShaderBuffer waterTiles;
Gfx::OTaskShader waterTask;
Gfx::OMeshShader waterMesh;
Gfx::OFragmentShader waterFragment;
Gfx::ODescriptorLayout materialLayout;
Gfx::PDescriptorSet materialSet;
Gfx::OPipelineLayout waterLayout;
Gfx::PGraphicsPipeline waterPipeline;
Gfx::PViewport viewport;
};
DEFINE_REF(WaterRenderer)
}