Lighting is broken again
This commit is contained in:
@@ -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