Blender  V2.93
blender_shader.cpp
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 
17 #include "render/background.h"
18 #include "render/colorspace.h"
19 #include "render/graph.h"
20 #include "render/light.h"
21 #include "render/nodes.h"
22 #include "render/osl.h"
23 #include "render/scene.h"
24 #include "render/shader.h"
25 
26 #include "blender/blender_image.h"
27 #include "blender/blender_sync.h"
29 #include "blender/blender_util.h"
30 
31 #include "util/util_debug.h"
32 #include "util/util_foreach.h"
33 #include "util/util_set.h"
34 #include "util/util_string.h"
35 #include "util/util_task.h"
36 
38 
39 typedef map<void *, ShaderInput *> PtrInputMap;
40 typedef map<void *, ShaderOutput *> PtrOutputMap;
41 typedef map<string, ConvertNode *> ProxyMap;
42 
43 /* Find */
44 
45 void BlenderSync::find_shader(BL::ID &id, array<Node *> &used_shaders, Shader *default_shader)
46 {
47  Shader *shader = (id) ? shader_map.find(id) : default_shader;
48 
49  used_shaders.push_back_slow(shader);
50  shader->tag_used(scene);
51 }
52 
53 /* RNA translation utilities */
54 
56 {
57  return (VolumeSampling)get_enum(
58  ptr, "volume_sampling", VOLUME_NUM_SAMPLING, VOLUME_SAMPLING_DISTANCE);
59 }
60 
62 {
64  ptr, "volume_interpolation", VOLUME_NUM_INTERPOLATION, VOLUME_INTERPOLATION_LINEAR);
65 }
66 
68 {
70  ptr, "displacement_method", DISPLACE_NUM_METHODS, DISPLACE_BUMP);
71 }
72 
73 static int validate_enum_value(int value, int num_values, int default_value)
74 {
75  if (value >= num_values) {
76  return default_value;
77  }
78  return value;
79 }
80 
81 template<typename NodeType> static InterpolationType get_image_interpolation(NodeType &b_node)
82 {
83  int value = b_node.interpolation();
86 }
87 
88 template<typename NodeType> static ExtensionType get_image_extension(NodeType &b_node)
89 {
90  int value = b_node.extension();
92 }
93 
95 {
96  int value = b_image.alpha_mode();
98 }
99 
100 /* Attribute name translation utilities */
101 
102 /* Since Eevee needs to know whether the attribute is uniform or varying
103  * at the time it compiles the shader for the material, Blender had to
104  * introduce different namespaces (types) in its attribute node. However,
105  * Cycles already has object attributes that form a uniform namespace with
106  * the more common varying attributes. Without completely reworking the
107  * attribute handling in Cycles to introduce separate namespaces (this could
108  * be especially hard for OSL which directly uses the name string), the
109  * space identifier has to be added to the attribute name as a prefix.
110  *
111  * The prefixes include a control character to ensure the user specified
112  * name can't accidentally include a special prefix.
113  */
114 
115 static const string_view object_attr_prefix("\x01object:");
116 static const string_view instancer_attr_prefix("\x01instancer:");
117 
118 static ustring blender_attribute_name_add_type(const string &name, BlenderAttributeType type)
119 {
120  switch (type) {
121  case BL::ShaderNodeAttribute::attribute_type_OBJECT:
122  return ustring::concat(object_attr_prefix, name);
123  case BL::ShaderNodeAttribute::attribute_type_INSTANCER:
124  return ustring::concat(instancer_attr_prefix, name);
125  default:
126  return ustring(name);
127  }
128 }
129 
130 BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_real_name)
131 {
132  string_view sname(name);
133 
134  if (sname.substr(0, object_attr_prefix.size()) == object_attr_prefix) {
135  *r_real_name = sname.substr(object_attr_prefix.size());
136  return BL::ShaderNodeAttribute::attribute_type_OBJECT;
137  }
138 
139  if (sname.substr(0, instancer_attr_prefix.size()) == instancer_attr_prefix) {
140  *r_real_name = sname.substr(instancer_attr_prefix.size());
141  return BL::ShaderNodeAttribute::attribute_type_INSTANCER;
142  }
143 
144  return BL::ShaderNodeAttribute::attribute_type_GEOMETRY;
145 }
146 
147 /* Graph */
148 
149 static BL::NodeSocket get_node_output(BL::Node &b_node, const string &name)
150 {
151  for (BL::NodeSocket &b_out : b_node.outputs) {
152  if (b_out.name() == name) {
153  return b_out;
154  }
155  }
156  assert(0);
157  return *b_node.outputs.begin();
158 }
159 
160 static float3 get_node_output_rgba(BL::Node &b_node, const string &name)
161 {
162  BL::NodeSocket b_sock = get_node_output(b_node, name);
163  float value[4];
164  RNA_float_get_array(&b_sock.ptr, "default_value", value);
165  return make_float3(value[0], value[1], value[2]);
166 }
167 
168 static float get_node_output_value(BL::Node &b_node, const string &name)
169 {
170  BL::NodeSocket b_sock = get_node_output(b_node, name);
171  return RNA_float_get(&b_sock.ptr, "default_value");
172 }
173 
174 static float3 get_node_output_vector(BL::Node &b_node, const string &name)
175 {
176  BL::NodeSocket b_sock = get_node_output(b_node, name);
177  float value[3];
178  RNA_float_get_array(&b_sock.ptr, "default_value", value);
179  return make_float3(value[0], value[1], value[2]);
180 }
181 
182 static SocketType::Type convert_socket_type(BL::NodeSocket &b_socket)
183 {
184  switch (b_socket.type()) {
185  case BL::NodeSocket::type_VALUE:
186  return SocketType::FLOAT;
187  case BL::NodeSocket::type_INT:
188  return SocketType::INT;
189  case BL::NodeSocket::type_VECTOR:
190  return SocketType::VECTOR;
191  case BL::NodeSocket::type_RGBA:
192  return SocketType::COLOR;
193  case BL::NodeSocket::type_STRING:
194  return SocketType::STRING;
195  case BL::NodeSocket::type_SHADER:
196  return SocketType::CLOSURE;
197 
198  default:
199  return SocketType::UNDEFINED;
200  }
201 }
202 
203 static void set_default_value(ShaderInput *input,
204  BL::NodeSocket &b_sock,
205  BL::BlendData &b_data,
206  BL::ID &b_id)
207 {
208  Node *node = input->parent;
209  const SocketType &socket = input->socket_type;
210 
211  /* copy values for non linked inputs */
212  switch (input->type()) {
213  case SocketType::FLOAT: {
214  node->set(socket, get_float(b_sock.ptr, "default_value"));
215  break;
216  }
217  case SocketType::INT: {
218  node->set(socket, get_int(b_sock.ptr, "default_value"));
219  break;
220  }
221  case SocketType::COLOR: {
222  node->set(socket, float4_to_float3(get_float4(b_sock.ptr, "default_value")));
223  break;
224  }
225  case SocketType::NORMAL:
226  case SocketType::POINT:
227  case SocketType::VECTOR: {
228  node->set(socket, get_float3(b_sock.ptr, "default_value"));
229  break;
230  }
231  case SocketType::STRING: {
232  node->set(
233  socket,
234  (ustring)blender_absolute_path(b_data, b_id, get_string(b_sock.ptr, "default_value")));
235  break;
236  }
237  default:
238  break;
239  }
240 }
241 
242 static void get_tex_mapping(TextureNode *mapping, BL::TexMapping &b_mapping)
243 {
244  if (!b_mapping)
245  return;
246 
247  mapping->set_tex_mapping_translation(get_float3(b_mapping.translation()));
248  mapping->set_tex_mapping_rotation(get_float3(b_mapping.rotation()));
249  mapping->set_tex_mapping_scale(get_float3(b_mapping.scale()));
250  mapping->set_tex_mapping_type((TextureMapping::Type)b_mapping.vector_type());
251 
252  mapping->set_tex_mapping_x_mapping((TextureMapping::Mapping)b_mapping.mapping_x());
253  mapping->set_tex_mapping_y_mapping((TextureMapping::Mapping)b_mapping.mapping_y());
254  mapping->set_tex_mapping_z_mapping((TextureMapping::Mapping)b_mapping.mapping_z());
255 }
256 
258  BL::RenderEngine &b_engine,
259  BL::BlendData &b_data,
260  BL::Depsgraph &b_depsgraph,
261  BL::Scene &b_scene,
263  BL::ShaderNodeTree &b_ntree,
264  BL::ShaderNode &b_node)
265 {
266  ShaderNode *node = NULL;
267 
268  /* existing blender nodes */
269  if (b_node.is_a(&RNA_ShaderNodeRGBCurve)) {
270  BL::ShaderNodeRGBCurve b_curve_node(b_node);
271  BL::CurveMapping mapping(b_curve_node.mapping());
272  RGBCurvesNode *curves = graph->create_node<RGBCurvesNode>();
273  array<float3> curve_mapping_curves;
274  float min_x, max_x;
275  curvemapping_color_to_array(mapping, curve_mapping_curves, RAMP_TABLE_SIZE, true);
276  curvemapping_minmax(mapping, true, &min_x, &max_x);
277  curves->set_min_x(min_x);
278  curves->set_max_x(max_x);
279  curves->set_curves(curve_mapping_curves);
280  node = curves;
281  }
282  if (b_node.is_a(&RNA_ShaderNodeVectorCurve)) {
283  BL::ShaderNodeVectorCurve b_curve_node(b_node);
284  BL::CurveMapping mapping(b_curve_node.mapping());
285  VectorCurvesNode *curves = graph->create_node<VectorCurvesNode>();
286  array<float3> curve_mapping_curves;
287  float min_x, max_x;
288  curvemapping_color_to_array(mapping, curve_mapping_curves, RAMP_TABLE_SIZE, false);
289  curvemapping_minmax(mapping, false, &min_x, &max_x);
290  curves->set_min_x(min_x);
291  curves->set_max_x(max_x);
292  curves->set_curves(curve_mapping_curves);
293  node = curves;
294  }
295  else if (b_node.is_a(&RNA_ShaderNodeValToRGB)) {
296  RGBRampNode *ramp = graph->create_node<RGBRampNode>();
297  BL::ShaderNodeValToRGB b_ramp_node(b_node);
298  BL::ColorRamp b_color_ramp(b_ramp_node.color_ramp());
299  array<float3> ramp_values;
300  array<float> ramp_alpha;
301  colorramp_to_array(b_color_ramp, ramp_values, ramp_alpha, RAMP_TABLE_SIZE);
302  ramp->set_ramp(ramp_values);
303  ramp->set_ramp_alpha(ramp_alpha);
304  ramp->set_interpolate(b_color_ramp.interpolation() != BL::ColorRamp::interpolation_CONSTANT);
305  node = ramp;
306  }
307  else if (b_node.is_a(&RNA_ShaderNodeRGB)) {
308  ColorNode *color = graph->create_node<ColorNode>();
309  color->set_value(get_node_output_rgba(b_node, "Color"));
310  node = color;
311  }
312  else if (b_node.is_a(&RNA_ShaderNodeValue)) {
313  ValueNode *value = graph->create_node<ValueNode>();
314  value->set_value(get_node_output_value(b_node, "Value"));
315  node = value;
316  }
317  else if (b_node.is_a(&RNA_ShaderNodeCameraData)) {
318  node = graph->create_node<CameraNode>();
319  }
320  else if (b_node.is_a(&RNA_ShaderNodeInvert)) {
321  node = graph->create_node<InvertNode>();
322  }
323  else if (b_node.is_a(&RNA_ShaderNodeGamma)) {
324  node = graph->create_node<GammaNode>();
325  }
326  else if (b_node.is_a(&RNA_ShaderNodeBrightContrast)) {
327  node = graph->create_node<BrightContrastNode>();
328  }
329  else if (b_node.is_a(&RNA_ShaderNodeMixRGB)) {
330  BL::ShaderNodeMixRGB b_mix_node(b_node);
331  MixNode *mix = graph->create_node<MixNode>();
332  mix->set_mix_type((NodeMix)b_mix_node.blend_type());
333  mix->set_use_clamp(b_mix_node.use_clamp());
334  node = mix;
335  }
336  else if (b_node.is_a(&RNA_ShaderNodeSeparateRGB)) {
337  node = graph->create_node<SeparateRGBNode>();
338  }
339  else if (b_node.is_a(&RNA_ShaderNodeCombineRGB)) {
340  node = graph->create_node<CombineRGBNode>();
341  }
342  else if (b_node.is_a(&RNA_ShaderNodeSeparateHSV)) {
343  node = graph->create_node<SeparateHSVNode>();
344  }
345  else if (b_node.is_a(&RNA_ShaderNodeCombineHSV)) {
346  node = graph->create_node<CombineHSVNode>();
347  }
348  else if (b_node.is_a(&RNA_ShaderNodeSeparateXYZ)) {
349  node = graph->create_node<SeparateXYZNode>();
350  }
351  else if (b_node.is_a(&RNA_ShaderNodeCombineXYZ)) {
352  node = graph->create_node<CombineXYZNode>();
353  }
354  else if (b_node.is_a(&RNA_ShaderNodeHueSaturation)) {
355  node = graph->create_node<HSVNode>();
356  }
357  else if (b_node.is_a(&RNA_ShaderNodeRGBToBW)) {
358  node = graph->create_node<RGBToBWNode>();
359  }
360  else if (b_node.is_a(&RNA_ShaderNodeMapRange)) {
361  BL::ShaderNodeMapRange b_map_range_node(b_node);
362  MapRangeNode *map_range_node = graph->create_node<MapRangeNode>();
363  map_range_node->set_clamp(b_map_range_node.clamp());
364  map_range_node->set_range_type((NodeMapRangeType)b_map_range_node.interpolation_type());
365  node = map_range_node;
366  }
367  else if (b_node.is_a(&RNA_ShaderNodeClamp)) {
368  BL::ShaderNodeClamp b_clamp_node(b_node);
369  ClampNode *clamp_node = graph->create_node<ClampNode>();
370  clamp_node->set_clamp_type((NodeClampType)b_clamp_node.clamp_type());
371  node = clamp_node;
372  }
373  else if (b_node.is_a(&RNA_ShaderNodeMath)) {
374  BL::ShaderNodeMath b_math_node(b_node);
375  MathNode *math_node = graph->create_node<MathNode>();
376  math_node->set_math_type((NodeMathType)b_math_node.operation());
377  math_node->set_use_clamp(b_math_node.use_clamp());
378  node = math_node;
379  }
380  else if (b_node.is_a(&RNA_ShaderNodeVectorMath)) {
381  BL::ShaderNodeVectorMath b_vector_math_node(b_node);
382  VectorMathNode *vector_math_node = graph->create_node<VectorMathNode>();
383  vector_math_node->set_math_type((NodeVectorMathType)b_vector_math_node.operation());
384  node = vector_math_node;
385  }
386  else if (b_node.is_a(&RNA_ShaderNodeVectorRotate)) {
387  BL::ShaderNodeVectorRotate b_vector_rotate_node(b_node);
388  VectorRotateNode *vector_rotate_node = graph->create_node<VectorRotateNode>();
389  vector_rotate_node->set_rotate_type(
390  (NodeVectorRotateType)b_vector_rotate_node.rotation_type());
391  vector_rotate_node->set_invert(b_vector_rotate_node.invert());
392  node = vector_rotate_node;
393  }
394  else if (b_node.is_a(&RNA_ShaderNodeVectorTransform)) {
395  BL::ShaderNodeVectorTransform b_vector_transform_node(b_node);
396  VectorTransformNode *vtransform = graph->create_node<VectorTransformNode>();
397  vtransform->set_transform_type((NodeVectorTransformType)b_vector_transform_node.vector_type());
398  vtransform->set_convert_from(
399  (NodeVectorTransformConvertSpace)b_vector_transform_node.convert_from());
400  vtransform->set_convert_to(
401  (NodeVectorTransformConvertSpace)b_vector_transform_node.convert_to());
402  node = vtransform;
403  }
404  else if (b_node.is_a(&RNA_ShaderNodeNormal)) {
405  BL::Node::outputs_iterator out_it;
406  b_node.outputs.begin(out_it);
407 
408  NormalNode *norm = graph->create_node<NormalNode>();
409  norm->set_direction(get_node_output_vector(b_node, "Normal"));
410  node = norm;
411  }
412  else if (b_node.is_a(&RNA_ShaderNodeMapping)) {
413  BL::ShaderNodeMapping b_mapping_node(b_node);
414  MappingNode *mapping = graph->create_node<MappingNode>();
415  mapping->set_mapping_type((NodeMappingType)b_mapping_node.vector_type());
416  node = mapping;
417  }
418  else if (b_node.is_a(&RNA_ShaderNodeFresnel)) {
419  node = graph->create_node<FresnelNode>();
420  }
421  else if (b_node.is_a(&RNA_ShaderNodeLayerWeight)) {
422  node = graph->create_node<LayerWeightNode>();
423  }
424  else if (b_node.is_a(&RNA_ShaderNodeAddShader)) {
425  node = graph->create_node<AddClosureNode>();
426  }
427  else if (b_node.is_a(&RNA_ShaderNodeMixShader)) {
428  node = graph->create_node<MixClosureNode>();
429  }
430  else if (b_node.is_a(&RNA_ShaderNodeAttribute)) {
431  BL::ShaderNodeAttribute b_attr_node(b_node);
432  AttributeNode *attr = graph->create_node<AttributeNode>();
433  attr->set_attribute(blender_attribute_name_add_type(b_attr_node.attribute_name(),
434  b_attr_node.attribute_type()));
435  node = attr;
436  }
437  else if (b_node.is_a(&RNA_ShaderNodeBackground)) {
438  node = graph->create_node<BackgroundNode>();
439  }
440  else if (b_node.is_a(&RNA_ShaderNodeHoldout)) {
441  node = graph->create_node<HoldoutNode>();
442  }
443  else if (b_node.is_a(&RNA_ShaderNodeBsdfAnisotropic)) {
444  BL::ShaderNodeBsdfAnisotropic b_aniso_node(b_node);
445  AnisotropicBsdfNode *aniso = graph->create_node<AnisotropicBsdfNode>();
446 
447  switch (b_aniso_node.distribution()) {
448  case BL::ShaderNodeBsdfAnisotropic::distribution_BECKMANN:
449  aniso->set_distribution(CLOSURE_BSDF_MICROFACET_BECKMANN_ID);
450  break;
451  case BL::ShaderNodeBsdfAnisotropic::distribution_GGX:
452  aniso->set_distribution(CLOSURE_BSDF_MICROFACET_GGX_ID);
453  break;
454  case BL::ShaderNodeBsdfAnisotropic::distribution_MULTI_GGX:
455  aniso->set_distribution(CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID);
456  break;
457  case BL::ShaderNodeBsdfAnisotropic::distribution_ASHIKHMIN_SHIRLEY:
458  aniso->set_distribution(CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID);
459  break;
460  }
461 
462  node = aniso;
463  }
464  else if (b_node.is_a(&RNA_ShaderNodeBsdfDiffuse)) {
465  node = graph->create_node<DiffuseBsdfNode>();
466  }
467  else if (b_node.is_a(&RNA_ShaderNodeSubsurfaceScattering)) {
468  BL::ShaderNodeSubsurfaceScattering b_subsurface_node(b_node);
469 
470  SubsurfaceScatteringNode *subsurface = graph->create_node<SubsurfaceScatteringNode>();
471 
472  switch (b_subsurface_node.falloff()) {
473  case BL::ShaderNodeSubsurfaceScattering::falloff_CUBIC:
474  subsurface->set_falloff(CLOSURE_BSSRDF_CUBIC_ID);
475  break;
476  case BL::ShaderNodeSubsurfaceScattering::falloff_GAUSSIAN:
477  subsurface->set_falloff(CLOSURE_BSSRDF_GAUSSIAN_ID);
478  break;
479  case BL::ShaderNodeSubsurfaceScattering::falloff_BURLEY:
480  subsurface->set_falloff(CLOSURE_BSSRDF_BURLEY_ID);
481  break;
482  case BL::ShaderNodeSubsurfaceScattering::falloff_RANDOM_WALK:
483  subsurface->set_falloff(CLOSURE_BSSRDF_RANDOM_WALK_ID);
484  break;
485  }
486 
487  node = subsurface;
488  }
489  else if (b_node.is_a(&RNA_ShaderNodeBsdfGlossy)) {
490  BL::ShaderNodeBsdfGlossy b_glossy_node(b_node);
491  GlossyBsdfNode *glossy = graph->create_node<GlossyBsdfNode>();
492 
493  switch (b_glossy_node.distribution()) {
494  case BL::ShaderNodeBsdfGlossy::distribution_SHARP:
495  glossy->set_distribution(CLOSURE_BSDF_REFLECTION_ID);
496  break;
497  case BL::ShaderNodeBsdfGlossy::distribution_BECKMANN:
498  glossy->set_distribution(CLOSURE_BSDF_MICROFACET_BECKMANN_ID);
499  break;
500  case BL::ShaderNodeBsdfGlossy::distribution_GGX:
501  glossy->set_distribution(CLOSURE_BSDF_MICROFACET_GGX_ID);
502  break;
503  case BL::ShaderNodeBsdfGlossy::distribution_ASHIKHMIN_SHIRLEY:
504  glossy->set_distribution(CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID);
505  break;
506  case BL::ShaderNodeBsdfGlossy::distribution_MULTI_GGX:
507  glossy->set_distribution(CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID);
508  break;
509  }
510  node = glossy;
511  }
512  else if (b_node.is_a(&RNA_ShaderNodeBsdfGlass)) {
513  BL::ShaderNodeBsdfGlass b_glass_node(b_node);
514  GlassBsdfNode *glass = graph->create_node<GlassBsdfNode>();
515  switch (b_glass_node.distribution()) {
516  case BL::ShaderNodeBsdfGlass::distribution_SHARP:
517  glass->set_distribution(CLOSURE_BSDF_SHARP_GLASS_ID);
518  break;
519  case BL::ShaderNodeBsdfGlass::distribution_BECKMANN:
520  glass->set_distribution(CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID);
521  break;
522  case BL::ShaderNodeBsdfGlass::distribution_GGX:
523  glass->set_distribution(CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
524  break;
525  case BL::ShaderNodeBsdfGlass::distribution_MULTI_GGX:
526  glass->set_distribution(CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
527  break;
528  }
529  node = glass;
530  }
531  else if (b_node.is_a(&RNA_ShaderNodeBsdfRefraction)) {
532  BL::ShaderNodeBsdfRefraction b_refraction_node(b_node);
533  RefractionBsdfNode *refraction = graph->create_node<RefractionBsdfNode>();
534  switch (b_refraction_node.distribution()) {
535  case BL::ShaderNodeBsdfRefraction::distribution_SHARP:
536  refraction->set_distribution(CLOSURE_BSDF_REFRACTION_ID);
537  break;
538  case BL::ShaderNodeBsdfRefraction::distribution_BECKMANN:
539  refraction->set_distribution(CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID);
540  break;
541  case BL::ShaderNodeBsdfRefraction::distribution_GGX:
542  refraction->set_distribution(CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID);
543  break;
544  }
545  node = refraction;
546  }
547  else if (b_node.is_a(&RNA_ShaderNodeBsdfToon)) {
548  BL::ShaderNodeBsdfToon b_toon_node(b_node);
549  ToonBsdfNode *toon = graph->create_node<ToonBsdfNode>();
550  switch (b_toon_node.component()) {
551  case BL::ShaderNodeBsdfToon::component_DIFFUSE:
552  toon->set_component(CLOSURE_BSDF_DIFFUSE_TOON_ID);
553  break;
554  case BL::ShaderNodeBsdfToon::component_GLOSSY:
555  toon->set_component(CLOSURE_BSDF_GLOSSY_TOON_ID);
556  break;
557  }
558  node = toon;
559  }
560  else if (b_node.is_a(&RNA_ShaderNodeBsdfHair)) {
561  BL::ShaderNodeBsdfHair b_hair_node(b_node);
562  HairBsdfNode *hair = graph->create_node<HairBsdfNode>();
563  switch (b_hair_node.component()) {
564  case BL::ShaderNodeBsdfHair::component_Reflection:
565  hair->set_component(CLOSURE_BSDF_HAIR_REFLECTION_ID);
566  break;
567  case BL::ShaderNodeBsdfHair::component_Transmission:
568  hair->set_component(CLOSURE_BSDF_HAIR_TRANSMISSION_ID);
569  break;
570  }
571  node = hair;
572  }
573  else if (b_node.is_a(&RNA_ShaderNodeBsdfHairPrincipled)) {
574  BL::ShaderNodeBsdfHairPrincipled b_principled_hair_node(b_node);
576  principled_hair->set_parametrization(
577  (NodePrincipledHairParametrization)get_enum(b_principled_hair_node.ptr,
578  "parametrization",
582  }
583  else if (b_node.is_a(&RNA_ShaderNodeBsdfPrincipled)) {
584  BL::ShaderNodeBsdfPrincipled b_principled_node(b_node);
585  PrincipledBsdfNode *principled = graph->create_node<PrincipledBsdfNode>();
586  switch (b_principled_node.distribution()) {
587  case BL::ShaderNodeBsdfPrincipled::distribution_GGX:
588  principled->set_distribution(CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
589  break;
590  case BL::ShaderNodeBsdfPrincipled::distribution_MULTI_GGX:
591  principled->set_distribution(CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
592  break;
593  }
594  switch (b_principled_node.subsurface_method()) {
595  case BL::ShaderNodeBsdfPrincipled::subsurface_method_BURLEY:
596  principled->set_subsurface_method(CLOSURE_BSSRDF_PRINCIPLED_ID);
597  break;
598  case BL::ShaderNodeBsdfPrincipled::subsurface_method_RANDOM_WALK:
599  principled->set_subsurface_method(CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID);
600  break;
601  }
602  node = principled;
603  }
604  else if (b_node.is_a(&RNA_ShaderNodeBsdfTranslucent)) {
605  node = graph->create_node<TranslucentBsdfNode>();
606  }
607  else if (b_node.is_a(&RNA_ShaderNodeBsdfTransparent)) {
608  node = graph->create_node<TransparentBsdfNode>();
609  }
610  else if (b_node.is_a(&RNA_ShaderNodeBsdfVelvet)) {
611  node = graph->create_node<VelvetBsdfNode>();
612  }
613  else if (b_node.is_a(&RNA_ShaderNodeEmission)) {
614  node = graph->create_node<EmissionNode>();
615  }
616  else if (b_node.is_a(&RNA_ShaderNodeAmbientOcclusion)) {
617  BL::ShaderNodeAmbientOcclusion b_ao_node(b_node);
618  AmbientOcclusionNode *ao = graph->create_node<AmbientOcclusionNode>();
619  ao->set_samples(b_ao_node.samples());
620  ao->set_inside(b_ao_node.inside());
621  ao->set_only_local(b_ao_node.only_local());
622  node = ao;
623  }
624  else if (b_node.is_a(&RNA_ShaderNodeVolumeScatter)) {
625  node = graph->create_node<ScatterVolumeNode>();
626  }
627  else if (b_node.is_a(&RNA_ShaderNodeVolumeAbsorption)) {
628  node = graph->create_node<AbsorptionVolumeNode>();
629  }
630  else if (b_node.is_a(&RNA_ShaderNodeVolumePrincipled)) {
631  PrincipledVolumeNode *principled = graph->create_node<PrincipledVolumeNode>();
632  node = principled;
633  }
634  else if (b_node.is_a(&RNA_ShaderNodeNewGeometry)) {
635  node = graph->create_node<GeometryNode>();
636  }
637  else if (b_node.is_a(&RNA_ShaderNodeWireframe)) {
638  BL::ShaderNodeWireframe b_wireframe_node(b_node);
639  WireframeNode *wire = graph->create_node<WireframeNode>();
640  wire->set_use_pixel_size(b_wireframe_node.use_pixel_size());
641  node = wire;
642  }
643  else if (b_node.is_a(&RNA_ShaderNodeWavelength)) {
644  node = graph->create_node<WavelengthNode>();
645  }
646  else if (b_node.is_a(&RNA_ShaderNodeBlackbody)) {
647  node = graph->create_node<BlackbodyNode>();
648  }
649  else if (b_node.is_a(&RNA_ShaderNodeLightPath)) {
650  node = graph->create_node<LightPathNode>();
651  }
652  else if (b_node.is_a(&RNA_ShaderNodeLightFalloff)) {
653  node = graph->create_node<LightFalloffNode>();
654  }
655  else if (b_node.is_a(&RNA_ShaderNodeObjectInfo)) {
656  node = graph->create_node<ObjectInfoNode>();
657  }
658  else if (b_node.is_a(&RNA_ShaderNodeParticleInfo)) {
659  node = graph->create_node<ParticleInfoNode>();
660  }
661  else if (b_node.is_a(&RNA_ShaderNodeHairInfo)) {
662  node = graph->create_node<HairInfoNode>();
663  }
664  else if (b_node.is_a(&RNA_ShaderNodeVolumeInfo)) {
665  node = graph->create_node<VolumeInfoNode>();
666  }
667  else if (b_node.is_a(&RNA_ShaderNodeVertexColor)) {
668  BL::ShaderNodeVertexColor b_vertex_color_node(b_node);
669  VertexColorNode *vertex_color_node = graph->create_node<VertexColorNode>();
670  vertex_color_node->set_layer_name(ustring(b_vertex_color_node.layer_name()));
671  node = vertex_color_node;
672  }
673  else if (b_node.is_a(&RNA_ShaderNodeBump)) {
674  BL::ShaderNodeBump b_bump_node(b_node);
675  BumpNode *bump = graph->create_node<BumpNode>();
676  bump->set_invert(b_bump_node.invert());
677  node = bump;
678  }
679  else if (b_node.is_a(&RNA_ShaderNodeScript)) {
680 #ifdef WITH_OSL
681  if (scene->shader_manager->use_osl()) {
682  /* create script node */
683  BL::ShaderNodeScript b_script_node(b_node);
684 
685  ShaderManager *manager = scene->shader_manager;
686  string bytecode_hash = b_script_node.bytecode_hash();
687 
688  if (!bytecode_hash.empty()) {
689  node = OSLShaderManager::osl_node(
690  graph, manager, "", bytecode_hash, b_script_node.bytecode());
691  }
692  else {
693  string absolute_filepath = blender_absolute_path(
694  b_data, b_ntree, b_script_node.filepath());
695  node = OSLShaderManager::osl_node(graph, manager, absolute_filepath, "");
696  }
697  }
698 #else
699  (void)b_data;
700  (void)b_ntree;
701 #endif
702  }
703  else if (b_node.is_a(&RNA_ShaderNodeTexImage)) {
704  BL::ShaderNodeTexImage b_image_node(b_node);
705  BL::Image b_image(b_image_node.image());
706  BL::ImageUser b_image_user(b_image_node.image_user());
707  ImageTextureNode *image = graph->create_node<ImageTextureNode>();
708 
709  image->set_interpolation(get_image_interpolation(b_image_node));
710  image->set_extension(get_image_extension(b_image_node));
711  image->set_projection((NodeImageProjection)b_image_node.projection());
712  image->set_projection_blend(b_image_node.projection_blend());
713  BL::TexMapping b_texture_mapping(b_image_node.texture_mapping());
714  get_tex_mapping(image, b_texture_mapping);
715 
716  if (b_image) {
717  PointerRNA colorspace_ptr = b_image.colorspace_settings().ptr;
718  image->set_colorspace(ustring(get_enum_identifier(colorspace_ptr, "name")));
719 
720  image->set_animated(b_image_node.image_user().use_auto_refresh());
721  image->set_alpha_type(get_image_alpha_type(b_image));
722 
723  array<int> tiles;
724  for (BL::UDIMTile &b_tile : b_image.tiles) {
725  tiles.push_back_slow(b_tile.number());
726  }
727  image->set_tiles(tiles);
728 
729  /* builtin images will use callback-based reading because
730  * they could only be loaded correct from blender side
731  */
732  bool is_builtin = b_image.packed_file() || b_image.source() == BL::Image::source_GENERATED ||
733  b_image.source() == BL::Image::source_MOVIE ||
734  (b_engine.is_preview() && b_image.source() != BL::Image::source_SEQUENCE);
735 
736  if (is_builtin) {
737  /* for builtin images we're using image datablock name to find an image to
738  * read pixels from later
739  *
740  * also store frame number as well, so there's no differences in handling
741  * builtin names for packed images and movies
742  */
743  int scene_frame = b_scene.frame_current();
744  int image_frame = image_user_frame_number(b_image_user, b_image, scene_frame);
745  image->handle = scene->image_manager->add_image(
746  new BlenderImageLoader(b_image, image_frame), image->image_params());
747  }
748  else {
749  ustring filename = ustring(
750  image_user_file_path(b_image_user, b_image, b_scene.frame_current(), true));
751  image->set_filename(filename);
752  }
753  }
754  node = image;
755  }
756  else if (b_node.is_a(&RNA_ShaderNodeTexEnvironment)) {
757  BL::ShaderNodeTexEnvironment b_env_node(b_node);
758  BL::Image b_image(b_env_node.image());
759  BL::ImageUser b_image_user(b_env_node.image_user());
760  EnvironmentTextureNode *env = graph->create_node<EnvironmentTextureNode>();
761 
762  env->set_interpolation(get_image_interpolation(b_env_node));
763  env->set_projection((NodeEnvironmentProjection)b_env_node.projection());
764  BL::TexMapping b_texture_mapping(b_env_node.texture_mapping());
765  get_tex_mapping(env, b_texture_mapping);
766 
767  if (b_image) {
768  PointerRNA colorspace_ptr = b_image.colorspace_settings().ptr;
769  env->set_colorspace(ustring(get_enum_identifier(colorspace_ptr, "name")));
770 
771  env->set_animated(b_env_node.image_user().use_auto_refresh());
772  env->set_alpha_type(get_image_alpha_type(b_image));
773 
774  bool is_builtin = b_image.packed_file() || b_image.source() == BL::Image::source_GENERATED ||
775  b_image.source() == BL::Image::source_MOVIE ||
776  (b_engine.is_preview() && b_image.source() != BL::Image::source_SEQUENCE);
777 
778  if (is_builtin) {
779  int scene_frame = b_scene.frame_current();
780  int image_frame = image_user_frame_number(b_image_user, b_image, scene_frame);
781  env->handle = scene->image_manager->add_image(new BlenderImageLoader(b_image, image_frame),
782  env->image_params());
783  }
784  else {
785  env->set_filename(
786  ustring(image_user_file_path(b_image_user, b_image, b_scene.frame_current(), false)));
787  }
788  }
789  node = env;
790  }
791  else if (b_node.is_a(&RNA_ShaderNodeTexGradient)) {
792  BL::ShaderNodeTexGradient b_gradient_node(b_node);
793  GradientTextureNode *gradient = graph->create_node<GradientTextureNode>();
794  gradient->set_gradient_type((NodeGradientType)b_gradient_node.gradient_type());
795  BL::TexMapping b_texture_mapping(b_gradient_node.texture_mapping());
796  get_tex_mapping(gradient, b_texture_mapping);
797  node = gradient;
798  }
799  else if (b_node.is_a(&RNA_ShaderNodeTexVoronoi)) {
800  BL::ShaderNodeTexVoronoi b_voronoi_node(b_node);
801  VoronoiTextureNode *voronoi = graph->create_node<VoronoiTextureNode>();
802  voronoi->set_dimensions(b_voronoi_node.voronoi_dimensions());
803  voronoi->set_feature((NodeVoronoiFeature)b_voronoi_node.feature());
804  voronoi->set_metric((NodeVoronoiDistanceMetric)b_voronoi_node.distance());
805  BL::TexMapping b_texture_mapping(b_voronoi_node.texture_mapping());
806  get_tex_mapping(voronoi, b_texture_mapping);
807  node = voronoi;
808  }
809  else if (b_node.is_a(&RNA_ShaderNodeTexMagic)) {
810  BL::ShaderNodeTexMagic b_magic_node(b_node);
811  MagicTextureNode *magic = graph->create_node<MagicTextureNode>();
812  magic->set_depth(b_magic_node.turbulence_depth());
813  BL::TexMapping b_texture_mapping(b_magic_node.texture_mapping());
814  get_tex_mapping(magic, b_texture_mapping);
815  node = magic;
816  }
817  else if (b_node.is_a(&RNA_ShaderNodeTexWave)) {
818  BL::ShaderNodeTexWave b_wave_node(b_node);
819  WaveTextureNode *wave = graph->create_node<WaveTextureNode>();
820  wave->set_wave_type((NodeWaveType)b_wave_node.wave_type());
821  wave->set_bands_direction((NodeWaveBandsDirection)b_wave_node.bands_direction());
822  wave->set_rings_direction((NodeWaveRingsDirection)b_wave_node.rings_direction());
823  wave->set_profile((NodeWaveProfile)b_wave_node.wave_profile());
824  BL::TexMapping b_texture_mapping(b_wave_node.texture_mapping());
825  get_tex_mapping(wave, b_texture_mapping);
826  node = wave;
827  }
828  else if (b_node.is_a(&RNA_ShaderNodeTexChecker)) {
829  BL::ShaderNodeTexChecker b_checker_node(b_node);
830  CheckerTextureNode *checker = graph->create_node<CheckerTextureNode>();
831  BL::TexMapping b_texture_mapping(b_checker_node.texture_mapping());
832  get_tex_mapping(checker, b_texture_mapping);
833  node = checker;
834  }
835  else if (b_node.is_a(&RNA_ShaderNodeTexBrick)) {
836  BL::ShaderNodeTexBrick b_brick_node(b_node);
837  BrickTextureNode *brick = graph->create_node<BrickTextureNode>();
838  brick->set_offset(b_brick_node.offset());
839  brick->set_offset_frequency(b_brick_node.offset_frequency());
840  brick->set_squash(b_brick_node.squash());
841  brick->set_squash_frequency(b_brick_node.squash_frequency());
842  BL::TexMapping b_texture_mapping(b_brick_node.texture_mapping());
843  get_tex_mapping(brick, b_texture_mapping);
844  node = brick;
845  }
846  else if (b_node.is_a(&RNA_ShaderNodeTexNoise)) {
847  BL::ShaderNodeTexNoise b_noise_node(b_node);
848  NoiseTextureNode *noise = graph->create_node<NoiseTextureNode>();
849  noise->set_dimensions(b_noise_node.noise_dimensions());
850  BL::TexMapping b_texture_mapping(b_noise_node.texture_mapping());
851  get_tex_mapping(noise, b_texture_mapping);
852  node = noise;
853  }
854  else if (b_node.is_a(&RNA_ShaderNodeTexMusgrave)) {
855  BL::ShaderNodeTexMusgrave b_musgrave_node(b_node);
856  MusgraveTextureNode *musgrave_node = graph->create_node<MusgraveTextureNode>();
857  musgrave_node->set_musgrave_type((NodeMusgraveType)b_musgrave_node.musgrave_type());
858  musgrave_node->set_dimensions(b_musgrave_node.musgrave_dimensions());
859  BL::TexMapping b_texture_mapping(b_musgrave_node.texture_mapping());
860  get_tex_mapping(musgrave_node, b_texture_mapping);
861  node = musgrave_node;
862  }
863  else if (b_node.is_a(&RNA_ShaderNodeTexCoord)) {
864  BL::ShaderNodeTexCoord b_tex_coord_node(b_node);
866  tex_coord->set_from_dupli(b_tex_coord_node.from_instancer());
867  if (b_tex_coord_node.object()) {
868  tex_coord->set_use_transform(true);
869  tex_coord->set_ob_tfm(get_transform(b_tex_coord_node.object().matrix_world()));
870  }
871  node = tex_coord;
872  }
873  else if (b_node.is_a(&RNA_ShaderNodeTexSky)) {
874  BL::ShaderNodeTexSky b_sky_node(b_node);
875  SkyTextureNode *sky = graph->create_node<SkyTextureNode>();
876  sky->set_sky_type((NodeSkyType)b_sky_node.sky_type());
877  sky->set_sun_direction(normalize(get_float3(b_sky_node.sun_direction())));
878  sky->set_turbidity(b_sky_node.turbidity());
879  sky->set_ground_albedo(b_sky_node.ground_albedo());
880  sky->set_sun_disc(b_sky_node.sun_disc());
881  sky->set_sun_size(b_sky_node.sun_size());
882  sky->set_sun_intensity(b_sky_node.sun_intensity());
883  sky->set_sun_elevation(b_sky_node.sun_elevation());
884  sky->set_sun_rotation(b_sky_node.sun_rotation());
885  sky->set_altitude(b_sky_node.altitude());
886  sky->set_air_density(b_sky_node.air_density());
887  sky->set_dust_density(b_sky_node.dust_density());
888  sky->set_ozone_density(b_sky_node.ozone_density());
889  BL::TexMapping b_texture_mapping(b_sky_node.texture_mapping());
890  get_tex_mapping(sky, b_texture_mapping);
891  node = sky;
892  }
893  else if (b_node.is_a(&RNA_ShaderNodeTexIES)) {
894  BL::ShaderNodeTexIES b_ies_node(b_node);
895  IESLightNode *ies = graph->create_node<IESLightNode>();
896  switch (b_ies_node.mode()) {
897  case BL::ShaderNodeTexIES::mode_EXTERNAL:
898  ies->set_filename(ustring(blender_absolute_path(b_data, b_ntree, b_ies_node.filepath())));
899  break;
900  case BL::ShaderNodeTexIES::mode_INTERNAL:
901  ustring ies_content = ustring(get_text_datablock_content(b_ies_node.ies().ptr));
902  if (ies_content.empty()) {
903  ies_content = "\n";
904  }
905  ies->set_ies(ies_content);
906  break;
907  }
908  node = ies;
909  }
910  else if (b_node.is_a(&RNA_ShaderNodeTexWhiteNoise)) {
911  BL::ShaderNodeTexWhiteNoise b_tex_white_noise_node(b_node);
912  WhiteNoiseTextureNode *white_noise_node = graph->create_node<WhiteNoiseTextureNode>();
913  white_noise_node->set_dimensions(b_tex_white_noise_node.noise_dimensions());
914  node = white_noise_node;
915  }
916  else if (b_node.is_a(&RNA_ShaderNodeNormalMap)) {
917  BL::ShaderNodeNormalMap b_normal_map_node(b_node);
918  NormalMapNode *nmap = graph->create_node<NormalMapNode>();
919  nmap->set_space((NodeNormalMapSpace)b_normal_map_node.space());
920  nmap->set_attribute(ustring(b_normal_map_node.uv_map()));
921  node = nmap;
922  }
923  else if (b_node.is_a(&RNA_ShaderNodeTangent)) {
924  BL::ShaderNodeTangent b_tangent_node(b_node);
925  TangentNode *tangent = graph->create_node<TangentNode>();
926  tangent->set_direction_type((NodeTangentDirectionType)b_tangent_node.direction_type());
927  tangent->set_axis((NodeTangentAxis)b_tangent_node.axis());
928  tangent->set_attribute(ustring(b_tangent_node.uv_map()));
929  node = tangent;
930  }
931  else if (b_node.is_a(&RNA_ShaderNodeUVMap)) {
932  BL::ShaderNodeUVMap b_uvmap_node(b_node);
933  UVMapNode *uvm = graph->create_node<UVMapNode>();
934  uvm->set_attribute(ustring(b_uvmap_node.uv_map()));
935  uvm->set_from_dupli(b_uvmap_node.from_instancer());
936  node = uvm;
937  }
938  else if (b_node.is_a(&RNA_ShaderNodeTexPointDensity)) {
939  BL::ShaderNodeTexPointDensity b_point_density_node(b_node);
940  PointDensityTextureNode *point_density = graph->create_node<PointDensityTextureNode>();
941  point_density->set_space((NodeTexVoxelSpace)b_point_density_node.space());
942  point_density->set_interpolation(get_image_interpolation(b_point_density_node));
943  point_density->handle = scene->image_manager->add_image(
944  new BlenderPointDensityLoader(b_depsgraph, b_point_density_node),
945  point_density->image_params());
946 
947  b_point_density_node.cache_point_density(b_depsgraph);
948  node = point_density;
949 
950  /* Transformation form world space to texture space.
951  *
952  * NOTE: Do this after the texture is cached, this is because getting
953  * min/max will need to access this cache.
954  */
955  BL::Object b_ob(b_point_density_node.object());
956  if (b_ob) {
957  float3 loc, size;
958  point_density_texture_space(b_depsgraph, b_point_density_node, loc, size);
959  point_density->set_tfm(transform_translate(-loc) * transform_scale(size) *
960  transform_inverse(get_transform(b_ob.matrix_world())));
961  }
962  }
963  else if (b_node.is_a(&RNA_ShaderNodeBevel)) {
964  BL::ShaderNodeBevel b_bevel_node(b_node);
965  BevelNode *bevel = graph->create_node<BevelNode>();
966  bevel->set_samples(b_bevel_node.samples());
967  node = bevel;
968  }
969  else if (b_node.is_a(&RNA_ShaderNodeDisplacement)) {
970  BL::ShaderNodeDisplacement b_disp_node(b_node);
971  DisplacementNode *disp = graph->create_node<DisplacementNode>();
972  disp->set_space((NodeNormalMapSpace)b_disp_node.space());
973  node = disp;
974  }
975  else if (b_node.is_a(&RNA_ShaderNodeVectorDisplacement)) {
976  BL::ShaderNodeVectorDisplacement b_disp_node(b_node);
977  VectorDisplacementNode *disp = graph->create_node<VectorDisplacementNode>();
978  disp->set_space((NodeNormalMapSpace)b_disp_node.space());
979  disp->set_attribute(ustring(""));
980  node = disp;
981  }
982  else if (b_node.is_a(&RNA_ShaderNodeOutputAOV)) {
983  BL::ShaderNodeOutputAOV b_aov_node(b_node);
984  OutputAOVNode *aov = graph->create_node<OutputAOVNode>();
985  aov->set_name(ustring(b_aov_node.name()));
986  node = aov;
987  }
988 
989  if (node) {
990  node->name = b_node.name();
991  graph->add(node);
992  }
993 
994  return node;
995 }
996 
998 {
999  if (node->special_type == SHADER_SPECIAL_TYPE_OSL)
1000  return false;
1001 
1002  return true;
1003 }
1004 
1006  BL::Node &b_node,
1007  BL::NodeSocket &b_socket)
1008 {
1009  string name = b_socket.name();
1010 
1012  bool found = false;
1013  int counter = 0, total = 0;
1014 
1015  for (BL::NodeSocket &b_input : b_node.inputs) {
1016  if (b_input.name() == name) {
1017  if (!found) {
1018  counter++;
1019  }
1020  total++;
1021  }
1022 
1023  if (b_input.ptr.data == b_socket.ptr.data)
1024  found = true;
1025  }
1026 
1027  /* rename if needed */
1028  if (name == "Shader")
1029  name = "Closure";
1030 
1031  if (total > 1)
1032  name = string_printf("%s%d", name.c_str(), counter);
1033  }
1034 
1035  return node->input(name.c_str());
1036 }
1037 
1039  BL::Node &b_node,
1040  BL::NodeSocket &b_socket)
1041 {
1042  string name = b_socket.name();
1043 
1045  bool found = false;
1046  int counter = 0, total = 0;
1047 
1048  for (BL::NodeSocket &b_output : b_node.outputs) {
1049  if (b_output.name() == name) {
1050  if (!found) {
1051  counter++;
1052  }
1053  total++;
1054  }
1055 
1056  if (b_output.ptr.data == b_socket.ptr.data) {
1057  found = true;
1058  }
1059  }
1060 
1061  /* rename if needed */
1062  if (name == "Shader")
1063  name = "Closure";
1064 
1065  if (total > 1)
1066  name = string_printf("%s%d", name.c_str(), counter);
1067  }
1068 
1069  return node->output(name.c_str());
1070 }
1071 
1072 static void add_nodes(Scene *scene,
1073  BL::RenderEngine &b_engine,
1074  BL::BlendData &b_data,
1075  BL::Depsgraph &b_depsgraph,
1076  BL::Scene &b_scene,
1077  ShaderGraph *graph,
1078  BL::ShaderNodeTree &b_ntree,
1079  const ProxyMap &proxy_input_map,
1080  const ProxyMap &proxy_output_map)
1081 {
1082  /* add nodes */
1083  PtrInputMap input_map;
1084  PtrOutputMap output_map;
1085 
1086  /* find the node to use for output if there are multiple */
1087  BL::ShaderNode output_node = b_ntree.get_output_node(
1088  BL::ShaderNodeOutputMaterial::target_CYCLES);
1089 
1090  /* add nodes */
1091  for (BL::Node &b_node : b_ntree.nodes) {
1092  if (b_node.mute() || b_node.is_a(&RNA_NodeReroute)) {
1093  /* replace muted node with internal links */
1094  for (BL::NodeLink &b_link : b_node.internal_links) {
1095  BL::NodeSocket to_socket(b_link.to_socket());
1096  SocketType::Type to_socket_type = convert_socket_type(to_socket);
1097  if (to_socket_type == SocketType::UNDEFINED) {
1098  continue;
1099  }
1100 
1101  ConvertNode *proxy = graph->create_node<ConvertNode>(to_socket_type, to_socket_type, true);
1102 
1103  input_map[b_link.from_socket().ptr.data] = proxy->inputs[0];
1104  output_map[b_link.to_socket().ptr.data] = proxy->outputs[0];
1105 
1106  graph->add(proxy);
1107  }
1108  }
1109  else if (b_node.is_a(&RNA_ShaderNodeGroup) || b_node.is_a(&RNA_NodeCustomGroup) ||
1110  b_node.is_a(&RNA_ShaderNodeCustomGroup)) {
1111 
1112  BL::ShaderNodeTree b_group_ntree(PointerRNA_NULL);
1113  if (b_node.is_a(&RNA_ShaderNodeGroup))
1114  b_group_ntree = BL::ShaderNodeTree(((BL::NodeGroup)(b_node)).node_tree());
1115  else if (b_node.is_a(&RNA_NodeCustomGroup))
1116  b_group_ntree = BL::ShaderNodeTree(((BL::NodeCustomGroup)(b_node)).node_tree());
1117  else
1118  b_group_ntree = BL::ShaderNodeTree(((BL::ShaderNodeCustomGroup)(b_node)).node_tree());
1119 
1120  ProxyMap group_proxy_input_map, group_proxy_output_map;
1121 
1122  /* Add a proxy node for each socket
1123  * Do this even if the node group has no internal tree,
1124  * so that links have something to connect to and assert won't fail.
1125  */
1126  for (BL::NodeSocket &b_input : b_node.inputs) {
1127  SocketType::Type input_type = convert_socket_type(b_input);
1128  if (input_type == SocketType::UNDEFINED) {
1129  continue;
1130  }
1131 
1132  ConvertNode *proxy = graph->create_node<ConvertNode>(input_type, input_type, true);
1133  graph->add(proxy);
1134 
1135  /* register the proxy node for internal binding */
1136  group_proxy_input_map[b_input.identifier()] = proxy;
1137 
1138  input_map[b_input.ptr.data] = proxy->inputs[0];
1139 
1140  set_default_value(proxy->inputs[0], b_input, b_data, b_ntree);
1141  }
1142  for (BL::NodeSocket &b_output : b_node.outputs) {
1143  SocketType::Type output_type = convert_socket_type(b_output);
1144  if (output_type == SocketType::UNDEFINED) {
1145  continue;
1146  }
1147 
1148  ConvertNode *proxy = graph->create_node<ConvertNode>(output_type, output_type, true);
1149  graph->add(proxy);
1150 
1151  /* register the proxy node for internal binding */
1152  group_proxy_output_map[b_output.identifier()] = proxy;
1153 
1154  output_map[b_output.ptr.data] = proxy->outputs[0];
1155  }
1156 
1157  if (b_group_ntree) {
1158  add_nodes(scene,
1159  b_engine,
1160  b_data,
1161  b_depsgraph,
1162  b_scene,
1163  graph,
1164  b_group_ntree,
1165  group_proxy_input_map,
1166  group_proxy_output_map);
1167  }
1168  }
1169  else if (b_node.is_a(&RNA_NodeGroupInput)) {
1170  /* map each socket to a proxy node */
1171  for (BL::NodeSocket &b_output : b_node.outputs) {
1172  ProxyMap::const_iterator proxy_it = proxy_input_map.find(b_output.identifier());
1173  if (proxy_it != proxy_input_map.end()) {
1174  ConvertNode *proxy = proxy_it->second;
1175 
1176  output_map[b_output.ptr.data] = proxy->outputs[0];
1177  }
1178  }
1179  }
1180  else if (b_node.is_a(&RNA_NodeGroupOutput)) {
1181  BL::NodeGroupOutput b_output_node(b_node);
1182  /* only the active group output is used */
1183  if (b_output_node.is_active_output()) {
1184  /* map each socket to a proxy node */
1185  for (BL::NodeSocket &b_input : b_node.inputs) {
1186  ProxyMap::const_iterator proxy_it = proxy_output_map.find(b_input.identifier());
1187  if (proxy_it != proxy_output_map.end()) {
1188  ConvertNode *proxy = proxy_it->second;
1189 
1190  input_map[b_input.ptr.data] = proxy->inputs[0];
1191 
1192  set_default_value(proxy->inputs[0], b_input, b_data, b_ntree);
1193  }
1194  }
1195  }
1196  }
1197  else {
1198  ShaderNode *node = NULL;
1199 
1200  if (b_node.ptr.data == output_node.ptr.data) {
1201  node = graph->output();
1202  }
1203  else {
1204  BL::ShaderNode b_shader_node(b_node);
1205  node = add_node(
1206  scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree, b_shader_node);
1207  }
1208 
1209  if (node) {
1210  /* map node sockets for linking */
1211  for (BL::NodeSocket &b_input : b_node.inputs) {
1212  ShaderInput *input = node_find_input_by_name(node, b_node, b_input);
1213  if (!input) {
1214  /* XXX should not happen, report error? */
1215  continue;
1216  }
1217  input_map[b_input.ptr.data] = input;
1218 
1219  set_default_value(input, b_input, b_data, b_ntree);
1220  }
1221  for (BL::NodeSocket &b_output : b_node.outputs) {
1222  ShaderOutput *output = node_find_output_by_name(node, b_node, b_output);
1223  if (!output) {
1224  /* XXX should not happen, report error? */
1225  continue;
1226  }
1227  output_map[b_output.ptr.data] = output;
1228  }
1229  }
1230  }
1231  }
1232 
1233  /* connect nodes */
1234  for (BL::NodeLink &b_link : b_ntree.links) {
1235  /* Ignore invalid links to avoid unwanted cycles created in graph.
1236  * Also ignore links with unavailable sockets. */
1237  if (!(b_link.is_valid() && b_link.from_socket().enabled() && b_link.to_socket().enabled()) ||
1238  b_link.is_muted()) {
1239  continue;
1240  }
1241  /* get blender link data */
1242  BL::NodeSocket b_from_sock = b_link.from_socket();
1243  BL::NodeSocket b_to_sock = b_link.to_socket();
1244 
1245  ShaderOutput *output = 0;
1246  ShaderInput *input = 0;
1247 
1248  PtrOutputMap::iterator output_it = output_map.find(b_from_sock.ptr.data);
1249  if (output_it != output_map.end())
1250  output = output_it->second;
1251  PtrInputMap::iterator input_it = input_map.find(b_to_sock.ptr.data);
1252  if (input_it != input_map.end())
1253  input = input_it->second;
1254 
1255  /* either node may be NULL when the node was not exported, typically
1256  * because the node type is not supported */
1257  if (output && input)
1258  graph->connect(output, input);
1259  }
1260 }
1261 
1262 static void add_nodes(Scene *scene,
1263  BL::RenderEngine &b_engine,
1264  BL::BlendData &b_data,
1265  BL::Depsgraph &b_depsgraph,
1266  BL::Scene &b_scene,
1267  ShaderGraph *graph,
1268  BL::ShaderNodeTree &b_ntree)
1269 {
1270  static const ProxyMap empty_proxy_map;
1271  add_nodes(scene,
1272  b_engine,
1273  b_data,
1274  b_depsgraph,
1275  b_scene,
1276  graph,
1277  b_ntree,
1278  empty_proxy_map,
1279  empty_proxy_map);
1280 }
1281 
1282 /* Sync Materials */
1283 
1284 void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all)
1285 {
1286  shader_map.set_default(scene->default_surface);
1287 
1288  TaskPool pool;
1289  set<Shader *> updated_shaders;
1290 
1291  for (BL::ID &b_id : b_depsgraph.ids) {
1292  if (!b_id.is_a(&RNA_Material)) {
1293  continue;
1294  }
1295 
1296  BL::Material b_mat(b_id);
1297  Shader *shader;
1298 
1299  /* test if we need to sync */
1300  if (shader_map.add_or_update(&shader, b_mat) || update_all) {
1301  ShaderGraph *graph = new ShaderGraph();
1302 
1303  shader->name = b_mat.name().c_str();
1304  shader->set_pass_id(b_mat.pass_index());
1305 
1306  /* create nodes */
1307  if (b_mat.use_nodes() && b_mat.node_tree()) {
1308  BL::ShaderNodeTree b_ntree(b_mat.node_tree());
1309 
1310  add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree);
1311  }
1312  else {
1313  DiffuseBsdfNode *diffuse = graph->create_node<DiffuseBsdfNode>();
1314  diffuse->set_color(get_float3(b_mat.diffuse_color()));
1315  graph->add(diffuse);
1316 
1317  ShaderNode *out = graph->output();
1318  graph->connect(diffuse->output("BSDF"), out->input("Surface"));
1319  }
1320 
1321  /* settings */
1322  PointerRNA cmat = RNA_pointer_get(&b_mat.ptr, "cycles");
1323  shader->set_use_mis(get_boolean(cmat, "sample_as_light"));
1324  shader->set_use_transparent_shadow(get_boolean(cmat, "use_transparent_shadow"));
1325  shader->set_heterogeneous_volume(!get_boolean(cmat, "homogeneous_volume"));
1326  shader->set_volume_sampling_method(get_volume_sampling(cmat));
1327  shader->set_volume_interpolation_method(get_volume_interpolation(cmat));
1328  shader->set_volume_step_rate(get_float(cmat, "volume_step_rate"));
1329  shader->set_displacement_method(get_displacement_method(cmat));
1330 
1331  shader->set_graph(graph);
1332 
1333  /* By simplifying the shader graph as soon as possible, some
1334  * redundant shader nodes might be removed which prevents loading
1335  * unnecessary attributes later.
1336  *
1337  * However, since graph simplification also accounts for e.g. mix
1338  * weight, this would cause frequent expensive resyncs in interactive
1339  * sessions, so for those sessions optimization is only performed
1340  * right before compiling.
1341  */
1342  if (!preview) {
1344  /* NOTE: Update shaders out of the threads since those routines
1345  * are accessing and writing to a global context.
1346  */
1347  updated_shaders.insert(shader);
1348  }
1349  else {
1350  /* NOTE: Update tagging can access links which are being
1351  * optimized out.
1352  */
1353  shader->tag_update(scene);
1354  }
1355  }
1356  }
1357 
1358  pool.wait_work();
1359 
1360  foreach (Shader *shader, updated_shaders) {
1361  shader->tag_update(scene);
1362  }
1363 }
1364 
1365 /* Sync World */
1366 
1367 void BlenderSync::sync_world(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d, bool update_all)
1368 {
1369  Background *background = scene->background;
1370 
1371  BL::World b_world = b_scene.world();
1372 
1373  BlenderViewportParameters new_viewport_parameters(b_v3d);
1374 
1375  if (world_recalc || update_all || b_world.ptr.data != world_map ||
1376  viewport_parameters.modified(new_viewport_parameters)) {
1377  Shader *shader = scene->default_background;
1378  ShaderGraph *graph = new ShaderGraph();
1379 
1380  /* create nodes */
1381  if (new_viewport_parameters.use_scene_world && b_world && b_world.use_nodes() &&
1382  b_world.node_tree()) {
1383  BL::ShaderNodeTree b_ntree(b_world.node_tree());
1384 
1385  add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree);
1386 
1387  /* volume */
1388  PointerRNA cworld = RNA_pointer_get(&b_world.ptr, "cycles");
1389  shader->set_heterogeneous_volume(!get_boolean(cworld, "homogeneous_volume"));
1390  shader->set_volume_sampling_method(get_volume_sampling(cworld));
1391  shader->set_volume_interpolation_method(get_volume_interpolation(cworld));
1392  shader->set_volume_step_rate(get_float(cworld, "volume_step_size"));
1393  }
1394  else if (new_viewport_parameters.use_scene_world && b_world) {
1395  BackgroundNode *background = graph->create_node<BackgroundNode>();
1396  background->set_color(get_float3(b_world.color()));
1397  graph->add(background);
1398 
1399  ShaderNode *out = graph->output();
1400  graph->connect(background->output("Background"), out->input("Surface"));
1401  }
1402  else if (!new_viewport_parameters.use_scene_world) {
1403  float3 world_color;
1404  if (b_world) {
1405  world_color = get_float3(b_world.color());
1406  }
1407  else {
1408  world_color = zero_float3();
1409  }
1410 
1411  BackgroundNode *background = graph->create_node<BackgroundNode>();
1412  graph->add(background);
1413 
1414  LightPathNode *light_path = graph->create_node<LightPathNode>();
1415  graph->add(light_path);
1416 
1417  MixNode *mix_scene_with_background = graph->create_node<MixNode>();
1418  mix_scene_with_background->set_color2(world_color);
1419  graph->add(mix_scene_with_background);
1420 
1421  EnvironmentTextureNode *texture_environment = graph->create_node<EnvironmentTextureNode>();
1422  texture_environment->set_tex_mapping_type(TextureMapping::VECTOR);
1423  float3 rotation_z = texture_environment->get_tex_mapping_rotation();
1424  rotation_z[2] = new_viewport_parameters.studiolight_rotate_z;
1425  texture_environment->set_tex_mapping_rotation(rotation_z);
1426  texture_environment->set_filename(new_viewport_parameters.studiolight_path);
1427  graph->add(texture_environment);
1428 
1429  MixNode *mix_intensity = graph->create_node<MixNode>();
1430  mix_intensity->set_mix_type(NODE_MIX_MUL);
1431  mix_intensity->set_fac(1.0f);
1432  mix_intensity->set_color2(make_float3(new_viewport_parameters.studiolight_intensity,
1433  new_viewport_parameters.studiolight_intensity,
1434  new_viewport_parameters.studiolight_intensity));
1435  graph->add(mix_intensity);
1436 
1437  TextureCoordinateNode *texture_coordinate = graph->create_node<TextureCoordinateNode>();
1438  graph->add(texture_coordinate);
1439 
1440  MixNode *mix_background_with_environment = graph->create_node<MixNode>();
1441  mix_background_with_environment->set_fac(
1442  new_viewport_parameters.studiolight_background_alpha);
1443  mix_background_with_environment->set_color1(world_color);
1444  graph->add(mix_background_with_environment);
1445 
1446  ShaderNode *out = graph->output();
1447 
1448  graph->connect(texture_coordinate->output("Generated"),
1449  texture_environment->input("Vector"));
1450  graph->connect(texture_environment->output("Color"), mix_intensity->input("Color1"));
1451  graph->connect(light_path->output("Is Camera Ray"), mix_scene_with_background->input("Fac"));
1452  graph->connect(mix_intensity->output("Color"), mix_scene_with_background->input("Color1"));
1453  graph->connect(mix_intensity->output("Color"),
1454  mix_background_with_environment->input("Color2"));
1455  graph->connect(mix_background_with_environment->output("Color"),
1456  mix_scene_with_background->input("Color2"));
1457  graph->connect(mix_scene_with_background->output("Color"), background->input("Color"));
1458  graph->connect(background->output("Background"), out->input("Surface"));
1459  }
1460 
1461  if (b_world) {
1462  /* AO */
1463  BL::WorldLighting b_light = b_world.light_settings();
1464 
1465  background->set_use_ao(b_light.use_ambient_occlusion());
1466  background->set_ao_factor(b_light.ao_factor());
1467  background->set_ao_distance(b_light.distance());
1468 
1469  /* visibility */
1470  PointerRNA cvisibility = RNA_pointer_get(&b_world.ptr, "cycles_visibility");
1471  uint visibility = 0;
1472 
1473  visibility |= get_boolean(cvisibility, "camera") ? PATH_RAY_CAMERA : 0;
1474  visibility |= get_boolean(cvisibility, "diffuse") ? PATH_RAY_DIFFUSE : 0;
1475  visibility |= get_boolean(cvisibility, "glossy") ? PATH_RAY_GLOSSY : 0;
1476  visibility |= get_boolean(cvisibility, "transmission") ? PATH_RAY_TRANSMIT : 0;
1477  visibility |= get_boolean(cvisibility, "scatter") ? PATH_RAY_VOLUME_SCATTER : 0;
1478 
1479  background->set_visibility(visibility);
1480  }
1481  else {
1482  background->set_use_ao(false);
1483  background->set_ao_factor(0.0f);
1484  background->set_ao_distance(FLT_MAX);
1485  }
1486 
1487  shader->set_graph(graph);
1488  shader->tag_update(scene);
1489  }
1490 
1491  PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
1492  background->set_transparent(b_scene.render().film_transparent());
1493 
1494  if (background->get_transparent()) {
1495  background->set_transparent_glass(get_boolean(cscene, "film_transparent_glass"));
1496  background->set_transparent_roughness_threshold(
1497  get_float(cscene, "film_transparent_roughness"));
1498  }
1499  else {
1500  background->set_transparent_glass(false);
1501  background->set_transparent_roughness_threshold(0.0f);
1502  }
1503 
1504  background->set_use_shader(view_layer.use_background_shader |
1505  viewport_parameters.custom_viewport_parameters());
1506  background->set_use_ao(background->get_use_ao() && view_layer.use_background_ao);
1507 
1508  background->tag_update(scene);
1509 }
1510 
1511 /* Sync Lights */
1512 
1513 void BlenderSync::sync_lights(BL::Depsgraph &b_depsgraph, bool update_all)
1514 {
1515  shader_map.set_default(scene->default_light);
1516 
1517  for (BL::ID &b_id : b_depsgraph.ids) {
1518  if (!b_id.is_a(&RNA_Light)) {
1519  continue;
1520  }
1521 
1522  BL::Light b_light(b_id);
1523  Shader *shader;
1524 
1525  /* test if we need to sync */
1526  if (shader_map.add_or_update(&shader, b_light) || update_all) {
1527  ShaderGraph *graph = new ShaderGraph();
1528 
1529  /* create nodes */
1530  if (b_light.use_nodes() && b_light.node_tree()) {
1531  shader->name = b_light.name().c_str();
1532 
1533  BL::ShaderNodeTree b_ntree(b_light.node_tree());
1534 
1535  add_nodes(scene, b_engine, b_data, b_depsgraph, b_scene, graph, b_ntree);
1536  }
1537  else {
1538  EmissionNode *emission = graph->create_node<EmissionNode>();
1539  emission->set_color(one_float3());
1540  emission->set_strength(1.0f);
1541  graph->add(emission);
1542 
1543  ShaderNode *out = graph->output();
1544  graph->connect(emission->output("Emission"), out->input("Surface"));
1545  }
1546 
1547  shader->set_graph(graph);
1548  shader->tag_update(scene);
1549  }
1550  }
1551 }
1552 
1553 void BlenderSync::sync_shaders(BL::Depsgraph &b_depsgraph, BL::SpaceView3D &b_v3d)
1554 {
1555  /* for auto refresh images */
1556  ImageManager *image_manager = scene->image_manager;
1557  const int frame = b_scene.frame_current();
1558  const bool auto_refresh_update = image_manager->set_animation_frame_update(frame);
1559 
1560  shader_map.pre_sync();
1561 
1562  sync_world(b_depsgraph, b_v3d, auto_refresh_update);
1563  sync_lights(b_depsgraph, auto_refresh_update);
1564  sync_materials(b_depsgraph, auto_refresh_update);
1565 }
1566 
unsigned int uint
Definition: BLI_sys_types.h:83
struct Depsgraph Depsgraph
Definition: DEG_depsgraph.h:51
struct ID ID
struct CurveMapping CurveMapping
struct Image Image
struct ImageUser ImageUser
struct Light Light
struct Material Material
struct Object Object
struct Scene Scene
struct TexMapping TexMapping
struct World World
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Light Particle Volume Image Sky Noise Wave Voronoi Brick Texture Vector Combine Vertex Separate Vector White ColorRamp
struct RenderEngine RenderEngine
StructRNA RNA_ShaderNodeGamma
StructRNA RNA_ShaderNodeRGBCurve
StructRNA RNA_Material
StructRNA RNA_ShaderNodeMapping
StructRNA RNA_ShaderNodeNormal
StructRNA RNA_ShaderNodeRGB
StructRNA RNA_ShaderNodeRGBToBW
StructRNA RNA_ShaderNodeCameraData
StructRNA RNA_ShaderNodeValue
StructRNA RNA_Light
StructRNA RNA_ShaderNodeCombineRGB
StructRNA RNA_ShaderNodeMixRGB
StructRNA RNA_ShaderNodeOutputAOV
StructRNA RNA_ShaderNodeInvert
StructRNA RNA_ShaderNodeVectorCurve
StructRNA RNA_ShaderNodeVectorMath
StructRNA RNA_ShaderNodeValToRGB
StructRNA RNA_ShaderNodeHueSaturation
StructRNA RNA_ShaderNodeScript
StructRNA RNA_ShaderNodeMath
StructRNA RNA_ShaderNodeSeparateRGB
static float3 get_node_output_vector(BL::Node &b_node, const string &name)
static DisplacementMethod get_displacement_method(PointerRNA &ptr)
static float3 get_node_output_rgba(BL::Node &b_node, const string &name)
static VolumeSampling get_volume_sampling(PointerRNA &ptr)
static ShaderInput * node_find_input_by_name(ShaderNode *node, BL::Node &b_node, BL::NodeSocket &b_socket)
static BL::NodeSocket get_node_output(BL::Node &b_node, const string &name)
static ImageAlphaType get_image_alpha_type(BL::Image &b_image)
static int validate_enum_value(int value, int num_values, int default_value)
static void add_nodes(Scene *scene, BL::RenderEngine &b_engine, BL::BlendData &b_data, BL::Depsgraph &b_depsgraph, BL::Scene &b_scene, ShaderGraph *graph, BL::ShaderNodeTree &b_ntree, const ProxyMap &proxy_input_map, const ProxyMap &proxy_output_map)
static bool node_use_modified_socket_name(ShaderNode *node)
static ustring blender_attribute_name_add_type(const string &name, BlenderAttributeType type)
static ShaderOutput * node_find_output_by_name(ShaderNode *node, BL::Node &b_node, BL::NodeSocket &b_socket)
BlenderAttributeType blender_attribute_name_split_type(ustring name, string *r_real_name)
static void set_default_value(ShaderInput *input, BL::NodeSocket &b_sock, BL::BlendData &b_data, BL::ID &b_id)
map< void *, ShaderOutput * > PtrOutputMap
static VolumeInterpolation get_volume_interpolation(PointerRNA &ptr)
static const string_view instancer_attr_prefix("\x01instancer:")
static float get_node_output_value(BL::Node &b_node, const string &name)
static void get_tex_mapping(TextureNode *mapping, BL::TexMapping &b_mapping)
static SocketType::Type convert_socket_type(BL::NodeSocket &b_socket)
static ShaderNode * add_node(Scene *scene, BL::RenderEngine &b_engine, BL::BlendData &b_data, BL::Depsgraph &b_depsgraph, BL::Scene &b_scene, ShaderGraph *graph, BL::ShaderNodeTree &b_ntree, BL::ShaderNode &b_node)
static ExtensionType get_image_extension(NodeType &b_node)
static const string_view object_attr_prefix("\x01object:")
static InterpolationType get_image_interpolation(NodeType &b_node)
CCL_NAMESPACE_BEGIN typedef map< void *, ShaderInput * > PtrInputMap
map< string, ConvertNode * > ProxyMap
void point_density_texture_space(BL::Depsgraph &b_depsgraph, BL::ShaderNodeTexPointDensity &b_point_density_node, float3 &loc, float3 &size)
static float4 get_float4(const BL::Array< float, 4 > &array)
Definition: blender_util.h:310
static float get_float(PointerRNA &ptr, const char *name)
Definition: blender_util.h:359
static void curvemapping_minmax(BL::CurveMapping &cumap, bool rgb_curve, float *min_x, float *max_x)
Definition: blender_util.h:143
static bool get_boolean(PointerRNA &ptr, const char *name)
Definition: blender_util.h:349
static int get_int(PointerRNA &ptr, const char *name)
Definition: blender_util.h:369
static string get_enum_identifier(PointerRNA &ptr, const char *name)
Definition: blender_util.h:399
static string get_text_datablock_content(const PointerRNA &ptr)
Definition: blender_util.h:456
static void colorramp_to_array(BL::ColorRamp &ramp, array< float3 > &ramp_color, array< float > &ramp_alpha, int size)
Definition: blender_util.h:120
static float3 get_float3(const BL::Array< float, 2 > &array)
Definition: blender_util.h:295
static int get_enum(PointerRNA &ptr, const char *name, int num_values=-1, int default_value=-1)
Definition: blender_util.h:386
CCL_NAMESPACE_BEGIN typedef BL::ShaderNodeAttribute::attribute_type_enum BlenderAttributeType
Definition: blender_util.h:43
static void curvemapping_color_to_array(BL::CurveMapping &cumap, array< float3 > &data, int size, bool rgb_curve)
Definition: blender_util.h:169
static string blender_absolute_path(BL::BlendData &b_data, BL::ID &b_id, const string &path)
Definition: blender_util.h:438
static string image_user_file_path(BL::ImageUser &iuser, BL::Image &ima, int cfra, bool load_tiled)
Definition: blender_util.h:237
static string get_string(PointerRNA &ptr, const char *name)
Definition: blender_util.h:420
static Transform get_transform(const BL::Array< float, 16 > &array)
Definition: blender_util.h:277
static int image_user_frame_number(BL::ImageUser &iuser, BL::Image &ima, int cfra)
Definition: blender_util.h:254
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
#define output
SIMD_FORCE_INLINE btScalar norm() const
Return the norm (length) of the vector.
Definition: btVector3.h:263
ImageParams image_params() const
Definition: nodes.cpp:541
bool set_animation_frame_update(int frame)
Definition: image.cpp:321
ImageHandle add_image(const string &filename, const ImageParams &params)
Definition: image.cpp:368
ImageHandle handle
Definition: nodes.h:100
ImageParams image_params() const
Definition: nodes.cpp:275
ImageParams image_params() const
Definition: nodes.cpp:1799
ImageHandle handle
Definition: nodes.h:429
void simplify(Scene *scene)
Definition: graph.cpp:361
ShaderNode * parent
Definition: graph.h:111
SocketType::Type type()
Definition: graph.h:94
ustring name()
Definition: graph.h:86
const SocketType & socket_type
Definition: graph.h:110
virtual bool use_osl()
Definition: shader.h:184
ShaderInput * input(const char *name)
Definition: graph.cpp:111
vector< ShaderOutput * > outputs
Definition: graph.h:224
vector< ShaderInput * > inputs
Definition: graph.h:223
ShaderOutput * output(const char *name)
Definition: graph.cpp:121
ustring name()
Definition: graph.h:127
Definition: shader.h:80
void push_back_slow(const T &t)
Definition: util_array.h:263
bool add_or_update(T **r_data, const BL::ID &id)
void pre_sync()
T * find(const BL::ID &id)
void set_default(T *data)
OperationNode * node
Depsgraph * graph
Scene scene
#define function_bind
uint tex_coord
Definition: gpu_viewport.c:81
@ SHADER_SPECIAL_TYPE_OSL
Definition: graph.h:64
#define CCL_NAMESPACE_END
#define make_float3(x, y, z)
void KERNEL_FUNCTION_FULL_NAME() shader(KernelGlobals *kg, uint4 *input, float4 *output, int type, int filter, int i, int offset, int sample)
@ PATH_RAY_TRANSMIT
Definition: kernel_types.h:268
@ PATH_RAY_VOLUME_SCATTER
Definition: kernel_types.h:290
@ PATH_RAY_GLOSSY
Definition: kernel_types.h:270
@ PATH_RAY_DIFFUSE
Definition: kernel_types.h:269
@ PATH_RAY_CAMERA
Definition: kernel_types.h:266
#define RAMP_TABLE_SIZE
Definition: kernel_types.h:46
static float noise(int n)
struct node_tree node_tree
PointerRNA RNA_pointer_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6562
const PointerRNA PointerRNA_NULL
Definition: rna_access.c:71
void RNA_float_get_array(PointerRNA *ptr, const char *name, float *values)
Definition: rna_access.c:6378
float RNA_float_get(PointerRNA *ptr, const char *name)
Definition: rna_access.c:6355
VolumeInterpolation
Definition: shader.h:59
@ VOLUME_NUM_INTERPOLATION
Definition: shader.h:63
@ VOLUME_INTERPOLATION_LINEAR
Definition: shader.h:60
DisplacementMethod
Definition: shader.h:66
@ DISPLACE_NUM_METHODS
Definition: shader.h:71
@ DISPLACE_BUMP
Definition: shader.h:67
VolumeSampling
Definition: shader.h:51
@ VOLUME_NUM_SAMPLING
Definition: shader.h:56
@ VOLUME_SAMPLING_DISTANCE
Definition: shader.h:52
closure color principled_hair(normal N, color sigma, float roughnessu, float roughnessv, float coat, float alpha, float eta) BUILTIN
Definition: node.h:98
void set_value(const SocketType &input, const Node &other, const SocketType &other_input)
Definition: node.cpp:385
Shader * default_surface
Definition: scene.h:253
ImageManager * image_manager
Definition: scene.h:243
Shader * default_background
Definition: scene.h:256
Background * background
Definition: scene.h:230
ShaderManager * shader_manager
Definition: scene.h:245
Shader * default_light
Definition: scene.h:255
void push(TaskRunFunction &&task)
Definition: util_task.cpp:36
void wait_work(Summary *stats=NULL)
Definition: util_task.cpp:42
NodeClampType
Definition: svm_types.h:346
NodeEnvironmentProjection
Definition: svm_types.h:489
NodeMathType
Definition: svm_types.h:271
NodeMusgraveType
Definition: svm_types.h:396
NodeMapRangeType
Definition: svm_types.h:351
NodeWaveBandsDirection
Definition: svm_types.h:406
NodeMappingType
Definition: svm_types.h:358
NodeVectorTransformConvertSpace
Definition: svm_types.h:379
NodeTangentAxis
Definition: svm_types.h:463
NodePrincipledHairParametrization
Definition: svm_types.h:518
@ NODE_PRINCIPLED_HAIR_NUM
Definition: svm_types.h:522
@ NODE_PRINCIPLED_HAIR_REFLECTANCE
Definition: svm_types.h:519
NodeVoronoiFeature
Definition: svm_types.h:445
NodeWaveType
Definition: svm_types.h:404
NodeVoronoiDistanceMetric
Definition: svm_types.h:438
NodeSkyType
Definition: svm_types.h:426
NodeWaveProfile
Definition: svm_types.h:420
NodeTexVoxelSpace
Definition: svm_types.h:500
NodeMix
Definition: svm_types.h:249
@ NODE_MIX_MUL
Definition: svm_types.h:252
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
Definition: svm_types.h:559
@ CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID
Definition: svm_types.h:550
@ CLOSURE_BSSRDF_CUBIC_ID
Definition: svm_types.h:574
@ CLOSURE_BSSRDF_GAUSSIAN_ID
Definition: svm_types.h:575
@ CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID
Definition: svm_types.h:562
@ CLOSURE_BSSRDF_BURLEY_ID
Definition: svm_types.h:577
@ CLOSURE_BSDF_DIFFUSE_TOON_ID
Definition: svm_types.h:539
@ CLOSURE_BSDF_MICROFACET_GGX_ID
Definition: svm_types.h:544
@ CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID
Definition: svm_types.h:558
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID
Definition: svm_types.h:548
@ CLOSURE_BSDF_HAIR_TRANSMISSION_ID
Definition: svm_types.h:566
@ CLOSURE_BSDF_SHARP_GLASS_ID
Definition: svm_types.h:564
@ CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID
Definition: svm_types.h:561
@ CLOSURE_BSSRDF_RANDOM_WALK_ID
Definition: svm_types.h:578
@ CLOSURE_BSDF_REFRACTION_ID
Definition: svm_types.h:557
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
Definition: svm_types.h:547
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID
Definition: svm_types.h:560
@ CLOSURE_BSSRDF_PRINCIPLED_ID
Definition: svm_types.h:576
@ CLOSURE_BSSRDF_PRINCIPLED_RANDOM_WALK_ID
Definition: svm_types.h:579
@ CLOSURE_BSDF_GLOSSY_TOON_ID
Definition: svm_types.h:553
@ CLOSURE_BSDF_HAIR_REFLECTION_ID
Definition: svm_types.h:554
@ CLOSURE_BSDF_REFLECTION_ID
Definition: svm_types.h:543
NodeVectorRotateType
Definition: svm_types.h:365
NodeVectorTransformType
Definition: svm_types.h:373
NodeImageProjection
Definition: svm_types.h:477
NodeGradientType
Definition: svm_types.h:428
NodeTangentDirectionType
Definition: svm_types.h:458
NodeVectorMathType
Definition: svm_types.h:314
NodeWaveRingsDirection
Definition: svm_types.h:413
NodeNormalMapSpace
Definition: svm_types.h:469
static int magic(const Tex *tex, const float texvec[3], TexResult *texres)
#define mix(a, b, c)
Definition: util_hash.h:30
ccl_device_inline float3 float4_to_float3(const float4 a)
Definition: util_math.h:415
ccl_device_inline float2 normalize(const float2 &a)
ccl_device_inline float3 one_float3()
ccl_device_inline float3 zero_float3()
CCL_NAMESPACE_BEGIN string string_printf(const char *format,...)
Definition: util_string.cpp:32
ImageAlphaType
Definition: util_texture.h:68
@ IMAGE_ALPHA_NUM_TYPES
Definition: util_texture.h:75
@ IMAGE_ALPHA_AUTO
Definition: util_texture.h:73
InterpolationType
Definition: util_texture.h:38
@ INTERPOLATION_LINEAR
Definition: util_texture.h:40
@ INTERPOLATION_NUM_TYPES
Definition: util_texture.h:45
ExtensionType
Definition: util_texture.h:84
@ EXTENSION_REPEAT
Definition: util_texture.h:86
@ EXTENSION_NUM_TYPES
Definition: util_texture.h:92
Transform transform_inverse(const Transform &tfm)
ccl_device_inline Transform transform_translate(float3 t)
ccl_device_inline Transform transform_scale(float3 s)
PointerRNA * ptr
Definition: wm_files.c:3157