Finished water for real this time
This commit is contained in:
@@ -49,11 +49,33 @@ void meshMain(
|
|||||||
|
|
||||||
float lodDisplacement = 0;
|
float lodDisplacement = 0;
|
||||||
float3 camPos = pViewParams.cameraPos_WS.xyz;
|
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)
|
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 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;
|
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));
|
displacement = lerp(0.0f, displacement, pow(saturate(depth), pWaterMaterial.displacementDepthAttenuation));
|
||||||
|
|
||||||
worldPos += displacement;
|
worldPos += displacement;
|
||||||
worldPos.y = lodDisplacement;
|
worldPos.y += lodDisplacement;
|
||||||
|
|
||||||
WaterVertex v;
|
WaterVertex v;
|
||||||
v.position_WS = worldPos;
|
v.position_WS = worldPos;
|
||||||
|
|||||||
@@ -19,26 +19,25 @@ void taskMain(
|
|||||||
float tileDistance = distance / tile.extent;
|
float tileDistance = distance / tile.extent;
|
||||||
uint numMeshes = groupID.y + 1;
|
uint numMeshes = groupID.y + 1;
|
||||||
|
|
||||||
if(numMeshes == 4 && (tileDistance > 8))
|
if(numMeshes == 4 && tileDistance > 2)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(numMeshes == 3)
|
if(numMeshes == 3 && (tileDistance > 4 || tileDistance < 1))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(numMeshes == 2)
|
if(numMeshes == 2 && (tileDistance > 8 || tileDistance < 3))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(numMeshes == 1)
|
if(numMeshes == 1 && tileDistance < 7)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
WaterPayload payload;
|
WaterPayload payload;
|
||||||
payload.offset = bounding.minCorner;
|
payload.offset = bounding.minCorner;
|
||||||
payload.extent = tile.extent / numMeshes;
|
payload.extent = tile.extent / numMeshes;
|
||||||
// todo: hardcoded max lod
|
|
||||||
payload.numMeshes = numMeshes;
|
payload.numMeshes = numMeshes;
|
||||||
DispatchMesh(numMeshes, numMeshes, 1, payload);
|
DispatchMesh(numMeshes, numMeshes, 1, payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,11 +112,11 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
|
|||||||
.structSize = sizeof(ktxBasisParams),
|
.structSize = sizeof(ktxBasisParams),
|
||||||
.uastc = true,
|
.uastc = true,
|
||||||
.threadCount = 1,
|
.threadCount = 1,
|
||||||
.uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT,
|
.uastcFlags = KTX_PACK_UASTC_LEVEL_FASTER,
|
||||||
.uastcRDO = true,
|
.uastcRDO = true,
|
||||||
};
|
};
|
||||||
KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
|
KTX_ASSERT(ktxTexture2_CompressBasisEx(kTexture, &basisParams));
|
||||||
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 20));
|
KTX_ASSERT(ktxTexture2_DeflateZstd(kTexture, 2));
|
||||||
|
|
||||||
char writer[100];
|
char writer[100];
|
||||||
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
|
snprintf(writer, sizeof(writer), "%s version %s", "SeeleEngine", "0.0.1");
|
||||||
|
|||||||
+7
-7
@@ -64,19 +64,19 @@ int main() {
|
|||||||
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
|
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
|
||||||
.type = TextureImportType::TEXTURE_CUBEMAP,
|
.type = TextureImportType::TEXTURE_CUBEMAP,
|
||||||
});
|
});
|
||||||
|
//AssetImporter::importMesh(MeshImportArgs{
|
||||||
|
// .filePath = sourcePath / "import/models/ship.fbx",
|
||||||
|
// .importPath = "ship",
|
||||||
|
//});
|
||||||
AssetImporter::importMesh(MeshImportArgs{
|
AssetImporter::importMesh(MeshImportArgs{
|
||||||
.filePath = sourcePath / "import/models/ship.fbx",
|
.filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||||
.importPath = "ship",
|
.importPath = "Whitechapel",
|
||||||
});
|
});
|
||||||
// AssetImporter::importMesh(MeshImportArgs{
|
// 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",
|
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
|
||||||
// .importPath = "suburbs",
|
// .importPath = "suburbs",
|
||||||
// });
|
// });
|
||||||
|
getThreadPool().waitIdle();
|
||||||
vd->commitMeshes();
|
vd->commitMeshes();
|
||||||
WindowCreateInfo mainWindowInfo = {
|
WindowCreateInfo mainWindowInfo = {
|
||||||
.width = 1920,
|
.width = 1920,
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void Seele::addDebugVertex(DebugVertex vert) { gDebugVertices.add(vert); }
|
|||||||
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
|
void Seele::addDebugVertices(Array<DebugVertex> verts) { gDebugVertices.addAll(verts); }
|
||||||
|
|
||||||
BasePass::BasePass(Gfx::PGraphics graphics, PScene scene) : RenderPass(graphics, scene) {
|
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 = graphics->createPipelineLayout("BasePassLayout");
|
||||||
|
|
||||||
basePassLayout->addDescriptorLayout(viewParamsLayout);
|
basePassLayout->addDescriptorLayout(viewParamsLayout);
|
||||||
@@ -472,7 +472,7 @@ void BasePass::createRenderPass() {
|
|||||||
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
|
oLightGrid = resources->requestTexture("LIGHTCULLING_OLIGHTGRID");
|
||||||
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
|
tLightGrid = resources->requestTexture("LIGHTCULLING_TLIGHTGRID");
|
||||||
|
|
||||||
//waterRenderer->setViewport(viewport, renderPass);
|
waterRenderer->setViewport(viewport, renderPass);
|
||||||
|
|
||||||
// Debug rendering
|
// Debug rendering
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -358,6 +358,8 @@ void WaterRenderer::beginFrame() {
|
|||||||
.height = tile.height,
|
.height = tile.height,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
if (payloads.size() == 0)
|
||||||
|
return;
|
||||||
waterTiles = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
waterTiles = graphics->createShaderBuffer(ShaderBufferCreateInfo{
|
||||||
.sourceData =
|
.sourceData =
|
||||||
{
|
{
|
||||||
@@ -435,7 +437,6 @@ void WaterRenderer::beginFrame() {
|
|||||||
|
|
||||||
boyancyData->changeLayout(Gfx::SE_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, Gfx::SE_ACCESS_SHADER_WRITE_BIT,
|
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);
|
Gfx::SE_PIPELINE_STAGE_COMPUTE_SHADER_BIT, Gfx::SE_ACCESS_SHADER_READ_BIT, Gfx::SE_SHADER_STAGE_MESH_BIT_EXT);
|
||||||
|
|
||||||
updateMaterialDescriptor();
|
updateMaterialDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -463,6 +464,7 @@ void WaterRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass rende
|
|||||||
},
|
},
|
||||||
.rasterizationState =
|
.rasterizationState =
|
||||||
{
|
{
|
||||||
|
//.polygonMode = Gfx::SE_POLYGON_MODE_LINE,
|
||||||
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
|
.cullMode = Gfx::SE_CULL_MODE_BACK_BIT,
|
||||||
},
|
},
|
||||||
.colorBlend =
|
.colorBlend =
|
||||||
|
|||||||
@@ -54,11 +54,25 @@ void ThreadPool::runAsync(std::function<void()> func) {
|
|||||||
queueCV.notify_one();
|
queueCV.notify_one();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ThreadPool::waitIdle() {
|
||||||
|
std::unique_lock l(queueLock);
|
||||||
|
while (numWaiting < workers.size())
|
||||||
|
{
|
||||||
|
idleCV.wait(l);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ThreadPool::work() {
|
void ThreadPool::work() {
|
||||||
while (running) {
|
while (running) {
|
||||||
std::unique_lock l(queueLock);
|
std::unique_lock l(queueLock);
|
||||||
while (queue.empty()) {
|
while (queue.empty()) {
|
||||||
|
numWaiting++;
|
||||||
|
if (numWaiting == workers.size())
|
||||||
|
{
|
||||||
|
idleCV.notify_all();
|
||||||
|
}
|
||||||
queueCV.wait(l);
|
queueCV.wait(l);
|
||||||
|
numWaiting--;
|
||||||
if (!running) {
|
if (!running) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -72,7 +86,7 @@ void ThreadPool::work() {
|
|||||||
std::unique_lock t(taskLock);
|
std::unique_lock t(taskLock);
|
||||||
entry.task->numRemaining--;
|
entry.task->numRemaining--;
|
||||||
if (entry.task->numRemaining == 0) {
|
if (entry.task->numRemaining == 0) {
|
||||||
completedCV.notify_one();
|
completedCV.notify_all();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ class ThreadPool {
|
|||||||
~ThreadPool();
|
~ThreadPool();
|
||||||
void runAndWait(List<std::function<void()>> functions);
|
void runAndWait(List<std::function<void()>> functions);
|
||||||
void runAsync(std::function<void()> func);
|
void runAsync(std::function<void()> func);
|
||||||
|
void waitIdle();
|
||||||
private:
|
private:
|
||||||
struct TaskGroup {
|
struct TaskGroup {
|
||||||
uint64 numRemaining = 0;
|
uint64 numRemaining = 0;
|
||||||
@@ -22,6 +23,8 @@ class ThreadPool {
|
|||||||
|
|
||||||
std::mutex queueLock;
|
std::mutex queueLock;
|
||||||
std::condition_variable queueCV;
|
std::condition_variable queueCV;
|
||||||
|
std::atomic_uint32_t numWaiting = 0;
|
||||||
|
std::condition_variable idleCV;
|
||||||
List<QueueEntry> queue;
|
List<QueueEntry> queue;
|
||||||
|
|
||||||
void work();
|
void work();
|
||||||
|
|||||||
Reference in New Issue
Block a user