2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
2019-09-12 14:46:47 +02:00
|
|
|
* Copyright 2019, NVIDIA Corporation.
|
2022-02-11 13:53:21 +01:00
|
|
|
* Copyright 2019-2022 Blender Foundation. */
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2020-07-06 12:25:54 +02:00
|
|
|
// clang-format off
|
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
|
|
|
#include "kernel/device/optix/compat.h"
|
|
|
|
|
#include "kernel/device/optix/globals.h"
|
|
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
#include "kernel/device/gpu/image.h" /* Texture lookup uses normal CUDA intrinsics. */
|
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-11-18 14:25:30 +01:00
|
|
|
#include "kernel/tables.h"
|
|
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "kernel/integrator/state.h"
|
|
|
|
|
#include "kernel/integrator/state_flow.h"
|
|
|
|
|
#include "kernel/integrator/state_util.h"
|
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-24 14:19:19 +02:00
|
|
|
#include "kernel/integrator/intersect_closest.h"
|
|
|
|
|
#include "kernel/integrator/intersect_shadow.h"
|
|
|
|
|
#include "kernel/integrator/intersect_subsurface.h"
|
|
|
|
|
#include "kernel/integrator/intersect_volume_stack.h"
|
2020-07-06 12:25:54 +02:00
|
|
|
// clang-format on
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2021-11-24 15:19:02 +01:00
|
|
|
#define OPTIX_DEFINE_ABI_VERSION_ONLY
|
|
|
|
|
#include <optix_function_table.h>
|
|
|
|
|
|
2019-09-12 14:46:47 +02:00
|
|
|
template<typename T> ccl_device_forceinline T *get_payload_ptr_0()
|
|
|
|
|
{
|
2021-10-14 17:51:27 +02:00
|
|
|
return pointer_unpack_from_uint<T>(optixGetPayload_0(), optixGetPayload_1());
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
template<typename T> ccl_device_forceinline T *get_payload_ptr_2()
|
|
|
|
|
{
|
2021-10-14 17:51:27 +02:00
|
|
|
return pointer_unpack_from_uint<T>(optixGetPayload_2(), optixGetPayload_3());
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
2022-01-13 17:20:50 +01:00
|
|
|
template<typename T> ccl_device_forceinline T *get_payload_ptr_6()
|
|
|
|
|
{
|
|
|
|
|
return (T *)(((uint64_t)optixGetPayload_7() << 32) | optixGetPayload_6());
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
ccl_device_forceinline int get_object_id()
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
|
|
|
|
#ifdef __OBJECT_MOTION__
|
2021-11-19 13:01:23 +01:00
|
|
|
/* Always get the instance ID from the TLAS
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
* There might be a motion transform node between TLAS and BLAS which does not have one. */
|
2021-02-28 23:23:24 +01:00
|
|
|
return optixGetInstanceIdFromHandle(optixGetTransformListHandle(0));
|
2019-09-12 14:46:47 +02:00
|
|
|
#else
|
2021-02-28 23:23:24 +01:00
|
|
|
return optixGetInstanceId();
|
2019-09-12 14:46:47 +02:00
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_closest()
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
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
|
|
|
const int global_index = optixGetLaunchIndex().x;
|
|
|
|
|
const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] :
|
|
|
|
|
global_index;
|
2021-11-10 17:18:55 +01:00
|
|
|
integrator_intersect_closest(nullptr, path_index, __params.render_buffer);
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_shadow()
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
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
|
|
|
const int global_index = optixGetLaunchIndex().x;
|
|
|
|
|
const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] :
|
|
|
|
|
global_index;
|
|
|
|
|
integrator_intersect_shadow(nullptr, path_index);
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_subsurface()
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
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
|
|
|
const int global_index = optixGetLaunchIndex().x;
|
|
|
|
|
const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] :
|
|
|
|
|
global_index;
|
|
|
|
|
integrator_intersect_subsurface(nullptr, path_index);
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
extern "C" __global__ void __raygen__kernel_optix_integrator_intersect_volume_stack()
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
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
|
|
|
const int global_index = optixGetLaunchIndex().x;
|
|
|
|
|
const int path_index = (__params.path_index_array) ? __params.path_index_array[global_index] :
|
|
|
|
|
global_index;
|
|
|
|
|
integrator_intersect_volume_stack(nullptr, path_index);
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" __global__ void __miss__kernel_optix_miss()
|
|
|
|
|
{
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* 'kernel_path_lamp_emission' checks intersection distance, so need to set it even on a miss. */
|
2019-09-12 14:46:47 +02:00
|
|
|
optixSetPayload_0(__float_as_uint(optixGetRayTmax()));
|
|
|
|
|
optixSetPayload_5(PRIMITIVE_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" __global__ void __anyhit__kernel_optix_local_hit()
|
|
|
|
|
{
|
2021-12-01 17:30:46 +01:00
|
|
|
#if defined(__HAIR__) || defined(__POINTCLOUD__)
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
if (!optixIsTriangleHit()) {
|
2021-12-01 17:30:46 +01:00
|
|
|
/* Ignore curves and points. */
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-09-12 14:46:47 +02:00
|
|
|
#ifdef __BVH_LOCAL__
|
2021-02-28 23:23:24 +01:00
|
|
|
const int object = get_object_id();
|
2019-09-12 14:46:47 +02:00
|
|
|
if (object != optixGetPayload_4() /* local_object */) {
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Only intersect with matching object. */
|
2019-09-12 14:46:47 +02:00
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-13 17:20:50 +01:00
|
|
|
const int prim = optixGetPrimitiveIndex();
|
|
|
|
|
ccl_private Ray *const ray = get_payload_ptr_6<Ray>();
|
|
|
|
|
if (intersection_skip_self_local(ray->self, prim)) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 17:06:28 +01:00
|
|
|
const uint max_hits = optixGetPayload_5();
|
|
|
|
|
if (max_hits == 0) {
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Special case for when no hit information is requested, just report that something was hit */
|
2020-12-09 17:06:28 +01:00
|
|
|
optixSetPayload_5(true);
|
|
|
|
|
return optixTerminateRay();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-12 14:46:47 +02:00
|
|
|
int hit = 0;
|
|
|
|
|
uint *const lcg_state = get_payload_ptr_0<uint>();
|
|
|
|
|
LocalIntersection *const local_isect = get_payload_ptr_2<LocalIntersection>();
|
|
|
|
|
|
|
|
|
|
if (lcg_state) {
|
|
|
|
|
for (int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
|
|
|
|
|
if (optixGetRayTmax() == local_isect->hits[i].t) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hit = local_isect->num_hits++;
|
|
|
|
|
|
|
|
|
|
if (local_isect->num_hits > max_hits) {
|
|
|
|
|
hit = lcg_step_uint(lcg_state) % local_isect->num_hits;
|
|
|
|
|
if (hit >= max_hits) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (local_isect->num_hits && optixGetRayTmax() > local_isect->hits[0].t) {
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Record closest intersection only.
|
|
|
|
|
* Do not terminate ray here, since there is no guarantee about distance ordering in any-hit.
|
|
|
|
|
*/
|
2019-09-12 14:46:47 +02:00
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local_isect->num_hits = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Intersection *isect = &local_isect->hits[hit];
|
|
|
|
|
isect->t = optixGetRayTmax();
|
2021-02-28 23:23:24 +01:00
|
|
|
isect->prim = prim;
|
2019-09-12 14:46:47 +02:00
|
|
|
isect->object = get_object_id();
|
2021-02-28 23:23:24 +01:00
|
|
|
isect->type = kernel_tex_fetch(__objects, isect->object).primitive_type;
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2020-07-06 12:25:54 +02:00
|
|
|
const float2 barycentrics = optixGetTriangleBarycentrics();
|
|
|
|
|
isect->u = 1.0f - barycentrics.y - barycentrics.x;
|
|
|
|
|
isect->v = barycentrics.x;
|
2019-09-12 14:46:47 +02:00
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Record geometric normal. */
|
2021-02-28 23:23:24 +01:00
|
|
|
const uint tri_vindex = kernel_tex_fetch(__tri_vindex, prim).w;
|
2021-11-16 14:03:59 +01:00
|
|
|
const float3 tri_a = kernel_tex_fetch(__tri_verts, tri_vindex + 0);
|
|
|
|
|
const float3 tri_b = kernel_tex_fetch(__tri_verts, tri_vindex + 1);
|
|
|
|
|
const float3 tri_c = kernel_tex_fetch(__tri_verts, tri_vindex + 2);
|
2019-09-12 14:46:47 +02:00
|
|
|
local_isect->Ng[hit] = normalize(cross(tri_b - tri_a, tri_c - tri_a));
|
|
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Continue tracing (without this the trace call would return after the first hit). */
|
2019-09-12 14:46:47 +02:00
|
|
|
optixIgnoreIntersection();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" __global__ void __anyhit__kernel_optix_shadow_all_hit()
|
|
|
|
|
{
|
|
|
|
|
#ifdef __SHADOW_RECORD_ALL__
|
2021-02-28 23:23:24 +01:00
|
|
|
int prim = optixGetPrimitiveIndex();
|
|
|
|
|
const uint object = get_object_id();
|
2019-09-12 14:46:47 +02:00
|
|
|
# ifdef __VISIBILITY_FLAG__
|
|
|
|
|
const uint visibility = optixGetPayload_4();
|
2021-02-28 23:23:24 +01:00
|
|
|
if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) {
|
2021-10-13 18:19:51 +02:00
|
|
|
return optixIgnoreIntersection();
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
2022-01-13 17:20:50 +01:00
|
|
|
ccl_private Ray *const ray = get_payload_ptr_6<Ray>();
|
|
|
|
|
if (intersection_skip_self_shadow(ray->self, object, prim)) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
float u = 0.0f, v = 0.0f;
|
2021-02-28 23:23:24 +01:00
|
|
|
int type = 0;
|
2019-09-12 14:46:47 +02:00
|
|
|
if (optixIsTriangleHit()) {
|
|
|
|
|
const float2 barycentrics = optixGetTriangleBarycentrics();
|
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
|
|
|
u = 1.0f - barycentrics.y - barycentrics.x;
|
|
|
|
|
v = barycentrics.x;
|
2021-02-28 23:23:24 +01:00
|
|
|
type = kernel_tex_fetch(__objects, object).primitive_type;
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
2020-07-06 12:25:54 +02:00
|
|
|
# ifdef __HAIR__
|
2021-12-20 02:52:56 +01:00
|
|
|
else if ((optixGetHitKind() & (~PRIMITIVE_MOTION)) != PRIMITIVE_POINT) {
|
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
|
|
|
u = __uint_as_float(optixGetAttribute_0());
|
|
|
|
|
v = __uint_as_float(optixGetAttribute_1());
|
2020-07-06 12:25:54 +02:00
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim);
|
|
|
|
|
type = segment.type;
|
|
|
|
|
prim = segment.prim;
|
|
|
|
|
|
2021-11-24 15:19:02 +01:00
|
|
|
# if OPTIX_ABI_VERSION < 55
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Filter out curve endcaps. */
|
2020-07-06 12:25:54 +02:00
|
|
|
if (u == 0.0f || u == 1.0f) {
|
2021-10-13 18:19:51 +02:00
|
|
|
return optixIgnoreIntersection();
|
2020-07-06 12:25:54 +02:00
|
|
|
}
|
2021-11-24 15:19:02 +01:00
|
|
|
# endif
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
2020-07-06 12:25:54 +02:00
|
|
|
# endif
|
2021-12-01 17:30:46 +01:00
|
|
|
else {
|
|
|
|
|
type = kernel_tex_fetch(__objects, object).primitive_type;
|
|
|
|
|
u = 0.0f;
|
|
|
|
|
v = 0.0f;
|
|
|
|
|
}
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2021-10-13 18:19:51 +02:00
|
|
|
# ifndef __TRANSPARENT_SHADOWS__
|
|
|
|
|
/* No transparent shadows support compiled in, make opaque. */
|
|
|
|
|
optixSetPayload_5(true);
|
|
|
|
|
return optixTerminateRay();
|
|
|
|
|
# else
|
2021-09-20 16:16:11 +02:00
|
|
|
const uint max_hits = optixGetPayload_3();
|
|
|
|
|
const uint num_hits_packed = optixGetPayload_2();
|
|
|
|
|
const uint num_recorded_hits = uint16_unpack_from_uint_0(num_hits_packed);
|
|
|
|
|
const uint num_hits = uint16_unpack_from_uint_1(num_hits_packed);
|
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
|
|
|
/* If no transparent shadows, all light is blocked and we can stop immediately. */
|
2021-09-20 16:16:11 +02:00
|
|
|
if (num_hits >= max_hits ||
|
2021-10-13 18:19:51 +02:00
|
|
|
!(intersection_get_shader_flags(NULL, prim, type) & SD_HAS_TRANSPARENT_SHADOW)) {
|
|
|
|
|
optixSetPayload_5(true);
|
|
|
|
|
return optixTerminateRay();
|
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-09-20 16:16:11 +02:00
|
|
|
/* Always use baked shadow transparency for curves. */
|
2021-12-20 02:52:56 +01:00
|
|
|
if (type & PRIMITIVE_CURVE) {
|
2021-09-20 16:16:11 +02:00
|
|
|
float throughput = __uint_as_float(optixGetPayload_1());
|
|
|
|
|
throughput *= intersection_curve_shadow_transparency(nullptr, object, prim, u);
|
|
|
|
|
optixSetPayload_1(__float_as_uint(throughput));
|
|
|
|
|
optixSetPayload_2(uint16_pack_to_uint(num_recorded_hits, num_hits + 1));
|
|
|
|
|
|
|
|
|
|
if (throughput < CURVE_SHADOW_TRANSPARENCY_CUTOFF) {
|
2021-11-26 19:11:14 +01:00
|
|
|
optixSetPayload_5(true);
|
2021-09-20 16:16:11 +02:00
|
|
|
return optixTerminateRay();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Continue tracing. */
|
|
|
|
|
optixIgnoreIntersection();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-13 18:19:51 +02:00
|
|
|
/* Record transparent intersection. */
|
2021-09-20 16:16:11 +02:00
|
|
|
optixSetPayload_2(uint16_pack_to_uint(num_recorded_hits + 1, num_hits + 1));
|
2021-10-13 18:19:51 +02:00
|
|
|
|
2021-09-20 16:16:11 +02:00
|
|
|
uint record_index = num_recorded_hits;
|
2021-10-13 18:19:51 +02:00
|
|
|
|
2021-10-18 19:20:09 +02:00
|
|
|
const IntegratorShadowState state = optixGetPayload_0();
|
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-09-20 16:16:11 +02:00
|
|
|
const uint max_record_hits = min(max_hits, INTEGRATOR_SHADOW_ISECT_SIZE);
|
|
|
|
|
if (record_index >= max_record_hits) {
|
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
|
|
|
/* If maximum number of hits reached, find a hit to replace. */
|
2021-10-18 19:20:09 +02:00
|
|
|
float max_recorded_t = INTEGRATOR_STATE_ARRAY(state, shadow_isect, 0, t);
|
2021-09-20 16:16:11 +02:00
|
|
|
uint max_recorded_hit = 0;
|
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-09-20 16:16:11 +02:00
|
|
|
for (int i = 1; i < max_record_hits; i++) {
|
2021-10-18 19:20:09 +02:00
|
|
|
const float isect_t = INTEGRATOR_STATE_ARRAY(state, shadow_isect, i, t);
|
|
|
|
|
if (isect_t > max_recorded_t) {
|
|
|
|
|
max_recorded_t = isect_t;
|
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
|
|
|
max_recorded_hit = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (optixGetRayTmax() >= max_recorded_t) {
|
2021-10-13 18:19:51 +02:00
|
|
|
/* Accept hit, so that OptiX won't consider any more hits beyond the distance of the
|
|
|
|
|
* current hit anymore. */
|
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
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
record_index = max_recorded_hit;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 19:20:09 +02:00
|
|
|
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, record_index, u) = u;
|
|
|
|
|
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, record_index, v) = v;
|
|
|
|
|
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, record_index, t) = optixGetRayTmax();
|
|
|
|
|
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, record_index, prim) = prim;
|
|
|
|
|
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, record_index, object) = object;
|
|
|
|
|
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, record_index, type) = type;
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2021-09-20 16:16:11 +02:00
|
|
|
/* Continue tracing. */
|
2019-09-12 14:46:47 +02:00
|
|
|
optixIgnoreIntersection();
|
2021-10-13 18:19:51 +02:00
|
|
|
# endif /* __TRANSPARENT_SHADOWS__ */
|
|
|
|
|
#endif /* __SHADOW_RECORD_ALL__ */
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
extern "C" __global__ void __anyhit__kernel_optix_volume_test()
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
2021-12-01 17:30:46 +01:00
|
|
|
#if defined(__HAIR__) || defined(__POINTCLOUD__)
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
if (!optixIsTriangleHit()) {
|
|
|
|
|
/* Ignore curves. */
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
const uint object = get_object_id();
|
2019-09-12 14:46:47 +02:00
|
|
|
#ifdef __VISIBILITY_FLAG__
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
const uint visibility = optixGetPayload_4();
|
2021-02-28 23:23:24 +01:00
|
|
|
if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) {
|
2019-09-12 14:46:47 +02:00
|
|
|
return optixIgnoreIntersection();
|
2020-07-06 12:25:54 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
if ((kernel_tex_fetch(__object_flag, object) & SD_OBJECT_HAS_VOLUME) == 0) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
2022-01-13 17:20:50 +01:00
|
|
|
|
|
|
|
|
const int prim = optixGetPrimitiveIndex();
|
|
|
|
|
ccl_private Ray *const ray = get_payload_ptr_6<Ray>();
|
|
|
|
|
if (intersection_skip_self(ray->self, object, prim)) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" __global__ void __anyhit__kernel_optix_visibility_test()
|
|
|
|
|
{
|
2020-07-06 12:25:54 +02:00
|
|
|
#ifdef __HAIR__
|
2021-11-24 15:19:02 +01:00
|
|
|
# if OPTIX_ABI_VERSION < 55
|
2021-12-20 02:52:56 +01:00
|
|
|
if (optixGetPrimitiveType() == OPTIX_PRIMITIVE_TYPE_ROUND_CUBIC_BSPLINE) {
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Filter out curve endcaps. */
|
2020-07-06 12:25:54 +02:00
|
|
|
const float u = __uint_as_float(optixGetAttribute_0());
|
|
|
|
|
if (u == 0.0f || u == 1.0f) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-24 15:19:02 +01:00
|
|
|
# endif
|
2019-09-12 14:46:47 +02:00
|
|
|
#endif
|
|
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
const uint object = get_object_id();
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
const uint visibility = optixGetPayload_4();
|
2022-01-13 17:20:50 +01:00
|
|
|
#ifdef __VISIBILITY_FLAG__
|
2021-02-28 23:23:24 +01:00
|
|
|
if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) {
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
2022-01-13 17:20:50 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
const int prim = optixGetPrimitiveIndex();
|
|
|
|
|
ccl_private Ray *const ray = get_payload_ptr_6<Ray>();
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
|
2020-07-06 12:25:54 +02:00
|
|
|
if (visibility & PATH_RAY_SHADOW_OPAQUE) {
|
2022-01-13 17:20:50 +01:00
|
|
|
if (intersection_skip_self_shadow(ray->self, object, prim)) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Shadow ray early termination. */
|
|
|
|
|
return optixTerminateRay();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if (intersection_skip_self(ray->self, object, prim)) {
|
|
|
|
|
return optixIgnoreIntersection();
|
|
|
|
|
}
|
2020-07-06 12:25:54 +02:00
|
|
|
}
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" __global__ void __closesthit__kernel_optix_hit()
|
|
|
|
|
{
|
2021-02-28 23:23:24 +01:00
|
|
|
const int object = get_object_id();
|
|
|
|
|
const int prim = optixGetPrimitiveIndex();
|
|
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
optixSetPayload_0(__float_as_uint(optixGetRayTmax())); /* Intersection distance */
|
2021-02-28 23:23:24 +01:00
|
|
|
optixSetPayload_4(object);
|
2019-09-12 14:46:47 +02:00
|
|
|
|
|
|
|
|
if (optixIsTriangleHit()) {
|
|
|
|
|
const float2 barycentrics = optixGetTriangleBarycentrics();
|
|
|
|
|
optixSetPayload_1(__float_as_uint(1.0f - barycentrics.y - barycentrics.x));
|
|
|
|
|
optixSetPayload_2(__float_as_uint(barycentrics.x));
|
2021-02-28 23:23:24 +01:00
|
|
|
optixSetPayload_3(prim);
|
|
|
|
|
optixSetPayload_5(kernel_tex_fetch(__objects, object).primitive_type);
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
2021-12-20 02:52:56 +01:00
|
|
|
else if ((optixGetHitKind() & (~PRIMITIVE_MOTION)) != PRIMITIVE_POINT) {
|
2021-02-28 23:23:24 +01:00
|
|
|
const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, prim);
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
optixSetPayload_1(optixGetAttribute_0()); /* Same as 'optixGetCurveParameter()' */
|
2019-09-12 14:46:47 +02:00
|
|
|
optixSetPayload_2(optixGetAttribute_1());
|
2021-02-28 23:23:24 +01:00
|
|
|
optixSetPayload_3(segment.prim);
|
|
|
|
|
optixSetPayload_5(segment.type);
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
2021-12-01 17:30:46 +01:00
|
|
|
else {
|
|
|
|
|
optixSetPayload_1(0);
|
|
|
|
|
optixSetPayload_2(0);
|
|
|
|
|
optixSetPayload_3(prim);
|
|
|
|
|
optixSetPayload_5(kernel_tex_fetch(__objects, object).primitive_type);
|
|
|
|
|
}
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef __HAIR__
|
2021-02-28 23:23:24 +01:00
|
|
|
ccl_device_inline void optix_intersection_curve(const int prim, const int type)
|
2019-09-12 14:46:47 +02:00
|
|
|
{
|
2021-02-28 23:23:24 +01:00
|
|
|
const int object = get_object_id();
|
|
|
|
|
|
|
|
|
|
# ifdef __VISIBILITY_FLAG__
|
2019-09-12 14:46:47 +02:00
|
|
|
const uint visibility = optixGetPayload_4();
|
2021-02-28 23:23:24 +01:00
|
|
|
if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2019-11-22 17:30:22 +01:00
|
|
|
float3 P = optixGetObjectRayOrigin();
|
|
|
|
|
float3 dir = optixGetObjectRayDirection();
|
|
|
|
|
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* The direction is not normalized by default, but the curve intersection routine expects that */
|
2019-11-22 17:30:22 +01:00
|
|
|
float len;
|
|
|
|
|
dir = normalize_len(dir, &len);
|
2019-09-12 14:46:47 +02:00
|
|
|
|
|
|
|
|
# ifdef __OBJECT_MOTION__
|
|
|
|
|
const float time = optixGetRayTime();
|
|
|
|
|
# else
|
|
|
|
|
const float time = 0.0f;
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
Intersection isect;
|
|
|
|
|
isect.t = optixGetRayTmax();
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
/* Transform maximum distance into object space. */
|
2019-11-22 17:30:22 +01:00
|
|
|
if (isect.t != FLT_MAX)
|
|
|
|
|
isect.t *= len;
|
2019-09-12 14:46:47 +02:00
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
if (curve_intersect(NULL, &isect, P, dir, isect.t, object, prim, time, type)) {
|
2021-12-20 02:52:56 +01:00
|
|
|
static_assert(PRIMITIVE_ALL < 128, "Values >= 128 are reserved for OptiX internal use");
|
2019-11-22 17:30:22 +01:00
|
|
|
optixReportIntersection(isect.t / len,
|
2019-09-12 14:46:47 +02:00
|
|
|
type & PRIMITIVE_ALL,
|
Cycles: Rework OptiX visibility flags handling
Before the visibility test against the visibility flags was performed in an any-hit program in OptiX
(called `__anyhit__kernel_optix_visibility_test`), which was using the `__prim_visibility` array.
This is not entirely correct however, since `__prim_visibility` is filled with the merged visibility
flags of all objects that reference that primitive, so if one object uses different visibility flags
than another object, but they both are instances of the same geometry, they would appear the same
way. The reason that the any-hit program was used rather than the OptiX instance visibility mask is
that the latter is currently limited to 8 bits only, which is not sufficient to contain all Cycles
visibility flags (12 bits).
To mostly fix the problem with multiple instances and different visibility flags, I changed things to
use the OptiX instance visibility mask for a subset of the Cycles visibility flags (`PATH_RAY_CAMERA`
to `PATH_RAY_VOLUME_SCATTER`, which fit into 8 bits) and only fall back to the visibility test any-hit
program if that isn't enough (e.g. the ray visibility mask exceeds 8 bits or when using the built-in
curves from OptiX, since the any-hit program is then also used to skip the curve endcaps).
This may also improve performance in some cases, since by default OptiX can now perform the normal
scene intersection trace calls entirely on RT cores without having to jump back to the SM on every
hit to execute the any-hit program.
Fixes T89801
Differential Revision: https://developer.blender.org/D12604
2021-09-22 16:23:08 +02:00
|
|
|
__float_as_int(isect.u), /* Attribute_0 */
|
|
|
|
|
__float_as_int(isect.v)); /* Attribute_1 */
|
2019-09-12 14:46:47 +02:00
|
|
|
}
|
2020-02-18 20:54:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extern "C" __global__ void __intersection__curve_ribbon()
|
|
|
|
|
{
|
2021-02-28 23:23:24 +01:00
|
|
|
const KernelCurveSegment segment = kernel_tex_fetch(__curve_segments, optixGetPrimitiveIndex());
|
|
|
|
|
const int prim = segment.prim;
|
|
|
|
|
const int type = segment.type;
|
2021-12-20 02:52:56 +01:00
|
|
|
if (type & PRIMITIVE_CURVE_RIBBON) {
|
2020-02-18 20:54:41 +01:00
|
|
|
optix_intersection_curve(prim, type);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-01 17:30:46 +01:00
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef __POINTCLOUD__
|
|
|
|
|
extern "C" __global__ void __intersection__point()
|
|
|
|
|
{
|
|
|
|
|
const int prim = optixGetPrimitiveIndex();
|
|
|
|
|
const int object = get_object_id();
|
|
|
|
|
const int type = kernel_tex_fetch(__objects, object).primitive_type;
|
|
|
|
|
|
|
|
|
|
# ifdef __VISIBILITY_FLAG__
|
|
|
|
|
const uint visibility = optixGetPayload_4();
|
|
|
|
|
if ((kernel_tex_fetch(__objects, object).visibility & visibility) == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
float3 P = optixGetObjectRayOrigin();
|
|
|
|
|
float3 dir = optixGetObjectRayDirection();
|
|
|
|
|
|
|
|
|
|
/* The direction is not normalized by default, the point intersection routine expects that. */
|
|
|
|
|
float len;
|
|
|
|
|
dir = normalize_len(dir, &len);
|
|
|
|
|
|
|
|
|
|
# ifdef __OBJECT_MOTION__
|
|
|
|
|
const float time = optixGetRayTime();
|
|
|
|
|
# else
|
|
|
|
|
const float time = 0.0f;
|
|
|
|
|
# endif
|
|
|
|
|
|
|
|
|
|
Intersection isect;
|
|
|
|
|
isect.t = optixGetRayTmax();
|
|
|
|
|
/* Transform maximum distance into object space. */
|
|
|
|
|
if (isect.t != FLT_MAX) {
|
|
|
|
|
isect.t *= len;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (point_intersect(NULL, &isect, P, dir, isect.t, object, prim, time, type)) {
|
2021-12-20 02:52:56 +01:00
|
|
|
static_assert(PRIMITIVE_ALL < 128, "Values >= 128 are reserved for OptiX internal use");
|
2021-12-01 17:30:46 +01:00
|
|
|
optixReportIntersection(isect.t / len, type & PRIMITIVE_ALL);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-12 14:46:47 +02:00
|
|
|
#endif
|