Finished water for real this time

This commit is contained in:
Dynamitos
2024-08-30 09:29:41 +02:00
parent 0be1a3cbde
commit 88eacd067e
8 changed files with 61 additions and 21 deletions
+25 -3
View File
@@ -49,11 +49,33 @@ void meshMain(
float lodDisplacement = 0;
float3 camPos = pViewParams.cameraPos_WS.xyz;
float cameraDistance = distance(worldPos, float3(camPos.x, 0, camPos.z)) / params.extent;
float cameraDistance = distance(worldPos, camPos);
float threshold = 0;
if(params.numMeshes == 3)
{
threshold = 10;
}
if(params.numMeshes == 2)
{
threshold = 30;
}
if(params.numMeshes == 1)
{
threshold = 70;
}
if(params.numMeshes < 4)
{
lodDisplacement = exp(-(1 / (cameraDistance + 4)));
if(cameraDistance > threshold)
{
lodDisplacement = clamp(exp(-(1 / (cameraDistance + threshold))), 0, 1) - 1;
}
else
{
lodDisplacement = -1;
}
}
float3 displacement1 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile1, 0)).xyz * pWaterMaterial.contributeDisplacement1;
float3 displacement2 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile2, 1)).xyz * pWaterMaterial.contributeDisplacement2;
@@ -69,7 +91,7 @@ void meshMain(
displacement = lerp(0.0f, displacement, pow(saturate(depth), pWaterMaterial.displacementDepthAttenuation));
worldPos += displacement;
worldPos.y = lodDisplacement;
worldPos.y += lodDisplacement;
WaterVertex v;
v.position_WS = worldPos;
+4 -5
View File
@@ -19,26 +19,25 @@ void taskMain(
float tileDistance = distance / tile.extent;
uint numMeshes = groupID.y + 1;
if(numMeshes == 4 && (tileDistance > 8))
if(numMeshes == 4 && tileDistance > 2)
{
return;
}
if(numMeshes == 3)
if(numMeshes == 3 && (tileDistance > 4 || tileDistance < 1))
{
return;
}
if(numMeshes == 2)
if(numMeshes == 2 && (tileDistance > 8 || tileDistance < 3))
{
return;
}
if(numMeshes == 1)
if(numMeshes == 1 && tileDistance < 7)
{
return;
}
WaterPayload payload;
payload.offset = bounding.minCorner;
payload.extent = tile.extent / numMeshes;
// todo: hardcoded max lod
payload.numMeshes = numMeshes;
DispatchMesh(numMeshes, numMeshes, 1, payload);
}
+2 -2
View File
@@ -112,11 +112,11 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
.structSize = sizeof(ktxBasisParams),
.uastc = true,
.threadCount = 1,
.uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT,
.uastcFlags = KTX_PACK_UASTC_LEVEL_FASTER,
.uastcRDO = true,
};
KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 20));
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 2));
char writer[100];
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
+7 -7
View File
@@ -64,19 +64,19 @@ int main() {
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
.type = TextureImportType::TEXTURE_CUBEMAP,
});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/ship.fbx",
// .importPath = "ship",
//});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/ship.fbx",
.importPath = "ship",
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
.importPath = "Whitechapel",
});
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
// .importPath = "Whitechapel",
//);
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs",
// });
getThreadPool().waitIdle();
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
.width = 1920,
+2 -2
View File
@@ -26,7 +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);
waterRenderer = new WaterRenderer(graphics, scene, viewParamsLayout);
basePassLayout = graphics->createPipelineLayout("BasePassLayout");
basePassLayout->addDescriptorLayout(viewParamsLayout);
@@ -472,7 +472,7 @@ void BasePass::createRenderPass() {
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
//waterRenderer->setViewport(viewport, renderPass);
waterRenderer->setViewport(viewport, renderPass);
// Debug rendering
{
@@ -358,6 +358,8 @@ void WaterRenderer::beginFrame() {
.height = tile.height,
});
});
if (payloads.size() == 0)
return;
waterTiles = graphics->createShaderBuffer(ShaderBufferCreateInfo{
.sourceData =
{
@@ -435,7 +437,6 @@ void WaterRenderer::beginFrame() {
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();
}
@@ -463,6 +464,7 @@ void WaterRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass rende
},
.rasterizationState =
{
//.polygonMode = Gfx::SE_POLYGON_MODE_LINE,
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
},
.colorBlend =
+15 -1
View File
@@ -54,11 +54,25 @@ void ThreadPool::runAsync(std::function<void()> func) {
queueCV.notify_one();
}
void ThreadPool::waitIdle() {
std::unique_lock l(queueLock);
while (numWaiting < workers.size())
{
idleCV.wait(l);
}
}
void ThreadPool::work() {
while (running) {
std::unique_lock l(queueLock);
while (queue.empty()) {
numWaiting++;
if (numWaiting == workers.size())
{
idleCV.notify_all();
}
queueCV.wait(l);
numWaiting--;
if (!running) {
return;
}
@@ -72,7 +86,7 @@ void ThreadPool::work() {
std::unique_lock t(taskLock);
entry.task->numRemaining--;
if (entry.task->numRemaining == 0) {
completedCV.notify_one();
completedCV.notify_all();
}
}
}
+3
View File
@@ -11,6 +11,7 @@ class ThreadPool {
~ThreadPool();
void runAndWait(List<std::function<void()>> functions);
void runAsync(std::function<void()> func);
void waitIdle();
private:
struct TaskGroup {
uint64 numRemaining = 0;
@@ -22,6 +23,8 @@ class ThreadPool {
std::mutex queueLock;
std::condition_variable queueCV;
std::atomic_uint32_t numWaiting = 0;
std::condition_variable idleCV;
List<QueueEntry> queue;
void work();