particle system GPU culling refactor
This commit is contained in:
@@ -154,4 +154,19 @@ bool ConeInsideFrustum(Cone cone, Frustum frustum, float zNear, float zFar)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static const float4 frustumCorners[4] = {
|
||||
float4(-1, -1, 1, 1),
|
||||
float4(1, -1, 1, 1),
|
||||
float4(-1, 1, 1, 1),
|
||||
float4(1, 1, 1, 1)
|
||||
};
|
||||
static const Frustum frustum = {
|
||||
ComputePlane(float3(0,0,0), frustumCorners[2].xyz, frustumCorners[0].xyz),
|
||||
ComputePlane(float3(0,0,0), frustumCorners[1].xyz, frustumCorners[3].xyz),
|
||||
ComputePlane(float3(0,0,0), frustumCorners[0].xyz, frustumCorners[1].xyz),
|
||||
ComputePlane(float3(0,0,0), frustumCorners[3].xyz, frustumCorners[2].xyz)
|
||||
};
|
||||
|
||||
#endif // _CULLING_SHADER_HF_
|
||||
|
||||
@@ -9,7 +9,8 @@ void main(
|
||||
float grassLength = input[0].nor.w;
|
||||
float3 root = mul(float4(input[0].pos.xyz, 1), xWorld).xyz;
|
||||
|
||||
if (!IsVisible(root, grassLength))
|
||||
Sphere sphere = { mul(float4(root,1), g_xCamera_View).xyz, grassLength };
|
||||
if (!SphereInsideFrustum(sphere, frustum, 1, LOD2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -41,40 +41,6 @@ struct QGS_OUT
|
||||
float4 pos2D : SCREENPOSITION;
|
||||
};
|
||||
|
||||
inline bool IsVisible(in float3 root, in float length)
|
||||
{
|
||||
// culling:
|
||||
// View space eye position is always at the origin.
|
||||
const float3 eyePos = float3(0, 0, 0);
|
||||
|
||||
// Compute 4 points on the far clipping plane to use as the
|
||||
// frustum vertices.
|
||||
float4 corners[4];
|
||||
// Top left point
|
||||
corners[0] = float4(-1, -1, 1, 1);
|
||||
// Top right point
|
||||
corners[1] = float4(1, -1, 1, 1);
|
||||
// Bottom left point
|
||||
corners[2] = float4(-1, 1, 1, 1);
|
||||
// Bottom right point
|
||||
corners[3] = float4(1, 1, 1, 1);
|
||||
|
||||
// Now build the frustum planes from the view space points
|
||||
Frustum frustum;
|
||||
|
||||
// Left plane
|
||||
frustum.planes[0] = ComputePlane(eyePos, corners[2].xyz, corners[0].xyz);
|
||||
// Right plane
|
||||
frustum.planes[1] = ComputePlane(eyePos, corners[1].xyz, corners[3].xyz);
|
||||
// Top plane
|
||||
frustum.planes[2] = ComputePlane(eyePos, corners[0].xyz, corners[1].xyz);
|
||||
// Bottom plane
|
||||
frustum.planes[3] = ComputePlane(eyePos, corners[3].xyz, corners[2].xyz);
|
||||
|
||||
Sphere sphere = { mul(float4(root,1), g_xCamera_View).xyz, length };
|
||||
return SphereInsideFrustum(sphere, frustum, 1, LOD2);
|
||||
}
|
||||
|
||||
static const float3 MOD[] = {
|
||||
float3(-0.010735935, 0.01647018, 0.0062425877),
|
||||
float3(-0.06533369, 0.3647007, -0.13746321),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "globals.hlsli"
|
||||
#include "cullingShaderHF.hlsli"
|
||||
|
||||
CBUFFER(EmittedParticleCB, CBSLOT_OTHER_EMITTEDPARTICLE)
|
||||
{
|
||||
@@ -25,8 +26,16 @@ struct VertextoPixel
|
||||
};
|
||||
|
||||
[maxvertexcount(4)]
|
||||
void main(point GS_INPUT p[1], inout TriangleStream<VertextoPixel> triStream)
|
||||
void main(point GS_INPUT p[1], inout TriangleStream<VertextoPixel> triStream, uint vid : SV_PrimitiveID)
|
||||
{
|
||||
float quadLength = p[0].inSizOpMir.x*0.5f;
|
||||
|
||||
Sphere sphere = { mul(float4(p[0].pos.xyz,1), g_xCamera_View).xyz, quadLength };
|
||||
if (!SphereInsideFrustum(sphere, frustum, 1, g_xFrame_MainCamera_ZFarP))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
VertextoPixel p1 = (VertextoPixel)0;
|
||||
float2x2 rot = float2x2(
|
||||
cos(p[0].rot),-sin(p[0].rot),
|
||||
@@ -49,7 +58,6 @@ void main(point GS_INPUT p[1], inout TriangleStream<VertextoPixel> triStream)
|
||||
p[0].vel = mul(p[0].vel, (float3x3)g_xCamera_View);
|
||||
|
||||
|
||||
float quadLength = p[0].inSizOpMir.x*0.5f;
|
||||
|
||||
//p1.col = p[0].color;
|
||||
p1.opaAddDarkSiz = float4(saturate(p[0].inSizOpMir.y),xAdd.x,xAdd.y,p[0].inSizOpMir.x);
|
||||
|
||||
@@ -9,7 +9,8 @@ void main(
|
||||
float grassLength = input[0].nor.w;
|
||||
float3 root = mul(float4(input[0].pos.xyz,1), xWorld).xyz;
|
||||
|
||||
if (!IsVisible(root, grassLength))
|
||||
Sphere sphere = { mul(float4(root,1), g_xCamera_View).xyz, grassLength };
|
||||
if (!SphereInsideFrustum(sphere, frustum, 1, LOD2))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user