More water changes
This commit is contained in:
@@ -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,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
|
||||
|
||||
@@ -46,13 +46,22 @@ 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;
|
||||
float3 displacement4 = pWaterMaterial.displacementTextures.Sample(pWaterMaterial.sampler, float3(worldPos.xz * pWaterMaterial.tile4, 3)).xyz * pWaterMaterial.contributeDisplacement4;
|
||||
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 depth = 1 - (-ndcDepth + 1.0f) / 2.0f;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user