@@ -386,12 +386,11 @@ float get_omni_spot_attenuation(float distance, float inv_range, float decay) {
386
386
void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, float roughness,
387
387
inout vec3 diffuse_light, inout vec3 specular_light) {
388
388
vec3 light_rel_vec = omni_lights[idx].position - vertex;
389
- float sum_abs_rel_vec = 1.0 + abs (light_rel_vec.x) + abs (light_rel_vec.y) + abs (light_rel_vec.z); // Used to avoid overflows with length() when light_rel_vec components exceed sqrt(MAX_FLOAT_VALUE)
390
- float light_length = length (light_rel_vec / sum_abs_rel_vec) * sum_abs_rel_vec;
389
+ float light_length = length (light_rel_vec);
391
390
float omni_attenuation = get_omni_spot_attenuation(light_length, omni_lights[idx].inv_radius, omni_lights[idx].attenuation);
392
391
vec3 color = omni_lights[idx].color * omni_attenuation; // No light shaders here, so combine.
393
392
394
- light_compute(normal, light_rel_vec / light_length , eye_vec, color, false, roughness,
393
+ light_compute(normal, normalize ( light_rel_vec) , eye_vec, color, false, roughness,
395
394
diffuse_light,
396
395
specular_light);
397
396
}
@@ -402,19 +401,18 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, float
402
401
inout vec3 diffuse_light,
403
402
inout vec3 specular_light) {
404
403
vec3 light_rel_vec = spot_lights[idx].position - vertex;
405
- float sum_abs_rel_vec = 1.0 + abs (light_rel_vec.x) + abs (light_rel_vec.y) + abs (light_rel_vec.z); // Used to avoid overflows with length() when light_rel_vec components exceed sqrt(MAX_FLOAT_VALUE)
406
- float light_length = length (light_rel_vec / sum_abs_rel_vec) * sum_abs_rel_vec;
404
+ float light_length = length (light_rel_vec);
407
405
float spot_attenuation = get_omni_spot_attenuation(light_length, spot_lights[idx].inv_radius, spot_lights[idx].attenuation);
408
406
vec3 spot_dir = spot_lights[idx].direction;
409
- float scos = max (dot (- light_rel_vec / light_length , spot_dir), spot_lights[idx].cone_angle);
407
+ float scos = max (dot (- normalize ( light_rel_vec) , spot_dir), spot_lights[idx].cone_angle);
410
408
float spot_rim = max (0.0001 , (1.0 - scos) / (1.0 - spot_lights[idx].cone_angle));
411
409
412
410
mediump float cone_attenuation = spot_lights[idx].cone_attenuation;
413
411
spot_attenuation *= 1.0 - pow (spot_rim, cone_attenuation);
414
412
415
413
vec3 color = spot_lights[idx].color * spot_attenuation;
416
414
417
- light_compute(normal, light_rel_vec / light_length , eye_vec, color, false, roughness,
415
+ light_compute(normal, normalize ( light_rel_vec) , eye_vec, color, false, roughness,
418
416
diffuse_light, specular_light);
419
417
}
420
418
#endif // !defined(DISABLE_LIGHT_SPOT) || (defined(ADDITIVE_SPOT) && defined(USE_ADDITIVE_LIGHTING))
@@ -666,9 +664,8 @@ void main() {
666
664
#if defined(ADDITIVE_OMNI) || defined(ADDITIVE_SPOT)
667
665
// Apply normal bias at draw time to avoid issues with scaling non-fused geometry.
668
666
vec3 light_rel_vec = positional_shadows[positional_shadow_index].light_position - vertex_interp;
669
- float sum_abs_rel_vec = 1.0 + abs (light_rel_vec.x) + abs (light_rel_vec.y) + abs (light_rel_vec.z); // Used to avoid overflows with length() when light_rel_vec components exceed sqrt(MAX_FLOAT_VALUE)
670
- float light_length = length (light_rel_vec / sum_abs_rel_vec) * sum_abs_rel_vec;
671
- float aNdotL = abs (dot (normalize (normal_interp), light_rel_vec / light_length));
667
+ float light_length = length (light_rel_vec);
668
+ float aNdotL = abs (dot (normalize (normal_interp), normalize (light_rel_vec)));
672
669
vec3 normal_offset = (1.0 - aNdotL) * positional_shadows[positional_shadow_index].shadow_normal_bias * light_length * normal_interp;
673
670
674
671
#ifdef ADDITIVE_SPOT
@@ -1461,8 +1458,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f
1461
1458
#endif
1462
1459
inout vec3 diffuse_light, inout vec3 specular_light) {
1463
1460
vec3 light_rel_vec = omni_lights[idx].position - vertex;
1464
- float sum_abs_rel_vec = 1.0 + abs (light_rel_vec.x) + abs (light_rel_vec.y) + abs (light_rel_vec.z); // Used to avoid overflows with length() when light_rel_vec components exceed sqrt(MAX_FLOAT_VALUE)
1465
- float light_length = length (light_rel_vec / sum_abs_rel_vec) * sum_abs_rel_vec;
1461
+ float light_length = length (light_rel_vec);
1466
1462
float omni_attenuation = get_omni_spot_attenuation(light_length, omni_lights[idx].inv_radius, omni_lights[idx].attenuation);
1467
1463
vec3 color = omni_lights[idx].color;
1468
1464
float size_A = 0.0 ;
@@ -1474,7 +1470,7 @@ void light_process_omni(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f
1474
1470
1475
1471
omni_attenuation *= shadow;
1476
1472
1477
- light_compute(normal, light_rel_vec / light_length , eye_vec, size_A, color, false, omni_attenuation, f0, roughness, metallic, omni_lights[idx].specular_amount, albedo, alpha, screen_uv,
1473
+ light_compute(normal, normalize ( light_rel_vec) , eye_vec, size_A, color, false, omni_attenuation, f0, roughness, metallic, omni_lights[idx].specular_amount, albedo, alpha, screen_uv,
1478
1474
#ifdef LIGHT_BACKLIGHT_USED
1479
1475
backlight,
1480
1476
#endif
@@ -1510,11 +1506,10 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f
1510
1506
inout vec3 specular_light) {
1511
1507
1512
1508
vec3 light_rel_vec = spot_lights[idx].position - vertex;
1513
- float sum_abs_rel_vec = 1.0 + abs (light_rel_vec.x) + abs (light_rel_vec.y) + abs (light_rel_vec.z); // Used to avoid overflows with length() when light_rel_vec components exceed sqrt(MAX_FLOAT_VALUE)
1514
- float light_length = length (light_rel_vec / sum_abs_rel_vec) * sum_abs_rel_vec;
1509
+ float light_length = length (light_rel_vec);
1515
1510
float spot_attenuation = get_omni_spot_attenuation(light_length, spot_lights[idx].inv_radius, spot_lights[idx].attenuation);
1516
1511
vec3 spot_dir = spot_lights[idx].direction;
1517
- float scos = max (dot (- light_rel_vec / light_length , spot_dir), spot_lights[idx].cone_angle);
1512
+ float scos = max (dot (- normalize ( light_rel_vec) , spot_dir), spot_lights[idx].cone_angle);
1518
1513
float spot_rim = max (0.0001 , (1.0 - scos) / (1.0 - spot_lights[idx].cone_angle));
1519
1514
1520
1515
mediump float cone_attenuation = spot_lights[idx].cone_attenuation;
@@ -1531,7 +1526,7 @@ void light_process_spot(uint idx, vec3 vertex, vec3 eye_vec, vec3 normal, vec3 f
1531
1526
1532
1527
spot_attenuation *= shadow;
1533
1528
1534
- light_compute(normal, light_rel_vec / light_length , eye_vec, size_A, color, false, spot_attenuation, f0, roughness, metallic, spot_lights[idx].specular_amount, albedo, alpha, screen_uv,
1529
+ light_compute(normal, normalize ( light_rel_vec) , eye_vec, size_A, color, false, spot_attenuation, f0, roughness, metallic, spot_lights[idx].specular_amount, albedo, alpha, screen_uv,
1535
1530
#ifdef LIGHT_BACKLIGHT_USED
1536
1531
backlight,
1537
1532
#endif
0 commit comments