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