Blender V4.3
services_gpu.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009-2010 Sony Pictures Imageworks Inc., et al. All Rights Reserved.
2 * SPDX-FileCopyrightText: 2011-2022 Blender Foundation
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Adapted code from Open Shading Language. */
7
8#include "kernel/tables.h"
10
11#include "kernel/osl/osl.h"
12
13namespace DeviceStrings {
14
15/* "" */
17/* "common" */
18ccl_device_constant DeviceString u_common = 14645198576927606093ull;
19/* "world" */
20ccl_device_constant DeviceString u_world = 16436542438370751598ull;
21/* "shader" */
23/* "object" */
25/* "NDC" */
26ccl_device_constant DeviceString u_ndc = 5148305047403260775ull;
27/* "screen" */
28ccl_device_constant DeviceString u_screen = 14159088609039777114ull;
29/* "camera" */
30ccl_device_constant DeviceString u_camera = 2159505832145726196ull;
31/* "raster" */
32ccl_device_constant DeviceString u_raster = 7759263238610201778ull;
33/* "hsv" */
34ccl_device_constant DeviceString u_hsv = 2177035556331879497ull;
35/* "hsl" */
36ccl_device_constant DeviceString u_hsl = 7749766809258288148ull;
37/* "XYZ" */
38ccl_device_constant DeviceString u_xyz = 4957977063494975483ull;
39/* "xyY" */
40ccl_device_constant DeviceString u_xyy = 5138822319725660255ull;
41/* "sRGB" */
42ccl_device_constant DeviceString u_srgb = 15368599878474175032ull;
43/* "object:location" */
45/* "object:color" */
47/* "object:alpha" */
49/* "object:index" */
51/* "object:is_light" */
53/* "geom:dupli_generated" */
55/* "geom:dupli_uv" */
57/* "material:index" */
59/* "object:random" */
61/* "particle:index" */
63/* "particle:random" */
65/* "particle:age" */
67/* "particle:lifetime" */
69/* "particle:location" */
71/* "particle:rotation" */
73/* "particle:size" */
75/* "particle:velocity" */
77/* "particle:angular_velocity" */
79/* "geom:numpolyvertices" */
81/* "geom:trianglevertices" */
83/* "geom:polyvertices" */
85/* "geom:name" */
87/* "geom:undisplaced" */
89/* "geom:is_smooth" */
91/* "geom:is_curve" */
93/* "geom:curve_thickness" */
95/* "geom:curve_length" */
97/* "geom:curve_tangent_normal" */
99/* "geom:curve_random" */
101/* "geom:is_point" */
103/* "geom:point_radius" */
105/* "geom:point_position" */
107/* "geom:point_random" */
109/* "geom:normal_map_normal" */
111/* "path:ray_length" */
113/* "path:ray_depth" */
115/* "path:diffuse_depth" */
117/* "path:glossy_depth" */
119/* "path:transparent_depth" */
121/* "path:transmission_depth" */
123
124} // namespace DeviceStrings
125
126/* Closure */
127
130 ccl_private const float3 *weight)
131{
132 if (*weight == zero_float3() || !a) {
133 return nullptr;
134 }
135 else if (*weight == one_float3()) {
136 return a;
137 }
138
139 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
140
141 ccl_private uint8_t *closure_pool = sd->osl_closure_pool;
142 /* Align pointer to closure struct requirement */
143 closure_pool = reinterpret_cast<uint8_t *>(
144 (reinterpret_cast<size_t>(closure_pool) + alignof(OSLClosureMul) - 1) &
145 (-alignof(OSLClosureMul)));
146 sd->osl_closure_pool = closure_pool + sizeof(OSLClosureMul);
147
148 ccl_private OSLClosureMul *const closure = reinterpret_cast<ccl_private OSLClosureMul *>(
149 closure_pool);
150 closure->id = OSL_CLOSURE_MUL_ID;
151 closure->weight = *weight;
152 closure->closure = a;
153
154 return closure;
155}
156
159 float weight)
160{
161 if (weight == 0.0f || !a) {
162 return nullptr;
163 }
164 else if (weight == 1.0f) {
165 return a;
166 }
167
168 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
169
170 uint8_t *closure_pool = sd->osl_closure_pool;
171 /* Align pointer to closure struct requirement */
172 closure_pool = reinterpret_cast<uint8_t *>(
173 (reinterpret_cast<size_t>(closure_pool) + alignof(OSLClosureMul) - 1) &
174 (-alignof(OSLClosureMul)));
175 sd->osl_closure_pool = closure_pool + sizeof(OSLClosureMul);
176
177 ccl_private OSLClosureMul *const closure = reinterpret_cast<ccl_private OSLClosureMul *>(
178 closure_pool);
179 closure->id = OSL_CLOSURE_MUL_ID;
180 closure->weight = make_float3(weight, weight, weight);
181 closure->closure = a;
182
183 return closure;
184}
185
189{
190 if (!a) {
191 return b;
192 }
193 if (!b) {
194 return a;
195 }
196
197 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
198
199 ccl_private uint8_t *closure_pool = sd->osl_closure_pool;
200 /* Align pointer to closure struct requirement */
201 closure_pool = reinterpret_cast<uint8_t *>(
202 (reinterpret_cast<size_t>(closure_pool) + alignof(OSLClosureAdd) - 1) &
203 (-alignof(OSLClosureAdd)));
204 sd->osl_closure_pool = closure_pool + sizeof(OSLClosureAdd);
205
206 ccl_private OSLClosureAdd *const closure = reinterpret_cast<ccl_private OSLClosureAdd *>(
207 closure_pool);
208 closure->id = OSL_CLOSURE_ADD_ID;
209 closure->closureA = a;
210 closure->closureB = b;
211
212 return closure;
213}
214
216 ccl_private ShaderGlobals *sg, int id, int size)
217{
218 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
219
220 ccl_private uint8_t *closure_pool = sd->osl_closure_pool;
221 /* Align pointer to closure struct requirement */
222 closure_pool = reinterpret_cast<uint8_t *>(
223 (reinterpret_cast<size_t>(closure_pool) + alignof(OSLClosureComponent) - 1) &
224 (-alignof(OSLClosureComponent)));
225 sd->osl_closure_pool = closure_pool + sizeof(OSLClosureComponent) + size;
226
227 ccl_private OSLClosureComponent *const closure =
228 reinterpret_cast<ccl_private OSLClosureComponent *>(closure_pool);
229 closure->id = static_cast<OSLClosureType>(id);
230 closure->weight = one_float3();
231
232 return closure;
233}
234
236 ccl_private ShaderGlobals *sg, int id, int size, ccl_private const float3 *weight)
237{
238 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
239
240 ccl_private uint8_t *closure_pool = sd->osl_closure_pool;
241 /* Align pointer to closure struct requirement */
242 closure_pool = reinterpret_cast<uint8_t *>(
243 (reinterpret_cast<size_t>(closure_pool) + alignof(OSLClosureComponent) - 1) &
244 (-alignof(OSLClosureComponent)));
245 sd->osl_closure_pool = closure_pool + sizeof(OSLClosureComponent) + size;
246
247 ccl_private OSLClosureComponent *const closure =
248 reinterpret_cast<ccl_private OSLClosureComponent *>(closure_pool);
249 closure->id = static_cast<OSLClosureType>(id);
250 closure->weight = *weight;
251
252 return closure;
253}
254
255/* Utilities */
256
257#include "kernel/svm/math_util.h"
258#include "kernel/util/color.h"
259
260ccl_device_extern void osl_error(ccl_private ShaderGlobals *sg, const char *format, void *args) {}
261
262ccl_device_extern void osl_printf(ccl_private ShaderGlobals *sg, const char *format, void *args) {}
263
265{
266}
267
269 int length,
270 DeviceString symname,
272 DeviceString sourcefile,
273 int sourceline,
274 DeviceString groupname,
275 int layer,
276 DeviceString layername,
277 DeviceString shadername)
278{
279 const int result = indexvalue < 0 ? 0 : indexvalue >= length ? length - 1 : indexvalue;
280#if 0
281 if (result != indexvalue) {
282 printf("Index [%d] out of range\n", indexvalue);
283 }
284#endif
285 return result;
286}
287
289 int length,
290 DeviceString symname,
292 DeviceString sourcefile,
293 int sourceline,
294 DeviceString groupname,
295 int layer,
296 DeviceString layername,
297 DeviceString shadername)
298{
299 return osl_range_check(indexvalue,
300 length,
301 symname,
302 sg,
303 sourcefile,
304 sourceline,
305 groupname,
306 layer,
307 layername,
308 shadername);
309}
310
311/* Color Utilities */
312
315 float temperature)
316{
317 float3 color_rgb = rec709_to_rgb(nullptr, svm_math_blackbody_color_rec709(temperature));
318 color_rgb = max(color_rgb, zero_float3());
319 *result = color_rgb;
320}
321
324 float lambda_nm)
325{
327 color *= 1.0f / 2.52f; // Empirical scale from lg to make all comps <= 1
328
329 /* Clamp to zero if values are smaller */
330 *result = max(color, make_float3(0.0f, 0.0f, 0.0f));
331}
332
339
341 ccl_private float *result,
343{
344 for (int i = 0; i < 3; ++i) {
345 osl_luminance_fv(sg, result + i, color + i);
346 }
347}
348
350 ccl_private float3 *res,
351 DeviceString from)
352{
353 if (from == DeviceStrings::u_hsv) {
354 *res = hsv_to_rgb(*res);
355 }
356 else if (from == DeviceStrings::u_hsl) {
357 *res = hsl_to_rgb(*res);
358 }
359 else if (from == DeviceStrings::u_xyz) {
360 *res = xyz_to_rgb(nullptr, *res);
361 }
362 else if (from == DeviceStrings::u_xyy) {
363 *res = xyz_to_rgb(nullptr, xyY_to_xyz(res->x, res->y, res->z));
364 }
365}
366
368 ccl_private float3 *c_in,
369 int c_in_derivs,
370 ccl_private float3 *c_out,
371 int c_out_derivs,
372 DeviceString from,
373 DeviceString to)
374{
375 if (!c_out_derivs) {
376 c_in_derivs = false;
377 }
378 else if (!c_in_derivs) {
379 c_out[1] = zero_float3();
380 c_out[2] = zero_float3();
381 }
382
383 float3 rgb;
384
385 for (int i = 0; i < (c_in_derivs ? 3 : 1); ++i) {
386 if (from == DeviceStrings::u_hsv) {
387 rgb = hsv_to_rgb(c_in[i]);
388 }
389 else if (from == DeviceStrings::u_hsl) {
390 rgb = hsl_to_rgb(c_in[i]);
391 }
392 else if (from == DeviceStrings::u_xyz) {
393 rgb = xyz_to_rgb(nullptr, c_in[i]);
394 }
395 else if (from == DeviceStrings::u_xyy) {
396 rgb = xyz_to_rgb(nullptr, xyY_to_xyz(c_in[i].x, c_in[i].y, c_in[i].z));
397 }
398 else if (from == DeviceStrings::u_srgb) {
399 rgb = color_srgb_to_linear_v3(c_in[i]);
400 }
401 else {
402 rgb = c_in[i];
403 }
404
405 if (to == DeviceStrings::u_hsv) {
406 c_out[i] = rgb_to_hsv(rgb);
407 }
408 else if (to == DeviceStrings::u_hsl) {
409 c_out[i] = rgb_to_hsl(rgb);
410 }
411#if 0
412 else if (to == DeviceStrings::u_xyz) {
413 c_out[i] = rgb_to_xyz(nullptr, rgb);
414 }
415 else if (to == DeviceStrings::u_xyy) {
416 c_out[i] = xyz_to_xyY(rgb_to_xyz(nullptr, rgb));
417 }
418#endif
419 else if (to == DeviceStrings::u_srgb) {
420 c_out[i] = color_linear_to_srgb_v3(rgb);
421 }
422 else {
423 c_out[i] = rgb;
424 }
425 }
426
427 return true;
428}
429
430/* Matrix Utilities */
431
432#include "kernel/geom/object.h"
433#include "util/transform.h"
434
436{
437 res[0] = tfm.x.x;
438 res[1] = tfm.y.x;
439 res[2] = tfm.z.x;
440 res[3] = 0.0f;
441 res[4] = tfm.x.y;
442 res[5] = tfm.y.y;
443 res[6] = tfm.z.y;
444 res[7] = 0.0f;
445 res[8] = tfm.x.z;
446 res[9] = tfm.y.z;
447 res[10] = tfm.z.z;
448 res[11] = 0.0f;
449 res[12] = tfm.x.w;
450 res[13] = tfm.y.w;
451 res[14] = tfm.z.w;
452 res[15] = 1.0f;
453}
455{
456 res[0] = tfm.x.x;
457 res[1] = tfm.y.x;
458 res[2] = tfm.z.x;
459 res[3] = tfm.w.x;
460 res[4] = tfm.x.y;
461 res[5] = tfm.y.y;
462 res[6] = tfm.z.y;
463 res[7] = tfm.w.y;
464 res[8] = tfm.x.z;
465 res[9] = tfm.y.z;
466 res[10] = tfm.z.z;
467 res[11] = tfm.w.z;
468 res[12] = tfm.x.w;
469 res[13] = tfm.y.w;
470 res[14] = tfm.z.w;
471 res[15] = tfm.w.w;
472}
473ccl_device_forceinline void copy_identity_matrix(ccl_private float *res, float value = 1.0f)
474{
475 res[0] = value;
476 res[1] = 0.0f;
477 res[2] = 0.0f;
478 res[3] = 0.0f;
479 res[4] = 0.0f;
480 res[5] = value;
481 res[6] = 0.0f;
482 res[7] = 0.0f;
483 res[8] = 0.0f;
484 res[9] = 0.0f;
485 res[10] = value;
486 res[11] = 0.0f;
487 res[12] = 0.0f;
488 res[13] = 0.0f;
489 res[14] = 0.0f;
490 res[15] = value;
491}
493{
494 return make_transform(
495 m[0], m[4], m[8], m[12], m[1], m[5], m[9], m[13], m[2], m[6], m[10], m[14]);
496}
497
499 ccl_private const float *a,
500 ccl_private const float *b)
501{
502 const Transform tfm_a = convert_transform(a);
503 const Transform tfm_b = convert_transform(b);
504 copy_matrix(res, tfm_a * tfm_b);
505}
506
507ccl_device_extern void osl_mul_mmf(ccl_private float *res, ccl_private const float *a, float b)
508{
509 for (int i = 0; i < 16; ++i) {
510 res[i] = a[i] * b;
511 }
512}
513
515 ccl_private const float *a,
516 ccl_private const float *b)
517{
518 const Transform tfm_a = convert_transform(a);
519 const Transform tfm_b = convert_transform(b);
520 copy_matrix(res, tfm_a * transform_inverse(tfm_b));
521}
522
523ccl_device_extern void osl_div_mmf(ccl_private float *res, ccl_private const float *a, float b)
524{
525 for (int i = 0; i < 16; ++i) {
526 res[i] = a[i] / b;
527 }
528}
529
530ccl_device_extern void osl_div_mfm(ccl_private float *res, float a, ccl_private const float *b)
531{
532 const Transform tfm_b = convert_transform(b);
533 copy_matrix(res, transform_inverse(tfm_b));
534 for (int i = 0; i < 16; ++i) {
535 res[i] *= a;
536 }
537}
538
539ccl_device_extern void osl_div_m_ff(ccl_private float *res, float a, float b)
540{
541 float f = (b == 0) ? 0.0f : (a / b);
542 copy_identity_matrix(res, f);
543}
544
546 ccl_private const float *m,
547 ccl_private const float3 *v)
548{
549 const Transform tfm_m = convert_transform(m);
550 *res = transform_point(&tfm_m, *v);
551}
552
554 ccl_private const float *m,
555 ccl_private const float3 *v)
556{
557 for (int i = 0; i < 3; ++i) {
558 const Transform tfm_m = convert_transform(m + i * 16);
559 res[i] = transform_point(&tfm_m, v[i]);
560 }
561}
562
564 ccl_private const float *m,
565 ccl_private const float3 *v)
566{
567 const Transform tfm_m = convert_transform(m);
568 *res = transform_direction(&tfm_m, *v);
569}
570
572 ccl_private const float *m,
573 ccl_private const float3 *v)
574{
575 for (int i = 0; i < 3; ++i) {
576 const Transform tfm_m = convert_transform(m + i * 16);
577 res[i] = transform_direction(&tfm_m, v[i]);
578 }
579}
580
582 ccl_private const float *m,
583 ccl_private const float3 *v)
584{
585 const Transform tfm_m = convert_transform(m);
586 *res = transform_direction(&tfm_m, *v);
587}
588
590 ccl_private const float *m,
591 ccl_private const float3 *v)
592{
593 for (int i = 0; i < 3; ++i) {
594 const Transform tfm_m = convert_transform(m + i * 16);
595 res[i] = transform_direction(&tfm_m, v[i]);
596 }
597}
598
600 ccl_private float *res,
601 DeviceString from)
602{
603 if (from == DeviceStrings::u_common || from == DeviceStrings::u_world) {
605 return true;
606 }
607 if (from == DeviceStrings::u_shader || from == DeviceStrings::u_object) {
608 KernelGlobals kg = nullptr;
609 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
610 int object = sd->object;
611
612 if (object != OBJECT_NONE) {
613 const Transform tfm = object_get_transform(kg, sd);
614 copy_matrix(res, tfm);
615 return true;
616 }
617 else if (sd->type == PRIMITIVE_LAMP) {
618 const Transform tfm = lamp_fetch_transform(kg, sd->lamp, false);
619 copy_matrix(res, tfm);
620 return true;
621 }
622 }
623 else if (from == DeviceStrings::u_ndc) {
624 copy_matrix(res, kernel_data.cam.ndctoworld);
625 return true;
626 }
627 else if (from == DeviceStrings::u_raster) {
628 copy_matrix(res, kernel_data.cam.rastertoworld);
629 return true;
630 }
631 else if (from == DeviceStrings::u_screen) {
632 copy_matrix(res, kernel_data.cam.screentoworld);
633 return true;
634 }
635 else if (from == DeviceStrings::u_camera) {
636 copy_matrix(res, kernel_data.cam.cameratoworld);
637 return true;
638 }
639
640 return false;
641}
642
644 ccl_private float *res,
645 DeviceString to)
646{
649 return true;
650 }
652 KernelGlobals kg = nullptr;
653 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
654 int object = sd->object;
655
656 if (object != OBJECT_NONE) {
657 const Transform itfm = object_get_inverse_transform(kg, sd);
658 copy_matrix(res, itfm);
659 return true;
660 }
661 else if (sd->type == PRIMITIVE_LAMP) {
662 const Transform itfm = lamp_fetch_transform(kg, sd->lamp, true);
663 copy_matrix(res, itfm);
664 return true;
665 }
666 }
667 else if (to == DeviceStrings::u_ndc) {
668 copy_matrix(res, kernel_data.cam.worldtondc);
669 return true;
670 }
671 else if (to == DeviceStrings::u_raster) {
672 copy_matrix(res, kernel_data.cam.worldtoraster);
673 return true;
674 }
675 else if (to == DeviceStrings::u_screen) {
676 copy_matrix(res, kernel_data.cam.worldtoscreen);
677 return true;
678 }
679 else if (to == DeviceStrings::u_camera) {
680 copy_matrix(res, kernel_data.cam.worldtocamera);
681 return true;
682 }
683
684 return false;
685}
686
688 ccl_private float *res,
689 DeviceString from)
690{
691 float m_from[16];
692 if (osl_get_matrix(sg, m_from, from)) {
693 osl_mul_mmm(res, m_from, res);
694 return true;
695 }
696
697 return false;
698}
699
701 ccl_private float *res,
702 DeviceString from,
703 DeviceString to)
704{
705 float m_from[16], m_to[16];
706 if (osl_get_matrix(sg, m_from, from) && osl_get_inverse_matrix(sg, m_to, to)) {
707 osl_mul_mmm(res, m_from, m_to);
708 return true;
709 }
710
711 return false;
712}
713
715 ccl_private float3 *p_in,
716 int p_in_derivs,
717 ccl_private float3 *p_out,
718 int p_out_derivs,
719 DeviceString from,
720 DeviceString to,
721 int vectype)
722{
723 if (!p_out_derivs) {
724 p_in_derivs = false;
725 }
726 else if (!p_in_derivs) {
727 p_out[1] = zero_float3();
728 p_out[2] = zero_float3();
729 }
730
731 bool res;
732 float m[16];
733
734 if (from == DeviceStrings::u_common) {
735 res = osl_get_inverse_matrix(sg, m, to);
736 }
737 else if (to == DeviceStrings::u_common) {
738 res = osl_get_matrix(sg, m, from);
739 }
740 else {
741 res = osl_get_from_to_matrix(sg, m, from, to);
742 }
743
744 if (res) {
745 if (vectype == 2 /* TypeDesc::POINT */) {
746 if (p_in_derivs) {
747 osl_transform_dvmdv(p_out, m, p_in);
748 }
749 else {
750 osl_transform_vmv(p_out, m, p_in);
751 }
752 }
753 else if (vectype == 3 /* TypeDesc::VECTOR */) {
754 if (p_in_derivs) {
755 osl_transformv_dvmdv(p_out, m, p_in);
756 }
757 else {
758 osl_transformv_vmv(p_out, m, p_in);
759 }
760 }
761 else if (vectype == 4 /* TypeDesc::NORMAL */) {
762 if (p_in_derivs) {
763 osl_transformn_dvmdv(p_out, m, p_in);
764 }
765 else {
766 osl_transformn_vmv(p_out, m, p_in);
767 }
768 }
769 else {
770 res = false;
771 }
772 }
773 else {
774 p_out[0] = p_in[0];
775 if (p_in_derivs) {
776 p_out[1] = p_in[1];
777 p_out[2] = p_in[2];
778 }
779 }
780
781 return res;
782}
783
785 ccl_private float3 *p_in,
786 int p_in_derivs,
787 ccl_private float3 *p_out,
788 int p_out_derivs,
789 DeviceString from,
790 DeviceString to,
791 int vectype)
792{
793 return osl_transform_triple(sg, p_in, p_in_derivs, p_out, p_out_derivs, from, to, vectype);
794}
795
797{
798 copy_matrix(res, *reinterpret_cast<ccl_private const ProjectionTransform *>(m));
799}
800
801#if 0
802ccl_device_extern float osl_determinant_fm(ccl_private const float *m)
803{
804}
805#endif
806
807/* Attributes */
808
809#include "kernel/geom/geom.h"
810
811typedef long long TypeDesc;
812
814 TypeDesc type,
815 bool derivatives,
816 ccl_private void *val)
817{
818 const unsigned char type_basetype = type & 0xF;
819 const unsigned char type_aggregate = (type >> 8) & 0xF;
820 const int type_arraylen = type >> 32;
821
822 if (type_basetype == 11 /* TypeDesc::FLOAT */) {
823 if ((type_aggregate == 2 /* TypeDesc::VEC2 */) || (type_aggregate == 1 && type_arraylen == 2))
824 {
825 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
826 static_cast<ccl_private float *>(val)[i * 2 + 0] = fval[i];
827 static_cast<ccl_private float *>(val)[i * 2 + 1] = fval[i];
828 }
829 return true;
830 }
831 if ((type_aggregate == 3 /* TypeDesc::VEC3 */) || (type_aggregate == 1 && type_arraylen == 3))
832 {
833 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
834 static_cast<ccl_private float *>(val)[i * 3 + 0] = fval[i];
835 static_cast<ccl_private float *>(val)[i * 3 + 1] = fval[i];
836 static_cast<ccl_private float *>(val)[i * 3 + 2] = fval[i];
837 }
838 return true;
839 }
840 if ((type_aggregate == 4 /* TypeDesc::VEC4 */) || (type_aggregate == 1 && type_arraylen == 4))
841 {
842 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
843 static_cast<ccl_private float *>(val)[i * 4 + 0] = fval[i];
844 static_cast<ccl_private float *>(val)[i * 4 + 1] = fval[i];
845 static_cast<ccl_private float *>(val)[i * 4 + 2] = fval[i];
846 static_cast<ccl_private float *>(val)[i * 4 + 3] = 1.0f;
847 }
848 return true;
849 }
850 if ((type_aggregate == 1 /* TypeDesc::SCALAR */)) {
851 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
852 static_cast<ccl_private float *>(val)[i] = fval[i];
853 }
854 return true;
855 }
856 }
857
858 return false;
859}
861 TypeDesc type,
862 bool derivatives,
863 ccl_private void *val)
864{
865 float fv[3];
866
867 fv[0] = f;
868 fv[1] = 0.0f;
869 fv[2] = 0.0f;
870
871 return set_attribute_float(fv, type, derivatives, val);
872}
874 TypeDesc type,
875 bool derivatives,
876 ccl_private void *val)
877{
878 const unsigned char type_basetype = type & 0xF;
879 const unsigned char type_aggregate = (type >> 8) & 0xF;
880 const int type_arraylen = type >> 32;
881
882 if (type_basetype == 11 /* TypeDesc::FLOAT */) {
883 if ((type_aggregate == 2 /* TypeDesc::VEC2 */) || (type_aggregate == 1 && type_arraylen == 2))
884 {
885 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
886 static_cast<ccl_private float *>(val)[i * 2 + 0] = fval[i].x;
887 static_cast<ccl_private float *>(val)[i * 2 + 1] = fval[i].y;
888 }
889 return true;
890 }
891 if ((type_aggregate == 3 /* TypeDesc::VEC3 */) || (type_aggregate == 1 && type_arraylen == 3))
892 {
893 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
894 static_cast<ccl_private float *>(val)[i * 3 + 0] = fval[i].x;
895 static_cast<ccl_private float *>(val)[i * 3 + 1] = fval[i].y;
896 static_cast<ccl_private float *>(val)[i * 3 + 2] = 0.0f;
897 }
898 return true;
899 }
900 if ((type_aggregate == 4 /* TypeDesc::VEC4 */) || (type_aggregate == 1 && type_arraylen == 4))
901 {
902 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
903 static_cast<ccl_private float *>(val)[i * 4 + 0] = fval[i].x;
904 static_cast<ccl_private float *>(val)[i * 4 + 1] = fval[i].y;
905 static_cast<ccl_private float *>(val)[i * 4 + 2] = 0.0f;
906 static_cast<ccl_private float *>(val)[i * 4 + 3] = 1.0f;
907 }
908 return true;
909 }
910 if ((type_aggregate == 1 /* TypeDesc::SCALAR */)) {
911 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
912 static_cast<ccl_private float *>(val)[i] = fval[i].x;
913 }
914 return true;
915 }
916 }
917
918 return false;
919}
921 TypeDesc type,
922 bool derivatives,
923 ccl_private void *val)
924{
925 const unsigned char type_basetype = type & 0xF;
926 const unsigned char type_aggregate = (type >> 8) & 0xF;
927 const int type_arraylen = type >> 32;
928
929 if (type_basetype == 11 /* TypeDesc::FLOAT */) {
930 if ((type_aggregate == 3 /* TypeDesc::VEC3 */) || (type_aggregate == 1 && type_arraylen == 3))
931 {
932 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
933 static_cast<ccl_private float *>(val)[i * 3 + 0] = fval[i].x;
934 static_cast<ccl_private float *>(val)[i * 3 + 1] = fval[i].y;
935 static_cast<ccl_private float *>(val)[i * 3 + 2] = fval[i].z;
936 }
937 return true;
938 }
939 if ((type_aggregate == 4 /* TypeDesc::VEC4 */) || (type_aggregate == 1 && type_arraylen == 4))
940 {
941 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
942 static_cast<ccl_private float *>(val)[i * 4 + 0] = fval[i].x;
943 static_cast<ccl_private float *>(val)[i * 4 + 1] = fval[i].y;
944 static_cast<ccl_private float *>(val)[i * 4 + 2] = fval[i].z;
945 static_cast<ccl_private float *>(val)[i * 4 + 3] = 1.0f;
946 }
947 return true;
948 }
949 if ((type_aggregate == 1 /* TypeDesc::SCALAR */)) {
950 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
951 static_cast<ccl_private float *>(val)[i] = average(fval[i]);
952 }
953 return true;
954 }
955 }
956
957 return false;
958}
960 TypeDesc type,
961 bool derivatives,
962 ccl_private void *val)
963{
964 float3 fv[3];
965
966 fv[0] = f;
967 fv[1] = make_float3(0.0f, 0.0f, 0.0f);
968 fv[2] = make_float3(0.0f, 0.0f, 0.0f);
969
970 return set_attribute_float3(fv, type, derivatives, val);
971}
973 TypeDesc type,
974 bool derivatives,
975 ccl_private void *val)
976{
977 const unsigned char type_basetype = type & 0xF;
978 const unsigned char type_aggregate = (type >> 8) & 0xF;
979 const int type_arraylen = type >> 32;
980
981 if (type_basetype == 11 /* TypeDesc::FLOAT */) {
982 if ((type_aggregate == 3 /* TypeDesc::VEC3 */) || (type_aggregate == 1 && type_arraylen == 3))
983 {
984 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
985 static_cast<ccl_private float *>(val)[i * 3 + 0] = fval[i].x;
986 static_cast<ccl_private float *>(val)[i * 3 + 1] = fval[i].y;
987 static_cast<ccl_private float *>(val)[i * 3 + 2] = fval[i].z;
988 }
989 return true;
990 }
991 if ((type_aggregate == 4 /* TypeDesc::VEC4 */) || (type_aggregate == 1 && type_arraylen == 4))
992 {
993 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
994 static_cast<ccl_private float *>(val)[i * 4 + 0] = fval[i].x;
995 static_cast<ccl_private float *>(val)[i * 4 + 1] = fval[i].y;
996 static_cast<ccl_private float *>(val)[i * 4 + 2] = fval[i].z;
997 static_cast<ccl_private float *>(val)[i * 4 + 3] = fval[i].w;
998 }
999 return true;
1000 }
1001 if ((type_aggregate == 1 /* TypeDesc::SCALAR */)) {
1002 for (int i = 0; i < (derivatives ? 3 : 1); ++i) {
1003 static_cast<ccl_private float *>(val)[i] = average(float4_to_float3(fval[i]));
1004 }
1005 return true;
1006 }
1007 }
1008
1009 return false;
1010}
1012 TypeDesc type,
1013 ccl_private void *val)
1014{
1015 const unsigned char type_basetype = type & 0xF;
1016 const unsigned char type_aggregate = (type >> 8) & 0xF;
1017
1018 if (type_basetype == 11 /* TypeDesc::FLOAT */ && type_aggregate == 16 /* TypeDesc::MATRIX44 */) {
1019 copy_matrix(static_cast<ccl_private float *>(val), tfm);
1020 return true;
1021 }
1022
1023 return false;
1024}
1025
1028 DeviceString name,
1029 TypeDesc type,
1030 bool derivatives,
1031 ccl_private void *val)
1032{
1034 /* Ray Length */
1035 float f = sd->ray_length;
1036 return set_attribute_float(f, type, derivatives, val);
1037 }
1038
1039 return false;
1040}
1041
1044 const AttributeDescriptor &desc,
1045 TypeDesc type,
1046 bool derivatives,
1047 ccl_private void *val)
1048{
1049 if (desc.type == NODE_ATTR_FLOAT) {
1050 float fval[3];
1051#ifdef __VOLUME__
1052 if (primitive_is_volume_attribute(sd, desc))
1053 fval[0] = primitive_volume_attribute_float(kg, sd, desc);
1054 else
1055#endif
1057 kg, sd, desc, derivatives ? &fval[1] : nullptr, derivatives ? &fval[2] : nullptr);
1058 return set_attribute_float(fval, type, derivatives, val);
1059 }
1060 else if (desc.type == NODE_ATTR_FLOAT2) {
1061 float2 fval[3];
1062#ifdef __VOLUME__
1063 if (primitive_is_volume_attribute(sd, desc))
1064 return false;
1065 else
1066#endif
1068 kg, sd, desc, derivatives ? &fval[1] : nullptr, derivatives ? &fval[2] : nullptr);
1069 return set_attribute_float2(fval, type, derivatives, val);
1070 }
1071 else if (desc.type == NODE_ATTR_FLOAT3) {
1072 float3 fval[3];
1073#ifdef __VOLUME__
1074 if (primitive_is_volume_attribute(sd, desc))
1075 fval[0] = primitive_volume_attribute_float3(kg, sd, desc);
1076 else
1077#endif
1079 kg, sd, desc, derivatives ? &fval[1] : nullptr, derivatives ? &fval[2] : nullptr);
1080 return set_attribute_float3(fval, type, derivatives, val);
1081 }
1082 else if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
1083 float4 fval[3];
1084#ifdef __VOLUME__
1085 if (primitive_is_volume_attribute(sd, desc))
1086 fval[0] = primitive_volume_attribute_float4(kg, sd, desc);
1087 else
1088#endif
1090 kg, sd, desc, derivatives ? &fval[1] : nullptr, derivatives ? &fval[2] : nullptr);
1091 return set_attribute_float4(fval, type, derivatives, val);
1092 }
1093 else if (desc.type == NODE_ATTR_MATRIX) {
1094 Transform tfm = primitive_attribute_matrix(kg, desc);
1095 return set_attribute_matrix(tfm, type, val);
1096 }
1097
1098 return false;
1099}
1100
1103 DeviceString name,
1104 TypeDesc type,
1105 bool derivatives,
1106 ccl_private void *val)
1107{
1108 /* Object attributes */
1110 float3 f = object_location(kg, sd);
1111 return set_attribute_float3(f, type, derivatives, val);
1112 }
1113 else if (name == DeviceStrings::u_object_color) {
1114 float3 f = object_color(kg, sd->object);
1115 return set_attribute_float3(f, type, derivatives, val);
1116 }
1117 else if (name == DeviceStrings::u_object_alpha) {
1118 float f = object_alpha(kg, sd->object);
1119 return set_attribute_float(f, type, derivatives, val);
1120 }
1121 else if (name == DeviceStrings::u_object_index) {
1122 float f = object_pass_id(kg, sd->object);
1123 return set_attribute_float(f, type, derivatives, val);
1124 }
1125 else if (name == DeviceStrings::u_object_is_light) {
1126 float f = ((sd->type & PRIMITIVE_LAMP) != 0);
1127 return set_attribute_float(f, type, derivatives, val);
1128 }
1129 else if (name == DeviceStrings::u_geom_dupli_generated) {
1130 float3 f = object_dupli_generated(kg, sd->object);
1131 return set_attribute_float3(f, type, derivatives, val);
1132 }
1133 else if (name == DeviceStrings::u_geom_dupli_uv) {
1134 float3 f = object_dupli_uv(kg, sd->object);
1135 return set_attribute_float3(f, type, derivatives, val);
1136 }
1137 else if (name == DeviceStrings::u_material_index) {
1138 float f = shader_pass_id(kg, sd);
1139 return set_attribute_float(f, type, derivatives, val);
1140 }
1141 else if (name == DeviceStrings::u_object_random) {
1142 float f = object_random_number(kg, sd->object);
1143 return set_attribute_float(f, type, derivatives, val);
1144 }
1145
1146 /* Particle attributes */
1147 else if (name == DeviceStrings::u_particle_index) {
1148 int particle_id = object_particle_id(kg, sd->object);
1149 float f = particle_index(kg, particle_id);
1150 return set_attribute_float(f, type, derivatives, val);
1151 }
1152 else if (name == DeviceStrings::u_particle_random) {
1153 int particle_id = object_particle_id(kg, sd->object);
1154 float f = hash_uint2_to_float(particle_index(kg, particle_id), 0);
1155 return set_attribute_float(f, type, derivatives, val);
1156 }
1157
1158 else if (name == DeviceStrings::u_particle_age) {
1159 int particle_id = object_particle_id(kg, sd->object);
1160 float f = particle_age(kg, particle_id);
1161 return set_attribute_float(f, type, derivatives, val);
1162 }
1163 else if (name == DeviceStrings::u_particle_lifetime) {
1164 int particle_id = object_particle_id(kg, sd->object);
1165 float f = particle_lifetime(kg, particle_id);
1166 return set_attribute_float(f, type, derivatives, val);
1167 }
1168 else if (name == DeviceStrings::u_particle_location) {
1169 int particle_id = object_particle_id(kg, sd->object);
1170 float3 f = particle_location(kg, particle_id);
1171 return set_attribute_float3(f, type, derivatives, val);
1172 }
1173#if 0 /* unsupported */
1174 else if (name == DeviceStrings::u_particle_rotation) {
1175 int particle_id = object_particle_id(kg, sd->object);
1176 float4 f = particle_rotation(kg, particle_id);
1177 return set_attribute_float4(f, type, derivatives, val);
1178 }
1179#endif
1180 else if (name == DeviceStrings::u_particle_size) {
1181 int particle_id = object_particle_id(kg, sd->object);
1182 float f = particle_size(kg, particle_id);
1183 return set_attribute_float(f, type, derivatives, val);
1184 }
1185 else if (name == DeviceStrings::u_particle_velocity) {
1186 int particle_id = object_particle_id(kg, sd->object);
1187 float3 f = particle_velocity(kg, particle_id);
1188 return set_attribute_float3(f, type, derivatives, val);
1189 }
1191 int particle_id = object_particle_id(kg, sd->object);
1192 float3 f = particle_angular_velocity(kg, particle_id);
1193 return set_attribute_float3(f, type, derivatives, val);
1194 }
1195
1196 /* Geometry attributes */
1197#if 0 /* TODO */
1198 else if (name == DeviceStrings::u_geom_numpolyvertices) {
1199 return false;
1200 }
1201 else if (name == DeviceStrings::u_geom_trianglevertices ||
1203 return false;
1204 }
1205 else if (name == DeviceStrings::u_geom_name) {
1206 return false;
1207 }
1208#endif
1209 else if (name == DeviceStrings::u_is_smooth) {
1210 float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0);
1211 return set_attribute_float(f, type, derivatives, val);
1212 }
1213
1214#ifdef __HAIR__
1215 /* Hair attributes */
1216 else if (name == DeviceStrings::u_is_curve) {
1217 float f = (sd->type & PRIMITIVE_CURVE) != 0;
1218 return set_attribute_float(f, type, derivatives, val);
1219 }
1220 else if (name == DeviceStrings::u_curve_thickness) {
1221 float f = curve_thickness(kg, sd);
1222 return set_attribute_float(f, type, derivatives, val);
1223 }
1224 else if (name == DeviceStrings::u_curve_tangent_normal) {
1225 float3 f = curve_tangent_normal(kg, sd);
1226 return set_attribute_float3(f, type, derivatives, val);
1227 }
1228 else if (name == DeviceStrings::u_curve_random) {
1229 float f = curve_random(kg, sd);
1230 return set_attribute_float(f, type, derivatives, val);
1231 }
1232#endif
1233
1234#ifdef __POINTCLOUD__
1235 /* Point attributes */
1236 else if (name == DeviceStrings::u_is_point) {
1237 float f = (sd->type & PRIMITIVE_POINT) != 0;
1238 return set_attribute_float(f, type, derivatives, val);
1239 }
1240 else if (name == DeviceStrings::u_point_radius) {
1241 float f = point_radius(kg, sd);
1242 return set_attribute_float(f, type, derivatives, val);
1243 }
1244 else if (name == DeviceStrings::u_point_position) {
1245 float3 f = point_position(kg, sd);
1246 return set_attribute_float3(f, type, derivatives, val);
1247 }
1248 else if (name == DeviceStrings::u_point_random) {
1249 float f = point_random(kg, sd);
1250 return set_attribute_float(f, type, derivatives, val);
1251 }
1252#endif
1253
1254 else if (name == DeviceStrings::u_normal_map_normal) {
1255 if (sd->type & PRIMITIVE_TRIANGLE) {
1256 float3 f = triangle_smooth_normal_unnormalized(kg, sd, sd->Ng, sd->prim, sd->u, sd->v);
1257 return set_attribute_float3(f, type, derivatives, val);
1258 }
1259 else {
1260 return false;
1261 }
1262 }
1263
1264 return get_background_attribute(kg, sd, name, type, derivatives, val);
1265}
1266
1268 int derivatives,
1269 DeviceString object_name,
1270 DeviceString name,
1271 int array_lookup,
1272 int index,
1273 TypeDesc type,
1274 ccl_private void *res)
1275{
1276 KernelGlobals kg = nullptr;
1277 ccl_private ShaderData *const sd = static_cast<ccl_private ShaderData *>(sg->renderstate);
1278 int object;
1279
1280 if (object_name != DeviceStrings::_emptystring_) {
1281 /* TODO: Get object index from name */
1282 return false;
1283 }
1284 else {
1285 object = sd->object;
1286 }
1287
1288 const AttributeDescriptor desc = find_attribute(kg, object, sd->prim, sd->type, name);
1289 if (desc.offset != ATTR_STD_NOT_FOUND) {
1290 return get_object_attribute(kg, sd, desc, type, derivatives, res);
1291 }
1292 else {
1293 return get_object_standard_attribute(kg, sd, name, type, derivatives, res);
1294 }
1295}
1296
1297#if 0
1298ccl_device_extern bool osl_bind_interpolated_param(ccl_private ShaderGlobals *sg,
1299 DeviceString name,
1300 long long type,
1301 int userdata_has_derivs,
1302 ccl_private void *userdata_data,
1303 int symbol_has_derivs,
1304 ccl_private void *symbol_data,
1305 int symbol_data_size,
1306 ccl_private void *userdata_initialized,
1307 int userdata_index)
1308{
1309 return false;
1310}
1311#endif
1312
1313/* Noise */
1314
1315#include "kernel/svm/noise.h"
1316#include "util/hash.h"
1317
1319{
1320 return hash_uint(x);
1321}
1322
1327
1332
1337
1343
1348
1353
1358
1363
1368
1373
1374#define OSL_NOISE_IMPL(name, op) \
1375 ccl_device_extern float name##_ff(float x) \
1376 { \
1377 return op##_1d(x); \
1378 } \
1379 ccl_device_extern float name##_fff(float x, float y) \
1380 { \
1381 return op##_2d(make_float2(x, y)); \
1382 } \
1383 ccl_device_extern float name##_fv(ccl_private const float3 *v) \
1384 { \
1385 return op##_3d(*v); \
1386 } \
1387 ccl_device_extern float name##_fvf(ccl_private const float3 *v, float w) \
1388 { \
1389 return op##_4d(make_float4(v->x, v->y, v->z, w)); \
1390 } \
1391 ccl_device_extern void name##_vf(ccl_private float3 *res, float x) \
1392 { \
1393 /* TODO: This is not correct. Really need to change the hash function inside the noise \
1394 * function to spit out a vector instead of a scalar. */ \
1395 const float n = name##_ff(x); \
1396 res->x = n; \
1397 res->y = n; \
1398 res->z = n; \
1399 } \
1400 ccl_device_extern void name##_vff(ccl_private float3 *res, float x, float y) \
1401 { \
1402 const float n = name##_fff(x, y); \
1403 res->x = n; \
1404 res->y = n; \
1405 res->z = n; \
1406 } \
1407 ccl_device_extern void name##_vv(ccl_private float3 *res, ccl_private const float3 *v) \
1408 { \
1409 const float n = name##_fv(v); \
1410 res->x = n; \
1411 res->y = n; \
1412 res->z = n; \
1413 } \
1414 ccl_device_extern void name##_vvf( \
1415 ccl_private float3 *res, ccl_private const float3 *v, float w) \
1416 { \
1417 const float n = name##_fvf(v, w); \
1418 res->x = n; \
1419 res->y = n; \
1420 res->z = n; \
1421 } \
1422 ccl_device_extern void name##_dfdf(ccl_private float *res, ccl_private const float *x) \
1423 { \
1424 res[0] = name##_ff(x[0]); \
1425 res[1] = name##_ff(x[1]); \
1426 res[2] = name##_ff(x[2]); \
1427 } \
1428 ccl_device_extern void name##_dfdff( \
1429 ccl_private float *res, ccl_private const float *x, float y) \
1430 { \
1431 res[0] = name##_fff(x[0], y); \
1432 res[1] = name##_fff(x[1], y); \
1433 res[2] = name##_fff(x[2], y); \
1434 } \
1435 ccl_device_extern void name##_dffdf( \
1436 ccl_private float *res, float x, ccl_private const float *y) \
1437 { \
1438 res[0] = name##_fff(x, y[0]); \
1439 res[1] = name##_fff(x, y[1]); \
1440 res[2] = name##_fff(x, y[2]); \
1441 } \
1442 ccl_device_extern void name##_dfdfdf( \
1443 ccl_private float *res, ccl_private const float *x, ccl_private const float *y) \
1444 { \
1445 res[0] = name##_fff(x[0], y[0]); \
1446 res[1] = name##_fff(x[1], y[1]); \
1447 res[2] = name##_fff(x[2], y[2]); \
1448 } \
1449 ccl_device_extern void name##_dfdv(ccl_private float *res, ccl_private const float3 *v) \
1450 { \
1451 res[0] = name##_fv(&v[0]); \
1452 res[1] = name##_fv(&v[1]); \
1453 res[2] = name##_fv(&v[2]); \
1454 } \
1455 ccl_device_extern void name##_dfdvf( \
1456 ccl_private float *res, ccl_private const float3 *v, float w) \
1457 { \
1458 res[0] = name##_fvf(&v[0], w); \
1459 res[1] = name##_fvf(&v[1], w); \
1460 res[2] = name##_fvf(&v[2], w); \
1461 } \
1462 ccl_device_extern void name##_dfvdf( \
1463 ccl_private float *res, ccl_private const float3 *v, ccl_private const float *w) \
1464 { \
1465 res[0] = name##_fvf(v, w[0]); \
1466 res[1] = name##_fvf(v, w[1]); \
1467 res[2] = name##_fvf(v, w[2]); \
1468 } \
1469 ccl_device_extern void name##_dfdvdf( \
1470 ccl_private float *res, ccl_private const float3 *v, ccl_private const float *w) \
1471 { \
1472 res[0] = name##_fvf(&v[0], w[0]); \
1473 res[1] = name##_fvf(&v[1], w[1]); \
1474 res[2] = name##_fvf(&v[2], w[2]); \
1475 } \
1476 ccl_device_extern void name##_dvdf(ccl_private float3 *res, ccl_private const float *x) \
1477 { \
1478 name##_vf(&res[0], x[0]); \
1479 name##_vf(&res[1], x[1]); \
1480 name##_vf(&res[2], x[2]); \
1481 } \
1482 ccl_device_extern void name##_dvdff( \
1483 ccl_private float3 *res, ccl_private const float *x, float y) \
1484 { \
1485 name##_vff(&res[0], x[0], y); \
1486 name##_vff(&res[1], x[1], y); \
1487 name##_vff(&res[2], x[2], y); \
1488 } \
1489 ccl_device_extern void name##_dvfdf( \
1490 ccl_private float3 *res, float x, ccl_private const float *y) \
1491 { \
1492 name##_vff(&res[0], x, y[0]); \
1493 name##_vff(&res[1], x, y[1]); \
1494 name##_vff(&res[2], x, y[2]); \
1495 } \
1496 ccl_device_extern void name##_dvdfdf( \
1497 ccl_private float3 *res, ccl_private const float *x, ccl_private const float *y) \
1498 { \
1499 name##_vff(&res[0], x[0], y[0]); \
1500 name##_vff(&res[1], x[1], y[1]); \
1501 name##_vff(&res[2], x[2], y[2]); \
1502 } \
1503 ccl_device_extern void name##_dvdv(ccl_private float3 *res, ccl_private const float3 *v) \
1504 { \
1505 name##_vv(&res[0], &v[0]); \
1506 name##_vv(&res[1], &v[1]); \
1507 name##_vv(&res[2], &v[2]); \
1508 } \
1509 ccl_device_extern void name##_dvdvf( \
1510 ccl_private float3 *res, ccl_private const float3 *v, float w) \
1511 { \
1512 name##_vvf(&res[0], &v[0], w); \
1513 name##_vvf(&res[1], &v[1], w); \
1514 name##_vvf(&res[2], &v[2], w); \
1515 } \
1516 ccl_device_extern void name##_dvvdf( \
1517 ccl_private float3 *res, ccl_private const float3 *v, ccl_private const float *w) \
1518 { \
1519 name##_vvf(&res[0], v, w[0]); \
1520 name##_vvf(&res[1], v, w[1]); \
1521 name##_vvf(&res[2], v, w[2]); \
1522 } \
1523 ccl_device_extern void name##_dvdvdf( \
1524 ccl_private float3 *res, ccl_private const float3 *v, ccl_private const float *w) \
1525 { \
1526 name##_vvf(&res[0], &v[0], w[0]); \
1527 name##_vvf(&res[1], &v[1], w[1]); \
1528 name##_vvf(&res[2], &v[2], w[2]); \
1529 }
1532{
1533 const uint x = __float_as_uint(p);
1534 return hash_uint(x) / static_cast<float>(~0u);
1537{
1538 const uint x = __float_as_uint(p.x);
1539 const uint y = __float_as_uint(p.y);
1540 return hash_uint2(x, y) / static_cast<float>(~0u);
1543{
1544 const uint x = __float_as_uint(p.x);
1545 const uint y = __float_as_uint(p.y);
1546 const uint z = __float_as_uint(p.z);
1547 return hash_uint3(x, y, z) / static_cast<float>(~0u);
1550{
1551 const uint x = __float_as_uint(p.x);
1552 const uint y = __float_as_uint(p.y);
1553 const uint z = __float_as_uint(p.z);
1554 const uint w = __float_as_uint(p.w);
1555 return hash_uint4(x, y, z, w) / static_cast<float>(~0u);
1556}
1557
1558/* TODO: Implement all noise functions */
1559OSL_NOISE_IMPL(osl_hashnoise, hashnoise)
1560OSL_NOISE_IMPL(osl_noise, noise)
1561OSL_NOISE_IMPL(osl_snoise, snoise)
1562
1563/* Texturing */
1564
1565#include "kernel/util/ies.h"
1571}
1576}
1610}
1615}
1618 int nchannels,
1619 float alpha)
1620{
1621}
1624 DeviceString filename,
1625 ccl_private void *texture_handle,
1627 float s,
1628 float t,
1629 float dsdx,
1630 float dtdx,
1631 float dsdy,
1632 float dtdy,
1633 int nchannels,
1634 ccl_private float *result,
1635 ccl_private float *dresultdx,
1636 ccl_private float *dresultdy,
1637 ccl_private float *alpha,
1638 ccl_private float *dalphadx,
1639 ccl_private float *dalphady,
1640 ccl_private void *errormessage)
1641{
1642 const unsigned int type = OSL_TEXTURE_HANDLE_TYPE(texture_handle);
1643 const unsigned int slot = OSL_TEXTURE_HANDLE_SLOT(texture_handle);
1644
1645 switch (type) {
1647 const float4 rgba = kernel_tex_image_interp(nullptr, slot, s, 1.0f - t);
1648 if (nchannels > 0) {
1649 result[0] = rgba.x;
1650 }
1651 if (nchannels > 1) {
1652 result[1] = rgba.y;
1653 }
1654 if (nchannels > 2) {
1655 result[2] = rgba.z;
1656 }
1657 if (alpha) {
1658 *alpha = rgba.w;
1659 }
1660 return true;
1661 }
1663 if (nchannels > 0) {
1664 result[0] = kernel_ies_interp(nullptr, slot, s, t);
1665 }
1666 return true;
1667 }
1668 default: {
1669 return false;
1670 }
1671 }
1672}
1675 DeviceString filename,
1676 ccl_private void *texture_handle,
1678 ccl_private const float3 *P,
1679 ccl_private const float3 *dPdx,
1680 ccl_private const float3 *dPdy,
1681 ccl_private const float3 *dPdz,
1682 int nchannels,
1683 ccl_private float *result,
1684 ccl_private float *dresultds,
1685 ccl_private float *dresultdt,
1686 ccl_private float *alpha,
1687 ccl_private float *dalphadx,
1688 ccl_private float *dalphady,
1689 ccl_private void *errormessage)
1690{
1691 const unsigned int type = OSL_TEXTURE_HANDLE_TYPE(texture_handle);
1692 const unsigned int slot = OSL_TEXTURE_HANDLE_SLOT(texture_handle);
1693
1694 switch (type) {
1696 const float4 rgba = kernel_tex_image_interp_3d(nullptr, slot, *P, INTERPOLATION_NONE);
1697 if (nchannels > 0) {
1698 result[0] = rgba.x;
1699 }
1700 if (nchannels > 1) {
1701 result[1] = rgba.y;
1702 }
1703 if (nchannels > 2) {
1704 result[2] = rgba.z;
1705 }
1706 if (alpha) {
1707 *alpha = rgba.w;
1708 }
1709 return true;
1710 }
1711 default: {
1712 return false;
1713 }
1714 }
1715}
1718 DeviceString filename,
1719 ccl_private void *texture_handle,
1721 ccl_private const float3 *R,
1722 ccl_private const float3 *dRdx,
1723 ccl_private const float3 *dRdy,
1724 int nchannels,
1725 ccl_private float *result,
1726 ccl_private float *dresultds,
1727 ccl_private float *dresultdt,
1728 ccl_private float *alpha,
1729 ccl_private float *dalphax,
1730 ccl_private float *dalphay,
1731 ccl_private void *errormessage)
1732{
1733 if (nchannels > 0) {
1734 result[0] = 1.0f;
1735 }
1736 if (nchannels > 1) {
1737 result[1] = 0.0f;
1738 }
1739 if (nchannels > 2) {
1740 result[2] = 1.0f;
1741 }
1742 if (alpha) {
1743 *alpha = 1.0f;
1744 }
1745
1746 return false;
1747}
1750 DeviceString filename,
1751 ccl_private void *texture_handle,
1752 DeviceString dataname,
1753 int basetype,
1754 int arraylen,
1755 int aggegrate,
1756 ccl_private void *data,
1757 ccl_private void *errormessage)
1758{
1759 return false;
1760}
1763 DeviceString filename,
1764 ccl_private void *texture_handle,
1765 float s,
1766 float t,
1767 DeviceString dataname,
1768 int basetype,
1769 int arraylen,
1770 int aggegrate,
1771 ccl_private void *data,
1772 ccl_private void *errormessage)
1773{
1774 return osl_get_textureinfo(
1775 sg, filename, texture_handle, dataname, basetype, arraylen, aggegrate, data, errormessage);
1776}
1777
1778/* Standard library */
1780#define OSL_OP_IMPL_II(name, op) \
1781 ccl_device_extern int name##_ii(int a) \
1782 { \
1783 return op(a); \
1785#define OSL_OP_IMPL_IF(name, op) \
1786 ccl_device_extern int name##_if(float a) \
1787 { \
1788 return op(a); \
1790#define OSL_OP_IMPL_FF(name, op) \
1791 ccl_device_extern float name##_ff(float a) \
1792 { \
1793 return op(a); \
1795#define OSL_OP_IMPL_DFDF(name, op) \
1796 ccl_device_extern void name##_dfdf(ccl_private float *res, ccl_private const float *a) \
1797 { \
1798 for (int i = 0; i < 3; ++i) { \
1799 res[i] = op(a[i]); \
1800 } \
1802#define OSL_OP_IMPL_DFDV(name, op) \
1803 ccl_device_extern void name##_dfdv(ccl_private float *res, ccl_private const float3 *a) \
1804 { \
1805 for (int i = 0; i < 3; ++i) { \
1806 res[i] = op(a[i]); \
1807 } \
1809#define OSL_OP_IMPL_FV(name, op) \
1810 ccl_device_extern float name##_fv(ccl_private const float3 *a) \
1811 { \
1812 return op(*a); \
1814#define OSL_OP_IMPL_VV(name, op) \
1815 ccl_device_extern void name##_vv(ccl_private float3 *res, ccl_private const float3 *a) \
1816 { \
1817 *res = op(*a); \
1819#define OSL_OP_IMPL_VV_(name, op) \
1820 ccl_device_extern void name##_vv(ccl_private float3 *res, ccl_private const float3 *a) \
1821 { \
1822 res->x = op(a->x); \
1823 res->y = op(a->y); \
1824 res->z = op(a->z); \
1826#define OSL_OP_IMPL_DVDV(name, op) \
1827 ccl_device_extern void name##_dvdv(ccl_private float3 *res, ccl_private const float3 *a) \
1828 { \
1829 for (int i = 0; i < 3; ++i) { \
1830 res[i] = op(a[i]); \
1831 } \
1833#define OSL_OP_IMPL_DVDV_(name, op) \
1834 ccl_device_extern void name##_dvdv(ccl_private float3 *res, ccl_private const float3 *a) \
1835 { \
1836 for (int i = 0; i < 3; ++i) { \
1837 res[i].x = op(a[i].x); \
1838 res[i].y = op(a[i].y); \
1839 res[i].z = op(a[i].z); \
1840 } \
1841 }
1843#define OSL_OP_IMPL_III(name, op) \
1844 ccl_device_extern int name##_iii(int a, int b) \
1845 { \
1846 return op(a, b); \
1848#define OSL_OP_IMPL_FFF(name, op) \
1849 ccl_device_extern float name##_fff(float a, float b) \
1850 { \
1851 return op(a, b); \
1853#define OSL_OP_IMPL_FVV(name, op) \
1854 ccl_device_extern float name##_fvv(ccl_private const float3 *a, ccl_private const float3 *b) \
1855 { \
1856 return op(*a, *b); \
1858#define OSL_OP_IMPL_DFFDF(name, op) \
1859 ccl_device_extern void name##_dffdf( \
1860 ccl_private float *res, float a, ccl_private const float *b) \
1861 { \
1862 for (int i = 0; i < 3; ++i) { \
1863 res[i] = op(a, b[i]); \
1864 } \
1866#define OSL_OP_IMPL_DFDFF(name, op) \
1867 ccl_device_extern void name##_dfdff( \
1868 ccl_private float *res, ccl_private const float *a, float b) \
1869 { \
1870 for (int i = 0; i < 3; ++i) { \
1871 res[i] = op(a[i], b); \
1872 } \
1874#define OSL_OP_IMPL_DFDFDF(name, op) \
1875 ccl_device_extern void name##_dfdfdf( \
1876 ccl_private float *res, ccl_private const float *a, ccl_private const float *b) \
1877 { \
1878 for (int i = 0; i < 3; ++i) { \
1879 res[i] = op(a[i], b[i]); \
1880 } \
1882#define OSL_OP_IMPL_DFVDV(name, op) \
1883 ccl_device_extern void name##_dfvdv( \
1884 ccl_private float *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1885 { \
1886 for (int i = 0; i < 3; ++i) { \
1887 res[i] = op(a[0], b[i]); \
1888 } \
1890#define OSL_OP_IMPL_DFDVV(name, op) \
1891 ccl_device_extern void name##_dfdvv( \
1892 ccl_private float *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1893 { \
1894 for (int i = 0; i < 3; ++i) { \
1895 res[i] = op(a[i], b[0]); \
1896 } \
1898#define OSL_OP_IMPL_DFDVDV(name, op) \
1899 ccl_device_extern void name##_dfdvdv( \
1900 ccl_private float *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1901 { \
1902 for (int i = 0; i < 3; ++i) { \
1903 res[i] = op(a[i], b[i]); \
1904 } \
1906#define OSL_OP_IMPL_VVF_(name, op) \
1907 ccl_device_extern void name##_vvf( \
1908 ccl_private float3 *res, ccl_private const float3 *a, float b) \
1909 { \
1910 res->x = op(a->x, b); \
1911 res->y = op(a->y, b); \
1912 res->z = op(a->z, b); \
1914#define OSL_OP_IMPL_VVV(name, op) \
1915 ccl_device_extern void name##_vvv( \
1916 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1917 { \
1918 *res = op(*a, *b); \
1920#define OSL_OP_IMPL_VVV_(name, op) \
1921 ccl_device_extern void name##_vvv( \
1922 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1923 { \
1924 res->x = op(a->x, b->x); \
1925 res->y = op(a->y, b->y); \
1926 res->z = op(a->z, b->z); \
1928#define OSL_OP_IMPL_DVVDF_(name, op) \
1929 ccl_device_extern void name##_dvvdf( \
1930 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float *b) \
1931 { \
1932 for (int i = 0; i < 3; ++i) { \
1933 res[i].x = op(a[0].x, b[i]); \
1934 res[i].y = op(a[0].y, b[i]); \
1935 res[i].z = op(a[0].z, b[i]); \
1936 } \
1938#define OSL_OP_IMPL_DVDVF_(name, op) \
1939 ccl_device_extern void name##_dvdvf( \
1940 ccl_private float3 *res, ccl_private const float3 *a, float b) \
1941 { \
1942 for (int i = 0; i < 3; ++i) { \
1943 res[i].x = op(a[i].x, b); \
1944 res[i].y = op(a[i].y, b); \
1945 res[i].z = op(a[i].z, b); \
1946 } \
1948#define OSL_OP_IMPL_DVVDV(name, op) \
1949 ccl_device_extern void name##_dvvdv( \
1950 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1951 { \
1952 for (int i = 0; i < 3; ++i) { \
1953 res[i] = op(a[0], b[i]); \
1954 } \
1956#define OSL_OP_IMPL_DVVDV_(name, op) \
1957 ccl_device_extern void name##_dvvdv( \
1958 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1959 { \
1960 for (int i = 0; i < 3; ++i) { \
1961 res[i].x = op(a[0].x, b[i].x); \
1962 res[i].y = op(a[0].y, b[i].y); \
1963 res[i].z = op(a[0].z, b[i].z); \
1964 } \
1966#define OSL_OP_IMPL_DVDVV(name, op) \
1967 ccl_device_extern void name##_dvdvv( \
1968 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1969 { \
1970 for (int i = 0; i < 3; ++i) { \
1971 res[i] = op(a[i], b[0]); \
1972 } \
1974#define OSL_OP_IMPL_DVDVV_(name, op) \
1975 ccl_device_extern void name##_dvdvv( \
1976 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1977 { \
1978 for (int i = 0; i < 3; ++i) { \
1979 res[i].x = op(a[i].x, b[0].x); \
1980 res[i].y = op(a[i].y, b[0].y); \
1981 res[i].z = op(a[i].z, b[0].z); \
1982 } \
1984#define OSL_OP_IMPL_DVDVDF_(name, op) \
1985 ccl_device_extern void name##_dvdvdf( \
1986 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float *b) \
1987 { \
1988 for (int i = 0; i < 3; ++i) { \
1989 res[i].x = op(a[i].x, b[i]); \
1990 res[i].y = op(a[i].y, b[i]); \
1991 res[i].z = op(a[i].z, b[i]); \
1992 } \
1994#define OSL_OP_IMPL_DVDVDV(name, op) \
1995 ccl_device_extern void name##_dvdvdv( \
1996 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
1997 { \
1998 for (int i = 0; i < 3; ++i) { \
1999 res[i] = op(a[i], b[i]); \
2000 } \
2002#define OSL_OP_IMPL_DVDVDV_(name, op) \
2003 ccl_device_extern void name##_dvdvdv( \
2004 ccl_private float3 *res, ccl_private const float3 *a, ccl_private const float3 *b) \
2005 { \
2006 for (int i = 0; i < 3; ++i) { \
2007 res[i].x = op(a[i].x, b[i].x); \
2008 res[i].y = op(a[i].y, b[i].y); \
2009 res[i].z = op(a[i].z, b[i].z); \
2010 } \
2011 }
2013#define OSL_OP_IMPL_FFFF(name, op) \
2014 ccl_device_extern float name##_ffff(float a, float b, float c) \
2015 { \
2016 return op(a, b, c); \
2018#define OSL_OP_IMPL_DFFFDF(name, op) \
2019 ccl_device_extern void name##_dfffdf( \
2020 ccl_private float *res, float a, float b, ccl_private const float *c) \
2021 { \
2022 for (int i = 0; i < 3; ++i) { \
2023 res[i] = op(a, b, c[i]); \
2024 } \
2026#define OSL_OP_IMPL_DFFDFF(name, op) \
2027 ccl_device_extern void name##_dffdff( \
2028 ccl_private float *res, float a, ccl_private const float *b, float c) \
2029 { \
2030 for (int i = 0; i < 3; ++i) { \
2031 res[i] = op(a, b[i], c); \
2032 } \
2034#define OSL_OP_IMPL_DFFDFDF(name, op) \
2035 ccl_device_extern void name##_dffdfdf( \
2036 ccl_private float *res, float a, ccl_private const float *b, ccl_private const float *c) \
2037 { \
2038 for (int i = 0; i < 3; ++i) { \
2039 res[i] = op(a, b[i], c[i]); \
2040 } \
2041 }
2043#define OSL_OP_IMPL_DFDFFF(name, op) \
2044 ccl_device_extern void name##_dfdfff( \
2045 ccl_private float *res, ccl_private const float *a, float b, float c) \
2046 { \
2047 for (int i = 0; i < 3; ++i) { \
2048 res[i] = op(a[i], b, c); \
2049 } \
2051#define OSL_OP_IMPL_DFDFFDF(name, op) \
2052 ccl_device_extern void name##_dfdffdf( \
2053 ccl_private float *res, ccl_private const float *a, float b, ccl_private const float *c) \
2054 { \
2055 for (int i = 0; i < 3; ++i) { \
2056 res[i] = op(a[i], b, c[i]); \
2057 } \
2059#define OSL_OP_IMPL_DFDFDFF(name, op) \
2060 ccl_device_extern void name##_dfdfdff( \
2061 ccl_private float *res, ccl_private const float *a, ccl_private const float *b, float c) \
2062 { \
2063 for (int i = 0; i < 3; ++i) { \
2064 res[i] = op(a[i], b[i], c); \
2065 } \
2067#define OSL_OP_IMPL_DFDFDFDF(name, op) \
2068 ccl_device_extern void name##_dfdfdfdf(ccl_private float *res, \
2069 ccl_private const float *a, \
2070 ccl_private const float *b, \
2071 ccl_private const float *c) \
2072 { \
2073 for (int i = 0; i < 3; ++i) { \
2074 res[i] = op(a[i], b[i], c[i]); \
2075 } \
2076 }
2078#define OSL_OP_IMPL_XX(name, op) \
2079 OSL_OP_IMPL_FF(name, op) \
2080 OSL_OP_IMPL_DFDF(name, op) \
2081 OSL_OP_IMPL_VV_(name, op) \
2082 OSL_OP_IMPL_DVDV_(name, op)
2084#define OSL_OP_IMPL_XXX(name, op) \
2085 OSL_OP_IMPL_FFF(name, op) \
2086 OSL_OP_IMPL_DFFDF(name, op) \
2087 OSL_OP_IMPL_DFDFF(name, op) \
2088 OSL_OP_IMPL_DFDFDF(name, op) \
2089 OSL_OP_IMPL_VVV_(name, op) \
2090 OSL_OP_IMPL_DVVDV_(name, op) \
2091 OSL_OP_IMPL_DVDVV_(name, op) \
2092 OSL_OP_IMPL_DVDVDV_(name, op)
2093
2094OSL_OP_IMPL_XX(osl_acos, acosf)
2095OSL_OP_IMPL_XX(osl_asin, asinf)
2096OSL_OP_IMPL_XX(osl_atan, atanf)
2097OSL_OP_IMPL_XXX(osl_atan2, atan2f)
2098OSL_OP_IMPL_XX(osl_cos, cosf)
2099OSL_OP_IMPL_XX(osl_sin, sinf)
2100OSL_OP_IMPL_XX(osl_tan, tanf)
2101OSL_OP_IMPL_XX(osl_cosh, coshf)
2102OSL_OP_IMPL_XX(osl_sinh, sinhf)
2103OSL_OP_IMPL_XX(osl_tanh, tanhf)
2105ccl_device_forceinline int safe_divide(int a, int b)
2106{
2107 return (b != 0) ? a / b : 0;
2109ccl_device_forceinline int safe_modulo(int a, int b)
2110{
2111 return (b != 0) ? a % b : 0;
2112}
2113
2114OSL_OP_IMPL_III(osl_safe_div, safe_divide)
2115OSL_OP_IMPL_FFF(osl_safe_div, safe_divide)
2116OSL_OP_IMPL_III(osl_safe_mod, safe_modulo)
2118ccl_device_extern void osl_sincos_fff(float a, ccl_private float *b, ccl_private float *c)
2119{
2120 sincos(a, b, c);
2123 ccl_private float *b,
2124 ccl_private float *c)
2125{
2126 for (int i = 0; i < 3; ++i) {
2127 sincos(a[i], b + i, c);
2128 }
2131 ccl_private float *b,
2132 ccl_private float *c)
2133{
2134 for (int i = 0; i < 3; ++i) {
2135 sincos(a[i], b, c + i);
2136 }
2139 ccl_private float *b,
2140 ccl_private float *c)
2141{
2142 for (int i = 0; i < 3; ++i) {
2143 sincos(a[i], b + i, c + i);
2144 }
2149{
2150 sincos(a->x, &b->x, &c->x);
2151 sincos(a->y, &b->y, &c->y);
2152 sincos(a->z, &b->z, &c->z);
2157{
2158 for (int i = 0; i < 3; ++i) {
2159 sincos(a[i].x, &b[i].x, &c->x);
2160 sincos(a[i].y, &b[i].y, &c->y);
2161 sincos(a[i].z, &b[i].z, &c->z);
2162 }
2167{
2168 for (int i = 0; i < 3; ++i) {
2169 sincos(a[i].x, &b->x, &c[i].x);
2170 sincos(a[i].y, &b->y, &c[i].y);
2171 sincos(a[i].z, &b->z, &c[i].z);
2172 }
2177{
2178 for (int i = 0; i < 3; ++i) {
2179 sincos(a[i].x, &b[i].x, &c[i].x);
2180 sincos(a[i].y, &b[i].y, &c[i].y);
2181 sincos(a[i].z, &b[i].z, &c[i].z);
2182 }
2183}
2184
2185OSL_OP_IMPL_XX(osl_log, logf)
2186OSL_OP_IMPL_XX(osl_log2, log2f)
2187OSL_OP_IMPL_XX(osl_log10, log10f)
2188OSL_OP_IMPL_XX(osl_exp, expf)
2189OSL_OP_IMPL_XX(osl_exp2, exp2f)
2190OSL_OP_IMPL_XX(osl_expm1, expm1f)
2191OSL_OP_IMPL_XX(osl_erf, erff)
2192OSL_OP_IMPL_XX(osl_erfc, erfcf)
2193
2194OSL_OP_IMPL_XXX(osl_pow, safe_powf)
2199
2200OSL_OP_IMPL_XX(osl_sqrt, sqrtf)
2201OSL_OP_IMPL_XX(osl_inversesqrt, 1.0f / sqrtf)
2202OSL_OP_IMPL_XX(osl_cbrt, cbrtf)
2203
2204OSL_OP_IMPL_FF(osl_logb, logbf)
2205OSL_OP_IMPL_VV_(osl_logb, logbf)
2206
2207OSL_OP_IMPL_FF(osl_floor, floorf)
2208OSL_OP_IMPL_VV_(osl_floor, floorf)
2209OSL_OP_IMPL_FF(osl_ceil, ceilf)
2210OSL_OP_IMPL_VV_(osl_ceil, ceilf)
2211OSL_OP_IMPL_FF(osl_round, roundf)
2212OSL_OP_IMPL_VV_(osl_round, roundf)
2213OSL_OP_IMPL_FF(osl_trunc, truncf)
2214OSL_OP_IMPL_VV_(osl_trunc, truncf)
2216ccl_device_forceinline float step_impl(float edge, float x)
2217{
2218 return x < edge ? 0.0f : 1.0f;
2219}
2220
2223OSL_OP_IMPL_FFF(osl_step, step_impl)
2224OSL_OP_IMPL_VVV_(osl_step, step_impl)
2225
2226OSL_OP_IMPL_IF(osl_isnan, isnan)
2227OSL_OP_IMPL_IF(osl_isinf, isinf)
2228OSL_OP_IMPL_IF(osl_isfinite, isfinite)
2229
2230OSL_OP_IMPL_II(osl_abs, abs)
2231OSL_OP_IMPL_XX(osl_abs, fabsf)
2232OSL_OP_IMPL_II(osl_fabs, abs)
2233OSL_OP_IMPL_XX(osl_fabs, fabsf)
2239
2240OSL_OP_IMPL_FFFF(osl_smoothstep, smoothstep)
2241OSL_OP_IMPL_DFFFDF(osl_smoothstep, smoothstep)
2242OSL_OP_IMPL_DFFDFF(osl_smoothstep, smoothstep)
2243OSL_OP_IMPL_DFFDFDF(osl_smoothstep, smoothstep)
2244OSL_OP_IMPL_DFDFFF(osl_smoothstep, smoothstep)
2245OSL_OP_IMPL_DFDFFDF(osl_smoothstep, smoothstep)
2246OSL_OP_IMPL_DFDFDFF(osl_smoothstep, smoothstep)
2247OSL_OP_IMPL_DFDFDFDF(osl_smoothstep, smoothstep)
2248
2249OSL_OP_IMPL_FVV(osl_dot, dot)
2250OSL_OP_IMPL_DFDVV(osl_dot, dot)
2251OSL_OP_IMPL_DFVDV(osl_dot, dot)
2252OSL_OP_IMPL_DFDVDV(osl_dot, dot)
2253OSL_OP_IMPL_VVV(osl_cross, cross)
2254OSL_OP_IMPL_DVDVV(osl_cross, cross)
2255OSL_OP_IMPL_DVVDV(osl_cross, cross)
2256OSL_OP_IMPL_DVDVDV(osl_cross, cross)
2257OSL_OP_IMPL_FV(osl_length, len)
2258OSL_OP_IMPL_DFDV(osl_length, len)
2259OSL_OP_IMPL_FVV(osl_distance, distance)
2260OSL_OP_IMPL_DFDVV(osl_distance, distance)
2261OSL_OP_IMPL_DFVDV(osl_distance, distance)
2262OSL_OP_IMPL_DFDVDV(osl_distance, distance)
2263OSL_OP_IMPL_VV(osl_normalize, safe_normalize)
2264OSL_OP_IMPL_DVDV(osl_normalize, safe_normalize)
2268 ccl_private const float3 *p)
2269{
2270 if (sg->flipHandedness) {
2271 *res = cross(p[2], p[1]);
2272 }
2273 else {
2274 *res = cross(p[1], p[2]);
2275 }
2276}
2279{
2280 return len(cross(p[2], p[1]));
2281}
2284{
2285 return sqrtf(x[1] * x[1] + x[2] * x[2]);
2286}
2288ccl_device_extern void osl_filterwidth_vdv(ccl_private float *res, ccl_private const float *x)
2289{
2290 for (int i = 0; i < 3; ++i) {
2291 res[i] = osl_filterwidth_fdf(x + i);
2292 }
2293}
2296{
2297 return (sg->raytype & bit) != 0;
2298}
MINLINE float safe_powf(float base, float exponent)
MINLINE float safe_divide(float a, float b)
void rgb_to_hsl(float r, float g, float b, float *r_h, float *r_s, float *r_l)
void rgb_to_hsv(float r, float g, float b, float *r_h, float *r_s, float *r_v)
void hsv_to_rgb(float h, float s, float v, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:21
void hsl_to_rgb(float h, float s, float l, float *r_r, float *r_g, float *r_b)
Definition math_color.cc:38
unsigned int uint
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar length(const btQuaternion &q)
Return the length of a quaternion.
local_group_size(16, 16) .push_constant(Type b
#define printf
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)
#define kernel_data
const KernelGlobalsCPU *ccl_restrict KernelGlobals
#define ccl_device_forceinline
#define logf(x)
#define sinf(x)
#define cosf(x)
#define expf(x)
#define ccl_private
#define ccl_device_inline
#define ccl_device_extern
#define tanf(x)
#define ccl_device_constant
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define atan2f(x, y)
#define asinf(x)
#define ceilf(x)
#define atanf(x)
#define floorf(x)
#define acosf(x)
#define tanhf(x)
#define sinhf(x)
#define coshf(x)
#define fabsf(x)
#define __float_as_uint(x)
#define sqrtf(x)
int len
ccl_device_inline float3 triangle_smooth_normal_unnormalized(KernelGlobals kg, ccl_private const ShaderData *sd, float3 Ng, int prim, float u, float v)
ccl_device_inline uint hash_uint2(uint kx, uint ky)
Definition hash.h:89
ccl_device_inline uint hash_uint3(uint kx, uint ky, uint kz)
Definition hash.h:101
ccl_device_inline uint hash_uint4(uint kx, uint ky, uint kz, uint kw)
Definition hash.h:114
ccl_device_inline uint hash_uint(uint kx)
Definition hash.h:78
ccl_device_inline float hash_uint2_to_float(uint kx, uint ky)
Definition hash.h:141
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 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)
#define OSL_TEXTURE_HANDLE_SLOT(handle)
CCL_NAMESPACE_BEGIN typedef const char * DeviceString
#define OSL_TEXTURE_HANDLE_TYPE(handle)
#define OSL_TEXTURE_HANDLE_TYPE_SVM
#define OSL_TEXTURE_HANDLE_TYPE_IES
OSLClosureType
@ OSL_CLOSURE_MUL_ID
@ OSL_CLOSURE_ADD_ID
@ NODE_ATTR_FLOAT
@ NODE_ATTR_FLOAT3
@ NODE_ATTR_RGBA
@ NODE_ATTR_FLOAT2
@ NODE_ATTR_FLOAT4
@ NODE_ATTR_MATRIX
@ PRIMITIVE_LAMP
@ PRIMITIVE_CURVE
@ PRIMITIVE_TRIANGLE
@ PRIMITIVE_POINT
@ ATTR_STD_NOT_FOUND
#define OBJECT_NONE
ShaderData
@ SHADER_SMOOTH_NORMAL
ccl_device float3 rec709_to_rgb(KernelGlobals kg, float3 rec709)
ccl_device float linear_rgb_to_gray(KernelGlobals kg, float3 c)
ccl_device_inline float kernel_ies_interp(KernelGlobals kg, int slot, float h_angle, float v_angle)
format
MINLINE float smoothstep(float edge0, float edge1, float x)
MINLINE float compatible_signf(float f)
ccl_device_inline float average(const float2 a)
ccl_device_inline float2 safe_normalize(const float2 a)
ccl_device_inline float cross(const float2 a, const float2 b)
ccl_device_inline float3 one_float3()
Definition math_float3.h:24
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:15
ccl_device float3 svm_math_wavelength_color_xyz(float lambda_nm)
Definition math_util.h:244
ccl_device float3 svm_math_blackbody_color_rec709(float t)
Definition math_util.h:195
#define R
ccl_device_constant DeviceString u_particle_rotation
ccl_device_constant DeviceString u_point_position
ccl_device_constant DeviceString u_path_transparent_depth
ccl_device_constant DeviceString u_object_color
ccl_device_constant DeviceString u_is_point
ccl_device_constant DeviceString u_particle_lifetime
ccl_device_constant DeviceString u_geom_numpolyvertices
ccl_device_constant DeviceString u_is_curve
ccl_device_constant DeviceString u_material_index
ccl_device_constant DeviceString u_point_radius
ccl_device_constant DeviceString u_particle_location
ccl_device_constant DeviceString u_object_is_light
ccl_device_constant DeviceString u_path_ray_length
ccl_device_constant DeviceString u_path_diffuse_depth
ccl_device_constant DeviceString u_path_transmission_depth
ccl_device_constant DeviceString u_geom_dupli_uv
ccl_device_constant DeviceString u_object_location
ccl_device_constant DeviceString u_hsv
ccl_device_constant DeviceString u_xyy
ccl_device_constant DeviceString u_particle_age
ccl_device_constant DeviceString u_screen
ccl_device_constant DeviceString _emptystring_
ccl_device_constant DeviceString u_is_smooth
ccl_device_constant DeviceString u_normal_map_normal
ccl_device_constant DeviceString u_path_ray_depth
ccl_device_constant DeviceString u_path_glossy_depth
ccl_device_constant DeviceString u_world
ccl_device_constant DeviceString u_object_alpha
ccl_device_constant DeviceString u_object
ccl_device_constant DeviceString u_particle_velocity
ccl_device_constant DeviceString u_raster
ccl_device_constant DeviceString u_common
ccl_device_constant DeviceString u_camera
ccl_device_constant DeviceString u_curve_length
ccl_device_constant DeviceString u_xyz
ccl_device_constant DeviceString u_particle_index
ccl_device_constant DeviceString u_particle_size
ccl_device_constant DeviceString u_point_random
ccl_device_constant DeviceString u_geom_dupli_generated
ccl_device_constant DeviceString u_particle_angular_velocity
ccl_device_constant DeviceString u_shader
ccl_device_constant DeviceString u_srgb
ccl_device_constant DeviceString u_object_random
ccl_device_constant DeviceString u_ndc
ccl_device_constant DeviceString u_hsl
ccl_device_constant DeviceString u_object_index
ccl_device_constant DeviceString u_curve_tangent_normal
ccl_device_constant DeviceString u_geom_polyvertices
ccl_device_constant DeviceString u_geom_name
ccl_device_constant DeviceString u_curve_thickness
ccl_device_constant DeviceString u_particle_random
ccl_device_constant DeviceString u_geom_undisplaced
ccl_device_constant DeviceString u_curve_random
ccl_device_constant DeviceString u_geom_trianglevertices
color xyY_to_xyz(float x, float y, float Y)
Definition node_color.h:52
color xyz_to_rgb(float x, float y, float z)
Definition node_color.h:73
float distance(float a, float b)
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
ccl_device_extern OSLNoiseOptions * osl_get_noise_options(ccl_private ShaderGlobals *sg)
ccl_device_extern bool osl_transformc(ccl_private ShaderGlobals *sg, ccl_private float3 *c_in, int c_in_derivs, ccl_private float3 *c_out, int c_out_derivs, DeviceString from, DeviceString to)
ccl_device_extern void osl_sincos_dvdvv(ccl_private const float3 *a, ccl_private float3 *b, ccl_private float3 *c)
ccl_device_extern void osl_sincos_dfdfdf(ccl_private const float *a, ccl_private float *b, ccl_private float *c)
#define OSL_OP_IMPL_DVDVDV(name, op)
ccl_device_extern void osl_noiseparams_set_bandwidth(ccl_private OSLNoiseOptions *opt, float bandwidth)
ccl_device_forceinline void copy_matrix(ccl_private float *res, const Transform &tfm)
ccl_device_inline bool get_object_attribute(KernelGlobals kg, ccl_private ShaderData *sd, const AttributeDescriptor &desc, TypeDesc type, bool derivatives, ccl_private void *val)
#define OSL_OP_IMPL_FF(name, op)
#define OSL_OP_IMPL_DFDFFDF(name, op)
ccl_device_extern uint osl_range_check_err(int indexvalue, int length, DeviceString symname, ccl_private ShaderGlobals *sg, DeviceString sourcefile, int sourceline, DeviceString groupname, int layer, DeviceString layername, DeviceString shadername)
ccl_device_extern void osl_noiseparams_set_direction(ccl_private OSLNoiseOptions *opt, float3 *direction)
ccl_device_extern uint osl_hash_iv(ccl_private const float3 *v)
ccl_device_forceinline float hashnoise_3d(float3 p)
#define OSL_OP_IMPL_III(name, op)
#define OSL_OP_IMPL_DFFFDF(name, op)
ccl_device_extern bool osl_transform_triple_nonlinear(ccl_private ShaderGlobals *sg, ccl_private float3 *p_in, int p_in_derivs, ccl_private float3 *p_out, int p_out_derivs, DeviceString from, DeviceString to, int vectype)
ccl_device_extern uint osl_hash_ii(int x)
ccl_device_extern void osl_texture_set_stwidth(ccl_private OSLTextureOptions *opt, float width)
ccl_device_extern void osl_texture_set_twrap_code(ccl_private OSLTextureOptions *opt, int mode)
ccl_device_extern void osl_blackbody_vf(ccl_private ShaderGlobals *sg, ccl_private float3 *result, float temperature)
ccl_device_extern void osl_prepend_color_from(ccl_private ShaderGlobals *sg, ccl_private float3 *res, DeviceString from)
#define OSL_OP_IMPL_VV_(name, op)
ccl_device_extern void osl_texture_set_tblur(ccl_private OSLTextureOptions *opt, float blur)
#define OSL_OP_IMPL_VV(name, op)
ccl_device_extern void osl_texture_set_stwrap_code(ccl_private OSLTextureOptions *opt, int mode)
ccl_device_extern void osl_mul_mmf(ccl_private float *res, ccl_private const float *a, float b)
ccl_device_extern void osl_texture_set_stblur(ccl_private OSLTextureOptions *opt, float blur)
ccl_device_extern ccl_private OSLClosure * osl_add_closure_closure(ccl_private ShaderGlobals *sg, ccl_private OSLClosure *a, ccl_private OSLClosure *b)
ccl_device_extern void osl_sincos_dffdf(ccl_private const float *a, ccl_private float *b, ccl_private float *c)
#define OSL_OP_IMPL_DFDFDFDF(name, op)
#define OSL_OP_IMPL_XX(name, op)
ccl_device_extern uint osl_hash_iff(float x, float y)
ccl_device_extern ccl_private OSLClosure * osl_allocate_weighted_closure_component(ccl_private ShaderGlobals *sg, int id, int size, ccl_private const float3 *weight)
ccl_device_extern void osl_sincos_vvv(ccl_private const float3 *a, ccl_private float3 *b, ccl_private float3 *c)
ccl_device_extern bool osl_get_textureinfo_st(ccl_private ShaderGlobals *sg, DeviceString filename, ccl_private void *texture_handle, float s, float t, DeviceString dataname, int basetype, int arraylen, int aggegrate, ccl_private void *data, ccl_private void *errormessage)
ccl_device_extern void osl_transpose_mm(ccl_private float *res, ccl_private const float *m)
ccl_device_extern void osl_printf(ccl_private ShaderGlobals *sg, const char *format, void *args)
#define OSL_OP_IMPL_VVV(name, op)
#define OSL_OP_IMPL_FV(name, op)
ccl_device_extern void osl_texture_set_sblur(ccl_private OSLTextureOptions *opt, float blur)
ccl_device_extern void osl_texture_set_time(ccl_private OSLTextureOptions *opt, float time)
ccl_device_forceinline float step_impl(float edge, float x)
ccl_device_extern void osl_sincos_dvvdv(ccl_private const float3 *a, ccl_private float3 *b, ccl_private float3 *c)
#define OSL_OP_IMPL_DFDFFF(name, op)
ccl_device_extern float osl_filterwidth_fdf(ccl_private const float *x)
long long TypeDesc
ccl_device_extern bool osl_texture3d(ccl_private ShaderGlobals *sg, DeviceString filename, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, ccl_private const float3 *P, ccl_private const float3 *dPdx, ccl_private const float3 *dPdy, ccl_private const float3 *dPdz, int nchannels, ccl_private float *result, ccl_private float *dresultds, ccl_private float *dresultdt, ccl_private float *alpha, ccl_private float *dalphadx, ccl_private float *dalphady, ccl_private void *errormessage)
#define OSL_OP_IMPL_FFF(name, op)
ccl_device_extern bool osl_transform_triple(ccl_private ShaderGlobals *sg, ccl_private float3 *p_in, int p_in_derivs, ccl_private float3 *p_out, int p_out_derivs, DeviceString from, DeviceString to, int vectype)
ccl_device_inline bool set_attribute_matrix(ccl_private const Transform &tfm, TypeDesc type, ccl_private void *val)
ccl_device_extern bool osl_get_from_to_matrix(ccl_private ShaderGlobals *sg, ccl_private float *res, DeviceString from, DeviceString to)
ccl_device_forceinline Transform convert_transform(ccl_private const float *m)
ccl_device_extern void osl_noiseparams_set_anisotropic(ccl_private OSLNoiseOptions *opt, int anisotropic)
#define OSL_OP_IMPL_FFFF(name, op)
ccl_device_extern ccl_private OSLClosure * osl_allocate_closure_component(ccl_private ShaderGlobals *sg, int id, int size)
ccl_device_extern bool osl_texture(ccl_private ShaderGlobals *sg, DeviceString filename, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int nchannels, ccl_private float *result, ccl_private float *dresultdx, ccl_private float *dresultdy, ccl_private float *alpha, ccl_private float *dalphadx, ccl_private float *dalphady, ccl_private void *errormessage)
#define OSL_OP_IMPL_VVF_(name, op)
ccl_device_extern bool osl_raytype_bit(ccl_private ShaderGlobals *sg, int bit)
#define OSL_NOISE_IMPL(name, op)
ccl_device_extern void osl_texture_set_rwidth(ccl_private OSLTextureOptions *opt, float width)
ccl_device_extern void osl_luminance_dfdv(ccl_private ShaderGlobals *sg, ccl_private float *result, ccl_private float3 *color)
ccl_device_extern bool osl_get_inverse_matrix(ccl_private ShaderGlobals *sg, ccl_private float *res, DeviceString to)
ccl_device_extern ccl_private OSLClosure * osl_mul_closure_float(ccl_private ShaderGlobals *sg, ccl_private OSLClosure *a, float weight)
ccl_device_extern void osl_texture_set_rblur(ccl_private OSLTextureOptions *opt, float blur)
ccl_device_inline bool set_attribute_float2(ccl_private float2 fval[3], TypeDesc type, bool derivatives, ccl_private void *val)
#define OSL_OP_IMPL_DFDVV(name, op)
ccl_device_extern uint osl_hash_if(float x)
#define OSL_OP_IMPL_XXX(name, op)
ccl_device_extern uint osl_range_check(int indexvalue, int length, DeviceString symname, ccl_private ShaderGlobals *sg, DeviceString sourcefile, int sourceline, DeviceString groupname, int layer, DeviceString layername, DeviceString shadername)
#define OSL_OP_IMPL_FVV(name, op)
#define OSL_OP_IMPL_DFDVDV(name, op)
ccl_device_extern bool osl_get_textureinfo(ccl_private ShaderGlobals *sg, DeviceString filename, ccl_private void *texture_handle, DeviceString dataname, int basetype, int arraylen, int aggegrate, ccl_private void *data, ccl_private void *errormessage)
ccl_device_extern void osl_div_mfm(ccl_private float *res, float a, ccl_private const float *b)
ccl_device_extern ccl_private OSLTextureOptions * osl_get_texture_options(ccl_private ShaderGlobals *sg)
ccl_device_inline bool get_background_attribute(KernelGlobals kg, ccl_private ShaderData *sd, DeviceString name, TypeDesc type, bool derivatives, ccl_private void *val)
#define OSL_OP_IMPL_DFFDFF(name, op)
ccl_device_forceinline int safe_modulo(int a, int b)
#define OSL_OP_IMPL_VVV_(name, op)
ccl_device_extern void osl_texture_set_missingcolor_arena(ccl_private OSLTextureOptions *opt, ccl_private float3 *color)
ccl_device_extern void osl_texture_set_firstchannel(ccl_private OSLTextureOptions *opt, int firstchannel)
ccl_device_inline bool set_attribute_float(ccl_private float fval[3], TypeDesc type, bool derivatives, ccl_private void *val)
#define OSL_OP_IMPL_DVDVV(name, op)
ccl_device_inline bool get_object_standard_attribute(KernelGlobals kg, ccl_private ShaderData *sd, DeviceString name, TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_extern bool osl_prepend_matrix_from(ccl_private ShaderGlobals *sg, ccl_private float *res, DeviceString from)
#define OSL_OP_IMPL_DFFDFDF(name, op)
ccl_device_extern void osl_calculatenormal(ccl_private float3 *res, ccl_private ShaderGlobals *sg, ccl_private const float3 *p)
ccl_device_extern void osl_sincos_dfdff(ccl_private const float *a, ccl_private float *b, ccl_private float *c)
ccl_device_extern void osl_texture_set_fill(ccl_private OSLTextureOptions *opt, float fill)
ccl_device_extern void osl_wavelength_color_vf(ccl_private ShaderGlobals *sg, ccl_private float3 *result, float lambda_nm)
#define OSL_OP_IMPL_DFVDV(name, op)
ccl_device_extern void osl_warning(ccl_private ShaderGlobals *sg, const char *format, void *args)
ccl_device_extern void osl_noiseparams_set_do_filter(ccl_private OSLNoiseOptions *opt, int do_filter)
ccl_device_extern void osl_texture_set_missingcolor_alpha(ccl_private OSLTextureOptions *opt, int nchannels, float alpha)
ccl_device_extern void osl_transform_vmv(ccl_private float3 *res, ccl_private const float *m, ccl_private const float3 *v)
ccl_device_extern void osl_texture_set_twidth(ccl_private OSLTextureOptions *opt, float width)
ccl_device_forceinline float hashnoise_1d(float p)
ccl_device_extern void osl_noiseparams_set_impulses(ccl_private OSLNoiseOptions *opt, float impulses)
#define OSL_OP_IMPL_IF(name, op)
ccl_device_extern void osl_texture_set_rwrap_code(ccl_private OSLTextureOptions *opt, int mode)
ccl_device_extern void osl_sincos_dvdvdv(ccl_private const float3 *a, ccl_private float3 *b, ccl_private float3 *c)
#define OSL_OP_IMPL_DVDVDF_(name, op)
#define OSL_OP_IMPL_DVVDF_(name, op)
ccl_device_extern void osl_div_mmm(ccl_private float *res, ccl_private const float *a, ccl_private const float *b)
#define OSL_OP_IMPL_DVDV(name, op)
ccl_device_extern void osl_transformv_vmv(ccl_private float3 *res, ccl_private const float *m, ccl_private const float3 *v)
ccl_device_extern void osl_filterwidth_vdv(ccl_private float *res, ccl_private const float *x)
ccl_device_extern float osl_area(ccl_private const float3 *p)
ccl_device_inline bool set_attribute_float3(ccl_private float3 fval[3], TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_extern void osl_texture_set_swidth(ccl_private OSLTextureOptions *opt, float width)
ccl_device_extern void osl_texture_set_interp_code(ccl_private OSLTextureOptions *opt, int mode)
#define OSL_OP_IMPL_DFDFDFF(name, op)
ccl_device_extern void osl_transformn_vmv(ccl_private float3 *res, ccl_private const float *m, ccl_private const float3 *v)
#define OSL_OP_IMPL_II(name, op)
ccl_device_extern void osl_div_m_ff(ccl_private float *res, float a, float b)
#define OSL_OP_IMPL_DVDVF_(name, op)
ccl_device_extern void osl_mul_mmm(ccl_private float *res, ccl_private const float *a, ccl_private const float *b)
ccl_device_extern void osl_luminance_fv(ccl_private ShaderGlobals *sg, ccl_private float *result, ccl_private float3 *color)
ccl_device_inline bool set_attribute_float4(ccl_private float4 fval[3], TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_extern void osl_transformn_dvmdv(ccl_private float3 *res, ccl_private const float *m, ccl_private const float3 *v)
ccl_device_extern void osl_texture_set_swrap_code(ccl_private OSLTextureOptions *opt, int mode)
ccl_device_forceinline float hashnoise_4d(float4 p)
ccl_device_extern ccl_private OSLClosure * osl_mul_closure_color(ccl_private ShaderGlobals *sg, ccl_private OSLClosure *a, ccl_private const float3 *weight)
ccl_device_extern void osl_div_mmf(ccl_private float *res, ccl_private const float *a, float b)
ccl_device_extern void osl_texture_set_subimage(ccl_private OSLTextureOptions *opt, int subimage)
#define OSL_OP_IMPL_DVVDV(name, op)
ccl_device_extern uint osl_hash_ivf(ccl_private const float3 *v, float w)
ccl_device_forceinline float hashnoise_2d(float2 p)
ccl_device_extern bool osl_get_attribute(ccl_private ShaderGlobals *sg, int derivatives, DeviceString object_name, DeviceString name, int array_lookup, int index, TypeDesc type, ccl_private void *res)
ccl_device_forceinline void copy_identity_matrix(ccl_private float *res, float value=1.0f)
ccl_device_extern void osl_sincos_fff(float a, ccl_private float *b, ccl_private float *c)
ccl_device_extern void osl_transform_dvmdv(ccl_private float3 *res, ccl_private const float *m, ccl_private const float3 *v)
ccl_device_extern bool osl_environment(ccl_private ShaderGlobals *sg, DeviceString filename, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, ccl_private const float3 *R, ccl_private const float3 *dRdx, ccl_private const float3 *dRdy, int nchannels, ccl_private float *result, ccl_private float *dresultds, ccl_private float *dresultdt, ccl_private float *alpha, ccl_private float *dalphax, ccl_private float *dalphay, ccl_private void *errormessage)
#define OSL_OP_IMPL_DFDV(name, op)
ccl_device_extern bool osl_get_matrix(ccl_private ShaderGlobals *sg, ccl_private float *res, DeviceString from)
ccl_device_extern void osl_error(ccl_private ShaderGlobals *sg, const char *format, void *args)
ccl_device_extern void osl_transformv_dvmdv(ccl_private float3 *res, ccl_private const float *m, ccl_private const float3 *v)
unsigned char uint8_t
Definition stdint.h:78
static bool find_attribute(const std::string &attributes, const char *search_attribute)
NodeAttributeType type
float4 y
Definition transform.h:24
float4 x
Definition transform.h:24
float4 z
Definition transform.h:24
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 Transform make_transform(float a, float b, float c, float d, float e, float f, float g, float h, float i, float j, float k, float l)
Definition transform.h:133
ccl_device_inline Transform transform_inverse(const Transform tfm)
Definition transform.h:423
ccl_device_inline float3 transform_direction(ccl_private const Transform *t, const float3 a)
Definition transform.h:94
CCL_NAMESPACE_END CCL_NAMESPACE_BEGIN ccl_device_inline float3 transform_point(ccl_private const Transform *t, const float3 a)
Definition transform.h:63
float max
ccl_device float3 color_srgb_to_linear_v3(float3 c)
Definition util/color.h:309
ccl_device float3 color_linear_to_srgb_v3(float3 c)
Definition util/color.h:315
ccl_device_inline int abs(int x)
Definition util/math.h:120
ccl_device_inline float3 float4_to_float3(const float4 a)
Definition util/math.h:535
@ INTERPOLATION_NONE