2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2014-03-29 13:03:48 +01: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
|
|
|
#pragma once
|
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Attributes
|
|
|
|
|
*
|
|
|
|
|
* We support an arbitrary number of attributes on various mesh elements.
|
|
|
|
|
* On vertices, triangles, curve keys, curves, meshes and volume grids.
|
|
|
|
|
* Most of the code for attribute reading is in the primitive files.
|
|
|
|
|
*
|
|
|
|
|
* Lookup of attributes is different between OSL and SVM, as OSL is ustring
|
|
|
|
|
* based while for SVM we use integer ids. */
|
|
|
|
|
|
2021-11-18 14:25:05 +01:00
|
|
|
/* Patch index for triangle, -1 if not subdivision triangle */
|
|
|
|
|
|
2022-09-09 11:55:35 +02:00
|
|
|
ccl_device_inline uint subd_triangle_patch(KernelGlobals kg, int prim)
|
2021-11-18 14:25:05 +01:00
|
|
|
{
|
2022-09-09 11:55:35 +02:00
|
|
|
return (prim != PRIM_NONE) ? kernel_data_fetch(tri_patch, prim) : ~0;
|
2021-11-18 14:25:05 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2022-09-09 11:55:35 +02:00
|
|
|
ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, int prim, int type)
|
2016-07-16 19:42:28 -04:00
|
|
|
{
|
2022-09-09 11:55:35 +02:00
|
|
|
if ((type & PRIMITIVE_TRIANGLE) && subd_triangle_patch(kg, prim) != ~0) {
|
2016-07-16 19:42:28 -04:00
|
|
|
return ATTR_PRIM_SUBD;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-02-03 21:40:58 +01:00
|
|
|
return ATTR_PRIM_GEOMETRY;
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-01 17:36:27 -04:00
|
|
|
ccl_device_inline AttributeDescriptor attribute_not_found()
|
|
|
|
|
{
|
2016-07-16 22:57:06 -04:00
|
|
|
const AttributeDescriptor desc = {
|
|
|
|
|
ATTR_ELEMENT_NONE, (NodeAttributeType)0, 0, ATTR_STD_NOT_FOUND};
|
2016-07-01 17:36:27 -04:00
|
|
|
return desc;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Find attribute based on ID */
|
|
|
|
|
|
2021-10-17 16:10:10 +02:00
|
|
|
ccl_device_inline uint object_attribute_map_offset(KernelGlobals kg, int object)
|
2017-11-05 17:40:36 +01:00
|
|
|
{
|
2022-06-17 17:16:37 +02:00
|
|
|
return kernel_data_fetch(objects, object).attribute_map_offset;
|
2017-11-05 17:40:36 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 11:55:35 +02:00
|
|
|
ccl_device_inline AttributeDescriptor
|
|
|
|
|
find_attribute(KernelGlobals kg, int object, int prim, int type, uint64_t id)
|
2014-03-29 13:03:48 +01:00
|
|
|
{
|
2022-09-09 11:55:35 +02:00
|
|
|
if (object == OBJECT_NONE) {
|
2016-07-01 17:36:27 -04:00
|
|
|
return attribute_not_found();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* for SVM, find attribute by unique id */
|
2022-09-09 11:55:35 +02:00
|
|
|
uint attr_offset = object_attribute_map_offset(kg, object);
|
|
|
|
|
attr_offset += attribute_primitive_type(kg, prim, type);
|
2022-06-17 17:16:37 +02:00
|
|
|
AttributeMap attr_map = kernel_data_fetch(attributes_map, attr_offset);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-06-16 19:02:55 +02:00
|
|
|
while (attr_map.id != id) {
|
|
|
|
|
if (UNLIKELY(attr_map.id == ATTR_STD_NONE)) {
|
|
|
|
|
if (UNLIKELY(attr_map.element == 0)) {
|
2020-10-26 15:37:07 +01:00
|
|
|
return attribute_not_found();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Chain jump to a different part of the table. */
|
2022-06-16 19:02:55 +02:00
|
|
|
attr_offset = attr_map.offset;
|
2020-10-26 15:37:07 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attr_offset += ATTR_PRIM_TYPES;
|
2015-01-31 14:39:19 +05:00
|
|
|
}
|
2022-06-17 17:16:37 +02:00
|
|
|
attr_map = kernel_data_fetch(attributes_map, attr_offset);
|
2014-03-29 13:03:48 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-01 17:36:27 -04:00
|
|
|
AttributeDescriptor desc;
|
2022-06-16 19:02:55 +02:00
|
|
|
desc.element = (AttributeElement)attr_map.element;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-09 11:55:35 +02:00
|
|
|
if (prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH &&
|
2016-08-17 10:33:28 -04:00
|
|
|
desc.element != ATTR_ELEMENT_VOXEL && desc.element != ATTR_ELEMENT_OBJECT)
|
|
|
|
|
{
|
2016-07-01 17:36:27 -04:00
|
|
|
return attribute_not_found();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* return result */
|
2022-06-16 19:02:55 +02:00
|
|
|
desc.offset = (attr_map.element == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND :
|
|
|
|
|
(int)attr_map.offset;
|
|
|
|
|
desc.type = (NodeAttributeType)attr_map.type;
|
|
|
|
|
desc.flags = (AttributeFlag)attr_map.flags;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-07-01 17:36:27 -04:00
|
|
|
return desc;
|
2014-03-29 13:03:48 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-09 11:55:35 +02:00
|
|
|
ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals kg,
|
|
|
|
|
ccl_private const ShaderData *sd,
|
|
|
|
|
uint64_t id)
|
|
|
|
|
{
|
|
|
|
|
return find_attribute(kg, sd->object, sd->prim, sd->type, id);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
/* Transform matrix attribute on meshes */
|
|
|
|
|
|
2022-09-09 11:55:35 +02:00
|
|
|
ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, const AttributeDescriptor desc)
|
2014-03-29 13:03:48 +01:00
|
|
|
{
|
|
|
|
|
Transform tfm;
|
|
|
|
|
|
2022-06-17 17:16:37 +02:00
|
|
|
tfm.x = kernel_data_fetch(attributes_float4, desc.offset + 0);
|
|
|
|
|
tfm.y = kernel_data_fetch(attributes_float4, desc.offset + 1);
|
|
|
|
|
tfm.z = kernel_data_fetch(attributes_float4, desc.offset + 2);
|
2014-03-29 13:03:48 +01:00
|
|
|
|
|
|
|
|
return tfm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|