More water changes
This commit is contained in:
@@ -102,7 +102,7 @@ void taskMain(
|
|||||||
{
|
{
|
||||||
#ifdef DEPTH_CULLING
|
#ifdef DEPTH_CULLING
|
||||||
// if the meshlet bounding box is behind the cached depth buffer, we skip
|
// if the meshlet bounding box is behind the cached depth buffer, we skip
|
||||||
if(isBoxVisible(meshlet.bounding))
|
//if(isBoxVisible(meshlet.bounding))
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
uint index;
|
uint index;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ struct WaterPayload
|
|||||||
{
|
{
|
||||||
float3 offset;
|
float3 offset;
|
||||||
float extent;
|
float extent;
|
||||||
|
uint numMeshes;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct WaterTile
|
struct WaterTile
|
||||||
@@ -17,6 +18,7 @@ struct WaterVertex
|
|||||||
float3 position_WS : POSITION0;
|
float3 position_WS : POSITION0;
|
||||||
float2 texCoord : TEXCOORD0;
|
float2 texCoord : TEXCOORD0;
|
||||||
float depth : DEPTH;
|
float depth : DEPTH;
|
||||||
|
uint lod : BONEINDEX;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MaterialParams
|
struct MaterialParams
|
||||||
|
|||||||
@@ -46,13 +46,22 @@ void meshMain(
|
|||||||
float2 base = VERT[i];
|
float2 base = VERT[i];
|
||||||
float3 objectPos = float3(base.x, 0, base.y);
|
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);
|
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 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;
|
||||||
float3 displacement3 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile3, 2)).xyz * pWaterMaterial.contributeDisplacement3;
|
float3 displacement3 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile3, 2)).xyz * pWaterMaterial.contributeDisplacement3;
|
||||||
float3 displacement4 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile4, 3)).xyz * pWaterMaterial.contributeDisplacement4;
|
float3 displacement4 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile4, 3)).xyz * pWaterMaterial.contributeDisplacement4;
|
||||||
float3 displacement = displacement1 + displacement2 + displacement3 + displacement4;
|
float3 displacement = displacement1 + displacement2 + displacement3 + displacement4;
|
||||||
|
|
||||||
float4 clipPos = mul(vp, float4(worldPos, 1));
|
float4 clipPos = mul(vp, float4(worldPos, 1));
|
||||||
float ndcDepth = clipPos.z / clipPos.w;
|
float ndcDepth = clipPos.z / clipPos.w;
|
||||||
|
|
||||||
float depth = 1 - (-ndcDepth + 1.0f) / 2.0f;
|
float depth = 1 - (-ndcDepth + 1.0f) / 2.0f;
|
||||||
@@ -60,12 +69,14 @@ 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;
|
||||||
|
|
||||||
WaterVertex v;
|
WaterVertex v;
|
||||||
v.position_WS = worldPos;
|
v.position_WS = worldPos;
|
||||||
v.position_CS = mul(vp, float4(worldPos, 1));
|
v.position_CS = mul(vp, float4(worldPos, 1));
|
||||||
v.texCoord = worldPos.xz;
|
v.texCoord = worldPos.xz;
|
||||||
v.depth = depth;
|
v.depth = depth;
|
||||||
|
v.lod = params.numMeshes;
|
||||||
vertices[i] = v;
|
vertices[i] = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,6 +98,23 @@ float4 main(WaterVertex vert) : SV_TARGET {
|
|||||||
float3 output = (1 - F) * scatter + specular + F * envReflection;
|
float3 output = (1 - F) * scatter + specular + F * envReflection;
|
||||||
output = max(0.0f, output);
|
output = max(0.0f, output);
|
||||||
output = lerp(output, pWaterMaterial.foamColor, saturate(foam));
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,23 +3,42 @@ import Common;
|
|||||||
import Scene;
|
import Scene;
|
||||||
import WaterCommon;
|
import WaterCommon;
|
||||||
|
|
||||||
|
|
||||||
[numthreads(1, 1, 1)]
|
[numthreads(1, 1, 1)]
|
||||||
[shader("amplification")]
|
[shader("amplification")]
|
||||||
void taskMain(
|
void taskMain(
|
||||||
uint threadID: SV_GroupThreadID,
|
uint threadID: SV_GroupThreadID,
|
||||||
uint groupID: SV_GroupID, )
|
uint3 groupID: SV_GroupID
|
||||||
{
|
) {
|
||||||
WaterTile tile = pWaterMaterial.tiles[groupID];
|
WaterTile tile = pWaterMaterial.tiles[groupID.x];
|
||||||
GroupMemoryBarrierWithGroupSync();
|
GroupMemoryBarrierWithGroupSync();
|
||||||
AABB bounding;
|
AABB bounding;
|
||||||
bounding.minCorner = float3(tile.location.x, tile.height, tile.location.y) * tile.extent;
|
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;
|
bounding.maxCorner = float3(tile.location.x + 1, tile.height, tile.location.y + 1) * tile.extent;
|
||||||
float3 median = (bounding.minCorner + bounding.maxCorner) / 2;
|
float3 median = (bounding.minCorner + bounding.maxCorner) / 2;
|
||||||
float distance = distance(median, pViewParams.cameraPos_WS.xyz);
|
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;
|
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;
|
||||||
DispatchMesh(numMeshes, numMeshes, 1, payload);
|
DispatchMesh(numMeshes, numMeshes, 1, payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ void TextureLoader::importAsset(TextureImportArgs args) {
|
|||||||
PTextureAsset ref = asset;
|
PTextureAsset ref = asset;
|
||||||
asset->setStatus(Asset::Status::Loading);
|
asset->setStatus(Asset::Status::Loading);
|
||||||
AssetRegistry::get().registerTexture(std::move(asset));
|
AssetRegistry::get().registerTexture(std::move(asset));
|
||||||
import(args, ref);
|
getThreadPool().runAsync([=](){import(args, ref);});
|
||||||
}
|
}
|
||||||
|
|
||||||
PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset; }
|
PTextureAsset TextureLoader::getPlaceholderTexture() { return placeholderAsset; }
|
||||||
@@ -111,7 +111,7 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
|
|||||||
ktxBasisParams basisParams = {
|
ktxBasisParams basisParams = {
|
||||||
.structSize = sizeof(ktxBasisParams),
|
.structSize = sizeof(ktxBasisParams),
|
||||||
.uastc = true,
|
.uastc = true,
|
||||||
.threadCount = std::thread::hardware_concurrency(),
|
.threadCount = 1,
|
||||||
.uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT,
|
.uastcFlags = KTX_PACK_UASTC_LEVEL_DEFAULT,
|
||||||
.uastcRDO = true,
|
.uastcRDO = true,
|
||||||
};
|
};
|
||||||
@@ -146,6 +146,6 @@ void TextureLoader::import(TextureImportArgs args, PTextureAsset textureAsset) {
|
|||||||
textureAsset->setTexture(std::move(serialized));
|
textureAsset->setTexture(std::move(serialized));
|
||||||
|
|
||||||
AssetRegistry::saveAsset(textureAsset, TextureAsset::IDENTIFIER, textureAsset->getFolderPath(), textureAsset->getName());
|
AssetRegistry::saveAsset(textureAsset, TextureAsset::IDENTIFIER, textureAsset->getFolderPath(), textureAsset->getName());
|
||||||
|
|
||||||
textureAsset->setStatus(Asset::Status::Ready);
|
textureAsset->setStatus(Asset::Status::Ready);
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-3
@@ -64,9 +64,10 @@ 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{
|
AssetImporter::importMesh(MeshImportArgs{
|
||||||
// .filePath = sourcePath / "import/models/sheepsbody.fbx",
|
.filePath = sourcePath / "import/models/ship.glb",
|
||||||
//});
|
.importPath = "ship",
|
||||||
|
});
|
||||||
// AssetImporter::importMesh(MeshImportArgs{
|
// AssetImporter::importMesh(MeshImportArgs{
|
||||||
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
// .filePath = sourcePath / "import/models/after-the-rain-vr-sound/source/Whitechapel.glb",
|
||||||
// .importPath = "Whitechapel",
|
// .importPath = "Whitechapel",
|
||||||
@@ -75,6 +76,7 @@ int main() {
|
|||||||
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
|
// .filePath = sourcePath / "import/models/city-suburbs/source/city-suburbs.obj",
|
||||||
// .importPath = "suburbs",
|
// .importPath = "suburbs",
|
||||||
// });
|
// });
|
||||||
|
|
||||||
vd->commitMeshes();
|
vd->commitMeshes();
|
||||||
WindowCreateInfo mainWindowInfo = {
|
WindowCreateInfo mainWindowInfo = {
|
||||||
.width = 1920,
|
.width = 1920,
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ Gfx::ORenderCommand WaterRenderer::render(Gfx::PDescriptorSet viewParamsSet) {
|
|||||||
waterCommand->setViewport(viewport);
|
waterCommand->setViewport(viewport);
|
||||||
waterCommand->bindPipeline(waterPipeline);
|
waterCommand->bindPipeline(waterPipeline);
|
||||||
waterCommand->bindDescriptor({viewParamsSet, materialSet});
|
waterCommand->bindDescriptor({viewParamsSet, materialSet});
|
||||||
waterCommand->drawMesh(waterTiles->getNumElements(), 1, 1);
|
waterCommand->drawMesh(waterTiles->getNumElements(), 4, 1);
|
||||||
return waterCommand;
|
return waterCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ void WaterRenderer::setViewport(Gfx::PViewport _viewport, Gfx::PRenderPass rende
|
|||||||
.blendAttachments =
|
.blendAttachments =
|
||||||
{
|
{
|
||||||
Gfx::ColorBlendState::BlendAttachment{
|
Gfx::ColorBlendState::BlendAttachment{
|
||||||
.blendEnable = true,
|
.blendEnable = false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class WaterRenderer {
|
|||||||
Gfx::OSampler linearRepeatSampler;
|
Gfx::OSampler linearRepeatSampler;
|
||||||
|
|
||||||
struct MaterialParams {
|
struct MaterialParams {
|
||||||
Vector sunDirection = Vector(-1.29f, -1.0f, 4.86f);
|
Vector sunDirection = Vector(-5, 0.6186, 5);
|
||||||
float displacementDepthAttenuation = 1;
|
float displacementDepthAttenuation = 1;
|
||||||
|
|
||||||
float foamSubtract0 = 0.04f;
|
float foamSubtract0 = 0.04f;
|
||||||
@@ -116,7 +116,7 @@ class WaterRenderer {
|
|||||||
float normalDepthAttenuation = 1;
|
float normalDepthAttenuation = 1;
|
||||||
float roughness = 0.075f;
|
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;
|
float foamRoughnessModifier = 0;
|
||||||
|
|
||||||
Vector scatterColor = Vector(0.016f, 0.0735f, 0.16f);
|
Vector scatterColor = Vector(0.016f, 0.0735f, 0.16f);
|
||||||
|
|||||||
Reference in New Issue
Block a user