14#define LIGHT_ATTENUATION_THRESHOLD 1e-6f
30 return LightVector{.L = light.sun.direction, .dist = 1.0f};
40 if (!is_directional && is_area_light(light.type)) {
41 LightAreaData area = light.area;
43 float3 lP = transform_point_inversed(light.object_to_world,
P);
44 float2 ls_closest_point = lP.xy;
45 if (light.type == LIGHT_ELLIPSE) {
46 ls_closest_point /=
max(1.0f,
length(ls_closest_point / area.size));
49 ls_closest_point =
clamp(ls_closest_point, -area.size, area.size);
52 float3(ls_closest_point, 0.0f));
70 return transform_point_inversed(light.object_to_world, point);
78 float factor =
square(dist) * inv_sqr_influence;
85 LightSpotData spot = light.spot;
88 float spotmask =
smoothstep(0.0f, 1.0f, ellipse * spot.spot_mul + spot.spot_bias);
89 return (lL.
z > 0.0f) ? spotmask : 0.0f;
97 if (is_spot_light(light.type)) {
100 if (is_area_light(light.type)) {
101 return float(
dot(
L, light.z_axis()) > 0.0f);
108 if (is_sun_light(light.type)) {
109 return light.sun.shape_radius;
111 if (is_area_light(light.type)) {
112 return length(light.area.size);
114 return light.local.local.shape_radius;
123 LightData light,
float3 L,
float distance_to_light,
float3 Ng,
const bool is_transmission)
128 float sin_light_angle =
dot(
L, is_transmission ? -Ng : Ng);
131 float dist = sin_solid_angle + (is_transmission ? -sin_light_angle : sin_light_angle);
132 return saturate((dist + 0.1f) * 10.0f);
138 if (!is_directional) {
140 light.local.local.influence_radius_invsqr_surface);
148 if (!is_directional) {
150 light.local.local.influence_radius_invsqr_volume);
159 if (is_directional) {
167 float r_sqr =
square(light.local.local.shape_radius);
169 float power = 2.0f / (d_sqr + r_sqr + lv.
dist *
sqrt(d_sqr + r_sqr));
171 if (is_area_light(light.type)) {
187 return sphere_radius *
208 float3 Px = light.x_axis();
209 float3 Py = light.y_axis();
211 if (light.type == LIGHT_RECT) {
212 LightAreaData area = light.area;
214 shape.
v[0] = Px * area.size.x + Py * -area.size.y;
215 shape.
v[1] = Px * area.size.x + Py * area.size.y;
216 shape.
v[2] = -shape.
v[0];
217 shape.
v[3] = -shape.
v[1];
229 if (!is_area_light(light.type)) {
234 if (is_sphere_light(light.type)) {
238 else if (is_oriented_disk_light(light.type)) {
240 size =
float2(light.local.local.shape_radius);
242 else if (is_sun_light(light.type)) {
243 size =
float2(light.sun.shape_radius);
247 size =
float2(light.area.size);
250 shape.
v[0] = Px * -size.x + Py * -size.y;
251 shape.
v[1] = Px * size.x + Py * -size.y;
252 shape.
v[2] = -shape.
v[0];
272 return light.power_factor[type & 3u] *
273 (type != LIGHT_VOLUME ?
light.shape_power :
light.point_power);
void make_orthonormal_basis(float3 N, float3 &T, float3 &B)
float light_attenuation_facing(LightData light, float3 L, float distance_to_light, float3 Ng, const bool is_transmission)
float light_point_light(LightData light, const bool is_directional, LightVector lv)
float light_shape_radius(LightData light)
float light_spot_attenuation(LightData light, float3 L)
float light_influence_attenuation(float dist, float inv_sqr_influence)
float light_sphere_disk_radius(float sphere_radius, float distance_to_sphere)
float light_attenuation_volume(LightData light, const bool is_directional, LightVector lv)
float light_attenuation_surface(LightData light, const bool is_directional, LightVector lv)
float3 light_world_to_local_point(LightData light, float3 point)
float light_attenuation_common(LightData light, const bool is_directional, float3 L)
float3 light_world_to_local_direction(LightData light, float3 L)
T smoothstep(T, T, T) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
constexpr T inversesqrt(T) RET
float distance(float, float) RET
VecBase< float, 3 > cross(VecOp< float, 3 >, VecOp< float, 3 >) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
VecT normalize_and_get_length(VecT vector, float &out_length)
float length_squared(VecT a)
bool bitmask64_test(uint2 bitmask, uint bit_index)
ccl_device_inline float2 power(const float2 v, const float e)
VecBase< float, 2 > float2
VecBase< float, 3 > float3
float power_get(LightData light, LightingType type)
bool light_linking_affects_receiver(uint2 light_set_membership, uchar receiver_light_set)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
static LightShape get(LightData light, LightVector lv)
float disk_radius_projected
static LightVector get(LightData light, const bool is_directional, float3 P)
static LightVector get_shape_closest(LightData light, const bool is_directional, float3 P)