MDL SDK API nvidia_logo_transpbg.gif Up
target_code_types.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2026 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
6
7#ifndef MI_NEURAYLIB_TARGET_CODE_TYPES_H
8#define MI_NEURAYLIB_TARGET_CODE_TYPES_H
9
10// If neither TARGET_CODE_USE_CUDA_TYPES nor TARGET_CODE_USE_NEURAY_TYPES is set,
11// it will default to CUDA types when compiled by a CUDA compiler and use Neuray types otherwise.
12
13#if defined(TARGET_CODE_USE_CUDA_TYPES) && defined(TARGET_CODE_USE_NEURAY_TYPES)
14#error "Only one of TARGET_CODE_USE_CUDA_TYPES and TARGET_CODE_USE_NEURAY_TYPES may be defined."
15#endif
16
19#ifndef MDL_DF_SPECTRAL_SAMPLES
20#define MDL_DF_SPECTRAL_SAMPLES 5
21#endif // !MDL_DF_SPECTRAL_SAMPLES
22
23#if !defined(TARGET_CODE_USE_NEURAY_TYPES) && \
24 (defined(TARGET_CODE_USE_CUDA_TYPES) || defined(__CUDA_ARCH__))
25
26#include <vector_types.h>
27
28// Disable all FORCE_32_BIT enum values.
29#define MI_NEURAYLIB_DEPRECATED_ENUM_VALUE(X,Y)
30
31namespace mi {
32
33namespace neuraylib {
34
40using tct_float = float;
41
43using tct_float2 = float2;
44
46using tct_float3 = float3;
47
49using tct_float4 = float4;
50
51// Aligned float4.
52using tct_float4_a16 = float4;
53
55using tct_int = int;
56
58using tct_uint = unsigned;
59
60#else
61
63#include <mi/neuraylib/version.h> // for MI_NEURAYLIB_DEPRECATED_ENUM_VALUE
64
65namespace mi {
66
67namespace neuraylib {
68
74using tct_float = float;
75
78
81
84
85// Aligned float4.
86struct alignas(16) tct_float4_a16
87{
88 float x, y, z, w;
89};
90
93
96
97#endif
98
100using tct_bool = bool;
101
104 float values[MDL_DF_SPECTRAL_SAMPLES];
105};
106
108template<typename T>
110{
111 T val, dx, dy;
112};
113
115template<bool with_derivatives>
117
118template<>
119struct tct_traits<false>
120{
121 using tct_derivable_float = tct_float;
122 using tct_derivable_float2 = tct_float2;
123 using tct_derivable_float3 = tct_float3;
124 using tct_derivable_float4 = tct_float4_a16;
125 using tct_coord2_type = const tct_float[2];
126};
127
128template<>
129struct tct_traits<true>
130{
131 using tct_derivable_float = tct_deriv<tct_float>;
132 using tct_derivable_float2 = tct_deriv<tct_float2>;
133 using tct_derivable_float3 = tct_deriv<tct_float3>;
134 using tct_derivable_float4 = tct_deriv<tct_float4_a16>;
135 using tct_coord2_type = const tct_derivable_float2 *;
136};
137
140
143
146
149
152
155
158
159
174{
178
192 char const *ro_data_segment;
193};
194
195
223template<bool with_derivatives = false>
225{
227
233
237
240 typename traits::tct_derivable_float3 position;
241
245
249 typename traits::tct_derivable_float3 const *text_coords;
250
257
264
271 tct_float4_a16 *text_results;
272
286 char const *ro_data_segment;
287
293 tct_float4_a16 const *world_to_object;
294
300 tct_float4_a16 const *object_to_world;
301
307
312};
313
316template<bool with_derivatives = false>
320};
321
324
327
330
333
334
339{
342
346
350
353 TEX_WRAP_CLIP = 3
355
358{
361
365
366
367// Forward declaration of texture handler structure.
368struct Texture_handler_base;
369
370
373template<bool with_derivatives = false>
375{
378
380 void (*m_tex_lookup_float4_2d)(
381 tct_float result[4],
382 Texture_handler_base const *self,
383 tct_uint texture_idx,
384 typename traits::tct_coord2_type coord,
385 Tex_wrap_mode wrap_u,
386 Tex_wrap_mode wrap_v,
387 tct_float const crop_u[2],
388 tct_float const crop_v[2],
389 tct_float frame);
390
392 void (*m_tex_lookup_float3_2d)(
393 tct_float result[3],
394 Texture_handler_base const *self,
395 tct_uint texture_idx,
396 typename traits::tct_coord2_type coord,
397 Tex_wrap_mode wrap_u,
398 Tex_wrap_mode wrap_v,
399 tct_float const crop_u[2],
400 tct_float const crop_v[2],
401 tct_float frame);
402
404 void (*m_tex_texel_float4_2d)(
405 tct_float result[4],
406 Texture_handler_base const *self,
407 tct_uint texture_idx,
408 tct_int const coord[2],
409 tct_int const uv_tile[2],
410 tct_float frame);
411
413 void (*m_tex_lookup_float4_3d)(
414 tct_float result[4],
415 Texture_handler_base const *self,
416 tct_uint texture_idx,
417 tct_float const coord[3],
418 Tex_wrap_mode wrap_u,
419 Tex_wrap_mode wrap_v,
420 Tex_wrap_mode wrap_w,
421 tct_float const crop_u[2],
422 tct_float const crop_v[2],
423 tct_float const crop_w[2],
424 tct_float frame);
425
427 void (*m_tex_lookup_float3_3d)(
428 tct_float result[3],
429 Texture_handler_base const *self,
430 tct_uint texture_idx,
431 tct_float const coord[3],
432 Tex_wrap_mode wrap_u,
433 Tex_wrap_mode wrap_v,
434 Tex_wrap_mode wrap_w,
435 tct_float const crop_u[2],
436 tct_float const crop_v[2],
437 tct_float const crop_w[2],
438 tct_float frame);
439
441 void (*m_tex_texel_float4_3d)(
442 tct_float result[4],
443 Texture_handler_base const *self,
444 tct_uint texture_idx,
445 tct_int const coord[3],
446 tct_float frame);
447
449 void (*m_tex_lookup_float4_cube)(
450 tct_float result[4],
451 Texture_handler_base const *self,
452 tct_uint texture_idx,
453 tct_float const coord[3]);
454
456 void (*m_tex_lookup_float3_cube)(
457 tct_float result[3],
458 Texture_handler_base const *self,
459 tct_uint texture_idx,
460 tct_float const coord[3]);
461
465 void (*m_tex_resolution_2d)(
466 tct_int result[2],
467 Texture_handler_base const *self,
468 tct_uint texture_idx,
469 tct_int const uv_tile[2],
470 tct_float frame);
471
475 void (*m_tex_resolution_3d)(
476 tct_int result[3],
477 Texture_handler_base const *self,
478 tct_uint texture_idx,
479 tct_float frame);
480
482 tct_bool (*m_tex_texture_isvalid)(
483 Texture_handler_base const *self,
484 tct_uint texture_idx);
485
488 void (*m_tex_frame)(
489 tct_int result[2],
490 Texture_handler_base const *self,
491 tct_uint texture_idx);
492
494 tct_float (*m_df_light_profile_power)(
495 Texture_handler_base const *self,
496 tct_uint light_profile_index);
497
499 tct_float (*m_df_light_profile_maximum)(
500 Texture_handler_base const *self,
501 tct_uint light_profile_index);
502
504 tct_bool (*m_df_light_profile_isvalid)(
505 Texture_handler_base const *self,
506 tct_uint light_profile_index);
507
509 tct_float (*m_df_light_profile_evaluate)(
510 Texture_handler_base const *self,
511 tct_uint light_profile_index,
512 tct_float const theta_phi[2]);
513
515 void (*m_df_light_profile_sample)(
516 tct_float result[3],
518 Texture_handler_base const *self,
519 tct_uint light_profile_index,
520 tct_float const xi[3]);
521
523 tct_float (*m_df_light_profile_pdf)(
524 Texture_handler_base const *self,
525 tct_uint light_profile_index,
526 tct_float const theta_phi[2]);
527
529 tct_bool (*m_df_bsdf_measurement_isvalid)(
530 Texture_handler_base const *self,
531 tct_uint bsdf_measurement_index);
532
537 void (*m_df_bsdf_measurement_resolution)(
538 tct_uint result[3],
539 Texture_handler_base const *self,
540 tct_uint bsdf_measurement_index,
541 Mbsdf_part part);
542
544 void (*m_df_bsdf_measurement_evaluate)(
545 tct_float result[3],
546 Texture_handler_base const *self,
547 tct_uint bsdf_measurement_index,
548 tct_float const theta_phi_in[2],
549 tct_float const theta_phi_out[2],
550 Mbsdf_part part);
551
553 void (*m_df_bsdf_measurement_sample)(
554 tct_float result[3],
556 Texture_handler_base const *self,
557 tct_uint bsdf_measurement_index,
558 tct_float const theta_phi_out[2],
559 tct_float const xi[3],
561 Mbsdf_part part);
562
564 tct_float (*m_df_bsdf_measurement_pdf)(
565 Texture_handler_base const *self,
566 tct_uint bsdf_measurement_index,
567 tct_float const theta_phi_in[2],
568 tct_float const theta_phi_out[2],
569 Mbsdf_part part);
570
572 void (*m_df_bsdf_measurement_albedos)(
573 tct_float result[4],
579 Texture_handler_base const *self,
580 tct_uint bsdf_measurement_index,
581 tct_float const theta_phi[2]);
582
584 void (*m_adapt_normal)(
585 tct_float result[3],
586 Texture_handler_base const *self_base,
588 tct_float const normal[3]);
589
591 void (*m_rgb_to_spectral_ior)(
592 tct_spectral_sample *result,
593 Texture_handler_base const *self_base,
595 tct_float const rgb[3]);
596
598 void (*m_rgb_to_spectral_reflectance)(
599 tct_spectral_sample *result,
600 Texture_handler_base const *self_base,
602 tct_float const rgb[3]);
603
605 void (*m_rgb_to_spectral_luminance)(
606 tct_spectral_sample *result,
607 Texture_handler_base const *self_base,
609 tct_float const rgb[3]);
610
612 void (*m_rgb_to_spectral_volume_coefficient)(
613 tct_spectral_sample *result,
614 Texture_handler_base const *self_base,
616 tct_float const rgb[3]);
617
619 void (*m_get_wavelengths)(
620 tct_spectral_sample *result,
621 Texture_handler_base const *self_base,
623
625 tct_bool (*m_scene_data_isvalid)(
626 Texture_handler_base const *self_base,
628 tct_uint scene_data_id);
629
631 tct_float (*m_scene_data_lookup_float)(
632 Texture_handler_base const *self_base,
634 tct_uint scene_data_id,
635 tct_float default_value,
636 tct_bool uniform_lookup);
637
639 void (*m_scene_data_lookup_float2)(
640 tct_float result[2],
641 Texture_handler_base const *self_base,
643 tct_uint scene_data_id,
644 tct_float const default_value[2],
645 tct_bool uniform_lookup);
646
648 void (*m_scene_data_lookup_float3)(
649 tct_float result[3],
650 Texture_handler_base const *self_base,
652 tct_uint scene_data_id,
653 tct_float const default_value[3],
654 tct_bool uniform_lookup);
655
657 void (*m_scene_data_lookup_float4)(
658 tct_float result[4],
659 Texture_handler_base const *self_base,
661 tct_uint scene_data_id,
662 tct_float const default_value[4],
663 tct_bool uniform_lookup);
664
666 tct_int (*m_scene_data_lookup_int)(
667 Texture_handler_base const *self_base,
669 tct_uint scene_data_id,
670 tct_int default_value,
671 tct_bool uniform_lookup);
672
674 void (*m_scene_data_lookup_int2)(
675 tct_int result[2],
676 Texture_handler_base const *self_base,
678 tct_uint scene_data_id,
679 tct_int const default_value[2],
680 tct_bool uniform_lookup);
681
683 void (*m_scene_data_lookup_int3)(
684 tct_int result[3],
685 Texture_handler_base const *self_base,
687 tct_uint scene_data_id,
688 tct_int const default_value[3],
689 tct_bool uniform_lookup);
690
692 void (*m_scene_data_lookup_int4)(
693 tct_int result[4],
694 Texture_handler_base const *self_base,
696 tct_uint scene_data_id,
697 tct_int const default_value[4],
698 tct_bool uniform_lookup);
699
701 void (*m_scene_data_lookup_color)(
702 tct_float result[3],
703 Texture_handler_base const *self_base,
705 tct_uint scene_data_id,
706 tct_float const default_value[3],
707 tct_bool uniform_lookup);
708
711 void (*m_scene_data_lookup_float4x4)(
712 tct_float result[16],
713 Texture_handler_base const *self_base,
715 tct_uint scene_data_id,
716 tct_float const default_value[16],
717 tct_bool uniform_lookup);
718
719 //
720 // The following functions are only used in the derivative variant,
721 // and can be \c nullptr in the non-derivative variant
722 //
723
725 void (*m_scene_data_lookup_deriv_float)(
726 tct_deriv_float *result,
727 Texture_handler_base const *self_base,
729 tct_uint scene_data_id,
730 tct_deriv_float const *default_value,
731 tct_bool uniform_lookup);
732
734 void (*m_scene_data_lookup_deriv_float2)(
735 tct_deriv_arr_float_2 *result,
736 Texture_handler_base const *self_base,
738 tct_uint scene_data_id,
739 tct_deriv_arr_float_2 const *default_value,
740 tct_bool uniform_lookup);
741
743 void (*m_scene_data_lookup_deriv_float3)(
744 tct_deriv_arr_float_3 *result,
745 Texture_handler_base const *self_base,
747 tct_uint scene_data_id,
748 tct_deriv_arr_float_3 const *default_value,
749 tct_bool uniform_lookup);
750
752 void (*m_scene_data_lookup_deriv_float4)(
753 tct_deriv_arr_float_4 *result,
754 Texture_handler_base const *self_base,
756 tct_uint scene_data_id,
757 tct_deriv_arr_float_4 const *default_value,
758 tct_bool uniform_lookup);
759
761 void (*m_scene_data_lookup_deriv_color)(
762 tct_deriv_arr_float_3 *result,
763 Texture_handler_base const *self_base,
765 tct_uint scene_data_id,
766 tct_deriv_arr_float_3 const *default_value,
767 tct_bool uniform_lookup);
768};
769
772
775
780{
784};
785
790{
794};
795
796
799{
800 void const *shared_data;
803};
804
807{
808 BSDF_EVENT_ABSORB = 0,
809
810 BSDF_EVENT_DIFFUSE = 1,
811 BSDF_EVENT_GLOSSY = 1 << 1,
812 BSDF_EVENT_SPECULAR = 1 << 2,
813 BSDF_EVENT_REFLECTION = 1 << 3,
814 BSDF_EVENT_TRANSMISSION = 1 << 4,
815
816 BSDF_EVENT_DIFFUSE_REFLECTION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_REFLECTION,
817 BSDF_EVENT_DIFFUSE_TRANSMISSION = BSDF_EVENT_DIFFUSE | BSDF_EVENT_TRANSMISSION,
818 BSDF_EVENT_GLOSSY_REFLECTION = BSDF_EVENT_GLOSSY | BSDF_EVENT_REFLECTION,
819 BSDF_EVENT_GLOSSY_TRANSMISSION = BSDF_EVENT_GLOSSY | BSDF_EVENT_TRANSMISSION,
820 BSDF_EVENT_SPECULAR_REFLECTION = BSDF_EVENT_SPECULAR | BSDF_EVENT_REFLECTION,
821 BSDF_EVENT_SPECULAR_TRANSMISSION = BSDF_EVENT_SPECULAR | BSDF_EVENT_TRANSMISSION
822 MI_NEURAYLIB_DEPRECATED_ENUM_VALUE(BSDF_EVENT_FORCE_32_BIT, 0xffffffffU)
823};
824
828#define MI_NEURAYLIB_BSDF_USE_MATERIAL_IOR (-1.0f)
829
832{
834
835 DF_FLAGS_ALLOW_REFLECT = 1,
836 DF_FLAGS_ALLOW_TRANSMIT = 2,
837 DF_FLAGS_ALLOW_REFLECT_AND_TRANSMIT = DF_FLAGS_ALLOW_REFLECT | DF_FLAGS_ALLOW_TRANSMIT,
838 DF_FLAGS_ALLOWED_SCATTER_MODE_MASK = DF_FLAGS_ALLOW_REFLECT_AND_TRANSMIT
839 MI_NEURAYLIB_DEPRECATED_ENUM_VALUE(DF_FLAGS_FORCE_32_BIT, 0xffffffffU)
840};
841
844{
847};
848
850struct alignas(16) Bsdf_sample_data_base {};
851
852template <Target_code_color_mode C = TCCM_RGB>
853struct Bsdf_sample_data : public Bsdf_sample_data_base {};
854
855// Explicit specialization for RGB case
856template<>
857struct Bsdf_sample_data<TCCM_RGB> : public Bsdf_sample_data_base
858{
859 tct_float3 ior1;
860 tct_float3 ior2;
861 tct_float3 k1;
862
863 tct_float3 k2;
864
865 tct_float4_a16 xi;
866
867 tct_float pdf;
868 tct_float3 bsdf_over_pdf;
869 Bsdf_event_type event_type;
870 tct_int handle;
871
872 Df_flags flags;
874};
875
876// Explicit specialization for spectral sampling case
877template<>
878struct Bsdf_sample_data<TCCM_SPECTRAL_SAMPLING> : public Bsdf_sample_data_base
879{
880 tct_spectral_sample ior1;
881 tct_spectral_sample ior2;
882 tct_float3 k1;
883
884 tct_float3 k2;
885
886 tct_float4_a16 xi;
887
888 tct_spectral_sample pdf;
889 tct_spectral_sample bsdf_over_pdf;
890 Bsdf_event_type event_type;
891 tct_int handle;
892
893 Df_flags flags;
895};
896
899{
906};
907
909struct alignas(16) Bsdf_evaluate_data_base {};
910
911template<Df_handle_slot_mode N, Target_code_color_mode C = TCCM_RGB>
912struct Bsdf_evaluate_data : public Bsdf_evaluate_data_base {};
913
914template<Df_handle_slot_mode N>
915struct Bsdf_evaluate_data<N, TCCM_RGB> : public Bsdf_evaluate_data_base
916{
917 tct_float3 ior1;
918 tct_float3 ior2;
919 tct_float3 k1;
920
921 tct_float3 k2;
922 tct_int handle_offset;
925 tct_float3 bsdf_diffuse[static_cast<size_t>(N)];
927 tct_float3 bsdf_glossy[static_cast<size_t>(N)];
929 tct_float pdf;
930
931 Df_flags flags;
933};
934
935template<Df_handle_slot_mode N>
936struct Bsdf_evaluate_data<N, TCCM_SPECTRAL_SAMPLING> : public Bsdf_evaluate_data_base
937{
938 tct_spectral_sample ior1;
939 tct_spectral_sample ior2;
940 tct_float3 k1;
941
942 tct_float3 k2;
943 tct_int handle_offset;
946 tct_spectral_sample bsdf_diffuse[static_cast<size_t>(N)];
948 tct_spectral_sample bsdf_glossy[static_cast<size_t>(N)];
950 tct_spectral_sample pdf;
951
952 Df_flags flags;
954};
955
956template<>
957struct Bsdf_evaluate_data<DF_HSM_POINTER, TCCM_RGB> : public Bsdf_evaluate_data_base
958{
959 tct_float3 ior1;
960 tct_float3 ior2;
961 tct_float3 k1;
962
963 tct_float3 k2;
964 tct_int handle_offset;
966 tct_int handle_count;
967 tct_float3* bsdf_diffuse;
968 tct_float3* bsdf_glossy;
969 tct_float pdf;
970
971 Df_flags flags;
973};
974
975template<>
976struct Bsdf_evaluate_data<DF_HSM_POINTER, TCCM_SPECTRAL_SAMPLING> : public Bsdf_evaluate_data_base
977{
978 tct_spectral_sample ior1;
979 tct_spectral_sample ior2;
980 tct_float3 k1;
981
982 tct_float3 k2;
983 tct_int handle_offset;
985 tct_int handle_count;
987 tct_spectral_sample* bsdf_diffuse;
988 tct_spectral_sample* bsdf_glossy;
989 tct_spectral_sample pdf;
990
991 Df_flags flags;
993};
994
995template<>
996struct Bsdf_evaluate_data<DF_HSM_NONE, TCCM_RGB> : public Bsdf_evaluate_data_base
997{
998 tct_float3 ior1;
999 tct_float3 ior2;
1000 tct_float3 k1;
1001
1002 tct_float3 k2;
1003 tct_float3 bsdf_diffuse;
1004 tct_float3 bsdf_glossy;
1005 tct_float pdf;
1006
1007 Df_flags flags;
1009};
1010
1011template<>
1012struct Bsdf_evaluate_data<DF_HSM_NONE, TCCM_SPECTRAL_SAMPLING> : public Bsdf_evaluate_data_base
1013{
1014 tct_spectral_sample ior1;
1015 tct_spectral_sample ior2;
1016 tct_float3 k1;
1017
1018 tct_float3 k2;
1019 tct_spectral_sample bsdf_diffuse;
1020 tct_spectral_sample bsdf_glossy;
1021 tct_spectral_sample pdf;
1022
1023 Df_flags flags;
1025};
1026
1028struct alignas(16) Bsdf_pdf_data_base {};
1029
1030template <Target_code_color_mode C = TCCM_RGB>
1031struct Bsdf_pdf_data : public Bsdf_pdf_data_base {};
1032
1033// Explicit specialization for RGB case
1034template<>
1035struct Bsdf_pdf_data<TCCM_RGB> : public Bsdf_pdf_data_base
1036{
1037 tct_float3 ior1;
1038 tct_float3 ior2;
1039 tct_float3 k1;
1040
1041 tct_float3 k2;
1042 tct_float pdf;
1043
1044 Df_flags flags;
1046};
1047
1048// Explicit specialization for spectral case
1049template<>
1050struct Bsdf_pdf_data<TCCM_SPECTRAL_SAMPLING> : public Bsdf_pdf_data_base
1051{
1052 tct_spectral_sample ior1;
1053 tct_spectral_sample ior2;
1054 tct_float3 k1;
1055
1056 tct_float3 k2;
1057 tct_spectral_sample pdf;
1058
1059 Df_flags flags;
1061};
1062
1064struct alignas(16) Bsdf_auxiliary_data_base {};
1065
1066template<Df_handle_slot_mode N, Target_code_color_mode C = TCCM_RGB>
1067struct Bsdf_auxiliary_data : public Bsdf_auxiliary_data_base {};
1068
1069template<Df_handle_slot_mode N>
1070struct Bsdf_auxiliary_data<N, TCCM_RGB> : public Bsdf_auxiliary_data_base
1071{
1072 tct_float3 ior1;
1073 tct_float3 ior2;
1074 tct_float3 k1;
1075
1076 tct_int handle_offset;
1079 tct_float3 albedo_diffuse[static_cast<size_t>(N)];
1081 tct_float3 albedo_glossy[static_cast<size_t>(N)];
1083 tct_float3 normal[static_cast<size_t>(N)];
1084 tct_float3 roughness[static_cast<size_t>(N)];
1086
1087 Df_flags flags;
1089};
1090
1091template<Df_handle_slot_mode N>
1092struct Bsdf_auxiliary_data<N, TCCM_SPECTRAL_SAMPLING> : public Bsdf_auxiliary_data_base
1093{
1094 tct_spectral_sample ior1;
1095 tct_spectral_sample ior2;
1096 tct_float3 k1;
1097
1098 tct_int handle_offset;
1101 tct_spectral_sample albedo_diffuse[static_cast<size_t>(N)];
1103 tct_spectral_sample albedo_glossy[static_cast<size_t>(N)];
1105 tct_float3 normal[static_cast<size_t>(N)];
1106 tct_float3 roughness[static_cast<size_t>(N)];
1109
1110 Df_flags flags;
1112};
1113
1114template<>
1115struct Bsdf_auxiliary_data<DF_HSM_POINTER, TCCM_RGB> : public Bsdf_auxiliary_data_base
1116{
1117 tct_float3 ior1;
1118 tct_float3 ior2;
1119 tct_float3 k1;
1120
1121 tct_int handle_offset;
1124 tct_int handle_count;
1125 tct_float3* albedo_diffuse;
1126 tct_float3* albedo_glossy;
1127 tct_float3* normal;
1128 tct_float3* roughness;
1130
1131 Df_flags flags;
1133};
1134
1135template<>
1136struct Bsdf_auxiliary_data<DF_HSM_POINTER, TCCM_SPECTRAL_SAMPLING> : public Bsdf_auxiliary_data_base
1137{
1138 tct_spectral_sample ior1;
1139 tct_spectral_sample ior2;
1140 tct_float3 k1;
1141
1142 tct_int handle_offset;
1145 tct_int handle_count;
1146 tct_spectral_sample* albedo_diffuse;
1147 tct_spectral_sample* albedo_glossy;
1148 tct_float3* normal;
1149 tct_float3* roughness;
1151
1152 Df_flags flags;
1154};
1155
1156template<>
1157struct Bsdf_auxiliary_data<DF_HSM_NONE, TCCM_RGB> : public Bsdf_auxiliary_data_base
1158{
1159 tct_float3 ior1;
1160 tct_float3 ior2;
1161 tct_float3 k1;
1162
1163 tct_float3 albedo_diffuse;
1164 tct_float3 albedo_glossy;
1165 tct_float3 normal;
1166 tct_float3 roughness;
1168
1169 Df_flags flags;
1171};
1172
1173template<>
1174struct Bsdf_auxiliary_data<DF_HSM_NONE, TCCM_SPECTRAL_SAMPLING> : public Bsdf_auxiliary_data_base
1175{
1176 tct_spectral_sample ior1;
1177 tct_spectral_sample ior2;
1178 tct_float3 k1;
1179
1180 tct_spectral_sample albedo_diffuse;
1181 tct_spectral_sample albedo_glossy;
1182 tct_float3 normal;
1183 tct_float3 roughness;
1185
1186 Df_flags flags;
1188};
1189
1190// Signatures for generated target code functions.
1191
1201 void *result,
1202 Shading_state_environment const *state,
1203 Resource_data const *res_data,
1204 char const *arg_block_data);
1205
1206
1216 void *result,
1217 Shading_state_material const *state,
1218 Resource_data const *res_data,
1219 char const *arg_block_data);
1220
1221
1231 void *result,
1233 Resource_data const *res_data,
1234 char const *arg_block_data);
1235
1236
1237// SWIG has problems with these function type definitions, so ignore in SWIG.
1238#ifndef SWIG
1239template<typename T>
1240struct Material_function
1241{
1251 using Type = T(
1252 Shading_state_material const *state,
1253 Resource_data const *res_data,
1254 char const *arg_block_data);
1255
1265 using Type_with_derivs = T(
1267 Resource_data const *res_data,
1268 char const *arg_block_data);
1269};
1270#endif // not SWIG
1271
1272
1286 Resource_data const *res_data,
1287 char const *arg_block_data);
1288
1289
1303 Resource_data const *res_data,
1304 char const *arg_block_data);
1305
1306
1317 Shading_state_material const *state,
1318 Resource_data const *res_data,
1319 char const *arg_block_data);
1320
1321
1333 Resource_data const *res_data,
1334 char const *arg_block_data);
1335
1336
1347 Shading_state_material const *state,
1348 Resource_data const *res_data,
1349 char const *arg_block_data);
1350
1351
1363 Resource_data const *res_data,
1364 char const *arg_block_data);
1365
1366
1376 Bsdf_pdf_data_base *data,
1377 Shading_state_material const *state,
1378 Resource_data const *res_data,
1379 char const *arg_block_data);
1380
1381
1391 Bsdf_pdf_data_base *data,
1393 Resource_data const *res_data,
1394 char const *arg_block_data);
1395
1406 Shading_state_material const *state,
1407 Resource_data const *res_data,
1408 char const *arg_block_data);
1409
1410
1422 Resource_data const *res_data,
1423 char const *arg_block_data);
1424
1427{
1428 EDF_EVENT_NONE = 0,
1429 EDF_EVENT_EMISSION = 1
1430 MI_NEURAYLIB_DEPRECATED_ENUM_VALUE(EDF_EVENT_FORCE_32_BIT, 0xffffffffU)
1431};
1432
1433
1435struct alignas(16) Edf_sample_data_base {};
1436
1437template <Target_code_color_mode C = TCCM_RGB>
1438struct Edf_sample_data : public Edf_sample_data_base {};
1439
1440// Explicit specialization for RGB case
1441template<>
1442struct Edf_sample_data<TCCM_RGB> : public Edf_sample_data_base
1443{
1444 tct_float4_a16 xi;
1445 tct_float3 k1;
1446 tct_float pdf;
1447 tct_float3 edf_over_pdf;
1448 Edf_event_type event_type;
1449 tct_int handle;
1450};
1451
1452// Explicit specialization for spectral sampling case
1453template<>
1454struct Edf_sample_data<TCCM_SPECTRAL_SAMPLING> : public Edf_sample_data_base
1455{
1456 tct_float4_a16 xi;
1457 tct_float3 k1;
1458 tct_spectral_sample pdf;
1459 tct_spectral_sample edf_over_pdf;
1460 Edf_event_type event_type;
1461 tct_int handle;
1462};
1463
1465struct alignas(16) Edf_evaluate_data_base {};
1466
1467template<Df_handle_slot_mode N, Target_code_color_mode C = TCCM_RGB>
1468struct Edf_evaluate_data : public Edf_evaluate_data_base {};
1469
1470template<Df_handle_slot_mode N>
1471struct Edf_evaluate_data<N, TCCM_RGB> : public Edf_evaluate_data_base
1472{
1473 tct_float3 k1;
1474 tct_int handle_offset;
1477 tct_float cos;
1478 tct_float3 edf[static_cast<size_t>(N)];
1479 tct_float pdf;
1480};
1481
1482template<Df_handle_slot_mode N>
1483struct Edf_evaluate_data<N, TCCM_SPECTRAL_SAMPLING> : public Edf_evaluate_data_base
1484{
1485 tct_float3 k1;
1486 tct_int handle_offset;
1489 tct_float cos;
1490 tct_spectral_sample edf[static_cast<size_t>(N)];
1491 tct_spectral_sample pdf;
1492};
1493
1494template<>
1495struct Edf_evaluate_data<DF_HSM_POINTER, TCCM_RGB> : public Edf_evaluate_data_base
1496{
1497 tct_float3 k1;
1498 tct_int handle_offset;
1501 tct_int handle_count;
1502 tct_float cos;
1503 tct_float3* edf;
1504 tct_float pdf;
1505};
1506
1507template<>
1508struct Edf_evaluate_data<DF_HSM_POINTER, TCCM_SPECTRAL_SAMPLING> : public Edf_evaluate_data_base
1509{
1510 tct_float3 k1;
1511 tct_int handle_offset;
1514 tct_int handle_count;
1515 tct_float cos;
1516 tct_spectral_sample* edf;
1517 tct_spectral_sample pdf;
1518};
1519
1520template<>
1521struct Edf_evaluate_data<DF_HSM_NONE, TCCM_RGB> : public Edf_evaluate_data_base
1522{
1523 tct_float3 k1;
1524 tct_float cos;
1525 tct_float3 edf;
1526 tct_float pdf;
1527};
1528
1529template<>
1530struct Edf_evaluate_data<DF_HSM_NONE, TCCM_SPECTRAL_SAMPLING> : public Edf_evaluate_data_base
1531{
1532 tct_float3 k1;
1533 tct_float cos;
1534 tct_spectral_sample edf;
1535 tct_spectral_sample pdf;
1536};
1537
1539struct alignas(16) Edf_pdf_data
1540{
1543};
1544
1546struct alignas(16) Edf_auxiliary_data_base {};
1547
1548template<Df_handle_slot_mode N>
1549struct Edf_auxiliary_data : public Edf_auxiliary_data_base
1550{
1551 tct_float3 k1;
1552 tct_int handle_offset;
1555
1556 // reserved for future use
1557};
1558
1559template<>
1560struct Edf_auxiliary_data<DF_HSM_POINTER> : public Edf_auxiliary_data_base
1561{
1562 tct_float3 k1;
1563 tct_int handle_offset;
1566 tct_int handle_count;
1567
1568 // reserved for future use
1569};
1570
1571template<>
1572struct Edf_auxiliary_data<DF_HSM_NONE> : public Edf_auxiliary_data_base
1573{
1574 tct_float3 k1;
1575
1576 // reserved for future use
1577};
1578
1592 Resource_data const *res_data,
1593 char const *arg_block_data);
1594
1595
1609 Resource_data const *res_data,
1610 char const *arg_block_data);
1611
1612
1623 Shading_state_material const *state,
1624 Resource_data const *res_data,
1625 char const *arg_block_data);
1626
1627
1639 Resource_data const *res_data,
1640 char const *arg_block_data);
1641
1642
1653 Shading_state_material const *state,
1654 Resource_data const *res_data,
1655 char const *arg_block_data);
1656
1657
1669 Resource_data const *res_data,
1670 char const *arg_block_data);
1671
1672
1681using Edf_pdf_function = void(
1682 Edf_pdf_data *data,
1683 Shading_state_material const *state,
1684 Resource_data const *res_data,
1685 char const *arg_block_data);
1686
1687
1697 Edf_pdf_data *data,
1699 Resource_data const *res_data,
1700 char const *arg_block_data);
1701
1702
1713 Shading_state_material const *state,
1714 Resource_data const *res_data,
1715 char const *arg_block_data);
1716
1717
1729 Resource_data const *res_data,
1730 char const *arg_block_data);
1731 // end group mi_neuray_mdl_compiler
1733
1734} // namespace neuraylib
1735
1736} // namespace mi
1737
1738#endif // MI_NEURAYLIB_TARGET_CODE_TYPES_H
int Sint32
32-bit signed integer.
Definition: types.h:46
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:546
math::Vector_struct<Float32, 2> Float32_2_struct
Vector of two Float32 (underlying POD type).
Definition: vector_typedefs.h:187
math::Vector_struct<Float32, 4> Float32_4_struct
Vector of four Float32 (underlying POD type).
Definition: vector_typedefs.h:201
math::Vector_struct<Float32, 3> Float32_3_struct
Vector of three Float32 (underlying POD type).
Definition: vector_typedefs.h:194
bool tct_bool
A bool.
Definition: target_code_types.h:100
float tct_float
A float.
Definition: target_code_types.h:74
void(Bsdf_sample_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_sample_function_with_derivs
Signature of the importance sampling function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1334
void(void *result, Shading_state_environment const *state, Resource_data const *res_data, char const *arg_block_data) Environment_function
Signature of environment functions created via mi::neuraylib::IMdl_backend::translate_environment() a...
Definition: target_code_types.h:1204
Df_handle_slot_mode
Type of Bsdf_evaluate_data variants, depending on the backend and its configuration.
Definition: target_code_types.h:899
mi::Float32_4_struct tct_float4
A float4.
Definition: target_code_types.h:83
mi::Float32_2_struct tct_float2
A float2.
Definition: target_code_types.h:77
Bsdf_event_type
The type of events created by BSDF importance sampling.
Definition: target_code_types.h:807
void(Edf_sample_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Edf_sample_function
Signature of the importance sampling function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1625
void(Edf_auxiliary_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Edf_auxiliary_function_with_derivs
Signature of the auxiliary function for material distribution functions created via mi::neuraylib::IM...
Definition: target_code_types.h:1730
void(Bsdf_auxiliary_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_auxiliary_function
Signature of the auxiliary function for material distribution functions created via mi::neuraylib::IM...
Definition: target_code_types.h:1408
tct_traits<true>::tct_derivable_float tct_deriv_float
A float with derivatives.
Definition: target_code_types.h:139
void(void *result, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Material_expr_function
Signature of material expression functions created via mi::neuraylib::IMdl_backend::translate_materia...
Definition: target_code_types.h:1219
void(Bsdf_pdf_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_pdf_function
Signature of the probability density function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1379
void(Bsdf_evaluate_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_evaluate_function_with_derivs
Signature of the evaluation function for material distribution functions created via mi::neuraylib::I...
Definition: target_code_types.h:1364
void(Edf_evaluate_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Edf_evaluate_function
Signature of the evaluation function for material distribution functions created via mi::neuraylib::I...
Definition: target_code_types.h:1655
void(Edf_sample_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Edf_sample_function_with_derivs
Signature of the importance sampling function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1640
void(Edf_auxiliary_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Edf_auxiliary_function
Signature of the auxiliary function for material distribution functions created via mi::neuraylib::IM...
Definition: target_code_types.h:1715
Mbsdf_part
MBSDFs can consist of two parts, which can be selected using this enumeration.
Definition: target_code_types.h:358
void(Shading_state_material *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_init_function
Signature of the initialization function for material distribution functions created via mi::neurayli...
Definition: target_code_types.h:1287
Tex_wrap_mode
The texture wrap modes as defined by tex::wrap_mode in the MDL specification.
Definition: target_code_types.h:339
void(Shading_state_material_with_derivs *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_init_function_with_derivs
Signature of the initialization function for material distribution functions created via mi::neurayli...
Definition: target_code_types.h:1304
mi::Float32_3_struct tct_float3
A float3.
Definition: target_code_types.h:80
void(Edf_evaluate_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Edf_evaluate_function_with_derivs
Signature of the evaluation function for material distribution functions created via mi::neuraylib::I...
Definition: target_code_types.h:1670
void(void *result, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Material_expr_function_with_derivs
Signature of material expression functions created via mi::neuraylib::IMdl_backend::translate_materia...
Definition: target_code_types.h:1234
void(Bsdf_auxiliary_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_auxiliary_function_with_derivs
Signature of the auxiliary function for material distribution functions created via mi::neuraylib::IM...
Definition: target_code_types.h:1423
Edf_event_type
The type of events created by EDF importance sampling.
Definition: target_code_types.h:1427
mi::Sint32 tct_int
An int.
Definition: target_code_types.h:92
void(Edf_pdf_data *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Edf_pdf_function
Signature of the probability density function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1685
mi::Uint32 tct_uint
An unsigned int.
Definition: target_code_types.h:95
void(Shading_state_material_with_derivs *state, Resource_data const *res_data, char const *arg_block_data) Edf_init_function_with_derivs
Signature of the initialization function for material distribution functions created via mi::neurayli...
Definition: target_code_types.h:1610
Df_flags
Flags controlling the calculation of DF results.
Definition: target_code_types.h:832
tct_traits<true>::tct_derivable_float2 tct_deriv_float2
A float2 with derivatives.
Definition: target_code_types.h:142
void(Bsdf_evaluate_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_evaluate_function
Signature of the evaluation function for material distribution functions created via mi::neuraylib::I...
Definition: target_code_types.h:1349
void(Edf_pdf_data *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Edf_pdf_function_with_derivs
Signature of the probability density function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1700
void(Bsdf_pdf_data_base *data, Shading_state_material_with_derivs const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_pdf_function_with_derivs
Signature of the probability density function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1394
tct_traits<true>::tct_derivable_float4 tct_deriv_float4
A float4 with derivatives.
Definition: target_code_types.h:148
void(Shading_state_material *state, Resource_data const *res_data, char const *arg_block_data) Edf_init_function
Signature of the initialization function for material distribution functions created via mi::neurayli...
Definition: target_code_types.h:1593
void(Bsdf_sample_data_base *data, Shading_state_material const *state, Resource_data const *res_data, char const *arg_block_data) Bsdf_sample_function
Signature of the importance sampling function for material distribution functions created via mi::neu...
Definition: target_code_types.h:1319
tct_traits<true>::tct_derivable_float3 tct_deriv_float3
A float3 with derivatives.
Definition: target_code_types.h:145
Target_code_color_mode
Spectral rendering enabled or disabled depending on the backend and its configuration.
Definition: target_code_types.h:844
@ DF_HSM_POINTER
Uses renderer defined buffers; not supported by all backends.
Definition: target_code_types.h:900
@ DF_HSM_FIXED_2
fixed size array for processing 2 handle at a time
Definition: target_code_types.h:903
@ DF_HSM_NONE
No slots, handles are ignored completely.
Definition: target_code_types.h:901
@ DF_HSM_FIXED_8
fixed size array for processing 8 handle at a time
Definition: target_code_types.h:905
@ DF_HSM_FIXED_1
fixed size array for processing 1 handle at a time
Definition: target_code_types.h:902
@ DF_HSM_FIXED_4
fixed size array for processing 4 handle at a time
Definition: target_code_types.h:904
@ MBSDF_DATA_TRANSMISSION
the bidirectional transmission distribution function (BTDF)
Definition: target_code_types.h:363
@ MBSDF_DATA_REFLECTION
the bidirectional reflection distribution function (BRDF)
Definition: target_code_types.h:360
@ TEX_WRAP_CLIP
tex::wrap_clip: makes the texture lookup return zero for texture coordinates outside of the range
Definition: target_code_types.h:353
@ TEX_WRAP_MIRRORED_REPEAT
tex::wrap_mirrored_repeat: like wrap_repeat but takes one minus the fractional part every other inter...
Definition: target_code_types.h:349
@ TEX_WRAP_REPEAT
tex::wrap_repeat: takes the fractional part of the lookup coordinate effectively repeating the textur...
Definition: target_code_types.h:345
@ TEX_WRAP_CLAMP
tex::wrap_clamp: clamps the lookup coordinate to the range
Definition: target_code_types.h:341
@ DF_FLAGS_NONE
allows nothing -> black
Definition: target_code_types.h:833
@ TCCM_RGB
no spectral sampling, use RGB
Definition: target_code_types.h:845
@ TCCM_SPECTRAL_SAMPLING
spectral sampling, use spectral samples
Definition: target_code_types.h:846
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: example_derivatives.dox:5
Major and minor version number and an optional qualifier.
Generic storage class template for math vector representations storing DIM elements of type T.
Definition: vector.h:135
Input and output structure for BSDF auxiliary calculation data.
Definition: target_code_types.h:1064
Input and output structure for BSDF evaluation data.
Definition: target_code_types.h:909
Input and output structure for BSDF PDF calculation data.
Definition: target_code_types.h:1028
Input and output structure for BSDF sampling data.
Definition: target_code_types.h:850
Input and output structure for EDF auxiliary calculation data.
Definition: target_code_types.h:1546
Input and output structure for EDF evaluation data.
Definition: target_code_types.h:1465
Input and output structure for EDF PDF calculation data.
Definition: target_code_types.h:1540
tct_float pdf
output: pdf (non-projected hemisphere)
Definition: target_code_types.h:1542
tct_float3 k1
input: outgoing direction
Definition: target_code_types.h:1541
Input and output structure for EDF sampling data.
Definition: target_code_types.h:1435
The data structure providing access to resources for generated code.
Definition: target_code_types.h:799
void const * shared_data
currently unused, should be nullptr
Definition: target_code_types.h:800
Texture_handler_base const * texture_handler
will be provided as "self" parameter to texture functions
Definition: target_code_types.h:801
The MDL environment state structure inside the MDL SDK is a representation of the renderer state in t...
Definition: target_code_types.h:174
tct_float3 direction
The result of state::direction().
Definition: target_code_types.h:177
char const * ro_data_segment
A pointer to a read-only data segment.
Definition: target_code_types.h:192
The MDL material state structure inside the MDL SDK is a representation of the renderer state as defi...
Definition: target_code_types.h:225
tct_float3 normal
The result of state::normal().
Definition: target_code_types.h:232
char const * ro_data_segment
A pointer to a read-only data segment.
Definition: target_code_types.h:286
tct_int object_id
The result of state::object_id().
Definition: target_code_types.h:306
traits::tct_derivable_float3 position
The result of state::position().
Definition: target_code_types.h:240
tct_float3 const * tangent_v
An array containing the results of state::texture_tangent_v(i).
Definition: target_code_types.h:263
tct_float4_a16 const * object_to_world
A 4x4 transformation matrix in row-major order transforming from object to world coordinates.
Definition: target_code_types.h:300
traits::tct_derivable_float3 const * text_coords
An array containing the results of state::texture_coordinate(i).
Definition: target_code_types.h:249
tct_float4_a16 const * world_to_object
A 4x4 transformation matrix in row-major order transforming from world to object coordinates.
Definition: target_code_types.h:293
tct_float animation_time
The result of state::animation_time().
Definition: target_code_types.h:244
tct_float3 geom_normal
The result of state::geometry_normal().
Definition: target_code_types.h:236
tct_float3 const * tangent_u
An array containing the results of state::texture_tangent_u(i).
Definition: target_code_types.h:256
tct_float4_a16 * text_results
The texture results lookup table.
Definition: target_code_types.h:271
tct_float meters_per_scene_unit
The result of state::meters_per_scene_unit().
Definition: target_code_types.h:311
The MDL material state structure for spectral rendering.
Definition: target_code_types.h:317
tct_spectral_sample spectral_wavelengths
currently active wavelengths in nm
Definition: target_code_types.h:319
The texture handler structure that is passed to the texturing functions.
Definition: target_code_types.h:780
Texture_handler_vtable const * vtable
In vtable-mode, the vtable field is used to call the texturing functions.
Definition: target_code_types.h:783
The texture handler structure that is passed to the texturing functions with derivative support.
Definition: target_code_types.h:790
Texture_handler_deriv_vtable const * vtable
In vtable-mode, the vtable field is used to call the texturing functions.
Definition: target_code_types.h:793
The runtime for bitmap texture access for the generated target code can optionally be implemented in ...
Definition: target_code_types.h:375
A template struct with derivatives.
Definition: target_code_types.h:110
A floatN type for spectral sampling.
Definition: target_code_types.h:103
Helper traits struct to switch between derivative and non-derivative types.
Definition: target_code_types.h:116
#define MDL_DF_SPECTRAL_SAMPLES
The default number of elements in a spectral sample.
Definition: target_code_types.h:20
Typedefs for types from the math API.