Files
Seele/res/shaders/WaterTask.slang
T

44 lines
1.2 KiB
Plaintext
Raw Normal View History

2024-08-21 10:24:37 +02:00
import Bounding;
2024-08-13 22:44:04 +02:00
import Common;
import Scene;
import WaterCommon;
[numthreads(1, 1, 1)]
[shader("amplification")]
void taskMain(
uint threadID: SV_GroupThreadID,
2024-08-26 22:35:22 +02:00
uint3 groupID: SV_GroupID
) {
WaterTile tile = pWaterMaterial.tiles[groupID.x];
2024-08-21 10:24:37 +02:00
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;
2024-09-16 13:00:53 +02:00
float distance = distance(median, pViewParams.c.cameraPos_WS.xyz);
2024-08-26 22:35:22 +02:00
float tileDistance = distance / tile.extent;
uint numMeshes = groupID.y + 1;
2024-08-30 09:29:41 +02:00
if(numMeshes == 4 && tileDistance > 2)
2024-08-26 22:35:22 +02:00
{
return;
}
2024-08-30 09:29:41 +02:00
if(numMeshes == 3 && (tileDistance > 4 || tileDistance < 1))
2024-08-26 22:35:22 +02:00
{
return;
}
2024-08-30 09:29:41 +02:00
if(numMeshes == 2 && (tileDistance > 8 || tileDistance < 3))
2024-08-26 22:35:22 +02:00
{
return;
}
2024-08-30 09:29:41 +02:00
if(numMeshes == 1 && tileDistance < 7)
2024-08-26 22:35:22 +02:00
{
return;
}
2024-08-21 10:24:37 +02:00
WaterPayload payload;
payload.offset = bounding.minCorner;
payload.extent = tile.extent / numMeshes;
2024-08-26 22:35:22 +02:00
payload.numMeshes = numMeshes;
2024-08-21 10:24:37 +02:00
DispatchMesh(numMeshes, numMeshes, 1, payload);
2024-08-13 22:44:04 +02:00
}