Blender  V3.3
services.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 /* TODO(sergey): There is a bit of headers dependency hell going on
5  * here, so for now we just put here. In the future it might be better
6  * to have dedicated file for such tweaks.
7  */
8 #if (defined(__GNUC__) && !defined(__clang__)) && defined(NDEBUG)
9 # pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
10 # pragma GCC diagnostic ignored "-Wuninitialized"
11 #endif
12 
13 #include <string.h>
14 
15 #include "scene/colorspace.h"
16 #include "scene/mesh.h"
17 #include "scene/object.h"
18 #include "scene/pointcloud.h"
19 #include "scene/scene.h"
20 
21 #include "kernel/osl/closures.h"
22 #include "kernel/osl/globals.h"
23 #include "kernel/osl/services.h"
24 #include "kernel/osl/shader.h"
25 
26 #include "util/foreach.h"
27 #include "util/log.h"
28 #include "util/string.h"
29 
30 // clang-format off
34 
36 
39 
40 #include "kernel/geom/geom.h"
41 
42 #include "kernel/bvh/bvh.h"
43 
44 #include "kernel/camera/camera.h"
46 
49 
50 #include "kernel/util/color.h"
51 // clang-format on
52 
54 
55 /* RenderServices implementation */
56 
57 static void copy_matrix(OSL::Matrix44 &m, const Transform &tfm)
58 {
60  memcpy((void *)&m, &t, sizeof(m));
61 }
62 
63 static void copy_matrix(OSL::Matrix44 &m, const ProjectionTransform &tfm)
64 {
66  memcpy((void *)&m, &t, sizeof(m));
67 }
68 
69 /* static ustrings */
70 ustring OSLRenderServices::u_distance("distance");
71 ustring OSLRenderServices::u_index("index");
72 ustring OSLRenderServices::u_world("world");
73 ustring OSLRenderServices::u_camera("camera");
74 ustring OSLRenderServices::u_screen("screen");
75 ustring OSLRenderServices::u_raster("raster");
76 ustring OSLRenderServices::u_ndc("NDC");
77 ustring OSLRenderServices::u_object_location("object:location");
78 ustring OSLRenderServices::u_object_color("object:color");
79 ustring OSLRenderServices::u_object_alpha("object:alpha");
80 ustring OSLRenderServices::u_object_index("object:index");
81 ustring OSLRenderServices::u_geom_dupli_generated("geom:dupli_generated");
82 ustring OSLRenderServices::u_geom_dupli_uv("geom:dupli_uv");
83 ustring OSLRenderServices::u_material_index("material:index");
84 ustring OSLRenderServices::u_object_random("object:random");
85 ustring OSLRenderServices::u_particle_index("particle:index");
86 ustring OSLRenderServices::u_particle_random("particle:random");
87 ustring OSLRenderServices::u_particle_age("particle:age");
88 ustring OSLRenderServices::u_particle_lifetime("particle:lifetime");
89 ustring OSLRenderServices::u_particle_location("particle:location");
90 ustring OSLRenderServices::u_particle_rotation("particle:rotation");
91 ustring OSLRenderServices::u_particle_size("particle:size");
92 ustring OSLRenderServices::u_particle_velocity("particle:velocity");
93 ustring OSLRenderServices::u_particle_angular_velocity("particle:angular_velocity");
94 ustring OSLRenderServices::u_geom_numpolyvertices("geom:numpolyvertices");
95 ustring OSLRenderServices::u_geom_trianglevertices("geom:trianglevertices");
96 ustring OSLRenderServices::u_geom_polyvertices("geom:polyvertices");
97 ustring OSLRenderServices::u_geom_name("geom:name");
98 ustring OSLRenderServices::u_geom_undisplaced("geom:undisplaced");
99 ustring OSLRenderServices::u_is_smooth("geom:is_smooth");
100 ustring OSLRenderServices::u_is_curve("geom:is_curve");
101 ustring OSLRenderServices::u_curve_thickness("geom:curve_thickness");
102 ustring OSLRenderServices::u_curve_length("geom:curve_length");
103 ustring OSLRenderServices::u_curve_tangent_normal("geom:curve_tangent_normal");
104 ustring OSLRenderServices::u_curve_random("geom:curve_random");
105 ustring OSLRenderServices::u_is_point("geom:is_point");
106 ustring OSLRenderServices::u_point_radius("geom:point_radius");
107 ustring OSLRenderServices::u_point_position("geom:point_position");
108 ustring OSLRenderServices::u_point_random("geom:point_random");
109 ustring OSLRenderServices::u_normal_map_normal("geom:normal_map_normal");
110 ustring OSLRenderServices::u_path_ray_length("path:ray_length");
111 ustring OSLRenderServices::u_path_ray_depth("path:ray_depth");
112 ustring OSLRenderServices::u_path_diffuse_depth("path:diffuse_depth");
113 ustring OSLRenderServices::u_path_glossy_depth("path:glossy_depth");
114 ustring OSLRenderServices::u_path_transparent_depth("path:transparent_depth");
115 ustring OSLRenderServices::u_path_transmission_depth("path:transmission_depth");
116 ustring OSLRenderServices::u_trace("trace");
117 ustring OSLRenderServices::u_hit("hit");
118 ustring OSLRenderServices::u_hitdist("hitdist");
119 ustring OSLRenderServices::u_N("N");
120 ustring OSLRenderServices::u_Ng("Ng");
121 ustring OSLRenderServices::u_P("P");
122 ustring OSLRenderServices::u_I("I");
123 ustring OSLRenderServices::u_u("u");
124 ustring OSLRenderServices::u_v("v");
126 
127 OSLRenderServices::OSLRenderServices(OSL::TextureSystem *texture_system)
128  : texture_system(texture_system)
129 {
130 }
131 
133 {
134  if (texture_system) {
135  VLOG_INFO << "OSL texture system stats:\n" << texture_system->getstats();
136  }
137 }
138 
139 bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg,
140  OSL::Matrix44 &result,
141  OSL::TransformationPtr xform,
142  float time)
143 {
144  /* this is only used for shader and object space, we don't really have
145  * a concept of shader space, so we just use object space for both. */
146  if (xform) {
147  const ShaderData *sd = (const ShaderData *)xform;
148  const KernelGlobalsCPU *kg = sd->osl_globals;
149  int object = sd->object;
150 
151  if (object != OBJECT_NONE) {
152 #ifdef __OBJECT_MOTION__
153  Transform tfm;
154 
155  if (time == sd->time)
156  tfm = object_get_transform(kg, sd);
157  else
158  tfm = object_fetch_transform_motion_test(kg, object, time, NULL);
159 #else
160  const Transform tfm = object_get_transform(kg, sd);
161 #endif
162  copy_matrix(result, tfm);
163 
164  return true;
165  }
166  else if (sd->type == PRIMITIVE_LAMP) {
167  const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false);
168  copy_matrix(result, tfm);
169 
170  return true;
171  }
172  }
173 
174  return false;
175 }
176 
177 bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
178  OSL::Matrix44 &result,
179  OSL::TransformationPtr xform,
180  float time)
181 {
182  /* this is only used for shader and object space, we don't really have
183  * a concept of shader space, so we just use object space for both. */
184  if (xform) {
185  const ShaderData *sd = (const ShaderData *)xform;
186  const KernelGlobalsCPU *kg = sd->osl_globals;
187  int object = sd->object;
188 
189  if (object != OBJECT_NONE) {
190 #ifdef __OBJECT_MOTION__
191  Transform itfm;
192 
193  if (time == sd->time)
194  itfm = object_get_inverse_transform(kg, sd);
195  else
196  object_fetch_transform_motion_test(kg, object, time, &itfm);
197 #else
198  const Transform itfm = object_get_inverse_transform(kg, sd);
199 #endif
200  copy_matrix(result, itfm);
201 
202  return true;
203  }
204  else if (sd->type == PRIMITIVE_LAMP) {
205  const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true);
206  copy_matrix(result, itfm);
207 
208  return true;
209  }
210  }
211 
212  return false;
213 }
214 
215 bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg,
216  OSL::Matrix44 &result,
217  ustring from,
218  float time)
219 {
220  ShaderData *sd = (ShaderData *)(sg->renderstate);
221  const KernelGlobalsCPU *kg = sd->osl_globals;
222 
223  if (from == u_ndc) {
224  copy_matrix(result, kernel_data.cam.ndctoworld);
225  return true;
226  }
227  else if (from == u_raster) {
228  copy_matrix(result, kernel_data.cam.rastertoworld);
229  return true;
230  }
231  else if (from == u_screen) {
232  copy_matrix(result, kernel_data.cam.screentoworld);
233  return true;
234  }
235  else if (from == u_camera) {
236  copy_matrix(result, kernel_data.cam.cameratoworld);
237  return true;
238  }
239  else if (from == u_world) {
240  result.makeIdentity();
241  return true;
242  }
243 
244  return false;
245 }
246 
247 bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
248  OSL::Matrix44 &result,
249  ustring to,
250  float time)
251 {
252  ShaderData *sd = (ShaderData *)(sg->renderstate);
253  const KernelGlobalsCPU *kg = sd->osl_globals;
254 
255  if (to == u_ndc) {
256  copy_matrix(result, kernel_data.cam.worldtondc);
257  return true;
258  }
259  else if (to == u_raster) {
260  copy_matrix(result, kernel_data.cam.worldtoraster);
261  return true;
262  }
263  else if (to == u_screen) {
264  copy_matrix(result, kernel_data.cam.worldtoscreen);
265  return true;
266  }
267  else if (to == u_camera) {
268  copy_matrix(result, kernel_data.cam.worldtocamera);
269  return true;
270  }
271  else if (to == u_world) {
272  result.makeIdentity();
273  return true;
274  }
275 
276  return false;
277 }
278 
279 bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg,
280  OSL::Matrix44 &result,
281  OSL::TransformationPtr xform)
282 {
283  /* this is only used for shader and object space, we don't really have
284  * a concept of shader space, so we just use object space for both. */
285  if (xform) {
286  const ShaderData *sd = (const ShaderData *)xform;
287  const KernelGlobalsCPU *kg = sd->osl_globals;
288  int object = sd->object;
289 
290  if (object != OBJECT_NONE) {
291  const Transform tfm = object_get_transform(kg, sd);
292  copy_matrix(result, tfm);
293 
294  return true;
295  }
296  else if (sd->type == PRIMITIVE_LAMP) {
297  const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false);
298  copy_matrix(result, tfm);
299 
300  return true;
301  }
302  }
303 
304  return false;
305 }
306 
307 bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
308  OSL::Matrix44 &result,
309  OSL::TransformationPtr xform)
310 {
311  /* this is only used for shader and object space, we don't really have
312  * a concept of shader space, so we just use object space for both. */
313  if (xform) {
314  const ShaderData *sd = (const ShaderData *)xform;
315  const KernelGlobalsCPU *kg = sd->osl_globals;
316  int object = sd->object;
317 
318  if (object != OBJECT_NONE) {
319  const Transform tfm = object_get_inverse_transform(kg, sd);
320  copy_matrix(result, tfm);
321 
322  return true;
323  }
324  else if (sd->type == PRIMITIVE_LAMP) {
325  const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true);
326  copy_matrix(result, itfm);
327 
328  return true;
329  }
330  }
331 
332  return false;
333 }
334 
335 bool OSLRenderServices::get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, ustring from)
336 {
337  ShaderData *sd = (ShaderData *)(sg->renderstate);
338  const KernelGlobalsCPU *kg = sd->osl_globals;
339 
340  if (from == u_ndc) {
341  copy_matrix(result, kernel_data.cam.ndctoworld);
342  return true;
343  }
344  else if (from == u_raster) {
345  copy_matrix(result, kernel_data.cam.rastertoworld);
346  return true;
347  }
348  else if (from == u_screen) {
349  copy_matrix(result, kernel_data.cam.screentoworld);
350  return true;
351  }
352  else if (from == u_camera) {
353  copy_matrix(result, kernel_data.cam.cameratoworld);
354  return true;
355  }
356 
357  return false;
358 }
359 
360 bool OSLRenderServices::get_inverse_matrix(OSL::ShaderGlobals *sg,
361  OSL::Matrix44 &result,
362  ustring to)
363 {
364  ShaderData *sd = (ShaderData *)(sg->renderstate);
365  const KernelGlobalsCPU *kg = sd->osl_globals;
366 
367  if (to == u_ndc) {
368  copy_matrix(result, kernel_data.cam.worldtondc);
369  return true;
370  }
371  else if (to == u_raster) {
372  copy_matrix(result, kernel_data.cam.worldtoraster);
373  return true;
374  }
375  else if (to == u_screen) {
376  copy_matrix(result, kernel_data.cam.worldtoscreen);
377  return true;
378  }
379  else if (to == u_camera) {
380  copy_matrix(result, kernel_data.cam.worldtocamera);
381  return true;
382  }
383 
384  return false;
385 }
386 
387 bool OSLRenderServices::get_array_attribute(OSL::ShaderGlobals *sg,
388  bool derivatives,
389  ustring object,
390  TypeDesc type,
391  ustring name,
392  int index,
393  void *val)
394 {
395  return false;
396 }
397 
398 static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, void *val)
399 {
400  if (type == TypeFloatArray4) {
401  float *fval = (float *)val;
402  fval[0] = f[0].x;
403  fval[1] = f[0].y;
404  fval[2] = 0.0f;
405  fval[3] = 1.0f;
406 
407  if (derivatives) {
408  fval[4] = f[1].x;
409  fval[5] = f[1].y;
410  fval[6] = 0.0f;
411  fval[7] = 0.0f;
412 
413  fval[8] = f[2].x;
414  fval[9] = f[2].y;
415  fval[10] = 0.0f;
416  fval[11] = 0.0f;
417  }
418  return true;
419  }
420  else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
421  type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
422  float *fval = (float *)val;
423 
424  fval[0] = f[0].x;
425  fval[1] = f[0].y;
426  fval[2] = 0.0f;
427 
428  if (derivatives) {
429  fval[3] = f[1].x;
430  fval[4] = f[1].y;
431  fval[5] = 0.0f;
432 
433  fval[6] = f[2].x;
434  fval[7] = f[2].y;
435  fval[8] = 0.0f;
436  }
437 
438  return true;
439  }
440  else if (type == TypeDesc::TypeFloat) {
441  float *fval = (float *)val;
442  fval[0] = average(f[0]);
443 
444  if (derivatives) {
445  fval[1] = average(f[1]);
446  fval[2] = average(f[2]);
447  }
448 
449  return true;
450  }
451 
452  return false;
453 }
454 
455 static bool set_attribute_float2(float2 f, TypeDesc type, bool derivatives, void *val)
456 {
457  float2 fv[3];
458 
459  fv[0] = f;
460  fv[1] = make_float2(0.0f, 0.0f);
461  fv[2] = make_float2(0.0f, 0.0f);
462 
463  return set_attribute_float2(fv, type, derivatives, val);
464 }
465 
466 static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val)
467 {
468  if (type == TypeFloatArray4) {
469  float *fval = (float *)val;
470  fval[0] = f[0].x;
471  fval[1] = f[0].y;
472  fval[2] = f[0].z;
473  fval[3] = 1.0f;
474 
475  if (derivatives) {
476  fval[4] = f[1].x;
477  fval[5] = f[1].y;
478  fval[6] = f[1].z;
479  fval[7] = 0.0f;
480 
481  fval[8] = f[2].x;
482  fval[9] = f[2].y;
483  fval[10] = f[2].z;
484  fval[11] = 0.0f;
485  }
486  return true;
487  }
488  else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
489  type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
490  float *fval = (float *)val;
491 
492  fval[0] = f[0].x;
493  fval[1] = f[0].y;
494  fval[2] = f[0].z;
495 
496  if (derivatives) {
497  fval[3] = f[1].x;
498  fval[4] = f[1].y;
499  fval[5] = f[1].z;
500 
501  fval[6] = f[2].x;
502  fval[7] = f[2].y;
503  fval[8] = f[2].z;
504  }
505 
506  return true;
507  }
508  else if (type == TypeDesc::TypeFloat) {
509  float *fval = (float *)val;
510  fval[0] = average(f[0]);
511 
512  if (derivatives) {
513  fval[1] = average(f[1]);
514  fval[2] = average(f[2]);
515  }
516 
517  return true;
518  }
519 
520  return false;
521 }
522 
523 static bool set_attribute_float3(float3 f, TypeDesc type, bool derivatives, void *val)
524 {
525  float3 fv[3];
526 
527  fv[0] = f;
528  fv[1] = make_float3(0.0f, 0.0f, 0.0f);
529  fv[2] = make_float3(0.0f, 0.0f, 0.0f);
530 
531  return set_attribute_float3(fv, type, derivatives, val);
532 }
533 
534 /* Attributes with the TypeRGBA type descriptor should be retrieved and stored
535  * in a float array of size 4 (e.g. node_vertex_color.osl), this array have
536  * a type descriptor TypeFloatArray4. If the storage is not a TypeFloatArray4,
537  * we either store the first three components in a vector, store the average of
538  * the components in a float, or fail the retrieval and do nothing. We allow
539  * this for the correct operation of the Attribute node.
540  */
541 
542 static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, void *val)
543 {
544  float *fval = (float *)val;
545  if (type == TypeFloatArray4) {
546  fval[0] = f[0].x;
547  fval[1] = f[0].y;
548  fval[2] = f[0].z;
549  fval[3] = f[0].w;
550 
551  if (derivatives) {
552  fval[4] = f[1].x;
553  fval[5] = f[1].y;
554  fval[6] = f[1].z;
555  fval[7] = f[1].w;
556 
557  fval[8] = f[2].x;
558  fval[9] = f[2].y;
559  fval[10] = f[2].z;
560  fval[11] = f[2].w;
561  }
562  return true;
563  }
564  else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
565  type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
566  fval[0] = f[0].x;
567  fval[1] = f[0].y;
568  fval[2] = f[0].z;
569 
570  if (derivatives) {
571  fval[3] = f[1].x;
572  fval[4] = f[1].y;
573  fval[5] = f[1].z;
574 
575  fval[6] = f[2].x;
576  fval[7] = f[2].y;
577  fval[8] = f[2].z;
578  }
579  return true;
580  }
581  else if (type == TypeDesc::TypeFloat) {
582  fval[0] = average(float4_to_float3(f[0]));
583 
584  if (derivatives) {
585  fval[1] = average(float4_to_float3(f[1]));
586  fval[2] = average(float4_to_float3(f[2]));
587  }
588  return true;
589  }
590  return false;
591 }
592 
593 static bool set_attribute_float4(float4 f, TypeDesc type, bool derivatives, void *val)
594 {
595  float4 fv[3];
596 
597  fv[0] = f;
598  fv[1] = zero_float4();
599  fv[2] = zero_float4();
600 
601  return set_attribute_float4(fv, type, derivatives, val);
602 }
603 
604 static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val)
605 {
606  if (type == TypeFloatArray4) {
607  float *fval = (float *)val;
608  fval[0] = f[0];
609  fval[1] = f[0];
610  fval[2] = f[0];
611  fval[3] = 1.0f;
612 
613  if (derivatives) {
614  fval[4] = f[1];
615  fval[5] = f[1];
616  fval[6] = f[1];
617  fval[7] = 0.0f;
618 
619  fval[8] = f[2];
620  fval[9] = f[2];
621  fval[10] = f[2];
622  fval[11] = 0.0f;
623  }
624  return true;
625  }
626  else if (type == TypeDesc::TypePoint || type == TypeDesc::TypeVector ||
627  type == TypeDesc::TypeNormal || type == TypeDesc::TypeColor) {
628  float *fval = (float *)val;
629  fval[0] = f[0];
630  fval[1] = f[0];
631  fval[2] = f[0];
632 
633  if (derivatives) {
634  fval[3] = f[1];
635  fval[4] = f[1];
636  fval[5] = f[1];
637 
638  fval[6] = f[2];
639  fval[7] = f[2];
640  fval[8] = f[2];
641  }
642 
643  return true;
644  }
645  else if (type == TypeDesc::TypeFloat) {
646  float *fval = (float *)val;
647  fval[0] = f[0];
648 
649  if (derivatives) {
650  fval[1] = f[1];
651  fval[2] = f[2];
652  }
653 
654  return true;
655  }
656 
657  return false;
658 }
659 
660 static bool set_attribute_float(float f, TypeDesc type, bool derivatives, void *val)
661 {
662  float fv[3];
663 
664  fv[0] = f;
665  fv[1] = 0.0f;
666  fv[2] = 0.0f;
667 
668  return set_attribute_float(fv, type, derivatives, val);
669 }
670 
671 static bool set_attribute_int(int i, TypeDesc type, bool derivatives, void *val)
672 {
673  if (type.basetype == TypeDesc::INT && type.aggregate == TypeDesc::SCALAR && type.arraylen == 0) {
674  int *ival = (int *)val;
675  ival[0] = i;
676 
677  if (derivatives) {
678  ival[1] = 0;
679  ival[2] = 0;
680  }
681 
682  return true;
683  }
684 
685  return false;
686 }
687 
688 static bool set_attribute_string(ustring str, TypeDesc type, bool derivatives, void *val)
689 {
690  if (type.basetype == TypeDesc::STRING && type.aggregate == TypeDesc::SCALAR &&
691  type.arraylen == 0) {
692  ustring *sval = (ustring *)val;
693  sval[0] = str;
694 
695  if (derivatives) {
696  sval[1] = OSLRenderServices::u_empty;
697  sval[2] = OSLRenderServices::u_empty;
698  }
699 
700  return true;
701  }
702 
703  return false;
704 }
705 
706 static bool set_attribute_float3_3(float3 P[3], TypeDesc type, bool derivatives, void *val)
707 {
708  if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
709  float *fval = (float *)val;
710 
711  fval[0] = P[0].x;
712  fval[1] = P[0].y;
713  fval[2] = P[0].z;
714 
715  fval[3] = P[1].x;
716  fval[4] = P[1].y;
717  fval[5] = P[1].z;
718 
719  fval[6] = P[2].x;
720  fval[7] = P[2].y;
721  fval[8] = P[2].z;
722 
723  if (type.arraylen > 3)
724  memset(fval + 3 * 3, 0, sizeof(float) * 3 * (type.arraylen - 3));
725  if (derivatives)
726  memset(fval + type.arraylen * 3, 0, sizeof(float) * 2 * 3 * type.arraylen);
727 
728  return true;
729  }
730 
731  return false;
732 }
733 
734 static bool set_attribute_matrix(const Transform &tfm, TypeDesc type, void *val)
735 {
736  if (type == TypeDesc::TypeMatrix) {
737  copy_matrix(*(OSL::Matrix44 *)val, tfm);
738  return true;
739  }
740 
741  return false;
742 }
743 
745  const ShaderData *sd,
746  const OSLGlobals::Attribute &attr,
747  const TypeDesc &type,
748  bool derivatives,
749  void *val)
750 {
751  if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
752  attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
753  float3 fval[3];
754  if (primitive_is_volume_attribute(sd, attr.desc)) {
755  fval[0] = primitive_volume_attribute_float3(kg, sd, attr.desc);
756  }
757  else {
758  memset(fval, 0, sizeof(fval));
760  kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
761  }
762  return set_attribute_float3(fval, type, derivatives, val);
763  }
764  else if (attr.type == TypeFloat2) {
765  if (primitive_is_volume_attribute(sd, attr.desc)) {
766  assert(!"Float2 attribute not support for volumes");
767  return false;
768  }
769  else {
770  float2 fval[3];
772  kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
773  return set_attribute_float2(fval, type, derivatives, val);
774  }
775  }
776  else if (attr.type == TypeDesc::TypeFloat) {
777  float fval[3];
778  if (primitive_is_volume_attribute(sd, attr.desc)) {
779  memset(fval, 0, sizeof(fval));
780  fval[0] = primitive_volume_attribute_float(kg, sd, attr.desc);
781  }
782  else {
784  kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
785  }
786  return set_attribute_float(fval, type, derivatives, val);
787  }
788  else if (attr.type == TypeDesc::TypeFloat4 || attr.type == TypeRGBA) {
789  float4 fval[3];
790  if (primitive_is_volume_attribute(sd, attr.desc)) {
791  memset(fval, 0, sizeof(fval));
792  fval[0] = primitive_volume_attribute_float4(kg, sd, attr.desc);
793  }
794  else {
796  kg, sd, attr.desc, (derivatives) ? &fval[1] : NULL, (derivatives) ? &fval[2] : NULL);
797  }
798  return set_attribute_float4(fval, type, derivatives, val);
799  }
800  else {
801  return false;
802  }
803 }
804 
805 static bool get_mesh_attribute(const KernelGlobalsCPU *kg,
806  const ShaderData *sd,
807  const OSLGlobals::Attribute &attr,
808  const TypeDesc &type,
809  bool derivatives,
810  void *val)
811 {
812  if (attr.type == TypeDesc::TypeMatrix) {
813  Transform tfm = primitive_attribute_matrix(kg, sd, attr.desc);
814  return set_attribute_matrix(tfm, type, val);
815  }
816  else {
817  return false;
818  }
819 }
820 
822  TypeDesc type,
823  bool derivatives,
824  void *val)
825 {
826  if (attr.type == TypeDesc::TypePoint || attr.type == TypeDesc::TypeVector ||
827  attr.type == TypeDesc::TypeNormal || attr.type == TypeDesc::TypeColor) {
828  const float *data = (const float *)attr.value.data();
829  return set_attribute_float3(make_float3(data[0], data[1], data[2]), type, derivatives, val);
830  }
831  else if (attr.type == TypeFloat2) {
832  const float *data = (const float *)attr.value.data();
833  return set_attribute_float2(make_float2(data[0], data[1]), type, derivatives, val);
834  }
835  else if (attr.type == TypeDesc::TypeFloat) {
836  const float *data = (const float *)attr.value.data();
837  return set_attribute_float(data[0], type, derivatives, val);
838  }
839  else if (attr.type == TypeRGBA || attr.type == TypeDesc::TypeFloat4) {
840  const float *data = (const float *)attr.value.data();
841  return set_attribute_float4(
842  make_float4(data[0], data[1], data[2], data[3]), type, derivatives, val);
843  }
844  else if (attr.type == type) {
845  size_t datasize = attr.value.datasize();
846 
847  memcpy(val, attr.value.data(), datasize);
848  if (derivatives) {
849  memset((char *)val + datasize, 0, datasize * 2);
850  }
851 
852  return true;
853  }
854  else {
855  return false;
856  }
857 }
858 
860  ShaderData *sd,
861  ustring name,
862  TypeDesc type,
863  bool derivatives,
864  void *val)
865 {
866  /* todo: turn this into hash table? */
867 
868  /* Object Attributes */
869  if (name == u_object_location) {
870  float3 f = object_location(kg, sd);
871  return set_attribute_float3(f, type, derivatives, val);
872  }
873  else if (name == u_object_color) {
874  float3 f = object_color(kg, sd->object);
875  return set_attribute_float3(f, type, derivatives, val);
876  }
877  else if (name == u_object_alpha) {
878  float f = object_alpha(kg, sd->object);
879  return set_attribute_float(f, type, derivatives, val);
880  }
881  else if (name == u_object_index) {
882  float f = object_pass_id(kg, sd->object);
883  return set_attribute_float(f, type, derivatives, val);
884  }
885  else if (name == u_geom_dupli_generated) {
886  float3 f = object_dupli_generated(kg, sd->object);
887  return set_attribute_float3(f, type, derivatives, val);
888  }
889  else if (name == u_geom_dupli_uv) {
890  float3 f = object_dupli_uv(kg, sd->object);
891  return set_attribute_float3(f, type, derivatives, val);
892  }
893  else if (name == u_material_index) {
894  float f = shader_pass_id(kg, sd);
895  return set_attribute_float(f, type, derivatives, val);
896  }
897  else if (name == u_object_random) {
898  float f = object_random_number(kg, sd->object);
899  return set_attribute_float(f, type, derivatives, val);
900  }
901 
902  /* Particle Attributes */
903  else if (name == u_particle_index) {
904  int particle_id = object_particle_id(kg, sd->object);
905  float f = particle_index(kg, particle_id);
906  return set_attribute_float(f, type, derivatives, val);
907  }
908  else if (name == u_particle_random) {
909  int particle_id = object_particle_id(kg, sd->object);
910  float f = hash_uint2_to_float(particle_index(kg, particle_id), 0);
911  return set_attribute_float(f, type, derivatives, val);
912  }
913 
914  else if (name == u_particle_age) {
915  int particle_id = object_particle_id(kg, sd->object);
916  float f = particle_age(kg, particle_id);
917  return set_attribute_float(f, type, derivatives, val);
918  }
919  else if (name == u_particle_lifetime) {
920  int particle_id = object_particle_id(kg, sd->object);
921  float f = particle_lifetime(kg, particle_id);
922  return set_attribute_float(f, type, derivatives, val);
923  }
924  else if (name == u_particle_location) {
925  int particle_id = object_particle_id(kg, sd->object);
926  float3 f = particle_location(kg, particle_id);
927  return set_attribute_float3(f, type, derivatives, val);
928  }
929 #if 0 /* unsupported */
930  else if (name == u_particle_rotation) {
931  int particle_id = object_particle_id(kg, sd->object);
932  float4 f = particle_rotation(kg, particle_id);
933  return set_attribute_float4(f, type, derivatives, val);
934  }
935 #endif
936  else if (name == u_particle_size) {
937  int particle_id = object_particle_id(kg, sd->object);
938  float f = particle_size(kg, particle_id);
939  return set_attribute_float(f, type, derivatives, val);
940  }
941  else if (name == u_particle_velocity) {
942  int particle_id = object_particle_id(kg, sd->object);
943  float3 f = particle_velocity(kg, particle_id);
944  return set_attribute_float3(f, type, derivatives, val);
945  }
946  else if (name == u_particle_angular_velocity) {
947  int particle_id = object_particle_id(kg, sd->object);
948  float3 f = particle_angular_velocity(kg, particle_id);
949  return set_attribute_float3(f, type, derivatives, val);
950  }
951 
952  /* Geometry Attributes */
953  else if (name == u_geom_numpolyvertices) {
954  return set_attribute_int(3, type, derivatives, val);
955  }
956  else if ((name == u_geom_trianglevertices || name == u_geom_polyvertices) &&
957  sd->type & PRIMITIVE_TRIANGLE) {
958  float3 P[3];
959 
960  if (sd->type & PRIMITIVE_MOTION) {
961  motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, P);
962  }
963  else {
964  triangle_vertices(kg, sd->prim, P);
965  }
966 
967  if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
968  object_position_transform(kg, sd, &P[0]);
969  object_position_transform(kg, sd, &P[1]);
970  object_position_transform(kg, sd, &P[2]);
971  }
972 
973  return set_attribute_float3_3(P, type, derivatives, val);
974  }
975  else if (name == u_geom_name) {
976  ustring object_name = kg->osl->object_names[sd->object];
977  return set_attribute_string(object_name, type, derivatives, val);
978  }
979  else if (name == u_is_smooth) {
980  float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0);
981  return set_attribute_float(f, type, derivatives, val);
982  }
983  /* Hair Attributes */
984  else if (name == u_is_curve) {
985  float f = (sd->type & PRIMITIVE_CURVE) != 0;
986  return set_attribute_float(f, type, derivatives, val);
987  }
988  else if (name == u_curve_thickness) {
989  float f = curve_thickness(kg, sd);
990  return set_attribute_float(f, type, derivatives, val);
991  }
992  else if (name == u_curve_tangent_normal) {
993  float3 f = curve_tangent_normal(kg, sd);
994  return set_attribute_float3(f, type, derivatives, val);
995  }
996  else if (name == u_curve_random) {
997  float f = curve_random(kg, sd);
998  return set_attribute_float(f, type, derivatives, val);
999  }
1000  /* point attributes */
1001  else if (name == u_is_point) {
1002  float f = (sd->type & PRIMITIVE_POINT) != 0;
1003  return set_attribute_float(f, type, derivatives, val);
1004  }
1005  else if (name == u_point_radius) {
1006  float f = point_radius(kg, sd);
1007  return set_attribute_float(f, type, derivatives, val);
1008  }
1009  else if (name == u_point_position) {
1010  float3 f = point_position(kg, sd);
1011  return set_attribute_float3(f, type, derivatives, val);
1012  }
1013  else if (name == u_point_random) {
1014  float f = point_random(kg, sd);
1015  return set_attribute_float(f, type, derivatives, val);
1016  }
1017  else if (name == u_normal_map_normal) {
1018  if (sd->type & PRIMITIVE_TRIANGLE) {
1019  float3 f = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v);
1020  return set_attribute_float3(f, type, derivatives, val);
1021  }
1022  else {
1023  return false;
1024  }
1025  }
1026  else {
1027  return false;
1028  }
1029 }
1030 
1032  ShaderData *sd,
1033  ustring name,
1034  TypeDesc type,
1035  bool derivatives,
1036  void *val)
1037 {
1038  if (name == u_path_ray_length) {
1039  /* Ray Length */
1040  float f = sd->ray_length;
1041  return set_attribute_float(f, type, derivatives, val);
1042  }
1043  else if (name == u_path_ray_depth) {
1044  /* Ray Depth */
1045  const IntegratorStateCPU *state = sd->osl_path_state;
1046  const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
1047  int f = (state) ? state->path.bounce : (shadow_state) ? shadow_state->shadow_path.bounce : 0;
1048  return set_attribute_int(f, type, derivatives, val);
1049  }
1050  else if (name == u_path_diffuse_depth) {
1051  /* Diffuse Ray Depth */
1052  const IntegratorStateCPU *state = sd->osl_path_state;
1053  const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
1054  int f = (state) ? state->path.diffuse_bounce :
1055  (shadow_state) ? shadow_state->shadow_path.diffuse_bounce :
1056  0;
1057  return set_attribute_int(f, type, derivatives, val);
1058  }
1059  else if (name == u_path_glossy_depth) {
1060  /* Glossy Ray Depth */
1061  const IntegratorStateCPU *state = sd->osl_path_state;
1062  const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
1063  int f = (state) ? state->path.glossy_bounce :
1064  (shadow_state) ? shadow_state->shadow_path.glossy_bounce :
1065  0;
1066  return set_attribute_int(f, type, derivatives, val);
1067  }
1068  else if (name == u_path_transmission_depth) {
1069  /* Transmission Ray Depth */
1070  const IntegratorStateCPU *state = sd->osl_path_state;
1071  const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
1072  int f = (state) ? state->path.transmission_bounce :
1073  (shadow_state) ? shadow_state->shadow_path.transmission_bounce :
1074  0;
1075  return set_attribute_int(f, type, derivatives, val);
1076  }
1077  else if (name == u_path_transparent_depth) {
1078  /* Transparent Ray Depth */
1079  const IntegratorStateCPU *state = sd->osl_path_state;
1080  const IntegratorShadowStateCPU *shadow_state = sd->osl_shadow_path_state;
1081  int f = (state) ? state->path.transparent_bounce :
1082  (shadow_state) ? shadow_state->shadow_path.transparent_bounce :
1083  0;
1084  return set_attribute_int(f, type, derivatives, val);
1085  }
1086  else if (name == u_ndc) {
1087  /* NDC coordinates with special exception for orthographic projection. */
1088  OSLThreadData *tdata = kg->osl_tdata;
1089  OSL::ShaderGlobals *globals = &tdata->globals;
1090  float3 ndc[3];
1091 
1092  if ((globals->raytype & PATH_RAY_CAMERA) && sd->object == OBJECT_NONE &&
1093  kernel_data.cam.type == CAMERA_ORTHOGRAPHIC) {
1094  ndc[0] = camera_world_to_ndc(kg, sd, sd->ray_P);
1095 
1096  if (derivatives) {
1097  ndc[1] = zero_float3();
1098  ndc[2] = zero_float3();
1099  }
1100  }
1101  else {
1102  ndc[0] = camera_world_to_ndc(kg, sd, sd->P);
1103 
1104  if (derivatives) {
1105  ndc[1] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dx) - ndc[0];
1106  ndc[2] = camera_world_to_ndc(kg, sd, sd->P + sd->dP.dy) - ndc[0];
1107  }
1108  }
1109 
1110  return set_attribute_float3(ndc, type, derivatives, val);
1111  }
1112  else
1113  return false;
1114 }
1115 
1116 bool OSLRenderServices::get_attribute(OSL::ShaderGlobals *sg,
1117  bool derivatives,
1118  ustring object_name,
1119  TypeDesc type,
1120  ustring name,
1121  void *val)
1122 {
1123  if (sg == NULL || sg->renderstate == NULL)
1124  return false;
1125 
1126  ShaderData *sd = (ShaderData *)(sg->renderstate);
1127  return get_attribute(sd, derivatives, object_name, type, name, val);
1128 }
1129 
1131  ShaderData *sd, bool derivatives, ustring object_name, TypeDesc type, ustring name, void *val)
1132 {
1133  const KernelGlobalsCPU *kg = sd->osl_globals;
1134  int prim_type = 0;
1135  int object;
1136 
1137  /* lookup of attribute on another object */
1138  if (object_name != u_empty) {
1139  OSLGlobals::ObjectNameMap::iterator it = kg->osl->object_name_map.find(object_name);
1140 
1141  if (it == kg->osl->object_name_map.end())
1142  return false;
1143 
1144  object = it->second;
1145  }
1146  else {
1147  object = sd->object;
1148  prim_type = attribute_primitive_type(kg, sd);
1149 
1150  if (object == OBJECT_NONE)
1151  return get_background_attribute(kg, sd, name, type, derivatives, val);
1152  }
1153 
1154  /* find attribute on object */
1155  object = object * ATTR_PRIM_TYPES + prim_type;
1156  OSLGlobals::AttributeMap &attribute_map = kg->osl->attribute_map[object];
1157  OSLGlobals::AttributeMap::iterator it = attribute_map.find(name);
1158 
1159  if (it != attribute_map.end()) {
1160  const OSLGlobals::Attribute &attr = it->second;
1161 
1162  if (attr.desc.element != ATTR_ELEMENT_OBJECT) {
1163  /* triangle and vertex attributes */
1164  if (get_primitive_attribute(kg, sd, attr, type, derivatives, val))
1165  return true;
1166  else
1167  return get_mesh_attribute(kg, sd, attr, type, derivatives, val);
1168  }
1169  else {
1170  /* object attribute */
1171  return get_object_attribute(attr, type, derivatives, val);
1172  }
1173  }
1174  else {
1175  /* not found in attribute, check standard object info */
1176  bool is_std_object_attribute = get_object_standard_attribute(
1177  kg, sd, name, type, derivatives, val);
1178 
1179  if (is_std_object_attribute)
1180  return true;
1181 
1182  return get_background_attribute(kg, sd, name, type, derivatives, val);
1183  }
1184 
1185  return false;
1186 }
1187 
1189  bool derivatives, ustring name, TypeDesc type, OSL::ShaderGlobals *sg, void *val)
1190 {
1191  return false; /* disabled by lockgeom */
1192 }
1193 
1194 #if OSL_LIBRARY_VERSION_CODE >= 11100
1195 TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename,
1196  OSL::ShadingContext *)
1197 #else
1198 
1199 TextureSystem::TextureHandle *OSLRenderServices::get_texture_handle(ustring filename)
1200 #endif
1201 {
1202  OSLTextureHandleMap::iterator it = textures.find(filename);
1203 
1204  /* For non-OIIO textures, just return a pointer to our own OSLTextureHandle. */
1205  if (it != textures.end()) {
1206  if (it->second->type != OSLTextureHandle::OIIO) {
1207  return (TextureSystem::TextureHandle *)it->second.get();
1208  }
1209  }
1210 
1211  /* Get handle from OpenImageIO. */
1212  OSL::TextureSystem *ts = texture_system;
1213  TextureSystem::TextureHandle *handle = ts->get_texture_handle(filename);
1214  if (handle == NULL) {
1215  return NULL;
1216  }
1217 
1218  /* Insert new OSLTextureHandle if needed. */
1219  if (it == textures.end()) {
1220  textures.insert(filename, new OSLTextureHandle(OSLTextureHandle::OIIO));
1221  it = textures.find(filename);
1222  }
1223 
1224  /* Assign OIIO texture handle and return. */
1225  it->second->oiio_handle = handle;
1226  return (TextureSystem::TextureHandle *)it->second.get();
1227 }
1228 
1229 bool OSLRenderServices::good(TextureSystem::TextureHandle *texture_handle)
1230 {
1231  OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
1232 
1233  if (handle->oiio_handle) {
1234  OSL::TextureSystem *ts = texture_system;
1235  return ts->good(handle->oiio_handle);
1236  }
1237  else {
1238  return true;
1239  }
1240 }
1241 
1242 bool OSLRenderServices::texture(ustring filename,
1243  TextureHandle *texture_handle,
1244  TexturePerthread *texture_thread_info,
1245  TextureOpt &options,
1246  OSL::ShaderGlobals *sg,
1247  float s,
1248  float t,
1249  float dsdx,
1250  float dtdx,
1251  float dsdy,
1252  float dtdy,
1253  int nchannels,
1254  float *result,
1255  float *dresultds,
1256  float *dresultdt,
1257  ustring *errormessage)
1258 {
1259  OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
1260  OSLTextureHandle::Type texture_type = (handle) ? handle->type : OSLTextureHandle::OIIO;
1261  ShaderData *sd = (ShaderData *)(sg->renderstate);
1262  KernelGlobals kernel_globals = sd->osl_globals;
1263  bool status = false;
1264 
1265  switch (texture_type) {
1266  case OSLTextureHandle::BEVEL: {
1267  /* Bevel shader hack. */
1268  if (nchannels >= 3) {
1269  const IntegratorStateCPU *state = sd->osl_path_state;
1270  if (state) {
1271  int num_samples = (int)s;
1272  float radius = t;
1273  float3 N = svm_bevel(kernel_globals, state, sd, radius, num_samples);
1274  result[0] = N.x;
1275  result[1] = N.y;
1276  result[2] = N.z;
1277  status = true;
1278  }
1279  }
1280  break;
1281  }
1282  case OSLTextureHandle::AO: {
1283  /* AO shader hack. */
1284  const IntegratorStateCPU *state = sd->osl_path_state;
1285  if (state) {
1286  int num_samples = (int)s;
1287  float radius = t;
1288  float3 N = make_float3(dsdx, dtdx, dsdy);
1289  int flags = 0;
1290  if ((int)dtdy) {
1291  flags |= NODE_AO_INSIDE;
1292  }
1293  if ((int)options.sblur) {
1294  flags |= NODE_AO_ONLY_LOCAL;
1295  }
1296  if ((int)options.tblur) {
1297  flags |= NODE_AO_GLOBAL_RADIUS;
1298  }
1299  result[0] = svm_ao(kernel_globals, state, sd, N, radius, num_samples, flags);
1300  status = true;
1301  }
1302  break;
1303  }
1304  case OSLTextureHandle::SVM: {
1305  int id = -1;
1306  if (handle->svm_slots[0].w == -1) {
1307  /* Packed single texture. */
1308  id = handle->svm_slots[0].y;
1309  }
1310  else {
1311  /* Packed tiled texture. */
1312  int tx = (int)s;
1313  int ty = (int)t;
1314  int tile = 1001 + 10 * ty + tx;
1315  for (int4 tile_node : handle->svm_slots) {
1316  if (tile_node.x == tile) {
1317  id = tile_node.y;
1318  break;
1319  }
1320  if (tile_node.z == tile) {
1321  id = tile_node.w;
1322  break;
1323  }
1324  }
1325  s -= tx;
1326  t -= ty;
1327  }
1328 
1329  float4 rgba;
1330  if (id == -1) {
1331  rgba = make_float4(
1333  }
1334  else {
1335  rgba = kernel_tex_image_interp(kernel_globals, id, s, 1.0f - t);
1336  }
1337 
1338  result[0] = rgba[0];
1339  if (nchannels > 1)
1340  result[1] = rgba[1];
1341  if (nchannels > 2)
1342  result[2] = rgba[2];
1343  if (nchannels > 3)
1344  result[3] = rgba[3];
1345  status = true;
1346  break;
1347  }
1348  case OSLTextureHandle::IES: {
1349  /* IES light. */
1350  result[0] = kernel_ies_interp(kernel_globals, handle->svm_slots[0].y, s, t);
1351  status = true;
1352  break;
1353  }
1354  case OSLTextureHandle::OIIO: {
1355  /* OpenImageIO texture cache. */
1356  OSL::TextureSystem *ts = texture_system;
1357 
1358  if (handle && handle->oiio_handle) {
1359  if (texture_thread_info == NULL) {
1360  OSLThreadData *tdata = kernel_globals->osl_tdata;
1361  texture_thread_info = tdata->oiio_thread_info;
1362  }
1363 
1364  status = ts->texture(handle->oiio_handle,
1365  texture_thread_info,
1366  options,
1367  s,
1368  t,
1369  dsdx,
1370  dtdx,
1371  dsdy,
1372  dtdy,
1373  nchannels,
1374  result,
1375  dresultds,
1376  dresultdt);
1377  }
1378  else {
1379  status = ts->texture(filename,
1380  options,
1381  s,
1382  t,
1383  dsdx,
1384  dtdx,
1385  dsdy,
1386  dtdy,
1387  nchannels,
1388  result,
1389  dresultds,
1390  dresultdt);
1391  }
1392 
1393  if (!status) {
1394  /* This might be slow, but prevents error messages leak and
1395  * other nasty stuff happening. */
1396  ts->geterror();
1397  }
1398  else if (handle && handle->processor) {
1400  }
1401  break;
1402  }
1403  }
1404 
1405  if (!status) {
1406  if (nchannels == 3 || nchannels == 4) {
1407  result[0] = 1.0f;
1408  result[1] = 0.0f;
1409  result[2] = 1.0f;
1410 
1411  if (nchannels == 4)
1412  result[3] = 1.0f;
1413  }
1414  }
1415 
1416  return status;
1417 }
1418 
1419 bool OSLRenderServices::texture3d(ustring filename,
1420  TextureHandle *texture_handle,
1421  TexturePerthread *texture_thread_info,
1422  TextureOpt &options,
1423  OSL::ShaderGlobals *sg,
1424  const OSL::Vec3 &P,
1425  const OSL::Vec3 &dPdx,
1426  const OSL::Vec3 &dPdy,
1427  const OSL::Vec3 &dPdz,
1428  int nchannels,
1429  float *result,
1430  float *dresultds,
1431  float *dresultdt,
1432  float *dresultdr,
1433  ustring *errormessage)
1434 {
1435  OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
1436  OSLTextureHandle::Type texture_type = (handle) ? handle->type : OSLTextureHandle::OIIO;
1437  bool status = false;
1438 
1439  switch (texture_type) {
1440  case OSLTextureHandle::SVM: {
1441  /* Packed texture. */
1442  ShaderData *sd = (ShaderData *)(sg->renderstate);
1443  KernelGlobals kernel_globals = sd->osl_globals;
1444  int slot = handle->svm_slots[0].y;
1445  float3 P_float3 = make_float3(P.x, P.y, P.z);
1447 
1448  result[0] = rgba[0];
1449  if (nchannels > 1)
1450  result[1] = rgba[1];
1451  if (nchannels > 2)
1452  result[2] = rgba[2];
1453  if (nchannels > 3)
1454  result[3] = rgba[3];
1455  status = true;
1456  break;
1457  }
1458  case OSLTextureHandle::OIIO: {
1459  /* OpenImageIO texture cache. */
1460  OSL::TextureSystem *ts = texture_system;
1461 
1462  if (handle && handle->oiio_handle) {
1463  if (texture_thread_info == NULL) {
1464  ShaderData *sd = (ShaderData *)(sg->renderstate);
1465  KernelGlobals kernel_globals = sd->osl_globals;
1466  OSLThreadData *tdata = kernel_globals->osl_tdata;
1467  texture_thread_info = tdata->oiio_thread_info;
1468  }
1469 
1470  status = ts->texture3d(handle->oiio_handle,
1471  texture_thread_info,
1472  options,
1473  P,
1474  dPdx,
1475  dPdy,
1476  dPdz,
1477  nchannels,
1478  result,
1479  dresultds,
1480  dresultdt,
1481  dresultdr);
1482  }
1483  else {
1484  status = ts->texture3d(filename,
1485  options,
1486  P,
1487  dPdx,
1488  dPdy,
1489  dPdz,
1490  nchannels,
1491  result,
1492  dresultds,
1493  dresultdt,
1494  dresultdr);
1495  }
1496 
1497  if (!status) {
1498  /* This might be slow, but prevents error messages leak and
1499  * other nasty stuff happening. */
1500  ts->geterror();
1501  }
1502  else if (handle && handle->processor) {
1504  }
1505  break;
1506  }
1507  case OSLTextureHandle::IES:
1508  case OSLTextureHandle::AO:
1509  case OSLTextureHandle::BEVEL: {
1510  status = false;
1511  break;
1512  }
1513  }
1514 
1515  if (!status) {
1516  if (nchannels == 3 || nchannels == 4) {
1517  result[0] = 1.0f;
1518  result[1] = 0.0f;
1519  result[2] = 1.0f;
1520 
1521  if (nchannels == 4)
1522  result[3] = 1.0f;
1523  }
1524  }
1525 
1526  return status;
1527 }
1528 
1529 bool OSLRenderServices::environment(ustring filename,
1530  TextureHandle *texture_handle,
1531  TexturePerthread *thread_info,
1532  TextureOpt &options,
1533  OSL::ShaderGlobals *sg,
1534  const OSL::Vec3 &R,
1535  const OSL::Vec3 &dRdx,
1536  const OSL::Vec3 &dRdy,
1537  int nchannels,
1538  float *result,
1539  float *dresultds,
1540  float *dresultdt,
1541  ustring *errormessage)
1542 {
1543  OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
1544  OSL::TextureSystem *ts = texture_system;
1545  bool status = false;
1546 
1547  if (handle && handle->oiio_handle) {
1548  if (thread_info == NULL) {
1549  ShaderData *sd = (ShaderData *)(sg->renderstate);
1550  KernelGlobals kernel_globals = sd->osl_globals;
1551  OSLThreadData *tdata = kernel_globals->osl_tdata;
1552  thread_info = tdata->oiio_thread_info;
1553  }
1554 
1555  status = ts->environment(handle->oiio_handle,
1556  thread_info,
1557  options,
1558  R,
1559  dRdx,
1560  dRdy,
1561  nchannels,
1562  result,
1563  dresultds,
1564  dresultdt);
1565  }
1566  else {
1567  status = ts->environment(
1568  filename, options, R, dRdx, dRdy, nchannels, result, dresultds, dresultdt);
1569  }
1570 
1571  if (!status) {
1572  if (nchannels == 3 || nchannels == 4) {
1573  result[0] = 1.0f;
1574  result[1] = 0.0f;
1575  result[2] = 1.0f;
1576 
1577  if (nchannels == 4)
1578  result[3] = 1.0f;
1579  }
1580  }
1581  else if (handle && handle->processor) {
1583  }
1584 
1585  return status;
1586 }
1587 
1588 #if OSL_LIBRARY_VERSION_CODE >= 11100
1589 bool OSLRenderServices::get_texture_info(ustring filename,
1590  TextureHandle *texture_handle,
1591  TexturePerthread *,
1592  OSL::ShadingContext *,
1593  int subimage,
1594  ustring dataname,
1595  TypeDesc datatype,
1596  void *data,
1597  ustring *)
1598 #else
1599 bool OSLRenderServices::get_texture_info(OSL::ShaderGlobals *sg,
1600  ustring filename,
1601  TextureHandle *texture_handle,
1602  int subimage,
1603  ustring dataname,
1604  TypeDesc datatype,
1605  void *data)
1606 #endif
1607 {
1608  OSLTextureHandle *handle = (OSLTextureHandle *)texture_handle;
1609 
1610  /* No texture info for other texture types. */
1611  if (handle && handle->type != OSLTextureHandle::OIIO) {
1612  return false;
1613  }
1614 
1615  /* Get texture info from OpenImageIO. */
1616  OSL::TextureSystem *ts = texture_system;
1617  return ts->get_texture_info(filename, subimage, dataname, datatype, data);
1618 }
1619 
1620 int OSLRenderServices::pointcloud_search(OSL::ShaderGlobals *sg,
1621  ustring filename,
1622  const OSL::Vec3 &center,
1623  float radius,
1624  int max_points,
1625  bool sort,
1626  size_t *out_indices,
1627  float *out_distances,
1628  int derivs_offset)
1629 {
1630  return 0;
1631 }
1632 
1633 int OSLRenderServices::pointcloud_get(OSL::ShaderGlobals *sg,
1634  ustring filename,
1635  size_t *indices,
1636  int count,
1637  ustring attr_name,
1638  TypeDesc attr_type,
1639  void *out_data)
1640 {
1641  return 0;
1642 }
1643 
1644 bool OSLRenderServices::pointcloud_write(OSL::ShaderGlobals *sg,
1645  ustring filename,
1646  const OSL::Vec3 &pos,
1647  int nattribs,
1648  const ustring *names,
1649  const TypeDesc *types,
1650  const void **data)
1651 {
1652  return false;
1653 }
1654 
1656  OSL::ShaderGlobals *sg,
1657  const OSL::Vec3 &P,
1658  const OSL::Vec3 &dPdx,
1659  const OSL::Vec3 &dPdy,
1660  const OSL::Vec3 &R,
1661  const OSL::Vec3 &dRdx,
1662  const OSL::Vec3 &dRdy)
1663 {
1664  /* todo: options.shader support, maybe options.traceset */
1665  ShaderData *sd = (ShaderData *)(sg->renderstate);
1666 
1667  /* setup ray */
1668  Ray ray;
1669 
1670  ray.P = TO_FLOAT3(P);
1671  ray.D = TO_FLOAT3(R);
1672  ray.tmin = 0.0f;
1673  ray.tmax = (options.maxdist == 1.0e30f) ? FLT_MAX : options.maxdist - options.mindist;
1674  ray.time = sd->time;
1675  ray.self.object = OBJECT_NONE;
1676  ray.self.prim = PRIM_NONE;
1678  ray.self.light_prim = PRIM_NONE;
1679 
1680  if (options.mindist == 0.0f) {
1681  /* avoid self-intersections */
1682  if (ray.P == sd->P) {
1683  ray.self.object = sd->object;
1684  ray.self.prim = sd->prim;
1685  }
1686  }
1687  else {
1688  /* offset for minimum distance */
1689  ray.P += options.mindist * ray.D;
1690  }
1691 
1692  /* ray differentials */
1693  differential3 dP;
1694  dP.dx = TO_FLOAT3(dPdx);
1695  dP.dy = TO_FLOAT3(dPdy);
1696  ray.dP = differential_make_compact(dP);
1697  differential3 dD;
1698  dD.dx = TO_FLOAT3(dRdx);
1699  dD.dy = TO_FLOAT3(dRdy);
1700  ray.dD = differential_make_compact(dD);
1701 
1702  /* allocate trace data */
1703  OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
1704  tracedata->ray = ray;
1705  tracedata->setup = false;
1706  tracedata->init = true;
1707  tracedata->hit = false;
1708  tracedata->sd.osl_globals = sd->osl_globals;
1709 
1710  const KernelGlobalsCPU *kg = sd->osl_globals;
1711 
1712  /* Can't ray-trace from shaders like displacement, before BVH exists. */
1713  if (kernel_data.bvh.bvh_layout == BVH_LAYOUT_NONE) {
1714  return false;
1715  }
1716 
1717  /* Ray-trace, leaving out shadow opaque to avoid early exit. */
1719  tracedata->hit = scene_intersect(kg, &ray, visibility, &tracedata->isect);
1720  return tracedata->hit;
1721 }
1722 
1723 bool OSLRenderServices::getmessage(OSL::ShaderGlobals *sg,
1724  ustring source,
1725  ustring name,
1726  TypeDesc type,
1727  void *val,
1728  bool derivatives)
1729 {
1730  OSLTraceData *tracedata = (OSLTraceData *)sg->tracedata;
1731 
1732  if (source == u_trace && tracedata->init) {
1733  if (name == u_hit) {
1734  return set_attribute_int(tracedata->hit, type, derivatives, val);
1735  }
1736  else if (tracedata->hit) {
1737  if (name == u_hitdist) {
1738  float f[3] = {tracedata->isect.t, 0.0f, 0.0f};
1739  return set_attribute_float(f, type, derivatives, val);
1740  }
1741  else {
1742  ShaderData *sd = &tracedata->sd;
1743  const KernelGlobalsCPU *kg = sd->osl_globals;
1744 
1745  if (!tracedata->setup) {
1746  /* lazy shader data setup */
1747  shader_setup_from_ray(kg, sd, &tracedata->ray, &tracedata->isect);
1748  tracedata->setup = true;
1749  }
1750 
1751  if (name == u_N) {
1752  return set_attribute_float3(sd->N, type, derivatives, val);
1753  }
1754  else if (name == u_Ng) {
1755  return set_attribute_float3(sd->Ng, type, derivatives, val);
1756  }
1757  else if (name == u_P) {
1758  float3 f[3] = {sd->P, sd->dP.dx, sd->dP.dy};
1759  return set_attribute_float3(f, type, derivatives, val);
1760  }
1761  else if (name == u_I) {
1762  float3 f[3] = {sd->I, sd->dI.dx, sd->dI.dy};
1763  return set_attribute_float3(f, type, derivatives, val);
1764  }
1765  else if (name == u_u) {
1766  float f[3] = {sd->u, sd->du.dx, sd->du.dy};
1767  return set_attribute_float(f, type, derivatives, val);
1768  }
1769  else if (name == u_v) {
1770  float f[3] = {sd->v, sd->dv.dx, sd->dv.dy};
1771  return set_attribute_float(f, type, derivatives, val);
1772  }
1773 
1774  return get_attribute(sd, derivatives, u_empty, type, name, val);
1775  }
1776  }
1777  }
1778 
1779  return false;
1780 }
1781 
unsigned int uint
Definition: BLI_sys_types.h:67
NSNotificationCenter * center
_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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint * textures
_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 const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
float float4[4]
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 Sky Generate a procedural sky texture Noise Generate fractal Perlin noise Wave Generate procedural bands or rings with noise 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
void sort(btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V, int t)
Helper function of 3X3 SVD for sorting singular values.
static void to_scene_linear(ustring colorspace, T *pixels, size_t num_pixels, bool is_rgba, bool compress_as_srgb)
Definition: colorspace.cpp:350
static ustring u_path_transmission_depth
Definition: services.h:306
static ustring u_particle_location
Definition: services.h:280
bool pointcloud_write(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 &pos, int nattribs, const ustring *names, const TypeDesc *types, const void **data) override
Definition: services.cpp:1644
static ustring u_object_alpha
Definition: services.h:270
static ustring u_u
Definition: services.h:314
bool get_inverse_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) override
Definition: services.cpp:177
static ustring u_raster
Definition: services.h:266
static ustring u_empty
Definition: services.h:316
static ustring u_curve_thickness
Definition: services.h:292
static ustring u_ndc
Definition: services.h:267
static ustring u_particle_index
Definition: services.h:276
static ustring u_point_position
Definition: services.h:297
static ustring u_point_radius
Definition: services.h:298
static bool get_object_standard_attribute(const KernelGlobalsCPU *kg, ShaderData *sd, ustring name, TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:859
static ustring u_curve_tangent_normal
Definition: services.h:294
static ustring u_path_diffuse_depth
Definition: services.h:303
static ustring u_normal_map_normal
Definition: services.h:300
static ustring u_index
Definition: services.h:262
bool get_matrix(OSL::ShaderGlobals *sg, OSL::Matrix44 &result, OSL::TransformationPtr xform, float time) override
Definition: services.cpp:139
static ustring u_curve_length
Definition: services.h:293
static ustring u_hit
Definition: services.h:308
static ustring u_material_index
Definition: services.h:274
static ustring u_path_ray_depth
Definition: services.h:302
static ustring u_point_random
Definition: services.h:299
static ustring u_is_smooth
Definition: services.h:290
static ustring u_object_location
Definition: services.h:268
static ustring u_curve_random
Definition: services.h:295
int pointcloud_get(OSL::ShaderGlobals *sg, ustring filename, size_t *indices, int count, ustring attr_name, TypeDesc attr_type, void *out_data) override
Definition: services.cpp:1633
static ustring u_particle_rotation
Definition: services.h:281
OSL::TextureSystem * texture_system
Definition: services.h:324
static ustring u_particle_velocity
Definition: services.h:283
static ustring u_particle_angular_velocity
Definition: services.h:284
static ustring u_N
Definition: services.h:310
static ustring u_path_glossy_depth
Definition: services.h:304
static ustring u_hitdist
Definition: services.h:309
static bool get_background_attribute(const KernelGlobalsCPU *kg, ShaderData *sd, ustring name, TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:1031
static ustring u_geom_dupli_uv
Definition: services.h:273
static ustring u_I
Definition: services.h:313
static ustring u_geom_undisplaced
Definition: services.h:289
static ustring u_geom_numpolyvertices
Definition: services.h:285
static ustring u_v
Definition: services.h:315
static ustring u_world
Definition: services.h:263
static ustring u_object_random
Definition: services.h:275
static ustring u_path_ray_length
Definition: services.h:301
bool getmessage(OSL::ShaderGlobals *sg, ustring source, ustring name, TypeDesc type, void *val, bool derivatives) override
Definition: services.cpp:1723
static ustring u_screen
Definition: services.h:265
bool environment(ustring filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy, int nchannels, float *result, float *dresultds, float *dresultdt, ustring *errormessage) override
Definition: services.cpp:1529
bool get_attribute(OSL::ShaderGlobals *sg, bool derivatives, ustring object, TypeDesc type, ustring name, void *val) override
Definition: services.cpp:1116
static ustring u_particle_random
Definition: services.h:277
static ustring u_camera
Definition: services.h:264
static ustring u_particle_age
Definition: services.h:278
static ustring u_P
Definition: services.h:312
OSLRenderServices(OSL::TextureSystem *texture_system)
Definition: services.cpp:127
bool texture(ustring filename, TextureSystem::TextureHandle *texture_handle, TexturePerthread *texture_thread_info, TextureOpt &options, OSL::ShaderGlobals *sg, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int nchannels, float *result, float *dresultds, float *dresultdt, ustring *errormessage) override
Definition: services.cpp:1242
bool get_texture_info(OSL::ShaderGlobals *sg, ustring filename, TextureHandle *texture_handle, int subimage, ustring dataname, TypeDesc datatype, void *data) override
Definition: services.cpp:1599
static ustring u_object_index
Definition: services.h:271
static ustring u_is_point
Definition: services.h:296
static ustring u_path_transparent_depth
Definition: services.h:305
TextureSystem::TextureHandle * get_texture_handle(ustring filename) override
Definition: services.cpp:1199
bool trace(TraceOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, const OSL::Vec3 &R, const OSL::Vec3 &dRdx, const OSL::Vec3 &dRdy) override
Definition: services.cpp:1655
static ustring u_particle_lifetime
Definition: services.h:279
bool texture3d(ustring filename, TextureHandle *texture_handle, TexturePerthread *texture_thread_info, TextureOpt &options, OSL::ShaderGlobals *sg, const OSL::Vec3 &P, const OSL::Vec3 &dPdx, const OSL::Vec3 &dPdy, const OSL::Vec3 &dPdz, int nchannels, float *result, float *dresultds, float *dresultdt, float *dresultdr, ustring *errormessage) override
Definition: services.cpp:1419
static ustring u_is_curve
Definition: services.h:291
static ustring u_object_color
Definition: services.h:269
static ustring u_distance
Definition: services.h:261
static ustring u_Ng
Definition: services.h:311
static ustring u_trace
Definition: services.h:307
bool get_userdata(bool derivatives, ustring name, TypeDesc type, OSL::ShaderGlobals *sg, void *val) override
Definition: services.cpp:1188
static ustring u_geom_trianglevertices
Definition: services.h:286
bool get_array_attribute(OSL::ShaderGlobals *sg, bool derivatives, ustring object, TypeDesc type, ustring name, int index, void *val) override
Definition: services.cpp:387
static ustring u_geom_polyvertices
Definition: services.h:287
static ustring u_particle_size
Definition: services.h:282
int pointcloud_search(OSL::ShaderGlobals *sg, ustring filename, const OSL::Vec3 &center, float radius, int max_points, bool sort, size_t *out_indices, float *out_distances, int derivs_offset) override
Definition: services.cpp:1620
static ustring u_geom_dupli_generated
Definition: services.h:272
bool good(TextureSystem::TextureHandle *texture_handle) override
Definition: services.cpp:1229
static ustring u_geom_name
Definition: services.h:288
int x
Definition: btConvexHull.h:149
int w
Definition: btConvexHull.h:149
int y
Definition: btConvexHull.h:149
int z
Definition: btConvexHull.h:149
#define TO_FLOAT3(v)
Definition: closures.h:89
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
CCL_NAMESPACE_BEGIN struct ProjectionTransform ProjectionTransform
ccl_device_inline ProjectionTransform projection_transpose(const ProjectionTransform &a)
CCL_NAMESPACE_BEGIN struct Options options
StackEntry * from
double time
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
ccl_device_forceinline float differential_make_compact(const differential3 D)
Definition: differential.h:117
SyclQueue void void size_t num_bytes SyclQueue void * kernel_globals
#define str(s)
uint pos
ccl_device_inline float hash_uint2_to_float(uint kx, uint ky)
Definition: hash.h:122
int count
ccl_device_intersect bool scene_intersect(KernelGlobals kg, ccl_private const Ray *ray, const uint visibility, ccl_private Intersection *isect)
ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, ccl_private ShaderData *sd, float3 P)
ccl_global const KernelWorkTile * tile
const int state
ccl_gpu_kernel_postfix int ccl_global int * indices
ccl_gpu_kernel_postfix ccl_global float int int int int ccl_global const float int int int int int int int int int int int int num_samples
ccl_device_inline uint attribute_primitive_type(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc)
ccl_device_inline float object_pass_id(KernelGlobals kg, int object)
ccl_device_inline float object_alpha(KernelGlobals kg, int object)
ccl_device float particle_age(KernelGlobals kg, int particle)
ccl_device float4 particle_rotation(KernelGlobals kg, int particle)
ccl_device_inline uint particle_index(KernelGlobals kg, int particle)
ccl_device_inline float3 object_location(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline float object_random_number(KernelGlobals kg, int object)
ccl_device float particle_lifetime(KernelGlobals kg, int particle)
ccl_device_inline void object_position_transform(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float3 *P)
ccl_device float3 particle_angular_velocity(KernelGlobals kg, int particle)
ccl_device_inline int object_particle_id(KernelGlobals kg, int object)
ccl_device_inline float3 object_color(KernelGlobals kg, int object)
ccl_device_inline Transform object_get_transform(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device int shader_pass_id(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device float3 particle_velocity(KernelGlobals kg, int particle)
ccl_device float3 particle_location(KernelGlobals kg, int particle)
ccl_device float particle_size(KernelGlobals kg, int particle)
ccl_device_inline Transform lamp_fetch_transform(KernelGlobals kg, int lamp, bool inverse)
ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, int object)
ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, int object)
ccl_device_inline Transform object_get_inverse_transform(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline float kernel_ies_interp(KernelGlobals kg, int slot, float h_angle, float v_angle)
@ NODE_AO_INSIDE
@ NODE_AO_GLOBAL_RADIUS
@ NODE_AO_ONLY_LOCAL
@ PRIMITIVE_LAMP
Definition: kernel/types.h:556
@ PRIMITIVE_MOTION
Definition: kernel/types.h:558
@ PRIMITIVE_CURVE
Definition: kernel/types.h:564
@ PRIMITIVE_TRIANGLE
Definition: kernel/types.h:551
@ PRIMITIVE_POINT
Definition: kernel/types.h:554
#define PRIM_NONE
Definition: kernel/types.h:41
@ PATH_RAY_SHADOW_OPAQUE
Definition: kernel/types.h:204
@ PATH_RAY_ALL_VISIBILITY
Definition: kernel/types.h:217
@ PATH_RAY_CAMERA
Definition: kernel/types.h:194
#define OBJECT_NONE
Definition: kernel/types.h:40
struct AttributeMap AttributeMap
ShaderData
Definition: kernel/types.h:925
@ SHADER_SMOOTH_NORMAL
Definition: kernel/types.h:435
@ SD_OBJECT_TRANSFORM_APPLIED
Definition: kernel/types.h:808
@ BVH_LAYOUT_NONE
@ ATTR_ELEMENT_OBJECT
Definition: kernel/types.h:599
@ ATTR_PRIM_TYPES
Definition: kernel/types.h:594
@ CAMERA_ORTHOGRAPHIC
Definition: kernel/types.h:466
#define VLOG_INFO
Definition: log.h:77
static char ** names
Definition: makesdna.c:65
static char ** types
Definition: makesdna.c:67
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
ccl_device_inline float3 zero_float3()
Definition: math_float3.h:80
ccl_device_inline float4 zero_float4()
Definition: math_float4.h:92
static float P(float k)
Definition: math_interp.c:25
#define N
#define R
#define make_float2(x, y)
Definition: metal/compat.h:203
#define make_float4(x, y, z, w)
Definition: metal/compat.h:205
#define make_float3(x, y, z)
Definition: metal/compat.h:204
ccl_device_inline void motion_triangle_vertices(KernelGlobals kg, int object, int prim, float time, float3 verts[3])
ccl_device float4 kernel_tex_image_interp_3d(KernelGlobals kg, int id, float3 P, InterpolationType interp)
ccl_device float4 kernel_tex_image_interp(KernelGlobals kg, int id, float x, float y)
static const VertexNature POINT
Definition: Nature.h:20
Eigen::Vector3d Vec3
Definition: numeric.h:106
static const pxr::TfToken rgba("rgba", pxr::TfToken::Immortal)
static constexpr TypeDesc TypeFloatArray4(TypeDesc::FLOAT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 4)
static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR)
CCL_NAMESPACE_BEGIN static constexpr OIIO_NAMESPACE_USING TypeDesc TypeFloat2(TypeDesc::FLOAT, TypeDesc::VEC2)
ccl_device_forceinline float3 primitive_surface_attribute_float3(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float3 *dx, ccl_private float3 *dy)
Definition: primitive.h:83
ccl_device_forceinline float2 primitive_surface_attribute_float2(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float2 *dx, ccl_private float2 *dy)
Definition: primitive.h:52
ccl_device_forceinline float4 primitive_surface_attribute_float4(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float4 *dx, ccl_private float4 *dy)
Definition: primitive.h:114
CCL_NAMESPACE_BEGIN ccl_device_forceinline float primitive_surface_attribute_float(KernelGlobals kg, ccl_private const ShaderData *sd, const AttributeDescriptor desc, ccl_private float *dx, ccl_private float *dy)
Definition: primitive.h:21
static const char * dataname(short id_code)
Definition: readfile.c:3021
static bool set_attribute_string(ustring str, TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:688
static bool set_attribute_float2(float2 f[3], TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:398
static bool set_attribute_float3_3(float3 P[3], TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:706
static bool set_attribute_int(int i, TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:671
static bool set_attribute_matrix(const Transform &tfm, TypeDesc type, void *val)
Definition: services.cpp:734
static bool set_attribute_float4(float4 f[3], TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:542
static bool get_mesh_attribute(const KernelGlobalsCPU *kg, const ShaderData *sd, const OSLGlobals::Attribute &attr, const TypeDesc &type, bool derivatives, void *val)
Definition: services.cpp:805
static bool get_object_attribute(const OSLGlobals::Attribute &attr, TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:821
static bool set_attribute_float(float f[3], TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:604
static bool get_primitive_attribute(const KernelGlobalsCPU *kg, const ShaderData *sd, const OSLGlobals::Attribute &attr, const TypeDesc &type, bool derivatives, void *val)
Definition: services.cpp:744
static bool set_attribute_float3(float3 f[3], TypeDesc type, bool derivatives, void *val)
Definition: services.cpp:466
static CCL_NAMESPACE_BEGIN void copy_matrix(OSL::Matrix44 &m, const Transform &tfm)
Definition: services.cpp:57
CCL_NAMESPACE_BEGIN ccl_device_inline void shader_setup_from_ray(KernelGlobals kg, ccl_private ShaderData *ccl_restrict sd, ccl_private const Ray *ccl_restrict ray, ccl_private const Intersection *ccl_restrict isect)
Definition: shader_data.h:28
ColorSpaceProcessor * processor
Definition: services.h:63
OSL::TextureSystem::TextureHandle * oiio_handle
Definition: services.h:62
vector< int4 > svm_slots
Definition: services.h:61
float tmax
Definition: kernel/types.h:527
float tmin
Definition: kernel/types.h:526
float dD
Definition: kernel/types.h:534
float3 P
Definition: kernel/types.h:524
float time
Definition: kernel/types.h:528
float dP
Definition: kernel/types.h:533
RaySelfPrimitives self
Definition: kernel/types.h:530
float3 D
Definition: kernel/types.h:525
float x
Definition: types_float2.h:15
float y
Definition: types_float2.h:15
float z
float y
float x
ccl_device_inline void triangle_vertices(KernelGlobals kg, int prim, float3 P[3])
Definition: triangle.h:65
ccl_device_inline float3 triangle_smooth_normal_unnormalized(KernelGlobals kg, ccl_private const ShaderData *sd, float3 Ng, int prim, float u, float v)
Definition: triangle.h:105
ccl_device_inline float3 float4_to_float3(const float4 a)
Definition: util/math.h:500
#define TEX_IMAGE_MISSING_R
Definition: util/texture.h:12
#define TEX_IMAGE_MISSING_B
Definition: util/texture.h:14
@ INTERPOLATION_NONE
Definition: util/texture.h:20
#define TEX_IMAGE_MISSING_A
Definition: util/texture.h:15
#define TEX_IMAGE_MISSING_G
Definition: util/texture.h:13