2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2021-04-15 16:36:35 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-12-26 17:53:57 +01:00
|
|
|
#include "kernel/globals.h"
|
|
|
|
|
#include "kernel/types.h"
|
|
|
|
|
|
2021-04-15 16:36:35 +02:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
ccl_device_inline bool intersection_ray_valid(const ccl_private Ray *ray)
|
2022-07-25 13:53:48 +02:00
|
|
|
{
|
|
|
|
|
/* NOTE: Due to some vectorization code non-finite origin point might
|
|
|
|
|
* cause lots of false-positive intersections which will overflow traversal
|
|
|
|
|
* stack.
|
|
|
|
|
* This code is a quick way to perform early output, to avoid crashes in
|
|
|
|
|
* such cases.
|
|
|
|
|
* From production scenes so far it seems it's enough to test first element
|
|
|
|
|
* only.
|
|
|
|
|
* Scene intersection may also called with empty rays for conditional trace
|
|
|
|
|
* calls that evaluate to false, so filter those out.
|
|
|
|
|
*/
|
|
|
|
|
return isfinite_safe(ray->P.x) && isfinite_safe(ray->D.x) && len_squared(ray->D) != 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-13 16:54:53 +02:00
|
|
|
/* Offset intersection distance by the smallest possible amount, to skip
|
|
|
|
|
* intersections at this distance. This works in cases where the ray start
|
|
|
|
|
* position is unchanged and only tmin is updated, since for self
|
2023-04-26 11:36:37 +02:00
|
|
|
* intersection we'll be comparing against the exact same distances.
|
|
|
|
|
*
|
|
|
|
|
* Always returns normalized floating point value. */
|
2022-07-13 16:54:53 +02:00
|
|
|
ccl_device_forceinline float intersection_t_offset(const float t)
|
|
|
|
|
{
|
2022-07-21 13:21:53 +10:00
|
|
|
/* This is a simplified version of `nextafterf(t, FLT_MAX)`, only dealing with
|
2022-07-13 16:54:53 +02:00
|
|
|
* non-negative and finite t. */
|
|
|
|
|
kernel_assert(t >= 0.0f && isfinite_safe(t));
|
2023-04-26 11:36:37 +02:00
|
|
|
|
|
|
|
|
/* Special handling of zero, which also includes handling of denormal values:
|
|
|
|
|
* always return smallest normalized value. If a denormalized zero is returned
|
|
|
|
|
* it will cause false-positive intersection detection with a distance of 0.
|
|
|
|
|
*
|
2023-11-09 09:34:50 +11:00
|
|
|
* The check relies on the fact that comparison of denormal values with zero
|
2023-04-26 11:36:37 +02:00
|
|
|
* returns true. */
|
|
|
|
|
if (t == 0.0f) {
|
2023-04-28 10:51:03 +02:00
|
|
|
/* The exact bit value of this should be 0x1p-126, but hex floating point values notation is
|
|
|
|
|
* not available in CUDA/OptiX. */
|
|
|
|
|
return FLT_MIN;
|
2023-04-26 11:36:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const uint32_t bits = __float_as_uint(t) + 1;
|
|
|
|
|
const float result = __uint_as_float(bits);
|
|
|
|
|
|
|
|
|
|
/* Assert that the calculated value is indeed considered to be offset from the
|
|
|
|
|
* original value. */
|
|
|
|
|
kernel_assert(result > t);
|
|
|
|
|
|
|
|
|
|
return result;
|
2022-07-13 16:54:53 +02:00
|
|
|
}
|
|
|
|
|
|
2022-07-18 21:07:06 +02:00
|
|
|
/* Ray offset to avoid self intersection.
|
|
|
|
|
*
|
|
|
|
|
* This function can be used to compute a modified ray start position for rays
|
|
|
|
|
* leaving from a surface. This is from:
|
|
|
|
|
* "A Fast and Robust Method for Avoiding Self-Intersection"
|
|
|
|
|
* Ray Tracing Gems, chapter 6.
|
|
|
|
|
*/
|
|
|
|
|
ccl_device_inline float3 ray_offset(const float3 P, const float3 Ng)
|
|
|
|
|
{
|
|
|
|
|
const float int_scale = 256.0f;
|
|
|
|
|
const int3 of_i = make_int3(
|
|
|
|
|
(int)(int_scale * Ng.x), (int)(int_scale * Ng.y), (int)(int_scale * Ng.z));
|
|
|
|
|
|
|
|
|
|
const float3 p_i = make_float3(
|
|
|
|
|
__int_as_float(__float_as_int(P.x) + ((P.x < 0) ? -of_i.x : of_i.x)),
|
|
|
|
|
__int_as_float(__float_as_int(P.y) + ((P.y < 0) ? -of_i.y : of_i.y)),
|
|
|
|
|
__int_as_float(__float_as_int(P.z) + ((P.z < 0) ? -of_i.z : of_i.z)));
|
|
|
|
|
const float origin = 1.0f / 32.0f;
|
|
|
|
|
const float float_scale = 1.0f / 65536.0f;
|
|
|
|
|
return make_float3(fabsf(P.x) < origin ? P.x + float_scale * Ng.x : p_i.x,
|
|
|
|
|
fabsf(P.y) < origin ? P.y + float_scale * Ng.y : p_i.y,
|
|
|
|
|
fabsf(P.z) < origin ? P.z + float_scale * Ng.z : p_i.z);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-25 17:38:03 +02:00
|
|
|
#ifndef __KERNEL_GPU__
|
2021-04-15 16:36:35 +02:00
|
|
|
ccl_device int intersections_compare(const void *a, const void *b)
|
|
|
|
|
{
|
|
|
|
|
const Intersection *isect_a = (const Intersection *)a;
|
|
|
|
|
const Intersection *isect_b = (const Intersection *)b;
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
if (isect_a->t < isect_b->t) {
|
2021-04-15 16:36:35 +02:00
|
|
|
return -1;
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
|
|
|
|
if (isect_a->t > isect_b->t) {
|
2021-04-15 16:36:35 +02:00
|
|
|
return 1;
|
2024-12-26 17:53:59 +01:00
|
|
|
}
|
|
|
|
|
return 0;
|
2021-04-15 16:36:35 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-10-07 17:27:22 +02:00
|
|
|
/* For subsurface scattering, only sorting a small amount of intersections
|
|
|
|
|
* so bubble sort is fine for CPU and GPU. */
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device_inline void sort_intersections_and_normals(ccl_private Intersection *hits,
|
|
|
|
|
ccl_private float3 *Ng,
|
2021-10-07 17:27:22 +02:00
|
|
|
uint num_hits)
|
|
|
|
|
{
|
|
|
|
|
bool swapped;
|
|
|
|
|
do {
|
|
|
|
|
swapped = false;
|
|
|
|
|
for (int j = 0; j < num_hits - 1; ++j) {
|
|
|
|
|
if (hits[j].t > hits[j + 1].t) {
|
2021-11-18 14:25:05 +01:00
|
|
|
Intersection tmp_hit = hits[j];
|
2021-10-20 13:37:39 +02:00
|
|
|
float3 tmp_Ng = Ng[j];
|
2021-10-07 17:27:22 +02:00
|
|
|
hits[j] = hits[j + 1];
|
|
|
|
|
Ng[j] = Ng[j + 1];
|
|
|
|
|
hits[j + 1] = tmp_hit;
|
|
|
|
|
Ng[j + 1] = tmp_Ng;
|
|
|
|
|
swapped = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
--num_hits;
|
|
|
|
|
} while (swapped);
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
/* Utility to quickly get flags from an intersection. */
|
2021-04-15 16:36:35 +02:00
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_forceinline int intersection_get_shader_flags(KernelGlobals kg,
|
|
|
|
|
const int prim,
|
|
|
|
|
const int type)
|
2021-04-15 16:36:35 +02:00
|
|
|
{
|
|
|
|
|
int shader = 0;
|
|
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (type & PRIMITIVE_TRIANGLE) {
|
2022-06-17 17:16:37 +02:00
|
|
|
shader = kernel_data_fetch(tri_shader, prim);
|
2021-04-15 16:36:35 +02:00
|
|
|
}
|
2021-12-01 17:30:46 +01:00
|
|
|
#ifdef __POINTCLOUD__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (type & PRIMITIVE_POINT) {
|
2022-06-17 17:16:37 +02:00
|
|
|
shader = kernel_data_fetch(points_shader, prim);
|
2021-12-01 17:30:46 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
2021-04-15 16:36:35 +02:00
|
|
|
#ifdef __HAIR__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (type & PRIMITIVE_CURVE) {
|
2022-06-17 17:16:37 +02:00
|
|
|
shader = kernel_data_fetch(curves, prim).shader_id;
|
2021-04-15 16:36:35 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-06-17 17:16:37 +02:00
|
|
|
return kernel_data_fetch(shaders, (shader & SHADER_MASK)).flags;
|
2021-04-15 16:36:35 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_forceinline int intersection_get_shader_from_isect_prim(KernelGlobals kg,
|
|
|
|
|
const int prim,
|
|
|
|
|
const int isect_type)
|
2021-04-15 16:36:35 +02:00
|
|
|
{
|
|
|
|
|
int shader = 0;
|
|
|
|
|
|
2021-12-20 02:52:56 +01:00
|
|
|
if (isect_type & PRIMITIVE_TRIANGLE) {
|
2022-06-17 17:16:37 +02:00
|
|
|
shader = kernel_data_fetch(tri_shader, prim);
|
2021-04-15 16:36:35 +02:00
|
|
|
}
|
2021-12-01 17:30:46 +01:00
|
|
|
#ifdef __POINTCLOUD__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (isect_type & PRIMITIVE_POINT) {
|
2022-06-17 17:16:37 +02:00
|
|
|
shader = kernel_data_fetch(points_shader, prim);
|
2021-12-01 17:30:46 +01:00
|
|
|
}
|
|
|
|
|
#endif
|
2021-04-15 16:36:35 +02:00
|
|
|
#ifdef __HAIR__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if (isect_type & PRIMITIVE_CURVE) {
|
2022-06-17 17:16:37 +02:00
|
|
|
shader = kernel_data_fetch(curves, prim).shader_id;
|
2021-04-15 16:36:35 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return shader & SHADER_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_forceinline int intersection_get_shader(
|
2024-12-29 17:32:00 +01:00
|
|
|
KernelGlobals kg, const ccl_private Intersection *ccl_restrict isect)
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
{
|
2021-02-28 23:23:24 +01:00
|
|
|
return intersection_get_shader_from_isect_prim(kg, isect->prim, isect->type);
|
2021-08-03 12:20:28 +02:00
|
|
|
}
|
|
|
|
|
|
Cycles: Kernel address space changes for MSL
This is the first of a sequence of changes to support compiling Cycles kernels as MSL (Metal Shading Language) in preparation for a Metal GPU device implementation.
MSL requires that all pointer types be declared with explicit address space attributes (device, thread, etc...). There is already precedent for this with Cycles' address space macros (ccl_global, ccl_private, etc...), therefore the first step of MSL-enablement is to apply these consistently. Line-for-line this represents the largest change required to enable MSL. Applying this change first will simplify future patches as well as offering the emergent benefit of enhanced descriptiveness.
The vast majority of deltas in this patch fall into one of two cases:
- Ensuring ccl_private is specified for thread-local pointer types
- Ensuring ccl_global is specified for device-wide pointer types
Additionally, the ccl_addr_space qualifier can be removed. Prior to Cycles X, ccl_addr_space was used as a context-dependent address space qualifier, but now it is either redundant (e.g. in struct typedefs), or can be replaced by ccl_global in the case of pointer types. Associated function variants (e.g. lcg_step_float_addrspace) are also redundant.
In cases where address space qualifiers are chained with "const", this patch places the address space qualifier first. The rationale for this is that the choice of address space is likely to have the greater impact on runtime performance and overall architecture.
The final part of this patch is the addition of a metal/compat.h header. This is partially complete and will be extended in future patches, paving the way for the full Metal implementation.
Ref T92212
Reviewed By: brecht
Maniphest Tasks: T92212
Differential Revision: https://developer.blender.org/D12864
2021-10-14 13:53:40 +01:00
|
|
|
ccl_device_forceinline int intersection_get_object_flags(
|
2024-12-29 17:32:00 +01:00
|
|
|
KernelGlobals kg, const ccl_private Intersection *ccl_restrict isect)
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
{
|
2022-06-17 17:16:37 +02:00
|
|
|
return kernel_data_fetch(object_flag, isect->object);
|
Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.
Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.
Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles
Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)
For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.
Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-20 17:59:20 +02:00
|
|
|
}
|
|
|
|
|
|
2021-10-13 18:19:51 +02:00
|
|
|
/* TODO: find a better (faster) solution for this. Maybe store offset per object for
|
|
|
|
|
* attributes needed in intersection? */
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline int intersection_find_attribute(KernelGlobals kg,
|
2021-10-13 18:19:51 +02:00
|
|
|
const int object,
|
|
|
|
|
const uint id)
|
|
|
|
|
{
|
2022-06-17 17:16:37 +02:00
|
|
|
uint attr_offset = kernel_data_fetch(objects, object).attribute_map_offset;
|
|
|
|
|
AttributeMap attr_map = kernel_data_fetch(attributes_map, attr_offset);
|
2021-10-13 18:19:51 +02:00
|
|
|
|
2022-06-16 19:02:55 +02:00
|
|
|
while (attr_map.id != id) {
|
|
|
|
|
if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) {
|
|
|
|
|
if (UNLIKELY(attr_map.element == 0)) {
|
2021-10-13 18:19:51 +02:00
|
|
|
return (int)ATTR_STD_NOT_FOUND;
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
/* Chain jump to a different part of the table. */
|
|
|
|
|
attr_offset = attr_map.offset;
|
2021-10-13 18:19:51 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attr_offset += ATTR_PRIM_TYPES;
|
|
|
|
|
}
|
2022-06-17 17:16:37 +02:00
|
|
|
attr_map = kernel_data_fetch(attributes_map, attr_offset);
|
2021-10-13 18:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* return result */
|
2024-12-26 17:53:59 +01:00
|
|
|
return (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : attr_map.offset;
|
2021-10-13 18:19:51 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-20 16:16:11 +02:00
|
|
|
/* Transparent Shadows */
|
|
|
|
|
|
|
|
|
|
/* Cut-off value to stop transparent shadow tracing when practically opaque. */
|
|
|
|
|
#define CURVE_SHADOW_TRANSPARENCY_CUTOFF 0.001f
|
|
|
|
|
|
2022-10-20 04:38:50 +02:00
|
|
|
ccl_device_inline float intersection_curve_shadow_transparency(
|
|
|
|
|
KernelGlobals kg, const int object, const int prim, const int type, const float u)
|
2021-09-20 16:16:11 +02:00
|
|
|
{
|
|
|
|
|
/* Find attribute. */
|
|
|
|
|
const int offset = intersection_find_attribute(kg, object, ATTR_STD_SHADOW_TRANSPARENCY);
|
|
|
|
|
if (offset == ATTR_STD_NOT_FOUND) {
|
|
|
|
|
/* If no shadow transparency attribute, assume opaque. */
|
|
|
|
|
return 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Interpolate transparency between curve keys. */
|
2022-06-17 17:16:37 +02:00
|
|
|
const KernelCurve kcurve = kernel_data_fetch(curves, prim);
|
2022-10-20 04:38:50 +02:00
|
|
|
const int k0 = kcurve.first_key + PRIMITIVE_UNPACK_SEGMENT(type);
|
2021-09-20 16:16:11 +02:00
|
|
|
const int k1 = k0 + 1;
|
|
|
|
|
|
2022-06-17 17:16:37 +02:00
|
|
|
const float f0 = kernel_data_fetch(attributes_float, offset + k0);
|
|
|
|
|
const float f1 = kernel_data_fetch(attributes_float, offset + k1);
|
2021-09-20 16:16:11 +02:00
|
|
|
|
|
|
|
|
return (1.0f - u) * f0 + u * f1;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
ccl_device_inline bool intersection_skip_self(const ccl_ray_data RaySelfPrimitives &self,
|
2022-01-13 17:20:50 +01:00
|
|
|
const int object,
|
|
|
|
|
const int prim)
|
|
|
|
|
{
|
|
|
|
|
return (self.prim == prim) && (self.object == object);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
ccl_device_inline bool intersection_skip_self_shadow(const ccl_ray_data RaySelfPrimitives &self,
|
2022-01-13 17:20:50 +01:00
|
|
|
const int object,
|
|
|
|
|
const int prim)
|
|
|
|
|
{
|
|
|
|
|
return ((self.prim == prim) && (self.object == object)) ||
|
|
|
|
|
((self.light_prim == prim) && (self.light_object == object));
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-29 17:32:00 +01:00
|
|
|
ccl_device_inline bool intersection_skip_self_local(const ccl_ray_data RaySelfPrimitives &self,
|
2022-01-13 17:20:50 +01:00
|
|
|
const int prim)
|
|
|
|
|
{
|
|
|
|
|
return (self.prim == prim);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-24 13:36:13 +02:00
|
|
|
#ifdef __SHADOW_LINKING__
|
2023-09-06 15:25:30 +02:00
|
|
|
ccl_device_inline uint64_t
|
2024-12-29 17:32:00 +01:00
|
|
|
ray_get_shadow_set_membership(KernelGlobals kg, const ccl_ray_data RaySelfPrimitives &self)
|
2023-05-24 13:36:13 +02:00
|
|
|
{
|
2023-09-06 09:53:29 +02:00
|
|
|
if (self.light != LAMP_NONE) {
|
|
|
|
|
return kernel_data_fetch(lights, self.light).shadow_set_membership;
|
2023-05-24 13:36:13 +02:00
|
|
|
}
|
|
|
|
|
|
2023-09-06 09:53:29 +02:00
|
|
|
if (self.light_object != OBJECT_NONE) {
|
|
|
|
|
return kernel_data_fetch(objects, self.light_object).shadow_set_membership;
|
2023-05-24 13:36:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return LIGHT_LINK_MASK_ALL;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
ccl_device_inline bool intersection_skip_shadow_link(KernelGlobals kg,
|
2024-12-29 17:32:00 +01:00
|
|
|
const ccl_ray_data RaySelfPrimitives &self,
|
2023-05-24 13:36:13 +02:00
|
|
|
const int isect_object)
|
|
|
|
|
{
|
|
|
|
|
#ifdef __SHADOW_LINKING__
|
|
|
|
|
if (!(kernel_data.kernel_features & KERNEL_FEATURE_SHADOW_LINKING)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-06 09:53:29 +02:00
|
|
|
const uint64_t set_membership = ray_get_shadow_set_membership(kg, self);
|
2023-05-24 13:36:13 +02:00
|
|
|
if (set_membership == LIGHT_LINK_MASK_ALL) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const uint blocker_set = kernel_data_fetch(objects, isect_object).blocker_shadow_set;
|
|
|
|
|
return ((uint64_t(1) << uint64_t(blocker_set)) & set_membership) == 0;
|
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-15 16:36:35 +02:00
|
|
|
CCL_NAMESPACE_END
|