2023-08-04 13:24:17 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2012-10-17 00:28:46 +00:00
|
|
|
|
2020-02-11 21:40:23 -07:00
|
|
|
#include "stdcycles.h"
|
2012-10-17 00:28:46 +00:00
|
|
|
|
|
|
|
|
shader node_light_falloff(float Strength = 0.0,
|
|
|
|
|
float Smooth = 0.0,
|
|
|
|
|
output float Quadratic = 0.0,
|
|
|
|
|
output float Linear = 0.0,
|
|
|
|
|
output float Constant = 0.0)
|
|
|
|
|
{
|
|
|
|
|
float ray_length = 0.0;
|
|
|
|
|
float strength = Strength;
|
2012-11-03 14:32:13 +00:00
|
|
|
getattribute("path:ray_length", ray_length);
|
2012-10-17 00:28:46 +00:00
|
|
|
|
2025-02-15 01:23:12 +01:00
|
|
|
if (ray_length == FLT_MAX) {
|
|
|
|
|
/* Distant lights (which have a ray_length of FLT_MAX) overflow when using most outputs of
|
|
|
|
|
* the light falloff node. So just ignore the node in that case. */
|
|
|
|
|
Quadratic = strength;
|
|
|
|
|
Linear = strength;
|
|
|
|
|
Constant = strength;
|
2012-10-17 00:28:46 +00:00
|
|
|
}
|
2025-02-15 01:23:12 +01:00
|
|
|
else {
|
|
|
|
|
if (Smooth > 0.0) {
|
|
|
|
|
float squared = ray_length * ray_length;
|
|
|
|
|
strength *= squared / (Smooth + squared);
|
|
|
|
|
}
|
2012-10-17 00:28:46 +00:00
|
|
|
|
2025-02-15 01:23:12 +01:00
|
|
|
Quadratic = strength;
|
|
|
|
|
Linear = (strength * ray_length);
|
|
|
|
|
Constant = (strength * ray_length * ray_length);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|