fixing light culling
This commit is contained in:
@@ -6,18 +6,30 @@ struct ViewParameter
|
||||
{
|
||||
float4x4 viewMatrix;
|
||||
float4x4 projectionMatrix;
|
||||
float4x4 inverseProjection;
|
||||
float4 cameraPos_WS;
|
||||
float2 screenDimensions;
|
||||
}
|
||||
layout(set = 0)
|
||||
ParameterBlock<ViewParameter> pViewParams;
|
||||
|
||||
float3 screenToClip(float3 screen)
|
||||
float4 clipToView(float4 clip)
|
||||
{
|
||||
float4 view = mul(pViewParams.inverseProjection, clip);
|
||||
|
||||
view = view / view.w;
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
float4 screenToView(float4 screen)
|
||||
{
|
||||
float2 texCoord = screen.xy / pViewParams.screenDimensions;
|
||||
|
||||
// Convert to clip space
|
||||
return float3( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z);
|
||||
float4 clip = float4( float2( texCoord.x, 1.0f-texCoord.y ) * 2.0f - 1.0f, screen.z, screen.w);
|
||||
|
||||
return clipToView(clip);
|
||||
}
|
||||
|
||||
struct Plane
|
||||
|
||||
@@ -32,27 +32,27 @@ 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);
|
||||
}
|
||||
float3 getClipPosition()
|
||||
float3 getViewPosition()
|
||||
{
|
||||
float4 position_CS = mul(pViewParams.projectionMatrix, mul(pViewParams.viewMatrix, position_WS));
|
||||
return position_CS.xyz / position_CS.w;
|
||||
float4 position_VS = mul(pViewParams.viewMatrix, position_WS);
|
||||
return position_VS.xyz / position_VS.w;
|
||||
}
|
||||
|
||||
bool insidePlane(Plane plane, float3 position_CS)
|
||||
bool insidePlane(Plane plane, float3 position_VS)
|
||||
{
|
||||
return dot(plane.n, position_CS) - plane.d < -colorRange.w;
|
||||
return dot(plane.n, position_VS) - plane.d < -colorRange.w;
|
||||
}
|
||||
|
||||
bool insideFrustum(Frustum frustum, float3 position_CS, float minDepth, float maxDepth)
|
||||
bool insideFrustum(Frustum frustum, float3 position_VS, float minDepth, float maxDepth)
|
||||
{
|
||||
bool result = true;
|
||||
if(position_CS.z - colorRange.w > minDepth || position_CS.z + colorRange.w < maxDepth)
|
||||
if(position_VS.z - colorRange.w > minDepth || position_VS.z + colorRange.w < maxDepth)
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
for(int i = 0; i < 4 && result; ++i)
|
||||
{
|
||||
if(insidePlane(frustum.sides[i], position_CS))
|
||||
if(insidePlane(frustum.sides[i], position_VS))
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user