2022-02-11 13:53:21 +01:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0
|
|
|
|
* Copyright 2011-2022 Blender Foundation */
|
2017-01-17 10:48:56 +01:00
|
|
|
|
|
|
|
/* Motion Triangle Primitive
|
|
|
|
*
|
|
|
|
* These are stored as regular triangles, plus extra positions and normals at
|
|
|
|
* times other than the frame center. Computing the triangle vertex positions
|
|
|
|
* or normals at a given ray time is a matter of interpolation of the two steps
|
|
|
|
* between which the ray time lies.
|
|
|
|
*
|
|
|
|
* The extra positions and normals are stored as ATTR_STD_MOTION_VERTEX_POSITION
|
|
|
|
* and ATTR_STD_MOTION_VERTEX_NORMAL mesh attributes.
|
|
|
|
*/
|
|
|
|
|
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
|
|
|
#pragma once
|
|
|
|
|
2017-01-17 10:48:56 +01:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2022-01-13 17:12:03 +01:00
|
|
|
/**
|
|
|
|
* Use the barycentric coordinates to get the intersection location
|
2017-01-17 10:48:56 +01:00
|
|
|
*/
|
2022-01-13 17:12:03 +01:00
|
|
|
ccl_device_inline float3 motion_triangle_point_from_uv(KernelGlobals kg,
|
|
|
|
ccl_private ShaderData *sd,
|
|
|
|
const int isect_object,
|
|
|
|
const int isect_prim,
|
|
|
|
const float u,
|
|
|
|
const float v,
|
|
|
|
float3 verts[3])
|
2017-01-17 10:48:56 +01:00
|
|
|
{
|
2022-01-13 17:12:03 +01:00
|
|
|
float w = 1.0f - u - v;
|
|
|
|
float3 P = u * verts[0] + v * verts[1] + w * verts[2];
|
2017-01-17 10:48:56 +01:00
|
|
|
|
2021-02-28 23:23:24 +01:00
|
|
|
if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
|
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 Transform tfm = object_get_transform(kg, sd);
|
2017-01-17 10:48:56 +01:00
|
|
|
P = transform_point(&tfm, P);
|
|
|
|
}
|
|
|
|
|
|
|
|
return P;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ray intersection. We simply compute the vertex positions at the given ray
|
|
|
|
* time and do a ray intersection with the resulting triangle.
|
|
|
|
*/
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool motion_triangle_intersect(KernelGlobals kg,
|
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_private Intersection *isect,
|
2017-03-23 16:16:05 +01:00
|
|
|
float3 P,
|
2017-03-27 17:06:37 +02:00
|
|
|
float3 dir,
|
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 tmax,
|
2017-03-23 16:16:05 +01:00
|
|
|
float time,
|
|
|
|
uint visibility,
|
|
|
|
int object,
|
2022-01-13 17:15:30 +01:00
|
|
|
int prim,
|
2017-03-23 16:16:05 +01:00
|
|
|
int prim_addr)
|
2017-01-17 10:48:56 +01:00
|
|
|
{
|
|
|
|
/* Get vertex locations for intersection. */
|
|
|
|
float3 verts[3];
|
2022-01-13 17:15:30 +01:00
|
|
|
motion_triangle_vertices(kg, object, prim, time, verts);
|
2017-01-17 10:48:56 +01:00
|
|
|
/* Ray-triangle intersection, unoptimized. */
|
|
|
|
float t, u, v;
|
2021-11-22 20:41:19 +01:00
|
|
|
if (ray_triangle_intersect(P, dir, tmax, verts[0], verts[1], verts[2], &u, &v, &t)) {
|
2017-01-17 10:48:56 +01:00
|
|
|
#ifdef __VISIBILITY_FLAG__
|
|
|
|
/* Visibility flag test. we do it here under the assumption
|
|
|
|
* that most triangles are culled by node flags.
|
|
|
|
*/
|
|
|
|
if (kernel_tex_fetch(__prim_visibility, prim_addr) & visibility)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
isect->t = t;
|
|
|
|
isect->u = u;
|
|
|
|
isect->v = v;
|
2021-02-28 23:23:24 +01:00
|
|
|
isect->prim = prim;
|
2022-01-13 17:15:30 +01:00
|
|
|
isect->object = object;
|
2017-01-17 10:48:56 +01:00
|
|
|
isect->type = PRIMITIVE_MOTION_TRIANGLE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-30 20:25:08 +01:00
|
|
|
/* Special ray intersection routines for local intersections. In that case we
|
2017-01-17 10:48:56 +01:00
|
|
|
* only want to intersect with primitives in the same object, and if case of
|
|
|
|
* multiple hits we pick a single random primitive as the intersection point.
|
2018-06-15 11:03:29 +02:00
|
|
|
* Returns whether traversal should be stopped.
|
2017-01-17 10:48:56 +01:00
|
|
|
*/
|
2017-10-30 20:25:08 +01:00
|
|
|
#ifdef __BVH_LOCAL__
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline bool motion_triangle_intersect_local(KernelGlobals kg,
|
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_private LocalIntersection *local_isect,
|
2017-01-17 10:48:56 +01:00
|
|
|
float3 P,
|
2017-03-27 17:06:37 +02:00
|
|
|
float3 dir,
|
2017-01-17 10:48:56 +01:00
|
|
|
float time,
|
|
|
|
int object,
|
2022-01-13 17:15:30 +01:00
|
|
|
int prim,
|
2017-01-17 10:48:56 +01:00
|
|
|
int prim_addr,
|
|
|
|
float tmax,
|
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_private uint *lcg_state,
|
2017-01-17 10:48:56 +01:00
|
|
|
int max_hits)
|
|
|
|
{
|
|
|
|
/* Get vertex locations for intersection. */
|
|
|
|
float3 verts[3];
|
2022-01-13 17:15:30 +01:00
|
|
|
motion_triangle_vertices(kg, object, prim, time, verts);
|
2017-01-17 10:48:56 +01:00
|
|
|
/* Ray-triangle intersection, unoptimized. */
|
|
|
|
float t, u, v;
|
2021-11-22 20:41:19 +01:00
|
|
|
if (!ray_triangle_intersect(P, dir, tmax, verts[0], verts[1], verts[2], &u, &v, &t)) {
|
2018-06-15 11:03:29 +02:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-15 11:03:29 +02:00
|
|
|
/* If no actual hit information is requested, just return here. */
|
|
|
|
if (max_hits == 0) {
|
|
|
|
return true;
|
2018-01-21 14:04:22 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-21 14:04:22 +01:00
|
|
|
int hit;
|
|
|
|
if (lcg_state) {
|
|
|
|
/* Record up to max_hits intersections. */
|
2017-10-30 20:25:08 +01:00
|
|
|
for (int i = min(max_hits, local_isect->num_hits) - 1; i >= 0; --i) {
|
|
|
|
if (local_isect->hits[i].t == t) {
|
2018-06-15 11:03:29 +02:00
|
|
|
return false;
|
2017-01-17 10:48:56 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2017-10-30 20:25:08 +01:00
|
|
|
local_isect->num_hits++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-30 20:25:08 +01:00
|
|
|
if (local_isect->num_hits <= max_hits) {
|
|
|
|
hit = local_isect->num_hits - 1;
|
2017-01-17 10:48:56 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Reservoir sampling: if we are at the maximum number of
|
|
|
|
* hits, randomly replace element or skip it.
|
|
|
|
*/
|
2017-10-30 20:25:08 +01:00
|
|
|
hit = lcg_step_uint(lcg_state) % local_isect->num_hits;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-01-17 10:48:56 +01:00
|
|
|
if (hit >= max_hits)
|
2018-06-15 11:03:29 +02:00
|
|
|
return false;
|
2017-01-17 10:48:56 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2018-01-21 14:04:22 +01:00
|
|
|
else {
|
|
|
|
/* Record closest intersection only. */
|
|
|
|
if (local_isect->num_hits && t > local_isect->hits[0].t) {
|
2018-06-15 11:03:29 +02:00
|
|
|
return false;
|
2018-01-21 14:04:22 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-21 14:04:22 +01:00
|
|
|
hit = 0;
|
|
|
|
local_isect->num_hits = 1;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-21 14:04:22 +01:00
|
|
|
/* Record intersection. */
|
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_private Intersection *isect = &local_isect->hits[hit];
|
2018-01-21 14:04:22 +01:00
|
|
|
isect->t = t;
|
|
|
|
isect->u = u;
|
|
|
|
isect->v = v;
|
2021-02-28 23:23:24 +01:00
|
|
|
isect->prim = prim;
|
2022-01-13 17:15:30 +01:00
|
|
|
isect->object = object;
|
2018-01-21 14:04:22 +01:00
|
|
|
isect->type = PRIMITIVE_MOTION_TRIANGLE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-01-21 14:04:22 +01:00
|
|
|
/* Record geometric normal. */
|
|
|
|
local_isect->Ng[hit] = normalize(cross(verts[1] - verts[0], verts[2] - verts[0]));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-15 11:03:29 +02:00
|
|
|
return false;
|
2017-01-17 10:48:56 +01:00
|
|
|
}
|
2017-10-30 20:25:08 +01:00
|
|
|
#endif /* __BVH_LOCAL__ */
|
2017-01-17 10:48:56 +01:00
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|