In Cycles lights can be given a light falloff node to control their light falloff. This worked by multiplying the light's strength by different combinations of the ray length, which would be FLT_MAX for distant lights. This resulting in almost every configuration of the light falloff node overflowing when used on distant lights, which is undesirable. This commit fixes this issue by ignoring most of the functions of the light falloff node when used on a distant light. And in the process fixes a small discrepancy between SVM and OSL when using the light falloff node on distant lights. Pull Request: https://projects.blender.org/blender/blender/pulls/134539
35 lines
1023 B
Plaintext
35 lines
1023 B
Plaintext
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
#include "stdcycles.h"
|
|
|
|
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;
|
|
getattribute("path:ray_length", ray_length);
|
|
|
|
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;
|
|
}
|
|
else {
|
|
if (Smooth > 0.0) {
|
|
float squared = ray_length * ray_length;
|
|
strength *= squared / (Smooth + squared);
|
|
}
|
|
|
|
Quadratic = strength;
|
|
Linear = (strength * ray_length);
|
|
Constant = (strength * ray_length * ray_length);
|
|
}
|
|
}
|