More water changes

This commit is contained in:
Dynamitos
2024-08-26 22:35:33 +02:00
parent ab721ec953
commit e3b06dfb22
9 changed files with 69 additions and 18 deletions
+1 -1
View File
@@ -102,7 +102,7 @@ void taskMain(
{
#ifdef DEPTH_CULLING
// if the meshlet bounding box is behind the cached depth buffer, we skip
if(isBoxVisible(meshlet.bounding))
//if(isBoxVisible(meshlet.bounding))
#endif
{
uint index;
+2
View File
@@ -2,6 +2,7 @@ struct WaterPayload
{
float3 offset;
float extent;
uint numMeshes;
};
struct WaterTile
@@ -17,6 +18,7 @@ struct WaterVertex
float3 position_WS : POSITION0;
float2 texCoord : TEXCOORD0;
float depth : DEPTH;
uint lod : BONEINDEX;
};
struct MaterialParams
+11
View File
@@ -46,6 +46,15 @@ void meshMain(
float2 base = VERT[i];
float3 objectPos = float3(base.x, 0, base.y);
float3 worldPos = params.offset + objectPos * params.extent + float3(groupID.x * params.extent, 0, groupID.y * params.extent);
float lodDisplacement = 0;
float3 camPos = pViewParams.cameraPos_WS.xyz;
float cameraDistance = distance(worldPos, float3(camPos.x, 0, camPos.z)) / params.extent;
if(params.numMeshes < 4)
{
lodDisplacement = exp(-(1 / (cameraDistance + 4)));
}
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 displacement3 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile3, 2)).xyz * pWaterMaterial.contributeDisplacement3;
@@ -60,12 +69,14 @@ void meshMain(
displacement = lerp(0.0f, displacement, pow(saturate(depth), pWaterMaterial.displacementDepthAttenuation));
worldPos += displacement;
worldPos.y = lodDisplacement;
WaterVertex v;
v.position_WS = worldPos;
v.position_CS = mul(vp, float4(worldPos, 1));
v.texCoord = worldPos.xz;
v.depth = depth;
v.lod = params.numMeshes;
vertices[i] = v;
}
}
+18 -1
View File
@@ -98,6 +98,23 @@ float4 main(WaterVertex vert) : SV_TARGET {
float3 output = (1 - F) * scatter + specular + F * envReflection;
output = max(0.0f, output);
output = lerp(output, pWaterMaterial.foamColor, saturate(foam));
return float4(output, 1);
return float4(output, 1.0f);
//if(vert.lod == 1)
//{
// return float4(1, 0, 0, 1.0f);
//}
//if(vert.lod == 2)
//{
// return float4(0, 1, 0, 1.0f);
//}
//if(vert.lod == 3)
//{
// return float4(0, 0, 1, 1.0f);
//}
//if(vert.lod == 4)
//{
// return float4(1, 1, 1, 1.0f);
//}
//return float4(0, 0, 0, 1);
}
+24 -5
View File
@@ -3,23 +3,42 @@ import Common;
import Scene;
import WaterCommon;
[numthreads(1, 1, 1)]
[shader("amplification")]
void taskMain(
uint threadID: SV_GroupThreadID,
uint groupID: SV_GroupID, )
{
WaterTile tile = pWaterMaterial.tiles[groupID];
uint3 groupID: SV_GroupID
) {
WaterTile tile = pWaterMaterial.tiles[groupID.x];
GroupMemoryBarrierWithGroupSync();
AABB bounding;
bounding.minCorner = float3(tile.location.x, tile.height, tile.location.y) * tile.extent;
bounding.maxCorner = float3(tile.location.x + 1, tile.height, tile.location.y + 1) * tile.extent;
float3 median = (bounding.minCorner + bounding.maxCorner) / 2;
float distance = distance(median, pViewParams.cameraPos_WS.xyz);
uint numMeshes = max(4 - uint(distance / tile.extent), 1);
float tileDistance = distance / tile.extent;
uint numMeshes = groupID.y + 1;
if(numMeshes == 4 && (tileDistance > 8))
{
return;
}
if(numMeshes == 3)
{
return;
}
if(numMeshes == 2)
{
return;
}
if(numMeshes == 1)
{
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
@@ -42,7 +42,7 @@ void TextureLoader::importAsset(TextureImportArgs args) {
PTextureAsset ref = asset;
asset->setStatus(Asset::Status::Loading);
AssetRegistry::get().registerTexture(std::move(asset));
import(args, ref);
getThreadPool().runAsync([=](){import(args, ref);});
}
PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset; }
@@ -111,7 +111,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
ktxBasisParams basisParams = {
.structSize = sizeof(ktxBasisParams),
.uastc = true,
.threadCount = std::thread::hardware_concurrency(),
.threadCount = 1,
.uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT,
.uastcRDO = true,
};
+5 -3
View File
@@ -64,9 +64,10 @@ int main() {
.filePath = sourcePath / "import/textures/skyboxsun5deg_tn.jpg",
.type = TextureImportType::TEXTURE_CUBEMAP,
});
//AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/sheepsbody.fbx",
//});
AssetImporter::importMesh(MeshImportArgs{
.filePath = sourcePath / "import/models/ship.glb",
.importPath = "ship",
});
// AssetImporter::importMesh(MeshImportArgs{
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
// .importPath = "Whitechapel",
@@ -75,6 +76,7 @@ int main() {
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
// .importPath = "suburbs",
// });
vd->commitMeshes();
WindowCreateInfo mainWindowInfo = {
.width = 1920,
@@ -444,7 +444,7 @@ Gfx::ORenderCommand WaterRenderer::render(Gfx::PDescriptorSet viewParamsSet) {
waterCommand->setViewport(viewport);
waterCommand->bindPipeline(waterPipeline);
waterCommand->bindDescriptor({viewParamsSet, materialSet});
waterCommand->drawMesh(waterTiles->getNumElements(), 1, 1);
waterCommand->drawMesh(waterTiles->getNumElements(), 4, 1);
return waterCommand;
}
@@ -471,7 +471,7 @@ void WaterRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass rende
.blendAttachments =
{
Gfx::ColorBlendState::BlendAttachment{
.blendEnable = true,
.blendEnable = false,
},
},
},
@@ -98,7 +98,7 @@ class WaterRenderer {
Gfx::OSampler linearRepeatSampler;
struct MaterialParams {
Vector sunDirection = Vector(-1.29f, -1.0f, 4.86f);
Vector sunDirection = Vector(-5, 0.6186, 5);
float displacementDepthAttenuation = 1;
float foamSubtract0 = 0.04f;
@@ -116,7 +116,7 @@ class WaterRenderer {
float normalDepthAttenuation = 1;
float roughness = 0.075f;
Vector sunIrradiance = Vector(1.0f, 0.694f, 0.32f);
Vector sunIrradiance = Vector(0.9921, 0.9058, 0.5450);
float foamRoughnessModifier = 0;
Vector scatterColor = Vector(0.016f, 0.0735f, 0.16f);