Blender V4.3
scene/attribute.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __ATTRIBUTE_H__
6#define __ATTRIBUTE_H__
7
8#include "scene/image.h"
9
10#include "kernel/types.h"
11
12#include "util/list.h"
13#include "util/param.h"
14#include "util/set.h"
15#include "util/types.h"
16#include "util/vector.h"
17
19
20class Attribute;
23class AttributeSet;
24class ImageHandle;
25class Geometry;
26class Hair;
27class Mesh;
28struct Transform;
29
30/* AttrKernelDataType.
31 *
32 * The data type of the device arrays storing the attribute's data. Those data types are different
33 * than the ones for attributes as some attribute types are stored in the same array, e.g. Point,
34 * Vector, and Transform are all stored as float3 in the kernel.
35 *
36 * The values of this enumeration are also used as flags to detect changes in AttributeSet. */
37
38enum AttrKernelDataType { FLOAT = 0, FLOAT2 = 1, FLOAT3 = 2, FLOAT4 = 3, UCHAR4 = 4, NUM = 5 };
39
40/* Attribute
41 *
42 * Arbitrary data layers on meshes.
43 * Supported types: Float, Color, Vector, Normal, Point */
44
45class Attribute {
46 public:
47 ustring name;
49
53 uint flags; /* enum AttributeFlag */
54
56
57 Attribute(ustring name,
58 TypeDesc type,
59 AttributeElement element,
60 Geometry *geom,
62 Attribute(Attribute &&other) = default;
63 Attribute(const Attribute &other) = delete;
64 Attribute &operator=(const Attribute &other) = delete;
65 ~Attribute();
66
67 void set(ustring name, TypeDesc type, AttributeElement element);
68 void resize(Geometry *geom, AttributePrimitive prim, bool reserve_only);
69 void resize(size_t num_elements);
70
71 size_t data_sizeof() const;
72 size_t element_size(Geometry *geom, AttributePrimitive prim) const;
73 size_t buffer_size(Geometry *geom, AttributePrimitive prim) const;
74
75 char *data()
76 {
77 return (buffer.size()) ? &buffer[0] : NULL;
78 }
80 {
81 assert(data_sizeof() == sizeof(float2));
82 return (float2 *)data();
83 }
85 {
86 assert(data_sizeof() == sizeof(float3));
87 return (float3 *)data();
88 }
89 float4 *data_float4()
90 {
91 assert(data_sizeof() == sizeof(float4));
92 return (float4 *)data();
93 }
94 float *data_float()
95 {
96 assert(data_sizeof() == sizeof(float));
97 return (float *)data();
98 }
100 {
101 assert(data_sizeof() == sizeof(uchar4));
102 return (uchar4 *)data();
103 }
105 {
106 assert(data_sizeof() == sizeof(Transform));
107 return (Transform *)data();
108 }
109
110 /* Attributes for voxels are images */
112 {
113 assert(data_sizeof() == sizeof(ImageHandle));
114 return *(ImageHandle *)data();
115 }
116
117 const char *data() const
118 {
119 return (buffer.size()) ? &buffer[0] : NULL;
120 }
121 const float2 *data_float2() const
122 {
123 assert(data_sizeof() == sizeof(float2));
124 return (const float2 *)data();
125 }
126 const float3 *data_float3() const
127 {
128 assert(data_sizeof() == sizeof(float3));
129 return (const float3 *)data();
130 }
131 const float4 *data_float4() const
132 {
133 assert(data_sizeof() == sizeof(float4));
134 return (const float4 *)data();
135 }
136 const float *data_float() const
137 {
138 assert(data_sizeof() == sizeof(float));
139 return (const float *)data();
140 }
142 {
143 assert(data_sizeof() == sizeof(Transform));
144 return (const Transform *)data();
145 }
146 const ImageHandle &data_voxel() const
147 {
148 assert(data_sizeof() == sizeof(ImageHandle));
149 return *(const ImageHandle *)data();
150 }
151
152 void zero_data(void *dst);
153 void add_with_weight(void *dst, void *src, float weight);
154
155 void add(const float &f);
156 void add(const float2 &f);
157 void add(const float3 &f);
158 void add(const uchar4 &f);
159 void add(const Transform &tfm);
160 void add(const char *data);
161
162 void set_data_from(Attribute &&other);
163
164 static bool same_storage(TypeDesc a, TypeDesc b);
165 static const char *standard_name(AttributeStandard std);
166 static AttributeStandard name_standard(const char *name);
167
168 static AttrKernelDataType kernel_type(const Attribute &attr);
169
170 void get_uv_tiles(Geometry *geom, AttributePrimitive prim, unordered_set<int> &tiles) const;
171};
172
173/* Attribute Set
174 *
175 * Set of attributes on a mesh. */
176
178 uint32_t modified_flag;
179
180 public:
183 list<Attribute> attributes;
184
188
189 Attribute *add(ustring name, TypeDesc type, AttributeElement element);
190 Attribute *find(ustring name) const;
191 void remove(ustring name);
192
193 Attribute *add(AttributeStandard std, ustring name = ustring());
194 Attribute *find(AttributeStandard std) const;
195 void remove(AttributeStandard std);
196
198 Attribute *find_matching(const Attribute &other);
199
200 void remove(Attribute *attribute);
201
202 void remove(list<Attribute>::iterator it);
203
204 void resize(bool reserve_only = false);
205 void clear(bool preserve_voxel_data = false);
206
207 /* Update the attributes in this AttributeSet with the ones from the new set,
208 * and remove any attribute not found on the new set from this. */
209 void update(AttributeSet &&new_attributes);
210
211 /* Return whether the attributes of the given kernel_type are modified, where "modified" means
212 * that some attributes of the given type were added or removed from this AttributeSet. This does
213 * not mean that the data of the remaining attributes in this AttributeSet were also modified. To
214 * check this, use Attribute.modified. */
215 bool modified(AttrKernelDataType kernel_type) const;
216
217 void clear_modified();
218
219 private:
220 /* Set the relevant modified flag for the attribute. Only attributes that are stored in device
221 * arrays will be considered for tagging this AttributeSet as modified. */
222 void tag_modified(const Attribute &attr);
223};
224
225/* AttributeRequest
226 *
227 * Request from a shader to use a certain attribute, so we can figure out
228 * which ones we need to export from the host app end store for the kernel.
229 * The attribute is found either by name or by standard attribute type. */
230
232 public:
233 ustring name;
235
236 /* temporary variables used by GeometryManager */
239
240 explicit AttributeRequest(ustring name_);
242};
243
244/* AttributeRequestSet
245 *
246 * Set of attributes requested by a shader. */
247
249 public:
251
254
255 void add(ustring name);
256 void add(AttributeStandard std);
257 void add(AttributeRequestSet &reqs);
258 void add_standard(ustring name);
259
260 bool find(ustring name);
261 bool find(AttributeStandard std);
262
263 size_t size();
264 void clear();
265
266 bool modified(const AttributeRequestSet &other);
267};
268
270
271#endif /* __ATTRIBUTE_H__ */
unsigned int uint
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a or normal between and object coordinate space Combine Create a color from its and value channels Color Attribute
vector< AttributeRequest > requests
bool find(ustring name)
void add(ustring name)
bool modified(const AttributeRequestSet &other)
void add_standard(ustring name)
AttributeRequest(ustring name_)
AttributeDescriptor subd_desc
AttributeDescriptor desc
AttributeStandard std
Geometry * geometry
Attribute * add(ustring name, TypeDesc type, AttributeElement element)
void update(AttributeSet &&new_attributes)
AttributeSet(AttributeSet &&)=default
list< Attribute > attributes
Attribute * find(ustring name) const
Attribute * find_matching(const Attribute &other)
bool modified(AttrKernelDataType kernel_type) const
void remove(ustring name)
AttributeSet(Geometry *geometry, AttributePrimitive prim)
void resize(bool reserve_only=false)
void clear(bool preserve_voxel_data=false)
AttributePrimitive prim
AttributeElement element
uchar4 * data_uchar4()
static bool same_storage(TypeDesc a, TypeDesc b)
void add_with_weight(void *dst, void *src, float weight)
static AttrKernelDataType kernel_type(const Attribute &attr)
char * data()
void set(ustring name, TypeDesc type, AttributeElement element)
static AttributeStandard name_standard(const char *name)
const ImageHandle & data_voxel() const
Attribute(const Attribute &other)=delete
TypeDesc type
const float4 * data_float4() const
void resize(Geometry *geom, AttributePrimitive prim, bool reserve_only)
size_t element_size(Geometry *geom, AttributePrimitive prim) const
void get_uv_tiles(Geometry *geom, AttributePrimitive prim, unordered_set< int > &tiles) const
const float3 * data_float3() const
vector< char > buffer
const float2 * data_float2() const
void set_data_from(Attribute &&other)
const float * data_float() const
Attribute & operator=(const Attribute &other)=delete
void zero_data(void *dst)
static const char * standard_name(AttributeStandard std)
Attribute(Attribute &&other)=default
const Transform * data_transform() const
float * data_float()
const char * data() const
size_t buffer_size(Geometry *geom, AttributePrimitive prim) const
AttributeStandard std
ImageHandle & data_voxel()
size_t data_sizeof() const
float3 * data_float3()
float4 * data_float4()
Transform * data_transform()
void add(const float &f)
float2 * data_float2()
Definition hair.h:14
local_group_size(16, 16) .push_constant(Type b
#define CCL_NAMESPACE_END
#define NULL
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
AttributeStandard
AttributeElement
AttributePrimitive
AttrKernelDataType
@ FLOAT4
@ NUM
@ FLOAT2
@ UCHAR4
@ FLOAT3
@ FLOAT
long long TypeDesc
unsigned int uint32_t
Definition stdint.h:80