@@ -264,7 +264,9 @@ void evaluateLight(
264
264
float falloffAttenuation = 1.0;
265
265
266
266
// evaluate omni part of the light
267
- getLightDirPoint(light.position);
267
+ vec3 lightDirW;
268
+ vec3 lightDirNormW;
269
+ evalOmniLight(light.position, lightDirW, lightDirNormW);
268
270
269
271
#ifdef CLUSTER_AREALIGHTS
270
272
@@ -283,7 +285,7 @@ void evaluateLight(
283
285
calcSphereLightValues(light.position, light.halfWidth, light.halfHeight);
284
286
}
285
287
286
- falloffAttenuation = getFalloffWindow(light.range, dLightDirW );
288
+ falloffAttenuation = getFalloffWindow(light.range, lightDirW );
287
289
288
290
} else
289
291
@@ -292,9 +294,9 @@ void evaluateLight(
292
294
{ // punctual light
293
295
294
296
if (isClusteredLightFalloffLinear(light))
295
- falloffAttenuation = getFalloffLinear(light.range, dLightDirW );
297
+ falloffAttenuation = getFalloffLinear(light.range, lightDirW );
296
298
else
297
- falloffAttenuation = getFalloffInvSquared(light.range, dLightDirW );
299
+ falloffAttenuation = getFalloffInvSquared(light.range, lightDirW );
298
300
}
299
301
300
302
if (falloffAttenuation > 0.00001) {
@@ -305,25 +307,25 @@ void evaluateLight(
305
307
306
308
// handle light shape
307
309
if (isClusteredLightRect(light)) {
308
- diffuseAttenuation = getRectLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW ) * 16.0;
310
+ diffuseAttenuation = getRectLightDiffuse(worldNormal, viewDir, lightDirW, lightDirNormW ) * 16.0;
309
311
} else if (isClusteredLightDisk(light)) {
310
- diffuseAttenuation = getDiskLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW ) * 16.0;
312
+ diffuseAttenuation = getDiskLightDiffuse(worldNormal, viewDir, lightDirW, lightDirNormW ) * 16.0;
311
313
} else { // sphere
312
- diffuseAttenuation = getSphereLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW ) * 16.0;
314
+ diffuseAttenuation = getSphereLightDiffuse(worldNormal, viewDir, lightDirW, lightDirNormW ) * 16.0;
313
315
}
314
316
315
317
} else
316
318
317
319
#endif
318
320
319
321
{
320
- falloffAttenuation *= getLightDiffuse(worldNormal, viewDir, dLightDirW, dLightDirNormW );
322
+ falloffAttenuation *= getLightDiffuse(worldNormal, viewDir, lightDirNormW );
321
323
}
322
324
323
325
// spot light falloff
324
326
if (isClusteredLightSpot(light)) {
325
327
decodeClusterLightSpot(light);
326
- falloffAttenuation *= getSpotEffect(light.direction, light.innerConeAngleCos, light.outerConeAngleCos, dLightDirNormW );
328
+ falloffAttenuation *= getSpotEffect(light.direction, light.innerConeAngleCos, light.outerConeAngleCos, lightDirNormW );
327
329
}
328
330
329
331
#if defined(CLUSTER_COOKIES) || defined(CLUSTER_SHADOWS)
@@ -352,7 +354,7 @@ void evaluateLight(
352
354
if (isClusteredLightSpot(light)) {
353
355
cookieAttenuation = getCookie2DClustered(TEXTURE_PASS(cookieAtlasTexture), lightProjectionMatrix, vPositionW, light.cookieIntensity, isClusteredLightCookieRgb(light), light.cookieChannelMask);
354
356
} 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);
356
358
}
357
359
}
358
360
@@ -369,23 +371,23 @@ void evaluateLight(
369
371
if (isClusteredLightSpot(light)) {
370
372
371
373
// spot shadow
372
- getShadowCoordPerspZbufferNormalOffset(lightProjectionMatrix, shadowParams, geometricNormal);
374
+ vec3 shadowCoord = getShadowCoordPerspZbufferNormalOffset(lightProjectionMatrix, shadowParams, geometricNormal);
373
375
374
376
#if defined(CLUSTER_SHADOW_TYPE_PCF1)
375
- float shadow = getShadowSpotClusteredPCF1(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
377
+ float shadow = getShadowSpotClusteredPCF1(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
376
378
#elif defined(CLUSTER_SHADOW_TYPE_PCF3)
377
- float shadow = getShadowSpotClusteredPCF3(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
379
+ float shadow = getShadowSpotClusteredPCF3(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
378
380
#elif defined(CLUSTER_SHADOW_TYPE_PCF5)
379
- float shadow = getShadowSpotClusteredPCF5(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
381
+ float shadow = getShadowSpotClusteredPCF5(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
380
382
#elif defined(CLUSTER_SHADOW_TYPE_PCSS)
381
- float shadow = getShadowSpotClusteredPCSS(SHADOWMAP_PASS(shadowAtlasTexture), dShadowCoord , shadowParams);
383
+ float shadow = getShadowSpotClusteredPCSS(SHADOWMAP_PASS(shadowAtlasTexture), shadowCoord , shadowParams);
382
384
#endif
383
385
falloffAttenuation *= mix(1.0, shadow, light.shadowIntensity);
384
386
385
387
} else {
386
388
387
389
// 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
389
391
390
392
#if defined(CLUSTER_SHADOW_TYPE_PCF1)
391
393
float shadow = getShadowOmniClusteredPCF1(SHADOWMAP_PASS(shadowAtlasTexture), shadowParams, light.omniAtlasViewport, shadowEdgePixels, dir);
@@ -478,12 +480,12 @@ void evaluateLight(
478
480
// specular and clear coat are material settings and get included by a define based on the material
479
481
#ifdef LIT_SPECULAR
480
482
481
- vec3 halfDir = normalize(-dLightDirNormW + viewDir);
483
+ vec3 halfDir = normalize(-lightDirNormW + viewDir);
482
484
483
485
// specular
484
486
#ifdef LIT_SPECULAR_FRESNEL
485
487
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 *
487
489
getFresnel(
488
490
dot(viewDir, halfDir),
489
491
gloss,
@@ -494,19 +496,19 @@ void evaluateLight(
494
496
#endif
495
497
);
496
498
#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;
498
500
#endif
499
501
500
502
#ifdef LIT_CLEARCOAT
501
503
#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));
503
505
#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;
505
507
#endif
506
508
#endif
507
509
508
510
#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;
510
512
#endif
511
513
512
514
#endif
@@ -515,8 +517,7 @@ void evaluateLight(
515
517
516
518
// Write to global attenuation values (for lightmapper)
517
519
dAtten = falloffAttenuation;
518
- dAttenD = diffuseAttenuation;
519
- dAtten3 = cookieAttenuation;
520
+ dLightDirNormW = lightDirNormW;
520
521
}
521
522
522
523
void evaluateClusterLight(
0 commit comments