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