Blender V5.3
services_shared.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2026 Blender Foundation
2 * SPDX-FileCopyrightText: Contributors to the OpenImageIO project
3 *
4 * SPDX-License-Identifier: Apache-2.0 */
5
6/* Shared functions between OSL on CPU and GPU. */
7
8#pragma once
9
11
13#include "kernel/geom/curve.h"
14#include "kernel/geom/gsplat.h"
16#include "kernel/geom/object.h"
17#include "kernel/geom/point.h"
20
21#include "kernel/image.h"
22#include "kernel/osl/strings.h"
24#include "kernel/util/ies.h"
27
28#include "util/hash.h"
29
30#ifndef __KERNEL_GPU__
31# include "kernel/svm/ao.h"
32# include "kernel/svm/bevel.h"
33#endif
34
36
37/* For GPU duplicate part of OpenImageIO TypeDesc as we don't use the headers at compile time. */
38#ifdef __KERNEL_GPU__
39struct TypeDesc {
40 enum BASETYPE {
41 UNKNOWN = 0,
42 NONE = 1,
43 UCHAR = 2,
44 CHAR = 3,
45 USHORT = 4,
46 SHORT = 5,
47 UINT = 6,
48 INT = 7,
49 ULONGLONG = 8,
50 LONGLONG = 9,
51 HALF = 10,
52 FLOAT = 11,
53 DOUBLE = 12,
54 STRING = 13,
55 PTR = 14,
56 LAST = 15,
57 };
58
59 enum AGGREGATE {
60 SCALAR = 1,
61 VEC2 = 2,
62 VEC3 = 3,
63 VEC4 = 4,
64 MATRIX33 = 15,
65 MATRIX44 = 16,
66 };
67
68 enum VECSEMANTICS {
69 NOSEMANTICS = 0,
70 COLOR = 1,
71 POINT = 2,
72 VECTOR = 3,
73 NORMAL = 4,
74 TIMECODE = 5,
75 };
76
77 unsigned char basetype;
78 unsigned char aggregate;
79 unsigned char vecsemantics;
80 unsigned char reserved;
81 int arraylen;
82
83 ccl_device_inline_method constexpr TypeDesc(BASETYPE b = UNKNOWN,
84 AGGREGATE a = SCALAR,
85 VECSEMANTICS v = NOSEMANTICS,
86 int l = 0)
87 : basetype(b), aggregate(a), vecsemantics(v), reserved(0), arraylen(l)
88 {
89 }
90
91 ccl_device_inline_method bool operator==(const ccl_private TypeDesc &other) const
92 {
93 return basetype == other.basetype && aggregate == other.aggregate &&
94 vecsemantics == other.vecsemantics && arraylen == other.arraylen;
95 }
96
97 ccl_device_inline_method bool operator!=(const ccl_private TypeDesc &other) const
98 {
99 return !(*this == other);
100 }
101};
102
103ccl_device_constant TypeDesc TypeFloat(TypeDesc::FLOAT, TypeDesc::SCALAR);
104ccl_device_constant TypeDesc TypeInt(TypeDesc::INT, TypeDesc::SCALAR);
105ccl_device_constant TypeDesc TypeString(TypeDesc::STRING, TypeDesc::SCALAR);
106ccl_device_constant TypeDesc TypeMatrix(TypeDesc::FLOAT, TypeDesc::MATRIX44);
107#endif
108
109/* Type Checking, recognizing both arrays and vectors. */
110
111ccl_device_inline bool is_type_float2(const TypeDesc t)
112{
113 return (t.basetype == TypeDesc::FLOAT && t.aggregate == TypeDesc::VEC2 && t.arraylen == 0) ||
114 t == TypeDesc(TypeDesc::FLOAT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 2);
115}
116
117ccl_device_inline bool is_type_float3(const TypeDesc t)
118{
119 return (t.basetype == TypeDesc::FLOAT && t.aggregate == TypeDesc::VEC3 && t.arraylen == 0) ||
120 t == TypeDesc(TypeDesc::FLOAT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 3);
121}
122
123ccl_device_inline bool is_type_float4(const TypeDesc t)
124{
125 return (t.basetype == TypeDesc::FLOAT && t.aggregate == TypeDesc::VEC4 && t.arraylen == 0) ||
126 t == TypeDesc(TypeDesc::FLOAT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 4);
127}
128
129ccl_device_inline bool is_type_int2(const TypeDesc t)
130{
131 return (t.basetype == TypeDesc::INT && t.aggregate == TypeDesc::VEC2 && t.arraylen == 0) ||
132 t == TypeDesc(TypeDesc::INT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 2);
133}
134
135ccl_device_inline bool is_type_int3(const TypeDesc t)
136{
137 return (t.basetype == TypeDesc::INT && t.aggregate == TypeDesc::VEC3 && t.arraylen == 0) ||
138 t == TypeDesc(TypeDesc::INT, TypeDesc::SCALAR, TypeDesc::NOSEMANTICS, 3);
139}
140
141/* Attribute Utilities */
142
143template<typename T>
145 const TypeDesc type,
146 bool derivatives,
147 ccl_private void *val);
148
149ccl_device_inline void set_data_float(const dual1 data, bool derivatives, ccl_private void *val)
150{
151 ccl_private float *fval = static_cast<ccl_private float *>(val);
152 fval[0] = data.val;
153 if (derivatives) {
154 fval[1] = data.dx;
155 fval[2] = data.dy;
156 }
157}
158
159ccl_device_inline void set_data_float3(const dual3 data, bool derivatives, ccl_private void *val)
160{
161 ccl_private float *fval = static_cast<ccl_private float *>(val);
162 copy_v3_v3(fval, data.val);
163 if (derivatives) {
164 copy_v3_v3(fval + 3, data.dx);
165 copy_v3_v3(fval + 6, data.dy);
166 }
167}
168
169ccl_device_inline void set_data_float4(const dual4 data, bool derivatives, ccl_private void *val)
170{
171 ccl_private float *fval = static_cast<ccl_private float *>(val);
172 copy_v4_v4(fval, data.val);
173 if (derivatives) {
174 copy_v4_v4(fval + 4, data.dx);
175 copy_v4_v4(fval + 8, data.dy);
176 }
177}
178
180 bool derivatives,
181 ccl_private void *val)
182{
183 ccl_private float *fval = static_cast<ccl_private float *>(val);
184 copy_v4_qt(fval, data.val);
185 if (derivatives) {
186 copy_v4_qt(fval + 4, data.dx);
187 copy_v4_qt(fval + 8, data.dy);
188 }
189}
190
191/* Matrix Utilities */
192
194{
195 res[0] = tfm.x.x;
196 res[1] = tfm.y.x;
197 res[2] = tfm.z.x;
198 res[3] = 0.0f;
199 res[4] = tfm.x.y;
200 res[5] = tfm.y.y;
201 res[6] = tfm.z.y;
202 res[7] = 0.0f;
203 res[8] = tfm.x.z;
204 res[9] = tfm.y.z;
205 res[10] = tfm.z.z;
206 res[11] = 0.0f;
207 res[12] = tfm.x.w;
208 res[13] = tfm.y.w;
209 res[14] = tfm.z.w;
210 res[15] = 1.0f;
211}
212
214{
215 res[0] = tfm.x.x;
216 res[1] = tfm.y.x;
217 res[2] = tfm.z.x;
218 res[3] = tfm.w.x;
219 res[4] = tfm.x.y;
220 res[5] = tfm.y.y;
221 res[6] = tfm.z.y;
222 res[7] = tfm.w.y;
223 res[8] = tfm.x.z;
224 res[9] = tfm.y.z;
225 res[10] = tfm.z.z;
226 res[11] = tfm.w.z;
227 res[12] = tfm.x.w;
228 res[13] = tfm.y.w;
229 res[14] = tfm.z.w;
230 res[15] = tfm.w.w;
231}
232
233/* Matrix */
234
236 ccl_private const ShaderData *sd,
237 ccl_private float *res)
238{
239 const int object = sd->object;
240 if (object != OBJECT_NONE) {
241 const Transform tfm = object_get_transform(kg, sd);
242 copy_matrix(res, tfm);
243 return true;
244 }
245 return false;
246}
247
249 ccl_private const ShaderData *sd,
250 ccl_private float *res,
251 float time)
252{
253 const int object = sd->object;
254 if (object != OBJECT_NONE) {
255#ifdef __OBJECT_MOTION__
256 Transform tfm;
257 if (time == sd->time) {
258 tfm = object_get_transform(kg, sd);
259 }
260 else {
261 tfm = object_fetch_transform_motion_test(kg, object, time, nullptr);
262 }
263#else
264 const Transform tfm = object_get_transform(kg, sd);
265#endif
266 copy_matrix(res, tfm);
267 return true;
268 }
269 return false;
270}
271
273 ccl_private const ShaderData *sd,
274 ccl_private float *res)
275{
276 const int object = sd->object;
277 if (object != OBJECT_NONE) {
278 const Transform tfm = object_get_inverse_transform(kg, sd);
279 copy_matrix(res, tfm);
280 return true;
281 }
282 return false;
283}
284
286 KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res, float time)
287{
288 const int object = sd->object;
289 if (object != OBJECT_NONE) {
290#ifdef __OBJECT_MOTION__
291 Transform itfm;
292 if (time == sd->time) {
293 itfm = object_get_inverse_transform(kg, sd);
294 }
295 else {
296 object_fetch_transform_motion_test(kg, object, time, &itfm);
297 }
298#else
299 const Transform itfm = object_get_inverse_transform(kg, sd);
300#endif
301 copy_matrix(res, itfm);
302 return true;
303 }
304 return false;
305}
306
308 DeviceString from,
309 ccl_private float *res)
310{
311 if (from == DeviceStrings::u_ndc) {
312 copy_matrix(res, kernel_data.cam.ndctoworld);
313 return true;
314 }
315 if (from == DeviceStrings::u_raster) {
316 copy_matrix(res, kernel_data.cam.rastertoworld);
317 return true;
318 }
319 if (from == DeviceStrings::u_screen) {
320 copy_matrix(res, kernel_data.cam.screentoworld);
321 return true;
322 }
323 if (from == DeviceStrings::u_camera) {
324 copy_matrix(res, kernel_data.cam.cameratoworld);
325 return true;
326 }
327 if (from == DeviceStrings::u_world) {
329 return true;
330 }
331 return false;
332}
333
335 DeviceString to,
336 ccl_private float *res)
337{
338 if (to == DeviceStrings::u_ndc) {
339 copy_matrix(res, kernel_data.cam.worldtondc);
340 return true;
341 }
342 if (to == DeviceStrings::u_raster) {
343 copy_matrix(res, kernel_data.cam.worldtoraster);
344 return true;
345 }
346 if (to == DeviceStrings::u_screen) {
347 copy_matrix(res, kernel_data.cam.worldtoscreen);
348 return true;
349 }
350 if (to == DeviceStrings::u_camera) {
351 copy_matrix(res, kernel_data.cam.worldtocamera);
352 return true;
353 }
354 if (to == DeviceStrings::u_world) {
356 return true;
357 }
358 return false;
359}
360
361/* Attribute Setting */
362
364 const TypeDesc type,
365 bool derivatives,
366 ccl_private void *val)
367{
368 if (is_type_float4(type)) {
369 set_data_float4(make_float4(make_float3(v)), derivatives, val);
370 return true;
371 }
372 if (is_type_float3(type)) {
373 set_data_float3(make_float3(v), derivatives, val);
374 return true;
375 }
376 if (type == TypeFloat) {
377 set_data_float(v, derivatives, val);
378 return true;
379 }
380
381 return false;
382}
383
385 const TypeDesc type,
386 bool derivatives,
387 ccl_private void *val)
388{
389 if (is_type_float4(type)) {
390 set_data_float4(make_float4(make_float3(v)), derivatives, val);
391 return true;
392 }
393 if (is_type_float3(type)) {
394 set_data_float3(make_float3(v), derivatives, val);
395 return true;
396 }
397 if (type == TypeFloat) {
398 set_data_float(average(v), derivatives, val);
399 return true;
400 }
401
402 return false;
403}
404
406 const TypeDesc type,
407 bool derivatives,
408 ccl_private void *val)
409{
410 if (is_type_float4(type)) {
411 set_data_float4(make_float4(v), derivatives, val);
412 return true;
413 }
414 if (is_type_float3(type)) {
415 set_data_float3(v, derivatives, val);
416 return true;
417 }
418 if (type == TypeFloat) {
419 set_data_float(average(v), derivatives, val);
420 return true;
421 }
422
423 return false;
424}
425
427 const TypeDesc type,
428 bool derivatives,
429 ccl_private void *val)
430{
431 if (is_type_float4(type)) {
432 set_data_float4(v, derivatives, val);
433 return true;
434 }
435 if (is_type_float3(type)) {
436 set_data_float3(make_float3(v), derivatives, val);
437 return true;
438 }
439 if (type == TypeFloat) {
440 set_data_float(average(make_float3(v)), derivatives, val);
441 return true;
442 }
443 return false;
444}
445
447 const TypeDesc type,
448 bool derivatives,
449 ccl_private void *val)
450{
451 if (is_type_float4(type)) {
452 set_data_quaternion(v, derivatives, val);
453 return true;
454 }
455 if (is_type_float3(type)) {
456 set_data_float3(make_float3(v), derivatives, val);
457 return true;
458 }
459 if (type == TypeFloat) {
460 set_data_float(average(make_float3(v)), derivatives, val);
461 return true;
462 }
463 return false;
464}
465
466template<typename T>
468 const TypeDesc type,
469 bool derivatives,
470 ccl_private void *val)
471{
472 return set_attribute(dual<T>(f), type, derivatives, val);
473}
474
476 const TypeDesc type,
477 bool derivatives,
478 ccl_private void *val)
479{
480 if (type == TypeInt) {
481 ccl_private int *ival = static_cast<ccl_private int *>(val);
482 ival[0] = i;
483
484 if (derivatives) {
485 ival[1] = 0;
486 ival[2] = 0;
487 }
488
489 return true;
490 }
491
492 return false;
493}
494
495#ifndef __KERNEL_GPU__
497 const TypeDesc type,
498 bool derivatives,
499 ccl_private void *val)
500{
501 if (type == TypeString) {
502 OSLUStringHash *sval = static_cast<OSLUStringHash *>(val);
503 sval[0] = str;
504
505 if (derivatives) {
506 sval[1] = OSLUStringHash();
507 sval[2] = OSLUStringHash();
508 }
509
510 return true;
511 }
512
513 return false;
514}
515#endif
516
518 const TypeDesc type,
519 ccl_private void *val)
520{
521 if (type == TypeMatrix) {
522 copy_matrix(static_cast<ccl_private float *>(val), tfm);
523 return true;
524 }
525
526 return false;
527}
528
530 TypeDesc type,
531 bool derivatives,
532 ccl_private void *val)
533{
534 if (type.vecsemantics == TypeDesc::POINT && type.arraylen >= 3) {
535 ccl_private float *fval = static_cast<ccl_private float *>(val);
536
537 copy_v3_v3(fval, P[0]);
538 copy_v3_v3(fval + 3, P[1]);
539 copy_v3_v3(fval + 6, P[2]);
540
541 if (type.arraylen > 3) {
542 for (int i = 3 * 3; i < type.arraylen * 3; i++) {
543 fval[i] = 0.0f;
544 }
545 }
546 if (derivatives) {
547 for (int i = type.arraylen * 3; i < type.arraylen * 3 * 3; i++) {
548 fval[i] = 0.0f;
549 }
550 }
551
552 return true;
553 }
554
555 return false;
556}
557
559 ccl_private const ShaderData *sd,
561{
562 if (!(sd->type & PRIMITIVE_TRIANGLE) || !(sd->shader & SHADER_SMOOTH_NORMAL)) {
563 /* TODO: implement for curve. */
564 return false;
565 }
566
567 const bool backfacing = (sd->runtime_flag & SR_BACKFACING);
568
569 /* Fallback when the smooth normal is zero. */
570 float3 Ng = backfacing ? -sd->Ng : sd->Ng;
572
573 if (sd->type == PRIMITIVE_TRIANGLE) {
575 kg, Ng, sd->object, sd->object_flag, sd->prim, sd->u, sd->v, sd->du, sd->dv, f.dx, f.dy);
576 }
577 else {
580 kg, Ng, sd->object, sd->prim, sd->time, sd->u, sd->v, sd->du, sd->dv, f.dx, f.dy);
581 }
582
583 if (sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED) {
584 /* Transform to local space. */
585 object_inverse_normal_transform(kg, sd, &f.val);
586 object_inverse_normal_transform(kg, sd, &f.dx);
587 object_inverse_normal_transform(kg, sd, &f.dy);
588 }
589
590 if (backfacing) {
591 f = -f;
592 }
593
594 f.dx -= f.val;
595 f.dy -= f.val;
596
597 return true;
598}
599
600/* Textures */
601
603 const int nchannels,
604 ccl_private float *result)
605{
606 if (nchannels > 0) {
607 result[0] = rgba.x;
608 }
609 if (nchannels > 1) {
610 result[1] = rgba.y;
611 }
612 if (nchannels > 2) {
613 result[2] = rgba.z;
614 }
615 if (nchannels > 3) {
616 result[3] = rgba.w;
617 }
618}
619
620ccl_device_forceinline float4 get_missingcolor(const float *missingcolor, const int nchannels)
621{
622 if (!missingcolor) {
623 return IMAGE_MISSING_RGBA;
624 }
625 float4 result = zero_float4();
626 if (nchannels > 0) {
627 result.x = missingcolor[0];
628 }
629 if (nchannels > 1) {
630 result.y = missingcolor[1];
631 }
632 if (nchannels > 2) {
633 result.z = missingcolor[2];
634 }
635 if (nchannels > 3) {
636 result.w = missingcolor[3];
637 }
638 return result;
639}
640
642 const int nchannels,
643 ccl_private float *result)
644{
645 if (nchannels > 0) {
646 result[0] = missingcolor[0];
647 }
648 if (nchannels > 1) {
649 result[1] = missingcolor[1];
650 }
651 if (nchannels > 2) {
652 result[2] = missingcolor[2];
653 }
654 if (nchannels > 3) {
655 result[3] = missingcolor[3];
656 }
657}
658
660 ccl_private void *texture_handle,
661 const float2 uv,
662 const bool use_uv,
663 DeviceString dataname,
664 const TypeDesc datatype,
665 void *data)
666{
667 const OSLTextureHandleType texture_type = OSL_TEXTURE_HANDLE_TYPE(texture_handle);
668 const int image_texture_or_udim_id = OSL_TEXTURE_HANDLE_ID(texture_handle);
669
670 if (texture_type != OSLTextureHandleType::IMAGE) {
671 return false;
672 }
673
674 int image_texture_id = image_texture_or_udim_id;
675 if (use_uv) {
676 float2 local_uv = uv;
677 image_texture_id = kernel_image_udim_map(kg, image_texture_or_udim_id, local_uv);
678 }
679 if (image_texture_id == KERNEL_IMAGE_NONE) {
680 return false;
681 }
682
683 const ccl_global KernelImageTexture &tex = kernel_data_fetch(image_textures, image_texture_id);
684 if (tex.image_info_id == KERNEL_IMAGE_NONE) {
685 return false;
686 }
687
688 if (dataname == DeviceStrings::u_resolution) {
689 if (is_type_int2(datatype)) {
690 int *res = static_cast<int *>(data);
691 res[0] = int(tex.width);
692 res[1] = int(tex.height);
693 return true;
694 }
695 if (is_type_float2(datatype)) {
696 float *res = static_cast<float *>(data);
697 res[0] = float(tex.width);
698 res[1] = float(tex.height);
699 return true;
700 }
701 if (is_type_int3(datatype)) {
702 int *res = static_cast<int *>(data);
703 res[0] = int(tex.width);
704 res[1] = int(tex.height);
705 res[2] = 1;
706 return true;
707 }
708 if (is_type_float3(datatype)) {
709 float *res = static_cast<float *>(data);
710 res[0] = float(tex.width);
711 res[1] = float(tex.height);
712 res[2] = 1.0f;
713 return true;
714 }
715 }
716 else if (dataname == DeviceStrings::u_channels) {
717 if (datatype == TypeInt) {
718 const int image_info_id = tex.image_info_id;
719 const ccl_global KernelImageInfo &info = kernel_data_fetch(image_info, image_info_id);
720 int channels = 4;
721 switch (info.data_type) {
727 channels = 4;
728 break;
730 channels = 3;
731 break;
739 channels = 1;
740 break;
742 channels = 0;
743 break;
744 }
745 *static_cast<int *>(data) = channels;
746 return true;
747 }
748 }
749 else if (dataname == DeviceStrings::u_exists) {
750 if (datatype == TypeInt) {
751 *static_cast<int *>(data) = 1;
752 return true;
753 }
754 }
755 else if (dataname == DeviceStrings::u_averagecolor) {
756 if (is_type_float3(datatype) || is_type_float4(datatype)) {
757 float *res = (float *)data;
758 res[0] = tex.average_color.x;
759 res[1] = tex.average_color.y;
760 res[2] = tex.average_color.z;
761 if (is_type_float4(datatype)) {
762 res[3] = tex.average_color.w;
763 }
764 return true;
765 }
766 }
767
768 return false;
769}
770
773 ccl_private void *texture_handle,
775 float s,
776 float t,
777 float dsdx,
778 float dtdx,
779 float dsdy,
780 float dtdy,
781 int nchannels,
782 float *result)
783{
784 const OSLTextureHandleType type = OSL_TEXTURE_HANDLE_TYPE(texture_handle);
785 const int image_texture_or_udim_id = OSL_TEXTURE_HANDLE_ID(texture_handle);
786
787 ccl_private ShaderData *sd = sg->sd;
788 bool status = false;
789
790 switch (type) {
792 const dual2 uv({s, t}, {dsdx, dtdx}, {dsdy, dtdy});
794 kg, sd, image_texture_or_udim_id, uv, get_missingcolor(opt->missingcolor, nchannels));
795
796 rgba_to_nchannels(rgba, nchannels, result);
797
798 status = true;
799 break;
800 }
802 if (nchannels > 0) {
803 result[0] = kernel_ies_interp(kg, image_texture_or_udim_id, s, t);
804 }
805 status = true;
806 break;
807 }
809#if !defined(__KERNEL_GPU__) && defined(__SHADER_RAYTRACE__)
810 /* Bevel shader hack. */
811 ConstIntegratorState state = sg->path_state;
812 if (nchannels >= 3 && state != nullptr) {
813 const int num_samples = int(s);
814 const float radius = t;
815 const float3 N = svm_bevel(kg, state, sd, radius, num_samples);
816 result[0] = N.x;
817 result[1] = N.y;
818 result[2] = N.z;
819 status = true;
820 }
821#else
822 if (nchannels >= 3) {
823 result[0] = sd->N.x;
824 result[1] = sd->N.y;
825 result[2] = sd->N.z;
826 status = true;
827 }
828#endif
829 break;
830 }
832#if !defined(__KERNEL_GPU__) && defined(__SHADER_RAYTRACE__)
833 /* AO shader hack. */
834 ConstIntegratorState state = sg->path_state;
835 if (state != nullptr) {
836 const int num_samples = int(s);
837 const float radius = t;
838 const float3 N = make_float3(dsdx, dtdx, dsdy);
839 int flags = 0;
840 if (int(dtdy)) {
841 flags |= NODE_AO_INSIDE;
842 }
843 if (opt->sblur) {
844 flags |= NODE_AO_ONLY_LOCAL;
845 }
846 if (opt->tblur) {
847 flags |= NODE_AO_GLOBAL_RADIUS;
848 }
849 result[0] = svm_ao(kg, state, sd, N, radius, num_samples, flags);
850 status = true;
851 }
852#else
853 result[0] = 1.0f;
854 status = true;
855#endif
856 break;
857 }
858 }
859
860 if (!status) {
861 if (opt->missingcolor) {
862 missingcolor_to_nchannels(opt->missingcolor, nchannels, result);
863 }
864 else {
865 rgba_to_nchannels(IMAGE_MISSING_RGBA, nchannels, result);
866 }
867 }
868
869 return status;
870}
871
874 ccl_private void *texture_handle,
875 float3 P,
876 float3 /*dPdx*/,
877 float3 /*dPdy*/,
878 float3 /*dPdz*/,
879 int nchannels,
880 float *result)
881{
882 const OSLTextureHandleType type = OSL_TEXTURE_HANDLE_TYPE(texture_handle);
883 const int image_texture_id = OSL_TEXTURE_HANDLE_ID(texture_handle);
884
885 bool status = false;
886
887 switch (type) {
889 const float4 rgba = kernel_image_interp_3d(
890 kg, sg->sd, image_texture_id, P, INTERPOLATION_NONE, false);
891
892 rgba_to_nchannels(rgba, nchannels, result);
893 status = true;
894 break;
895 }
896 default:
897 break;
898 }
899
900 if (!status) {
901 rgba_to_nchannels(IMAGE_MISSING_RGBA, nchannels, result);
902 }
903
904 return status;
905}
906
909 ccl_private void *texture_handle,
911 float3 R,
912 float3 dRdx,
913 float3 dRdy,
914 int nchannels,
915 float *result)
916{
917 const OSLTextureHandleType type = OSL_TEXTURE_HANDLE_TYPE(texture_handle);
918 const int image_texture_or_udim_id = OSL_TEXTURE_HANDLE_ID(texture_handle);
919
920 if (type == OSLTextureHandleType::IMAGE) {
921 ccl_private ShaderData *sd = sg->sd;
922 const dual3 R_dual(R, dRdx, dRdy);
923 /* Environment call is always equirectangular. */
924 const dual2 uv(direction_to_equirectangular(R_dual.val));
926 kg, sd, image_texture_or_udim_id, uv, get_missingcolor(opt->missingcolor, nchannels));
927 rgba_to_nchannels(rgba, nchannels, result);
928 return true;
929 }
930
931 if (opt->missingcolor) {
932 missingcolor_to_nchannels(opt->missingcolor, nchannels, result);
933 }
934 else {
935 rgba_to_nchannels(IMAGE_MISSING_RGBA, nchannels, result);
936 }
937
938 return false;
939}
940
941/* Scene Attributes */
942
944 DeviceString name,
945 const TypeDesc type,
946 bool derivatives,
947 ccl_private void *val)
948{
949 if (name == DeviceStrings::u_scene_time) {
950 return set_attribute(kernel_data.scene_time.time, type, derivatives, val);
951 }
952 if (name == DeviceStrings::u_scene_frame) {
953 return set_attribute(kernel_data.scene_time.frame, type, derivatives, val);
954 }
955 return false;
956}
957
958/* Object Attribute Retrieval */
959
960template<typename T>
962 ccl_private ShaderData *sd,
963 const AttributeDescriptor &desc,
964 const TypeDesc type,
965 bool derivatives,
966 ccl_private void *val)
967{
968 dual<T> data;
969#ifdef __VOLUME__
970 if (primitive_is_volume_attribute(sd)) {
971 data.val = primitive_volume_attribute<T>(kg, sd, desc, true);
972 }
973 else
974#endif
975 {
976 if (derivatives) {
977 data = primitive_surface_attribute<dual<T>>(kg, sd, desc);
978 }
979 else {
980 data = dual<T>(primitive_surface_attribute<T>(kg, sd, desc));
981 }
982 }
983 return set_attribute(data, type, derivatives, val);
984}
985
987 ccl_private ShaderData *sd,
988 const AttributeDescriptor &desc,
989 const TypeDesc type,
990 bool derivatives,
991 ccl_private void *val)
992{
993 if (desc.type == NODE_ATTR_FLOAT) {
994 return osl_shared_get_object_attribute_impl<float>(kg, sd, desc, type, derivatives, val);
995 }
996 if (desc.type == NODE_ATTR_FLOAT2) {
997 return osl_shared_get_object_attribute_impl<float2>(kg, sd, desc, type, derivatives, val);
998 }
999 if (desc.type == NODE_ATTR_FLOAT3) {
1000 return osl_shared_get_object_attribute_impl<float3>(kg, sd, desc, type, derivatives, val);
1001 }
1002 if (desc.type == NODE_ATTR_FLOAT4 || desc.type == NODE_ATTR_RGBA) {
1003 return osl_shared_get_object_attribute_impl<float4>(kg, sd, desc, type, derivatives, val);
1004 }
1005 if (desc.type == NODE_ATTR_QUATERNION) {
1006 return osl_shared_get_object_attribute_impl<Quaternion>(kg, sd, desc, type, derivatives, val);
1007 }
1008 if (desc.type == NODE_ATTR_MATRIX) {
1009 const Transform tfm = primitive_attribute_matrix(kg, desc);
1010 return set_attribute_matrix(tfm, type, val);
1011 }
1012 return false;
1013}
1014
1015/* Background Attributes */
1016
1019 ccl_private ShaderData *sd,
1020 DeviceString name,
1021 const TypeDesc type,
1022 bool derivatives,
1023 ccl_private void *val)
1024{
1025#ifdef __KERNEL_GPU__
1026 ConstIntegratorState state = (sg->shade_index > 0) ? (sg->shade_index - 1) : -1;
1027 ConstIntegratorShadowState shadow_state = (sg->shade_index < 0) ? (-sg->shade_index - 1) : -1;
1028# define READ_PATH_STATE(elem) \
1029 ((state != -1) ? INTEGRATOR_STATE(state, path, elem) : \
1030 (shadow_state != -1) ? INTEGRATOR_STATE(shadow_state, shadow_path, elem) : \
1031 0)
1032#else
1033 const IntegratorStateCPU *state = sg->path_state;
1034 const IntegratorShadowStateCPU *shadow_state = sg->shadow_path_state;
1035# define READ_PATH_STATE(elem) \
1036 ((state != nullptr) ? state->path.elem : \
1037 (shadow_state != nullptr) ? shadow_state->shadow_path.elem : \
1038 0)
1039#endif
1040
1041 if (name == DeviceStrings::u_path_ray_length) {
1042 /* Ray Length */
1043 const float f = sd->ray_length;
1044 return set_attribute(f, type, derivatives, val);
1045 }
1046 if (name == DeviceStrings::u_path_ray_depth) {
1047 /* Ray Depth */
1048 int f = READ_PATH_STATE(bounce);
1049
1050 /* Read bounce from different locations depending on if this is a shadow path. For background,
1051 * light emission and shadow evaluation from a surface or volume we are effectively one bounce
1052 * further. */
1055 {
1056 f += 1;
1057 }
1058
1059 return set_attribute(f, type, derivatives, val);
1060 }
1061 if (name == DeviceStrings::u_path_diffuse_depth) {
1062 /* Diffuse Ray Depth */
1063 const int f = READ_PATH_STATE(diffuse_bounce);
1064 return set_attribute(f, type, derivatives, val);
1065 }
1066 if (name == DeviceStrings::u_path_glossy_depth) {
1067 /* Glossy Ray Depth */
1068 const int f = READ_PATH_STATE(glossy_bounce);
1069 return set_attribute(f, type, derivatives, val);
1070 }
1071 if (name == DeviceStrings::u_path_transmission_depth) {
1072 /* Transmission Ray Depth */
1073 const int f = READ_PATH_STATE(transmission_bounce);
1074 return set_attribute(f, type, derivatives, val);
1075 }
1076 if (name == DeviceStrings::u_path_transparent_depth) {
1077 /* Transparent Ray Depth */
1078 const int f = READ_PATH_STATE(transparent_bounce);
1079 return set_attribute(f, type, derivatives, val);
1080 }
1081 if (name == DeviceStrings::u_path_portal_depth) {
1082 /* Portal Ray Depth */
1083 const int f = READ_PATH_STATE(portal_bounce);
1084 return set_attribute(f, type, derivatives, val);
1085 }
1086
1087#undef READ_PATH_STATE
1088
1089 if (name == DeviceStrings::u_ndc) {
1090 /* NDC coordinates with special exception for orthographic projection. */
1091 dual3 ndc;
1092
1094 sd->object == OBJECT_NONE && kernel_data.cam.type == CAMERA_ORTHOGRAPHIC)
1095 {
1096 ndc = dual3(camera_world_to_ndc(kg, sd, sd->ray_P));
1097 }
1098 else {
1099 ndc = dual3(camera_world_to_ndc(kg, sd, sd->P));
1100
1101 if (derivatives) {
1102 const differential3 dP = differential_from_compact(sd->Ng, sd->dP);
1103 ndc.dx = camera_world_to_ndc(kg, sd, sd->P + dP.dx) - ndc.val;
1104 ndc.dy = camera_world_to_ndc(kg, sd, sd->P + dP.dy) - ndc.val;
1105 }
1106 }
1107
1108 return set_attribute(ndc, type, derivatives, val);
1109 }
1110
1111 return osl_shared_get_scene_attribute(kg, name, type, derivatives, val);
1112}
1113
1114/* Object Standard Attributes */
1115
1118 ccl_private ShaderData *sd,
1119 DeviceString name,
1120 const TypeDesc type,
1121 bool derivatives,
1122 ccl_private void *val)
1123{
1124 /* Object Attributes */
1125 if (name == DeviceStrings::u_object_location) {
1126 const float3 f = object_location(kg, sd);
1127 return set_attribute(f, type, derivatives, val);
1128 }
1129 if (name == DeviceStrings::u_object_color) {
1130 const float3 f = object_color(kg, sd->object);
1131 return set_attribute(f, type, derivatives, val);
1132 }
1133 if (name == DeviceStrings::u_object_alpha) {
1134 const float f = object_alpha(kg, sd->object);
1135 return set_attribute(f, type, derivatives, val);
1136 }
1137 if (name == DeviceStrings::u_object_index) {
1138 const float f = object_pass_id(kg, sd->object);
1139 return set_attribute(f, type, derivatives, val);
1140 }
1141 if (name == DeviceStrings::u_object_is_light) {
1142 const float f = (sd->type & PRIMITIVE_LAMP) != 0;
1143 return set_attribute(f, type, derivatives, val);
1144 }
1145 if (name == DeviceStrings::u_geom_dupli_generated) {
1146 const float3 f = object_dupli_generated(kg, sd->object);
1147 return set_attribute(f, type, derivatives, val);
1148 }
1149 if (name == DeviceStrings::u_geom_dupli_uv) {
1150 const float3 f = object_dupli_uv(kg, sd->object);
1151 return set_attribute(f, type, derivatives, val);
1152 }
1153 if (name == DeviceStrings::u_material_index) {
1154 const float f = shader_pass_id(kg, sd);
1155 return set_attribute(f, type, derivatives, val);
1156 }
1157 if (name == DeviceStrings::u_object_random) {
1158 const float f = object_random_number(kg, sd->object);
1159 return set_attribute(f, type, derivatives, val);
1160 }
1161
1162 /* Particle Attributes */
1163 if (name == DeviceStrings::u_particle_index) {
1164 const int particle_id = object_particle_id(kg, sd->object);
1165 const float f = particle_index(kg, particle_id);
1166 return set_attribute(f, type, derivatives, val);
1167 }
1168 if (name == DeviceStrings::u_particle_random) {
1169 const int particle_id = object_particle_id(kg, sd->object);
1170 const float f = hash_uint2_to_float(particle_index(kg, particle_id), 0);
1171 return set_attribute(f, type, derivatives, val);
1172 }
1173 if (name == DeviceStrings::u_particle_age) {
1174 const int particle_id = object_particle_id(kg, sd->object);
1175 const float f = particle_age(kg, particle_id);
1176 return set_attribute(f, type, derivatives, val);
1177 }
1178 if (name == DeviceStrings::u_particle_lifetime) {
1179 const int particle_id = object_particle_id(kg, sd->object);
1180 const float f = particle_lifetime(kg, particle_id);
1181 return set_attribute(f, type, derivatives, val);
1182 }
1183 if (name == DeviceStrings::u_particle_location) {
1184 const int particle_id = object_particle_id(kg, sd->object);
1185 const float3 f = particle_location(kg, particle_id);
1186 return set_attribute(f, type, derivatives, val);
1187 }
1188#if 0 /* unsupported */
1189 if (name == DeviceStrings::u_particle_rotation) {
1190 const int particle_id = object_particle_id(kg, sd->object);
1191 const float4 f = particle_rotation(kg, particle_id);
1192 return set_attribute(f, type, derivatives, val);
1193 }
1194#endif
1195 if (name == DeviceStrings::u_particle_size) {
1196 const int particle_id = object_particle_id(kg, sd->object);
1197 const float f = particle_size(kg, particle_id);
1198 return set_attribute(f, type, derivatives, val);
1199 }
1200 if (name == DeviceStrings::u_particle_velocity) {
1201 const int particle_id = object_particle_id(kg, sd->object);
1202 const float3 f = particle_velocity(kg, particle_id);
1203 return set_attribute(f, type, derivatives, val);
1204 }
1205 if (name == DeviceStrings::u_particle_angular_velocity) {
1206 const int particle_id = object_particle_id(kg, sd->object);
1207 const float3 f = particle_angular_velocity(kg, particle_id);
1208 return set_attribute(f, type, derivatives, val);
1209 }
1210
1211 /* Geometry Attributes */
1212 if (name == DeviceStrings::u_geom_numpolyvertices) {
1213 return set_attribute(3, type, derivatives, val);
1214 }
1215 if ((name == DeviceStrings::u_geom_trianglevertices ||
1216 name == DeviceStrings::u_geom_polyvertices) &&
1217 sd->type & PRIMITIVE_TRIANGLE)
1218 {
1219 float3 P[3];
1220
1221 if (sd->type & PRIMITIVE_MOTION) {
1222 motion_triangle_vertices(kg, sd->object, sd->prim, sd->time, P);
1223 }
1224 else {
1225 triangle_vertices(kg, sd->object, sd->prim, P);
1226 }
1227
1228 if (!(sd->object_flag & SD_OBJECT_TRANSFORM_APPLIED)) {
1229 object_position_transform(kg, sd, &P[0]);
1230 object_position_transform(kg, sd, &P[1]);
1231 object_position_transform(kg, sd, &P[2]);
1232 }
1233
1234 return set_attribute_float3_3(P, type, derivatives, val);
1235 }
1236#ifndef __KERNEL_GPU__
1237 if (name == DeviceStrings::u_geom_name) {
1238 const ustring object_name = kg->osl.globals->object_names[sd->object];
1239 return set_attribute(object_name, type, derivatives, val);
1240 }
1241#endif
1242 if (name == DeviceStrings::u_is_smooth) {
1243 const float f = ((sd->shader & SHADER_SMOOTH_NORMAL) != 0);
1244 return set_attribute(f, type, derivatives, val);
1245 }
1246#ifdef __HAIR__
1247 /* Hair Attributes */
1248 if (name == DeviceStrings::u_is_curve) {
1249 const float f = (sd->type & PRIMITIVE_CURVE) != 0;
1250 return set_attribute(f, type, derivatives, val);
1251 }
1252 if (name == DeviceStrings::u_curve_thickness) {
1253 const float f = curve_thickness(kg, sd);
1254 return set_attribute(f, type, derivatives, val);
1255 }
1256 if (name == DeviceStrings::u_curve_tangent_normal) {
1257 const float3 f = curve_tangent_normal(sd);
1258 return set_attribute(f, type, derivatives, val);
1259 }
1260 if (name == DeviceStrings::u_curve_random) {
1261 const float f = curve_random(kg, sd);
1262 return set_attribute(f, type, derivatives, val);
1263 }
1264#endif
1265#ifdef __POINTCLOUD__
1266 /* Point Attributes */
1267 if (name == DeviceStrings::u_is_point) {
1268 const float f = (sd->type & PRIMITIVE_ANY_POINT) != 0;
1269 return set_attribute(f, type, derivatives, val);
1270 }
1271 if (name == DeviceStrings::u_point_radius) {
1272 const float f = point_radius(kg, sd);
1273 return set_attribute(f, type, derivatives, val);
1274 }
1275 if (name == DeviceStrings::u_point_position) {
1276 const float3 f = point_position(kg, sd);
1277 return set_attribute(f, type, derivatives, val);
1278 }
1279 if (name == DeviceStrings::u_point_random) {
1280 const float f = point_random(kg, sd);
1281 return set_attribute(f, type, derivatives, val);
1282 }
1283#endif
1284 if (name == DeviceStrings::u_normal_map_normal) {
1285 if (sd->type & PRIMITIVE_TRIANGLE) {
1287 kg, sd->object, sd->prim, ATTR_STD_NORMAL_UNDISPLACED);
1288 if (is_attribute_found(desc)) {
1289 return osl_shared_get_object_attribute(kg, sd, desc, type, derivatives, val);
1290 }
1292 return set_attribute(f, type, derivatives, val);
1293 }
1294 return false;
1295 }
1296 if (name == DeviceStrings::u_bump_map_normal) {
1297 dual3 f;
1298 if (!attribute_bump_map_normal(kg, sd, f)) {
1299 return false;
1300 }
1301 return set_attribute(f, type, derivatives, val);
1302 }
1303#if defined(__GSPLATS__)
1304 /* Gaussian splats attributes. */
1305 if (sd->type & PRIMITIVE_GSPLAT && name == DeviceStrings::u_geom_radiance) {
1306 const float3 radiance = gsplat_radiance(kg, *sd);
1307 return set_attribute(radiance, type, derivatives, val);
1308 }
1309#endif
1310 return osl_shared_get_background_attribute(kg, sg, sd, name, type, derivatives, val);
1311}
1312
1313/* Camera Attributes */
1314
1317 DeviceString name,
1318 const TypeDesc type,
1319 bool derivatives,
1320 ccl_private void *val)
1321{
1322 if (name == DeviceStrings::u_sensor_size) {
1323 const float2 sensor = make_float2(kernel_data.cam.sensorwidth, kernel_data.cam.sensorheight);
1324 return set_attribute(sensor, type, derivatives, val);
1325 }
1326 if (name == DeviceStrings::u_image_resolution) {
1327 const float2 image = make_float2(kernel_data.cam.width, kernel_data.cam.height);
1328 return set_attribute(image, type, derivatives, val);
1329 }
1330 if (name == DeviceStrings::u_aperture_aspect_ratio) {
1331 return set_attribute(1.0f / kernel_data.cam.inv_aperture_ratio, type, derivatives, val);
1332 }
1333 if (name == DeviceStrings::u_aperture_size) {
1334 return set_attribute(kernel_data.cam.aperturesize, type, derivatives, val);
1335 }
1336 if (name == DeviceStrings::u_aperture_position) {
1337 /* The random numbers for aperture sampling are packed into N. */
1338 const float2 rand_lens = make_float2(sg->N.x, sg->N.y);
1339 const float2 pos = camera_sample_aperture(&kernel_data.cam, rand_lens);
1340 return set_attribute(pos * kernel_data.cam.aperturesize, type, derivatives, val);
1341 }
1342 if (name == DeviceStrings::u_focal_distance) {
1343 return set_attribute(kernel_data.cam.focaldistance, type, derivatives, val);
1344 }
1345 return osl_shared_get_scene_attribute(kg, name, type, derivatives, val);
1346}
1347
#define UCHAR
Definition GeoCommon.h:8
#define USHORT
Definition GeoCommon.h:9
@ NONE
nullptr FLOAT
ccl_device float2 direction_to_equirectangular(const float3 dir)
ccl_device_forceinline float4 kernel_image_interp_with_udim(KernelGlobals kg, ccl_private ShaderData *sd, const int udim_id, dual2 uv, const float4 missing_rgba)
ccl_device_inline ProjectionTransform projection_identity()
#define kernel_assert(cond)
#define kernel_data
#define ccl_device_forceinline
#define kernel_data_fetch(name, index)
#define OBJECT_NONE
#define ccl_private
#define ccl_device_inline
#define OSL_RAYTYPE_TO_VISIBILITY(raytype)
#define ccl_device_template_spec
#define ccl_global
#define OSL_RAYTYPE_TO_PARTIAL_PATH_FLAG(raytype)
#define ccl_device_inline_method
#define ccl_device_constant
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_forceinline differential3 differential_from_compact(const float3 D, const float dD)
#define str(s)
ccl_device_inline float3 triangle_smooth_normal(KernelGlobals kg, float3 Ng, int object, int object_flag, int prim, float u, float v)
ccl_device_inline float3 triangle_smooth_normal_unnormalized_object_space(KernelGlobals kg, ccl_private const ShaderData *sd)
ccl_device_inline void triangle_vertices(KernelGlobals kg, const int object, const int prim, float3 P[3])
float hash_uint2_to_float(uint kx, uint ky)
#define image(slot, qualifiers, format)
float average(float2 a)
CCL_NAMESPACE_BEGIN ccl_device_forceinline int kernel_image_udim_map(KernelGlobals kg, const int id, ccl_private float2 &uv)
Definition image_2d.h:17
CCL_NAMESPACE_BEGIN ccl_device float2 camera_sample_aperture(ccl_constant KernelCamera *cam, const float2 rand)
ccl_device_inline float3 camera_world_to_ndc(KernelGlobals kg, ccl_private ShaderData *sd, float3 P)
const int state
CCL_NAMESPACE_BEGIN ccl_device_forceinline bool is_attribute_found(const ccl_private AttributeDescriptor &desc)
ccl_device Transform primitive_attribute_matrix(KernelGlobals kg, const AttributeDescriptor desc)
ccl_device_inline AttributeDescriptor find_attribute(const ccl_global AttributeMap *attributes_map, uint attr_offset, const int prim, const uint64_t id)
ccl_device_inline float3 object_dupli_uv(KernelGlobals kg, const int object)
ccl_device_inline int object_particle_id(KernelGlobals kg, const int object)
ccl_device int shader_pass_id(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device_inline Transform object_get_inverse_transform(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device float4 particle_rotation(KernelGlobals kg, const int particle)
ccl_device float3 particle_location(KernelGlobals kg, const int particle)
ccl_device float particle_lifetime(KernelGlobals kg, const int particle)
ccl_device float particle_age(KernelGlobals kg, const int particle)
ccl_device_inline uint particle_index(KernelGlobals kg, const int particle)
ccl_device_inline float3 object_color(KernelGlobals kg, const int object)
ccl_device_inline Transform object_get_transform(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device float3 particle_velocity(KernelGlobals kg, const int particle)
ccl_device_inline float object_alpha(KernelGlobals kg, const int object)
ccl_device float3 particle_angular_velocity(KernelGlobals kg, const int particle)
ccl_device_inline float3 object_dupli_generated(KernelGlobals kg, const int object)
ccl_device_inline float object_pass_id(KernelGlobals kg, const int object)
ccl_device float particle_size(KernelGlobals kg, const int particle)
ccl_device_inline void object_position_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private T *P)
ccl_device_inline void object_inverse_normal_transform(KernelGlobals kg, const ccl_private ShaderData *sd, ccl_private float3 *N)
ccl_device_inline float3 object_location(KernelGlobals kg, const ccl_private ShaderData *sd)
ccl_device_inline Transform object_fetch_transform_motion_test(KernelGlobals kg, const int object, const float time, ccl_private Transform *itfm)
ccl_device_inline float object_random_number(KernelGlobals kg, const int object)
OSLTextureHandleType
#define OSL_TEXTURE_HANDLE_TYPE(handle)
#define OSL_TEXTURE_HANDLE_ID(handle)
const char * DeviceString
@ NODE_ATTR_FLOAT
@ NODE_ATTR_QUATERNION
@ NODE_ATTR_FLOAT3
@ NODE_ATTR_RGBA
@ NODE_ATTR_FLOAT2
@ NODE_ATTR_FLOAT4
@ NODE_ATTR_MATRIX
@ NODE_AO_INSIDE
@ NODE_AO_GLOBAL_RADIUS
@ NODE_AO_ONLY_LOCAL
@ SR_BACKFACING
@ PRIMITIVE_LAMP
@ PRIMITIVE_MOTION
@ PRIMITIVE_MOTION_TRIANGLE
@ PRIMITIVE_GSPLAT
@ PRIMITIVE_CURVE
@ PRIMITIVE_ANY_POINT
@ PRIMITIVE_TRIANGLE
@ PATH_RAY_EMISSION
@ PATH_RAY_VISIBILITY_CAMERA
@ PATH_RAY_VISIBILITY_SHADOW
@ SD_OBJECT_TRANSFORM_APPLIED
@ SHADER_SMOOTH_NORMAL
@ ATTR_STD_NORMAL_UNDISPLACED
@ CAMERA_ORTHOGRAPHIC
ccl_device_inline float kernel_ies_interp(KernelGlobals kg, const int slot, const float h_angle, const float v_angle)
ccl_device_inline bool operator!=(const float2 a, const float2 b)
ccl_device_inline bool operator==(const float2 a, const float2 b)
ccl_device_inline void copy_v3_v3(ccl_private float *r, const float3 val)
ccl_device_inline void copy_v4_v4(ccl_private float *r, const float4 val)
CCL_NAMESPACE_BEGIN ccl_device_inline float4 zero_float4()
Definition math_float4.h:13
ccl_device_inline void copy_v4_qt(ccl_private float *r, const Quaternion val)
#define N
#define T
#define R
#define KERNEL_IMAGE_NONE
#define IMAGE_MISSING_RGBA
ccl_device_inline void motion_triangle_vertices(KernelGlobals kg, const int object, const uint3 tri_vindex, const int numsteps, const int numverts, const int step, const float t, float3 verts[3])
ccl_device_inline float3 motion_triangle_smooth_normal(KernelGlobals kg, const float3 Ng, const int object, const int prim, const uint3 tri_vindex, const int numsteps, const int step, const float t, const float u, const float v)
ATTR_WARN_UNUSED_RESULT const BMLoop * l
ATTR_WARN_UNUSED_RESULT const BMVert * v
OSL::ustringhash OSLUStringHash
Definition osl/compat.h:11
CCL_NAMESPACE_BEGIN ccl_device_forceinline T primitive_surface_attribute(KernelGlobals kg, const ccl_private ShaderData *sd, const AttributeDescriptor desc)
Definition primitive.h:32
#define ccl_device
#define make_float2
#define make_float4
ccl_device_forceinline void rgba_to_nchannels(const float4 rgba, const int nchannels, ccl_private float *result)
ccl_device_forceinline void copy_matrix(ccl_private float *res, const Transform &tfm)
ccl_device_forceinline float4 get_missingcolor(const float *missingcolor, const int nchannels)
ccl_device_inline bool osl_shared_get_object_standard_attribute(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private ShaderData *sd, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool is_type_float4(const TypeDesc t)
ccl_device_inline bool osl_shared_get_scene_attribute(KernelGlobals kg, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool is_type_float3(const TypeDesc t)
ccl_device_inline void set_data_float3(const dual3 data, bool derivatives, ccl_private void *val)
ccl_device_inline void set_data_quaternion(const dual< Quaternion > data, bool derivatives, ccl_private void *val)
ccl_device bool attribute_bump_map_normal(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private dual3 &f)
ccl_device_inline void set_data_float4(const dual4 data, bool derivatives, ccl_private void *val)
ccl_device_inline bool osl_shared_get_object_inverse_matrix_motion(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res, float time)
ccl_device_inline bool osl_shared_get_named_matrix(KernelGlobals kg, DeviceString from, ccl_private float *res)
ccl_device_inline bool osl_shared_get_object_matrix_motion(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res, float time)
ccl_device_inline void set_data_float(const dual1 data, bool derivatives, ccl_private void *val)
ccl_device bool osl_shared_environment(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, float3 R, float3 dRdx, float3 dRdy, int nchannels, float *result)
ccl_device bool osl_shared_get_texture_info(KernelGlobals kg, ccl_private void *texture_handle, const float2 uv, const bool use_uv, DeviceString dataname, const TypeDesc datatype, void *data)
ccl_device_inline bool is_type_int3(const TypeDesc t)
ccl_device_inline bool osl_shared_get_camera_attribute(KernelGlobals kg, ccl_private ShaderGlobals *sg, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool set_attribute(const dual< T > v, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool set_attribute_matrix(const Transform &tfm, const TypeDesc type, ccl_private void *val)
ccl_device_inline bool osl_shared_get_background_attribute(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private ShaderData *sd, DeviceString name, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_inline bool osl_shared_get_object_matrix(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res)
ccl_device_inline bool is_type_int2(const TypeDesc t)
#define READ_PATH_STATE(elem)
ccl_device bool osl_shared_texture3d(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private void *texture_handle, float3 P, float3, float3, float3, int nchannels, float *result)
ccl_device_inline bool osl_shared_get_object_attribute(KernelGlobals kg, ccl_private ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device bool osl_shared_texture(KernelGlobals kg, ccl_private ShaderGlobals *sg, ccl_private void *texture_handle, ccl_private OSLTextureOptions *opt, float s, float t, float dsdx, float dtdx, float dsdy, float dtdy, int nchannels, float *result)
ccl_device_inline bool osl_shared_get_named_inverse_matrix(KernelGlobals kg, DeviceString to, ccl_private float *res)
ccl_device_inline bool osl_shared_get_object_inverse_matrix(KernelGlobals kg, ccl_private const ShaderData *sd, ccl_private float *res)
ccl_device_inline bool osl_shared_get_object_attribute_impl(KernelGlobals kg, ccl_private ShaderData *sd, const AttributeDescriptor &desc, const TypeDesc type, bool derivatives, ccl_private void *val)
CCL_NAMESPACE_BEGIN ccl_device_inline bool is_type_float2(const TypeDesc t)
ccl_device_inline bool set_attribute_float3_3(const float3 P[3], TypeDesc type, bool derivatives, ccl_private void *val)
ccl_device_forceinline void missingcolor_to_nchannels(const float *missingcolor, const int nchannels, ccl_private float *result)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
const IntegratorShadowStateCPU * ConstIntegratorShadowState
Definition state.h:230
const IntegratorStateCPU * ConstIntegratorState
Definition state.h:228
NodeAttributeType type
float4 y
Definition transform.h:53
float4 x
Definition transform.h:53
float4 z
Definition transform.h:53
dual()=default
float y
Definition sky_math.h:225
float z
Definition sky_math.h:225
float x
Definition sky_math.h:225
float w
Definition sky_math.h:225
dual< float4 > dual4
Definition types_dual.h:107
dual< float3 > dual3
Definition types_dual.h:106
dual< float2 > dual2
Definition types_dual.h:105
dual< float > dual1
Definition types_dual.h:104
@ IMAGE_DATA_TYPE_BYTE
Definition types_image.h:40
@ IMAGE_DATA_TYPE_FLOAT
Definition types_image.h:39
@ IMAGE_DATA_TYPE_NANOVDB_FP16
Definition types_image.h:48
@ IMAGE_DATA_TYPE_FLOAT4
Definition types_image.h:36
@ IMAGE_DATA_TYPE_USHORT4
Definition types_image.h:42
@ IMAGE_DATA_TYPE_USHORT
Definition types_image.h:43
@ IMAGE_DATA_TYPE_NANOVDB_EMPTY
Definition types_image.h:49
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT
Definition types_image.h:44
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT3
Definition types_image.h:45
@ IMAGE_DATA_TYPE_HALF
Definition types_image.h:41
@ IMAGE_DATA_TYPE_BYTE4
Definition types_image.h:37
@ IMAGE_DATA_TYPE_HALF4
Definition types_image.h:38
@ IMAGE_DATA_TYPE_NANOVDB_FLOAT4
Definition types_image.h:46
@ IMAGE_DATA_TYPE_NANOVDB_FPN
Definition types_image.h:47
@ INTERPOLATION_NONE
Definition types_image.h:25