Lighting is broken again
This commit is contained in:
@@ -26,9 +26,6 @@ void computeFrustums(ComputeShaderInput in)
|
||||
topLeft + (in.dispatchThreadID.x + 1) * xStep + (in.dispatchThreadID.y + 1) * yStep
|
||||
};
|
||||
Frustum frustum;
|
||||
frustum.basePlane.n = float3(0, 0, -1);
|
||||
frustum.basePlane.d = 0;
|
||||
|
||||
frustum.sides[0] = computePlane(origin, corners[0], corners[2]);
|
||||
frustum.sides[1] = computePlane(origin, corners[3], corners[1]);
|
||||
frustum.sides[2] = computePlane(origin, corners[1], corners[0]);
|
||||
|
||||
@@ -98,12 +98,12 @@ void cullLights(ComputeShaderInput in)
|
||||
for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
PointLight light = pLightEnv.pointLights[i];
|
||||
light.updatePosition();
|
||||
float3 lightClip = light.getClipPosition();
|
||||
//TODO: why doesn't this check go through?
|
||||
if(light.insideFrustum(groupFrustum, nearClipVS, maxDepthVS))
|
||||
if(light.insideFrustum(groupFrustum, lightClip, nearClipVS, maxDepthVS))
|
||||
{
|
||||
tAppendLight(i);
|
||||
if(!light.insidePlane(minPlane))
|
||||
if(!light.insidePlane(minPlane, lightClip))
|
||||
{
|
||||
oAppendLight(i);
|
||||
}
|
||||
|
||||
@@ -39,9 +39,6 @@ void taskMain(
|
||||
// Bottom
|
||||
viewFrustum.sides[3].n = float3(0, 1, 0);
|
||||
viewFrustum.sides[3].d = -1;
|
||||
// Base
|
||||
viewFrustum.basePlane.n = float3(0, 0, -1);
|
||||
viewFrustum.basePlane.d = 0;
|
||||
}
|
||||
GroupMemoryBarrierWithGroupSync();
|
||||
MeshData mesh = pScene.meshData[groupID];
|
||||
|
||||
@@ -19,9 +19,13 @@ struct AABB
|
||||
corners[7] = mul(transform, float4(max.x, max.y, max.z, 1.0f));
|
||||
for(int i = 0; i < 8; ++i)
|
||||
{
|
||||
if(frustum.pointInside(corners[i].xyz / corners[i].w))
|
||||
float3 adjusted = corners[i].xyz / corners[i].w;
|
||||
if(adjusted.z > 0)
|
||||
{
|
||||
return true;
|
||||
if(frustum.pointInside(adjusted))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -36,13 +36,8 @@ struct Plane
|
||||
struct Frustum
|
||||
{
|
||||
Plane sides[4];
|
||||
Plane basePlane;
|
||||
bool pointInside(float3 point)
|
||||
{
|
||||
if (!basePlane.pointInside(point))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(int p = 0; p < 4; ++p)
|
||||
{
|
||||
if(!sides[p].pointInside(point))
|
||||
|
||||
@@ -23,7 +23,6 @@ struct PointLight : ILightEnv
|
||||
{
|
||||
float4 position_WS;
|
||||
float4 colorRange;
|
||||
float4 position_CS;
|
||||
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
@@ -33,33 +32,32 @@ struct PointLight : ILightEnv
|
||||
float illuminance = max(1 - d / colorRange.w, 0);
|
||||
return illuminance * brdf.evaluate(params.tbn, params.viewDir_TS, normalize(lightDir_TS), colorRange.xyz);
|
||||
}
|
||||
void updatePosition()
|
||||
float3 getClipPosition()
|
||||
{
|
||||
position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS));
|
||||
float4 position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS));
|
||||
return position_CS.xyz / position_CS.w;
|
||||
}
|
||||
|
||||
bool insidePlane(Plane plane)
|
||||
bool insidePlane(Plane plane, float3 position_CS)
|
||||
{
|
||||
float3 edge_CS = position_CS + plane.n * colorRange.w;
|
||||
return plane.pointInside(edge_CS);
|
||||
return dot(plane.n, position_CS) - plane.d < -colorRange.w;
|
||||
}
|
||||
|
||||
bool insideFrustum(Frustum frustum, float nearClipVS, float maxDepthVS)
|
||||
bool insideFrustum(Frustum frustum, float3 position_CS, float minDepth, float maxDepth)
|
||||
{
|
||||
float3 center_CS = clipPos.xyz / clipPos.w;
|
||||
if(insidePlane(frustum.basePlane, center_CS))
|
||||
bool result = true;
|
||||
if(position_CS.z - colorRange.w > minDepth || position_CS.z + colorRange.w < maxDepth)
|
||||
{
|
||||
return true;
|
||||
result = false;
|
||||
}
|
||||
uint result = 0;
|
||||
for(int i = 0; i < 4; ++i)
|
||||
for(int i = 0; i < 4 && result; ++i)
|
||||
{
|
||||
if(insidePlane(frustum.sides[i], center_CS))
|
||||
if(insidePlane(frustum.sides[i], position_CS))
|
||||
{
|
||||
result++;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
return result > 0;
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ struct VertexAttributes
|
||||
float4 worldPos = mul(transformMatrix, modelPos);
|
||||
float4 viewPos = mul(pViewParams.viewMatrix, worldPos);
|
||||
float4 clipPos = mul(pViewParams.projectionMatrix, viewPos);
|
||||
float3 tangent_WS = mul(float3x3(transformMatrix), normalize(tangent_MS));
|
||||
float3 biTangent_WS = mul(float3x3(transformMatrix), normalize(biTangent_MS));
|
||||
float3 normal_WS = mul(float3x3(transformMatrix), normalize(normal_MS));
|
||||
float3 tangent_WS = mul(float3x3(transformMatrix), tangent_MS);
|
||||
float3 biTangent_WS = mul(float3x3(transformMatrix), biTangent_MS);
|
||||
float3 normal_WS = mul(float3x3(transformMatrix), normal_MS);
|
||||
FragmentParameter result;
|
||||
result.viewDir_WS = pViewParams.cameraPos_WS.xyz - worldPos.xyz;
|
||||
result.normal_WS = normal_WS;
|
||||
|
||||
Reference in New Issue
Block a user