@@ -264,7 +264,9 @@ void evaluateLight(
264264 float falloffAttenuation = 1.0;
265265
266266 // evaluate omni part of the light
267- getLightDirPoint(light.position);
267+ vec3 lightDirW;
268+ vec3 lightDirNormW;
269+ evalOmniLight(light.position, lightDirW, lightDirNormW);
268270
269271 #ifdef CLUSTER_AREALIGHTS
270272
@@ -283,7 +285,7 @@ void evaluateLight(
283285 calcSphereLightValues(light.position, light.halfWidth, light.halfHeight);
284286 }
285287
286- falloffAttenuation = getFalloffWindow(light.range, dLightDirW );
288+ falloffAttenuation = getFalloffWindow(light.range, lightDirW );
287289
288290 } else
289291
@@ -292,9 +294,9 @@ void evaluateLight(
292294 { // punctual light
293295
294296 if (isClusteredLightFalloffLinear(light))
295- falloffAttenuation = getFalloffLinear(light.range, dLightDirW );
297+ falloffAttenuation = getFalloffLinear(light.range, lightDirW );
296298 else
297- falloffAttenuation = getFalloffInvSquared(light.range, dLightDirW );
299+ falloffAttenuation = getFalloffInvSquared(light.range, lightDirW );
298300 }
299301
300302 if (falloffAttenuation > 0.00001) {
@@ -305,25 +307,25 @@ void evaluateLight(
305307
306308 // handle light shape
307309 if (isClusteredLightRect(light)) {
308- diffuseAttenuation = getRectLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW ) * 16.0;
310+ diffuseAttenuation = getRectLightDiffuse(worldNormal, viewDir, lightDirW, lightDirNormW ) * 16.0;
309311 } else if (isClusteredLightDisk(light)) {
310- diffuseAttenuation = getDiskLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW ) * 16.0;
312+ diffuseAttenuation = getDiskLightDiffuse(worldNormal, viewDir, lightDirW, lightDirNormW ) * 16.0;
311313 } else { // sphere
312- diffuseAttenuation = getSphereLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW ) * 16.0;
314+ diffuseAttenuation = getSphereLightDiffuse(worldNormal, viewDir, lightDirW, lightDirNormW ) * 16.0;
313315 }
314316
315317 } else
316318
317319 #endif
318320
319321 {
320- falloffAttenuation *= getLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW );
322+ falloffAttenuation *= getLightDiffuse(worldNormal, viewDir, lightDirNormW );
321323 }
322324
323325 // spot light falloff
324326 if (isClusteredLightSpot(light)) {
325327 decodeClusterLightSpot(light);
326- falloffAttenuation *= getSpotEffect(light.direction, light.innerConeAngleCos, light.outerConeAngleCos, dLightDirNormW );
328+ falloffAttenuation *= getSpotEffect(light.direction, light.innerConeAngleCos, light.outerConeAngleCos, lightDirNormW );
327329 }
328330
329331 #if defined(CLUSTER_COOKIES) || defined(CLUSTER_SHADOWS)
@@ -352,7 +354,7 @@ void evaluateLight(
352354 if (isClusteredLightSpot(light)) {
353355 cookieAttenuation = getCookie2DClustered(TEXTURE_PASS(cookieAtlasTexture), lightProjectionMatrix, vPositionW, light.cookieIntensity, isClusteredLightCookieRgb(light), light.cookieChannelMask);
354356 } else {
355- cookieAttenuation = getCookieCubeClustered(TEXTURE_PASS(cookieAtlasTexture), dLightDirW , light.cookieIntensity, isClusteredLightCookieRgb(light), light.cookieChannelMask, shadowTextureResolution, shadowEdgePixels, light.omniAtlasViewport);
357+ cookieAttenuation = getCookieCubeClustered(TEXTURE_PASS(cookieAtlasTexture), lightDirW , light.cookieIntensity, isClusteredLightCookieRgb(light), light.cookieChannelMask, shadowTextureResolution, shadowEdgePixels, light.omniAtlasViewport);
356358 }
357359 }
358360
@@ -369,23 +371,23 @@ void evaluateLight(
369371 if (isClusteredLightSpot(light)) {
370372
371373 // spot shadow
372- getShadowCoordPerspZbufferNormalOffset(lightProjectionMatrix, shadowParams, geometricNormal);
374+ vec3 shadowCoord = getShadowCoordPerspZbufferNormalOffset(lightProjectionMatrix, shadowParams, geometricNormal);
373375
374376 #if defined(CLUSTER_SHADOW_TYPE_PCF1)
375- float shadow = getShadowSpotClusteredPCF1(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
377+ float shadow = getShadowSpotClusteredPCF1(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
376378 #elif defined(CLUSTER_SHADOW_TYPE_PCF3)
377- float shadow = getShadowSpotClusteredPCF3(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
379+ float shadow = getShadowSpotClusteredPCF3(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
378380 #elif defined(CLUSTER_SHADOW_TYPE_PCF5)
379- float shadow = getShadowSpotClusteredPCF5(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
381+ float shadow = getShadowSpotClusteredPCF5(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
380382 #elif defined(CLUSTER_SHADOW_TYPE_PCSS)
381- float shadow = getShadowSpotClusteredPCSS(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
383+ float shadow = getShadowSpotClusteredPCSS(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
382384 #endif
383385 falloffAttenuation *= mix(1.0, shadow, light.shadowIntensity);
384386
385387 } else {
386388
387389 // omni shadow
388- vec3 dir = normalOffsetPointShadow(shadowParams, dLightPosW, dLightDirW, dLightDirNormW , geometricNormal); // normalBias adjusted for distance
390+ vec3 dir = normalOffsetPointShadow(shadowParams, light.position, lightDirW, lightDirNormW , geometricNormal); // normalBias adjusted for distance
389391
390392 #if defined(CLUSTER_SHADOW_TYPE_PCF1)
391393 float shadow = getShadowOmniClusteredPCF1(SHADOWMAP_PASS(shadowAtlasTexture), shadowParams, light.omniAtlasViewport, shadowEdgePixels, dir);
@@ -478,12 +480,12 @@ void evaluateLight(
478480 // specular and clear coat are material settings and get included by a define based on the material
479481 #ifdef LIT_SPECULAR
480482
481- vec3 halfDir = normalize(-dLightDirNormW + viewDir);
483+ vec3 halfDir = normalize(-lightDirNormW + viewDir);
482484
483485 // specular
484486 #ifdef LIT_SPECULAR_FRESNEL
485487 dSpecularLight +=
486- getLightSpecular(halfDir, reflectionDir, worldNormal, viewDir, dLightDirNormW , gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation *
488+ getLightSpecular(halfDir, reflectionDir, worldNormal, viewDir, lightDirNormW , gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation *
487489 getFresnel(
488490 dot(viewDir, halfDir),
489491 gloss,
@@ -494,19 +496,19 @@ void evaluateLight(
494496 #endif
495497 );
496498 #else
497- dSpecularLight += getLightSpecular(halfDir, reflectionDir, worldNormal, viewDir, dLightDirNormW , gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation * specularity;
499+ dSpecularLight += getLightSpecular(halfDir, reflectionDir, worldNormal, viewDir, lightDirNormW , gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation * specularity;
498500 #endif
499501
500502 #ifdef LIT_CLEARCOAT
501503 #ifdef LIT_SPECULAR_FRESNEL
502- ccSpecularLight += getLightSpecular(halfDir, clearcoatReflectionDir, clearcoat_worldNormal, viewDir, dLightDirNormW , clearcoat_gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation * getFresnelCC(dot(viewDir, halfDir));
504+ ccSpecularLight += getLightSpecular(halfDir, clearcoatReflectionDir, clearcoat_worldNormal, viewDir, lightDirNormW , clearcoat_gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation * getFresnelCC(dot(viewDir, halfDir));
503505 #else
504- ccSpecularLight += getLightSpecular(halfDir, clearcoatReflectionDir, clearcoat_worldNormal, viewDir, dLightDirNormW , clearcoat_gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation;
506+ ccSpecularLight += getLightSpecular(halfDir, clearcoatReflectionDir, clearcoat_worldNormal, viewDir, lightDirNormW , clearcoat_gloss, tbn) * falloffAttenuation * light.color * cookieAttenuation;
505507 #endif
506508 #endif
507509
508510 #ifdef LIT_SHEEN
509- sSpecularLight += getLightSpecularSheen(halfDir, worldNormal, viewDir, dLightDirNormW , sheen_gloss) * falloffAttenuation * light.color * cookieAttenuation;
511+ sSpecularLight += getLightSpecularSheen(halfDir, worldNormal, viewDir, lightDirNormW , sheen_gloss) * falloffAttenuation * light.color * cookieAttenuation;
510512 #endif
511513
512514 #endif
@@ -515,8 +517,7 @@ void evaluateLight(
515517
516518 // Write to global attenuation values (for lightmapper)
517519 dAtten = falloffAttenuation;
518- dAttenD = diffuseAttenuation;
519- dAtten3 = cookieAttenuation;
520+ dLightDirNormW = lightDirNormW;
520521}
521522
522523void evaluateClusterLight(
0 commit comments