2020-06-02 11:46:18 +02:00
|
|
|
const static float PI = 3.1415926535897932f;
|
|
|
|
|
const static uint MAX_PARTICLES = 65536;
|
|
|
|
|
const static uint BLOCK_SIZE = 8;
|
|
|
|
|
|
2020-10-03 11:00:10 +02:00
|
|
|
struct ViewParameter
|
|
|
|
|
{
|
|
|
|
|
float4x4 viewMatrix;
|
|
|
|
|
float4x4 projectionMatrix;
|
2021-05-10 23:57:55 +02:00
|
|
|
float4x4 inverseProjection;
|
2020-10-03 11:00:10 +02:00
|
|
|
float4 cameraPos_WS;
|
2021-06-04 18:27:49 +02:00
|
|
|
float2 screenDimensions;
|
2020-10-03 11:00:10 +02:00
|
|
|
}
|
2021-05-06 17:02:10 +02:00
|
|
|
layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
|
2020-10-03 11:00:10 +02:00
|
|
|
ConstantBuffer<ViewParameter> gViewParams;
|
|
|
|
|
|
2020-06-02 11:46:18 +02:00
|
|
|
// Convert clip space coordinates to view space
|
|
|
|
|
float4 clipToView( float4 clip )
|
|
|
|
|
{
|
|
|
|
|
// View space position.
|
2021-05-10 23:57:55 +02:00
|
|
|
float4 view = mul( gViewParams.inverseProjection, clip );
|
2020-06-02 11:46:18 +02:00
|
|
|
// Perspective projection.
|
|
|
|
|
view = view / view.w;
|
|
|
|
|
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Convert screen space coordinates to view space.
|
|
|
|
|
float4 screenToView( float4 screen )
|
|
|
|
|
{
|
|
|
|
|
// Convert to normalized texture coordinates
|
2021-05-10 23:57:55 +02:00
|
|
|
float2 texCoord = screen.xy / gViewParams.screenDimensions;
|
2020-06-02 11:46:18 +02:00
|
|
|
|
|
|
|
|
// Convert to clip space
|
|
|
|
|
float4 clip = float4( float2( texCoord.x, -texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
|
|
|
|
|
|
|
|
|
|
return clipToView( clip );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Plane
|
|
|
|
|
{
|
|
|
|
|
float3 n;
|
|
|
|
|
float d;
|
|
|
|
|
float3 p0;
|
|
|
|
|
float3 p1;
|
|
|
|
|
float3 p2;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct Frustum
|
|
|
|
|
{
|
|
|
|
|
Plane planes[4];
|
|
|
|
|
};
|
|
|
|
|
Plane computePlane(float3 p0, float3 p1, float3 p2)
|
|
|
|
|
{
|
|
|
|
|
Plane plane;
|
|
|
|
|
|
|
|
|
|
float3 v0 = p2 - p0;
|
|
|
|
|
float3 v2 = p1 - p0;
|
|
|
|
|
|
|
|
|
|
plane.n = normalize(cross(v0, v2));
|
|
|
|
|
|
|
|
|
|
plane.d = dot(plane.n, p0);
|
|
|
|
|
plane.p0 = p0;
|
|
|
|
|
plane.p1 = p1;
|
|
|
|
|
plane.p2 = p2;
|
|
|
|
|
|
|
|
|
|
return plane;
|
|
|
|
|
}
|