Blender  V2.93
geom_attribute.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 /* Attributes
20  *
21  * We support an arbitrary number of attributes on various mesh elements.
22  * On vertices, triangles, curve keys, curves, meshes and volume grids.
23  * Most of the code for attribute reading is in the primitive files.
24  *
25  * Lookup of attributes is different between OSL and SVM, as OSL is ustring
26  * based while for SVM we use integer ids. */
27 
28 ccl_device_inline uint subd_triangle_patch(KernelGlobals *kg, const ShaderData *sd);
29 
31 {
32  if ((sd->type & PRIMITIVE_ALL_TRIANGLE) && subd_triangle_patch(kg, sd) != ~0) {
33  return ATTR_PRIM_SUBD;
34  }
35  else {
36  return ATTR_PRIM_GEOMETRY;
37  }
38 }
39 
41 {
42  const AttributeDescriptor desc = {
44  return desc;
45 }
46 
47 /* Find attribute based on ID */
48 
50 {
51  return kernel_tex_fetch(__objects, object).attribute_map_offset;
52 }
53 
55  const ShaderData *sd,
56  uint id)
57 {
58  if (sd->object == OBJECT_NONE) {
59  return attribute_not_found();
60  }
61 
62  /* for SVM, find attribute by unique id */
63  uint attr_offset = object_attribute_map_offset(kg, sd->object);
64  attr_offset += attribute_primitive_type(kg, sd);
65  uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
66 
67  while (attr_map.x != id) {
68  if (UNLIKELY(attr_map.x == ATTR_STD_NONE)) {
69  if (UNLIKELY(attr_map.y == 0)) {
70  return attribute_not_found();
71  }
72  else {
73  /* Chain jump to a different part of the table. */
74  attr_offset = attr_map.z;
75  }
76  }
77  else {
78  attr_offset += ATTR_PRIM_TYPES;
79  }
80  attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
81  }
82 
84  desc.element = (AttributeElement)attr_map.y;
85 
86  if (sd->prim == PRIM_NONE && desc.element != ATTR_ELEMENT_MESH &&
88  return attribute_not_found();
89  }
90 
91  /* return result */
92  desc.offset = (attr_map.y == ATTR_ELEMENT_NONE) ? (int)ATTR_STD_NOT_FOUND : (int)attr_map.z;
93  desc.type = (NodeAttributeType)(attr_map.w & 0xff);
94  desc.flags = (AttributeFlag)(attr_map.w >> 8);
95 
96  return desc;
97 }
98 
99 /* Transform matrix attribute on meshes */
100 
102  const ShaderData *sd,
103  const AttributeDescriptor desc)
104 {
105  Transform tfm;
106 
107  tfm.x = kernel_tex_fetch(__attributes_float3, desc.offset + 0);
108  tfm.y = kernel_tex_fetch(__attributes_float3, desc.offset + 1);
109  tfm.z = kernel_tex_fetch(__attributes_float3, desc.offset + 2);
110 
111  return tfm;
112 }
113 
unsigned int uint
Definition: BLI_sys_types.h:83
#define UNLIKELY(x)
ccl_device_inline uint object_attribute_map_offset(KernelGlobals *kg, int object)
ccl_device_inline uint attribute_primitive_type(KernelGlobals *kg, const ShaderData *sd)
ccl_device_inline AttributeDescriptor attribute_not_found()
CCL_NAMESPACE_BEGIN ccl_device_inline uint subd_triangle_patch(KernelGlobals *kg, const ShaderData *sd)
ccl_device Transform primitive_attribute_matrix(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc)
ccl_device_inline AttributeDescriptor find_attribute(KernelGlobals *kg, const ShaderData *sd, uint id)
#define kernel_tex_fetch(tex, index)
#define ccl_device
#define ccl_device_inline
#define CCL_NAMESPACE_END
@ PRIMITIVE_ALL_TRIANGLE
Definition: kernel_types.h:697
@ ATTR_STD_NOT_FOUND
Definition: kernel_types.h:773
@ ATTR_STD_NONE
Definition: kernel_types.h:745
#define PRIM_NONE
Definition: kernel_types.h:60
AttributeFlag
Definition: kernel_types.h:776
#define OBJECT_NONE
Definition: kernel_types.h:59
ShaderData
AttributeElement
Definition: kernel_types.h:729
@ ATTR_ELEMENT_NONE
Definition: kernel_types.h:730
@ ATTR_ELEMENT_VOXEL
Definition: kernel_types.h:741
@ ATTR_ELEMENT_OBJECT
Definition: kernel_types.h:731
@ ATTR_ELEMENT_MESH
Definition: kernel_types.h:732
@ ATTR_PRIM_SUBD
Definition: kernel_types.h:724
@ ATTR_PRIM_TYPES
Definition: kernel_types.h:726
@ ATTR_PRIM_GEOMETRY
Definition: kernel_types.h:723
AttributeElement element
Definition: kernel_types.h:782
NodeAttributeType type
Definition: kernel_types.h:783
NodeAttributeType
Definition: svm_types.h:166