Files
Seele/res/shaders/TerrainPass.slang
T

82 lines
2.3 KiB
Plaintext
Raw Normal View History

2024-08-13 22:44:04 +02:00
import Common;
2024-10-07 20:14:00 +02:00
import Parameters;
2024-08-13 22:44:04 +02:00
2024-10-07 20:14:00 +02:00
// Vertex input
struct VertexInput
{
2024-10-07 20:14:00 +02:00
uint instanceID : SV_InstanceID;
uint vertexID : SV_VertexID;
};
2024-10-07 20:14:00 +02:00
// Vertex output
struct VertexOutput
{
2024-10-07 20:14:00 +02:00
float4 positionCS : SV_POSITION;
uint triangleID : TRIANGLE_ID;
};
2024-10-07 20:14:00 +02:00
[shader("vertex")]
VertexOutput vert(VertexInput input)
{
2024-10-07 20:14:00 +02:00
// Initialize the output structure
VertexOutput output;
output = (VertexOutput)0;
2024-10-07 20:14:00 +02:00
// Evaluate the properties of this triangle
uint triangle_id = input.vertexID / 3;
uint local_vert_id = input.vertexID % 3;
2024-10-07 20:14:00 +02:00
// Operate the indirection
output.triangleID = pParams.indexedBisectorBuffer[triangle_id];
// Which vertex should be read?
local_vert_id = local_vert_id == 0 ? 2 : (local_vert_id == 2 ? 0 : 1);
2024-10-15 21:35:52 +02:00
float3 positionRWS = pParams.currentVertexBuffer[output.triangleID * 3 + local_vert_id].xyz;
2024-10-22 15:00:39 +02:00
//positionRWS.y = pParams.displacementMap.SampleLevel(pParams.displacementSampler, positionRWS.xz, 0).r;
2024-10-07 20:14:00 +02:00
2024-10-22 15:00:39 +02:00
float2 texCoord = positionRWS.xz / 1000;
positionRWS.y = pParams.displacementMap.SampleLevel(pParams.displacementSampler, texCoord, 0).r * 100;
2024-10-07 20:14:00 +02:00
// Apply the view projection
output.positionCS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, float4(positionRWS, 1.0)));
return output;
}
2024-10-07 20:14:00 +02:00
// Pixel input
struct PixelInput
{
float4 positionCS : SV_POSITION;
uint triangleID : TRIANGLE_ID;
};
[shader("pixel")]
2024-10-07 20:14:00 +02:00
float4 frag(PixelInput input) : SV_Target
{
2024-10-07 20:14:00 +02:00
return float4(0, 1, 0, 1);
}
[shader("compute")]
[numthreads(64, 1, 1)]
2024-10-15 21:35:52 +02:00
void EvaluateDeformation(uint currentID : SV_DispatchThreadID)
2024-10-07 20:14:00 +02:00
{
2024-10-15 21:35:52 +02:00
// This thread doesn't have any work to do, we're done
if (currentID >= pParams.indirectDrawBuffer[9] * 4)
2024-10-07 20:14:00 +02:00
return;
2024-10-15 21:35:52 +02:00
// Extract the bisector ID and the vertexID
2024-10-07 20:14:00 +02:00
uint bisectorID = currentID / 4;
uint localVertexID = currentID % 4;
2024-10-15 21:35:52 +02:00
// Operate the indirection
2024-10-07 20:14:00 +02:00
bisectorID = pParams.indexedBisectorBuffer[bisectorID];
2024-10-15 21:35:52 +02:00
// Evaluate the source vertex
2024-10-07 20:14:00 +02:00
currentID = localVertexID < 3 ? bisectorID * 3 + localVertexID : 3 * pParams.geometry.totalNumElements + bisectorID;
2024-10-15 21:35:52 +02:00
// Grab the position that we will be displacing
float3 positionWS = pParams.lebPositionBuffer[currentID].xyz;
float3 positionRWS = float3(positionWS - pViewParams.cameraPosition_WS.xyz);
2024-10-07 20:14:00 +02:00
2024-10-15 21:35:52 +02:00
pParams.currentVertexBuffer[currentID] = float4(positionRWS, 1);
}