Fixed lighting
This commit is contained in:
@@ -20,14 +20,18 @@ float4 fragmentMain(in FragmentParameter params) : SV_Target
|
||||
LightingParameter lightingParams = params.getLightingParameter();
|
||||
MaterialParameter materialParams = params.getMaterialParameter();
|
||||
let brdf = pMaterial.prepare(materialParams);
|
||||
uint2 tileIndex = uint2(floor(params.position_CS.xy / BLOCK_SIZE));
|
||||
uint startOffset = pLightCullingData.oLightGrid[tileIndex].x;
|
||||
uint lightCount = pLightCullingData.oLightGrid[tileIndex].y;
|
||||
float3 result = float3(0, 0, 0);
|
||||
for(int i = 0; i < pLightEnv.numDirectionalLights; ++i)
|
||||
{
|
||||
result += pLightEnv.directionalLights[i].illuminate(lightingParams, brdf);
|
||||
}
|
||||
for(int i = 0; i < pLightEnv.numPointLights; ++i)
|
||||
for(uint i = 0; i < lightCount; ++i)
|
||||
{
|
||||
result += pLightEnv.pointLights[i].illuminate(lightingParams, brdf);
|
||||
uint lightIndex = pLightCullingData.oLightIndexList[startOffset + lightCount];
|
||||
result += pLightEnv.pointLights[lightIndex].illuminate(lightingParams, brdf);
|
||||
}
|
||||
return float4(result, 1.0f);
|
||||
}
|
||||
|
||||
@@ -89,18 +89,18 @@ void cullLights(ComputeShaderInput in)
|
||||
float fMinDepth = asfloat(uMinDepth);
|
||||
float fMaxDepth = asfloat(uMaxDepth);
|
||||
|
||||
float minDepthVS = fMinDepth;
|
||||
float maxDepthVS = fMaxDepth;
|
||||
float nearClipVS = 0.1f;
|
||||
float minDepth = fMinDepth;
|
||||
float maxDepth = fMaxDepth;
|
||||
float nearClip = 0.1f;
|
||||
|
||||
Plane minPlane = {float3(0, 0, -1), -minDepthVS};
|
||||
Plane minPlane = {float3(0, 0, -1), -minDepth};
|
||||
|
||||
for ( uint i = in.groupIndex; i < pLightEnv.numPointLights; i += BLOCK_SIZE * BLOCK_SIZE )
|
||||
{
|
||||
PointLight light = pLightEnv.pointLights[i];
|
||||
float3 lightClip = light.getClipPosition();
|
||||
//TODO: why doesn't this check go through?
|
||||
if(light.insideFrustum(groupFrustum, lightClip, nearClipVS, maxDepthVS))
|
||||
if(light.insideFrustum(groupFrustum, lightClip, nearClip, maxDepth))
|
||||
{
|
||||
tAppendLight(i);
|
||||
if(!light.insidePlane(minPlane, lightClip))
|
||||
|
||||
@@ -26,7 +26,7 @@ struct PointLight : ILightEnv
|
||||
|
||||
float3 illuminate<B:IBRDF>(LightingParameter params, B brdf)
|
||||
{
|
||||
float3 lightDir_WS = position_WS.xyz - params.position_WS;
|
||||
float3 lightDir_WS = params.position_WS - position_WS.xyz;
|
||||
float3 lightDir_TS = mul(params.tbn, lightDir_WS);
|
||||
float d = length(lightDir_TS);
|
||||
float illuminance = max(1 - d / colorRange.w, 0);
|
||||
|
||||
Reference in New Issue
Block a user