Light Culling still doesn't work properly
This commit is contained in:
@@ -23,19 +23,26 @@ layout(set = INDEX_VIEW_PARAMS, binding = 3)
|
||||
StructuredBuffer<Frustum> frustums;
|
||||
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 4)
|
||||
RWStructuredBuffer<uint> oLightIndexCounter;
|
||||
globallycoherent RWStructuredBuffer<uint> oLightIndexCounter;
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 5)
|
||||
RWStructuredBuffer<uint> tLightIndexCounter;
|
||||
globallycoherent RWStructuredBuffer<uint> tLightIndexCounter;
|
||||
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 6)
|
||||
RWStructuredBuffer<uint> oLightIndexList;
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 7)
|
||||
RWStructuredBuffer<uint> tLightIndexList;
|
||||
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 8)
|
||||
RWTexture2D<uint2> oLightGrid;
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 9)
|
||||
RWTexture2D<uint2> tLightGrid;
|
||||
|
||||
// Debug
|
||||
//layout(set = INDEX_VIEW_PARAMS, binding = 10)
|
||||
//Texture2D lightCountHeatMap;
|
||||
//layout(set = INDEX_VIEW_PARAMS, binding = 11)
|
||||
//RWTexture2D<float4> debugTexture;
|
||||
|
||||
groupshared uint uMinDepth;
|
||||
groupshared uint uMaxDepth;
|
||||
|
||||
@@ -74,8 +81,8 @@ void tAppendLight(uint lightIndex)
|
||||
[shader("compute")]
|
||||
void cullLights(ComputeShaderInput in)
|
||||
{
|
||||
int3 texCoord = int3(in.dispatchThreadID.xy, 0);
|
||||
float fDepth = depthTextureVS.Load(texCoord).r;
|
||||
int2 texCoord = in.dispatchThreadID.xy;
|
||||
float fDepth = depthTextureVS.Load(int3(texCoord, 0)).r;
|
||||
|
||||
uint uDepth = asuint(fDepth);
|
||||
if(in.groupIndex == 0)
|
||||
@@ -88,6 +95,7 @@ void cullLights(ComputeShaderInput in)
|
||||
}
|
||||
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
InterlockedMin(uMinDepth, uDepth);
|
||||
InterlockedMax(uMaxDepth, uDepth);
|
||||
|
||||
@@ -120,22 +128,24 @@ void cullLights(ComputeShaderInput in)
|
||||
|
||||
if(in.groupIndex == 0)
|
||||
{
|
||||
InterlockedAdd(oLightIndexCounter[0], (uint)oLightCount, oLightIndexStartOffset);
|
||||
InterlockedAdd(oLightIndexCounter[0], oLightCount, oLightIndexStartOffset);
|
||||
oLightGrid[in.groupID.xy] = uint2(oLightIndexStartOffset, oLightCount);
|
||||
|
||||
InterlockedAdd(tLightIndexCounter[0], (uint)tLightCount, tLightIndexStartOffset);
|
||||
InterlockedAdd(tLightIndexCounter[0], tLightCount, tLightIndexStartOffset);
|
||||
tLightGrid[in.groupID.xy] = uint2(tLightIndexStartOffset, tLightCount);
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
|
||||
for (uint j = in.groupIndex; j < (uint)oLightCount; j += BLOCK_SIZE * BLOCK_SIZE)
|
||||
for (uint j = in.groupIndex; j < oLightCount; j += BLOCK_SIZE * BLOCK_SIZE)
|
||||
{
|
||||
oLightIndexList[oLightIndexStartOffset + j] = oLightList[j];
|
||||
}
|
||||
|
||||
// For transparent geometry.
|
||||
for ( uint k = in.groupIndex; k < (uint)tLightCount; k += BLOCK_SIZE * BLOCK_SIZE )
|
||||
for ( uint k = in.groupIndex; k < tLightCount; k += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
tLightIndexList[tLightIndexStartOffset + k] = tLightList[k];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
const static float PI = 3.1415926535897932f;
|
||||
const static uint MAX_PARTICLES = 65536;
|
||||
const static uint BLOCK_SIZE = 8;
|
||||
const static uint BLOCK_SIZE = 32;
|
||||
|
||||
struct ViewParameter
|
||||
{
|
||||
float4x4 viewMatrix;
|
||||
float4x4 projectionMatrix;
|
||||
float4x4 inverseProjection;
|
||||
float4x4 inverseProjection;
|
||||
float4 cameraPos_WS;
|
||||
float2 screenDimensions;
|
||||
float2 screenDimensions;
|
||||
}
|
||||
layout(set = INDEX_VIEW_PARAMS, binding = 0, std430)
|
||||
ConstantBuffer<ViewParameter> gViewParams;
|
||||
@@ -31,37 +31,31 @@ float4 screenToView( float4 screen )
|
||||
float2 texCoord = screen.xy / gViewParams.screenDimensions;
|
||||
|
||||
// Convert to clip space
|
||||
float4 clip = float4( float2( texCoord.x, -texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w );
|
||||
float4 clip = float4( float2( texCoord.x, 1.0f-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;
|
||||
float3 n;
|
||||
float d;
|
||||
};
|
||||
|
||||
struct Frustum
|
||||
{
|
||||
Plane planes[4];
|
||||
Plane planes[4];
|
||||
};
|
||||
Plane computePlane(float3 p0, float3 p1, float3 p2)
|
||||
{
|
||||
Plane plane;
|
||||
Plane plane;
|
||||
|
||||
float3 v0 = p2 - p0;
|
||||
float3 v2 = p1 - p0;
|
||||
float3 v0 = p1 - p0;
|
||||
float3 v2 = p2 - p0;
|
||||
|
||||
plane.n = normalize(cross(v0, v2));
|
||||
plane.n = normalize(cross(v0, v2));
|
||||
|
||||
plane.d = dot(plane.n, p0);
|
||||
plane.p0 = p0;
|
||||
plane.p1 = p1;
|
||||
plane.p2 = p2;
|
||||
plane.d = dot(plane.n, p0);
|
||||
|
||||
return plane;
|
||||
return plane;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ struct DirectionalLight : ILightEnv
|
||||
struct PointLight : ILightEnv
|
||||
{
|
||||
float4 positionWS;
|
||||
float4 positionVS;
|
||||
float4 colorRange;
|
||||
|
||||
float3 illuminate<B:IBRDF>(MaterialFragmentParameter input, B brdf, float3 viewDir)
|
||||
@@ -36,14 +35,14 @@ struct PointLight : ILightEnv
|
||||
|
||||
bool insidePlane(Plane plane)
|
||||
{
|
||||
return dot(plane.n, positionVS.xyz) - plane.d < -colorRange.w;
|
||||
return dot(plane.n, getViewPos().xyz) - plane.d < -colorRange.w;
|
||||
}
|
||||
|
||||
bool insideFrustum(Frustum frustum, float zNear, float zFar)
|
||||
{
|
||||
bool result = true;
|
||||
|
||||
if(positionVS.z - colorRange.w > zNear || positionVS.z + colorRange.w < zFar)
|
||||
if(getViewPos().z - colorRange.w > zNear || getViewPos().z + colorRange.w < zFar)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
@@ -56,6 +55,10 @@ struct PointLight : ILightEnv
|
||||
}
|
||||
return result;
|
||||
}
|
||||
float3 getViewPos()
|
||||
{
|
||||
return mul(gViewParams.viewMatrix, positionWS).xyz;
|
||||
}
|
||||
};
|
||||
|
||||
layout(set = INDEX_LIGHT_ENV, binding = 0, std430)
|
||||
|
||||
Reference in New Issue
Block a user