36 b.use_custom_socket_order();
41 .default_value({0.8f, 0.8f, 0.8f, 1.0f})
43 "Color of the material used for diffuse, subsurface, metallic and transmission");
44#define SOCK_BASE_COLOR_ID 0
51 "Blends between a dielectric and metallic material model. "
52 "At 0.0 the material consists of a diffuse or transmissive base layer, "
53 "with a specular reflection layer on top. A value of 1.0 gives a fully specular "
54 "reflection tinted with the base color, without diffuse reflection or transmission");
55#define SOCK_METALLIC_ID 1
62 "Specifies microfacet roughness of the surface for specular reflection and transmission"
63 " (0.0 is a perfect mirror reflection, 1.0 is completely rough)");
64#define SOCK_ROUGHNESS_ID 2
70 "Index of Refraction (IOR) for specular reflection and transmission. "
71 "For most materials, the IOR is between 1.0 (vacuum and air) and 4.0 (germanium). "
72 "The default value of 1.5 is a good approximation for glass");
79 .description(
"Controls the transparency of the surface, with 1.0 fully opaque");
80#define SOCK_ALPHA_ID 4
84 "A thin structure with the same material on both sides, useful for modeling thin "
85 "objects such as window, papers and leaves");
86#define SOCK_THIN_WALL_ID 5
88#define SOCK_NORMAL_ID 6
89 b.add_input<
decl::Float>(
"Weight"_ustr).available(is_gpu_internal);
90#define SOCK_WEIGHT_ID 7
100 "Specifies microfacet roughness of the diffuse base"
101 " (0.0 is perfect lambertian reflection, 1.0 is completely rough)");
102#define SOCK_DIFFUSE_ROUGHNESS_ID 8
112 if (radius_socket.is_inactive()) {
121 .short_label(
"Weight"_ustr)
123 "Blend between diffuse surface and subsurface scattering. "
124 "Typically should be zero or one (either fully diffuse or subsurface)");
125#define SOCK_SUBSURFACE_WEIGHT_ID 9
127 .default_value({1.0f, 0.2f, 0.1f})
130 .short_label(
"Radius"_ustr)
131 .description(
"Scattering radius per color channel (RGB), multiplied with Scale")
132 .usage_by_bool(
"Thin Wall"_ustr,
false);
133#define SOCK_SUBSURFACE_RADIUS_ID 10
135 .default_value(0.005f)
139 .short_label(
"Scale"_ustr)
140 .description(
"Scale factor of the subsurface scattering radius")
141 .usage_by_bool(
"Thin Wall"_ustr,
false);
142#define SOCK_SUBSURFACE_SCALE_ID 11
148 .short_label(
"IOR"_ustr)
149 .description(
"Index of Refraction (IOR) used for rays that enter the subsurface component")
151#define SOCK_SUBSURFACE_IOR_ID 12
157 .short_label(
"Anisotropy"_ustr)
159 "Directionality of volume scattering within the subsurface medium. "
160 "Zero scatters uniformly in all directions, positive values scatter more in the forward "
161 "direction, and negative values scatter more backwards. "
162 "For example, skin has been measured to have an anisotropy of 0.8")
169#define SOCK_SUBSURFACE_ANISOTROPY_ID 13
181 .short_label(
"IOR Level"_ustr)
183 "Adjustment to the Index of Refraction (IOR) to increase or decrease specular intensity "
184 "(0.5 means no adjustment, 0 removes all reflections, 1 doubles them at normal "
186#define SOCK_SPECULAR_ID 14
188 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
189 .short_label(
"Tint"_ustr)
191 "Tint dielectric reflection at normal incidence for artistic control, and metallic "
192 "reflection at near-grazing incidence to simulate complex index of refraction")
194#define SOCK_SPECULAR_TINT_ID 15
200 .short_label(
"Anisotropy"_ustr)
202 "Amount of anisotropy for specular reflection. "
203 "Higher values give elongated highlights along the tangent direction");
204#define SOCK_ANISOTROPIC_ID 16
210 .description(
"Rotates the direction of anisotropy, with 1.0 going full circle");
211#define SOCK_ANISOTROPIC_ROTATION_ID 17
214 .
description(
"Controls the tangent direction for anisotropy");
215#define SOCK_TANGENT_ID 18
224 .short_label(
"Weight"_ustr)
225 .description(
"Blend between transmission and other base layer components");
226#define SOCK_TRANSMISSION_WEIGHT_ID 19
232 .description(
"Linearly scales the amount of dispersion");
233#define SOCK_TRANSMISSION_DISPERSION_SCALE_ID 20
235 .default_value(20.0f)
239 "Abbe number of the base dielectric medium. Smaller number gives stronger dispersion");
240#define SOCK_TRANSMISSION_DISPERSION_ABBE_NUMBER_ID 21
249 .short_label(
"Weight"_ustr)
251 "Controls the intensity of the coat layer, both the reflection and the tinting. "
252 "Typically should be zero or one for physically-based materials");
253#define SOCK_COAT_WEIGHT_ID 22
255 .default_value(0.03f)
259 .short_label(
"Roughness"_ustr)
260 .description(
"The roughness of the coat layer");
261#define SOCK_COAT_ROUGHNESS_ID 23
268 "The Index of Refraction (IOR) of the coat layer "
269 "(affects its reflectivity as well as the falloff of coat tinting)");
270#define SOCK_COAT_IOR_ID 24
272 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
273 .short_label(
"Tint"_ustr)
275 "Adds a colored tint to the coat layer by modeling absorption in the layer. "
276 "Saturation increases at shallower angles, as the light travels farther "
277 "through the medium (depending on the Coat IOR)")
279#define SOCK_COAT_TINT_ID 25
281#define SOCK_COAT_NORMAL_ID 26
290 .short_label(
"Weight"_ustr)
292 "Intensity of the sheen layer, which simulates very small fibers on the surface");
293#define SOCK_SHEEN_WEIGHT_ID 27
299 .short_label(
"Roughness"_ustr)
301 "Roughness of the sheen layer. Low and high roughness values produce fuzzy or dusty "
302 "appearance, respectively");
303#define SOCK_SHEEN_ROUGHNESS_ID 28
305 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
308 .description(
"Color of the sheen reflection");
309#define SOCK_SHEEN_TINT_ID 29
314 .default_value({1.0f, 1.0f, 1.0f, 1.0f})
315 .short_label(
"Color"_ustr)
316 .
description(
"Color of light emission from the surface");
317#define SOCK_EMISSION_ID 30
324 "Strength of the emitted light. A value of 1.0 ensures "
325 "that the object in the image has the exact same color as the Emission Color")
327#define SOCK_EMISSION_STRENGTH_ID 31
336 .description(
"Thickness of the film in nanometers");
337#define SOCK_THIN_FILM_THICKNESS_ID 32
339 .default_value(1.33f)
342 .
description(
"Index of refraction (IOR) of the thin film");
343#define SOCK_THIN_FILM_IOR_ID 33
401 GPUNodeLink *subsurface_random_walk_radius_scale =
nullptr;
402 float random_walk_scale = 1.0f;
404 random_walk_scale = 4.0f *
M_PI;
406 subsurface_random_walk_radius_scale =
GPU_constant(&random_walk_scale);
418 if (use_transparency) {
424 if (use_translucent) {
431 const bool refraction_might_be_tinted = use_refract &&
433 coat_might_be_tinted);
437 specular_might_be_tinted |= coat_might_be_tinted;
439 specular_might_be_tinted |= (refraction_might_be_tinted &&
442 if (specular_might_be_tinted) {
446 if (refraction_might_be_tinted) {
458 const float zero = 0.0f;
473 "node_bsdf_principled",
477 subsurface_random_walk_radius_scale,
484 const int sss_method =
node->custom2;
494 using InputsType = std::map<std::string, NodeItem>;
497 auto bsdf_inputs = [&]() -> InputsType {
499 {
"base_color", get_input_value(
"Base Color", NodeItem::Type::Color3)},
500 {
"diffuse_roughness", get_input_value(
"Diffuse Roughness", NodeItem::Type::Float)},
501 {
"subsurface", get_input_value(
"Subsurface Weight", NodeItem::Type::Float)},
502 {
"subsurface_scale", get_input_value(
"Subsurface Scale", NodeItem::Type::Float)},
503# if MATERIALX_MAJOR_VERSION <= 1 && MATERIALX_MINOR_VERSION <= 38
504 {
"subsurface_radius", get_input_value(
"Subsurface Radius", NodeItem::Type::Vector3)},
506 {
"subsurface_radius", get_input_value(
"Subsurface Radius", NodeItem::Type::Color3)},
509 {
"subsurface_anisotropy", get_input_value(
"Subsurface Anisotropy", NodeItem::Type::Float)},
510 {
"metallic", get_input_value(
"Metallic", NodeItem::Type::Float)},
511 {
"specular", get_input_value(
"Specular IOR Level", NodeItem::Type::Float)},
512 {
"specular_tint", get_input_value(
"Specular Tint", NodeItem::Type::Color3)},
513 {
"roughness", get_input_value(
"Roughness", NodeItem::Type::Float)},
514 {
"anisotropic", get_input_value(
"Anisotropic", NodeItem::Type::Float)},
515 {
"anisotropic_rotation", get_input_value(
"Anisotropic Rotation", NodeItem::Type::Float)},
516 {
"sheen", get_input_value(
"Sheen Weight", NodeItem::Type::Float)},
517 {
"sheen_roughness", get_input_value(
"Sheen Roughness", NodeItem::Type::Float)},
518 {
"sheen_tint", get_input_value(
"Sheen Tint", NodeItem::Type::Color3)},
519 {
"coat", get_input_value(
"Coat Weight", NodeItem::Type::Float)},
520 {
"coat_roughness", get_input_value(
"Coat Roughness", NodeItem::Type::Float)},
521 {
"coat_ior", get_input_value(
"Coat IOR", NodeItem::Type::Float)},
522 {
"coat_tint", get_input_value(
"Coat Tint", NodeItem::Type::Color3)},
523 {
"ior", get_input_value(
"IOR", NodeItem::Type::Float)},
524 {
"transmission", get_input_value(
"Transmission Weight", NodeItem::Type::Float)},
525 {
"thin_film_thickness", get_input_value(
"Thin Film Thickness", NodeItem::Type::Float)},
526 {
"thin_film_IOR", get_input_value(
"Thin Film IOR", NodeItem::Type::Float)},
527 {
"alpha", get_input_value(
"Alpha", NodeItem::Type::Float)},
528 {
"normal", get_input_link(
"Normal", NodeItem::Type::Vector3)},
529 {
"coat_normal", get_input_link(
"Coat Normal", NodeItem::Type::Vector3)},
530 {
"tangent", get_input_link(
"Tangent", NodeItem::Type::Vector3)},
531 {
"geometry_thin_walled", get_input_value(
"Thin Wall", NodeItem::Type::Boolean)},
535 auto edf_inputs = [&]() -> InputsType {
537 {
"emission", get_input_value(
"Emission Strength", NodeItem::Type::Float)},
538 {
"emission_color", get_input_value(
"Emission Color", NodeItem::Type::Color3)},
542 NodeItem res = empty();
545 case NodeItem::Type::BSDF: {
546 auto in = bsdf_inputs();
548 NodeItem roughness =
in[
"roughness"];
549 NodeItem diffuse_roughness =
in[
"diffuse_roughness"];
550 NodeItem anisotropy =
in[
"anisotropic"];
551 NodeItem
rotation =
in[
"anisotropic_rotation"] * val(360.0f);
552 NodeItem base_color =
in[
"base_color"];
553 NodeItem specular =
in[
"specular"];
554 NodeItem coat =
in[
"coat"];
555 NodeItem ior =
in[
"ior"];
556 NodeItem normal =
in[
"normal"];
557 NodeItem tangent =
in[
"tangent"];
558 NodeItem coat_normal =
in[
"coat_normal"];
560 NodeItem n_main_tangent = empty();
561 if (tangent && normal) {
562 NodeItem n_tangent_rotate_normalize = tangent.rotate(rotation, normal).normalize();
563 n_main_tangent = anisotropy.if_else(
564 NodeItem::CompareOp::Greater, val(0.0f), n_tangent_rotate_normalize, tangent);
567 NodeItem n_coat_roughness_vector = create_node(
568 "roughness_anisotropy",
569 NodeItem::Type::Vector2,
570 {{
"roughness",
in[
"coat_roughness"]}, {
"anisotropy", anisotropy}});
572 NodeItem n_coat_bsdf = create_node(
"dielectric_bsdf",
573 NodeItem::Type::BSDF,
575 {
"tint",
in[
"coat_tint"]},
576 {
"ior",
in[
"coat_ior"]},
577 {
"scatter_mode", val(std::string(
"R"))},
578 {
"roughness", n_coat_roughness_vector},
579 {
"normal", coat_normal}});
581 if (tangent && coat_normal) {
582 NodeItem n_coat_tangent_rotate_normalize =
583 tangent.rotate(rotation, coat_normal).normalize();
584 NodeItem n_coat_tangent = anisotropy.if_else(
585 NodeItem::CompareOp::Greater, val(0.0f), n_coat_tangent_rotate_normalize, tangent);
587 n_coat_bsdf.set_input(
"tangent", n_coat_tangent);
590 NodeItem thin_film_thickness =
in[
"thin_film_thickness"];
591 NodeItem thin_film_ior =
in[
"thin_film_IOR"];
592 NodeItem n_thin_film_bsdf = create_node(
594 NodeItem::Type::BSDF,
595 {{
"thickness", thin_film_thickness}, {
"ior", thin_film_ior}});
597 NodeItem n_artistic_ior = create_node(
599 NodeItem::Type::Multioutput,
600 {{
"reflectivity", base_color * val(1.0f)}, {
"edge_color", base_color * specular}});
602 NodeItem n_ior_out = n_artistic_ior.add_output(
"ior", NodeItem::Type::Color3);
603 NodeItem n_extinction_out = n_artistic_ior.add_output(
"extinction", NodeItem::Type::Color3);
605 NodeItem n_coat_affect_roughness_multiply2 = coat * val(0.0f) *
in[
"coat_roughness"];
606 NodeItem n_coat_affected_roughness = n_coat_affect_roughness_multiply2.mix(roughness,
609 NodeItem n_main_roughness = create_node(
610 "roughness_anisotropy",
611 NodeItem::Type::Vector2,
612 {{
"roughness", n_coat_affected_roughness}, {
"anisotropy", anisotropy}});
614 NodeItem n_metal_bsdf = create_node(
"conductor_bsdf",
615 NodeItem::Type::BSDF,
617 {
"extinction", n_extinction_out},
618 {
"roughness", n_main_roughness},
620 {
"tangent", n_main_tangent}});
622 NodeItem n_specular_bsdf = create_node(
"dielectric_bsdf",
623 NodeItem::Type::BSDF,
624 {{
"weight", specular},
625 {
"tint",
in[
"specular_tint"]},
627 {
"scatter_mode", val(std::string(
"R"))},
628 {
"roughness", n_main_roughness},
630 {
"tangent", n_main_tangent}});
632 NodeItem n_coat_affected_transmission_roughness = n_coat_affect_roughness_multiply2.mix(
633 (roughness + roughness).
clamp(), val(1.0f));
635 NodeItem n_transmission_roughness = create_node(
636 "roughness_anisotropy",
637 NodeItem::Type::Vector2,
638 {{
"roughness", n_coat_affected_transmission_roughness}, {
"anisotropy", anisotropy}});
640 NodeItem n_transmission_bsdf = create_node(
"dielectric_bsdf",
641 NodeItem::Type::BSDF,
642 {{
"tint", base_color},
644 {
"roughness", n_transmission_roughness},
646 {
"tangent", n_main_tangent}});
648 NodeItem n_coat_gamma = coat.clamp(0.0f, 1.0f) * val(0.0f) + val(1.0f);
649 NodeItem n_coat_affected_subsurface_color = base_color.max(val(0.0f)) ^ n_coat_gamma;
652 NodeItem n_subsurface_bsdf = create_node(
654 NodeItem::Type::BSDF,
655 {{
"color", n_coat_affected_subsurface_color},
656 {
"radius",
in[
"subsurface_radius"] *
in[
"subsurface_scale"]},
657 {
"anisotropy",
in[
"subsurface_anisotropy"]},
658 {
"normal", normal}});
661 NodeItem n_subsurface_thin_walled_reflection_bsdf = create_node(
662 "oren_nayar_diffuse_bsdf",
663 NodeItem::Type::BSDF,
664 {{
"color", n_coat_affected_subsurface_color},
665 {
"roughness", diffuse_roughness},
666 {
"weight", val(1.0f)},
667 {
"normal", normal}});
668 NodeItem n_subsurface_thin_walled_transmission_bsdf = create_node(
670 NodeItem::Type::BSDF,
671 {{
"color", n_coat_affected_subsurface_color}, {
"normal", normal}});
673 NodeItem n_subsurface_thin_walled_brdf_factor = val(1.0f) -
in[
"subsurface_anisotropy"];
674 NodeItem n_one_plus_subsurface_scatter_anisotropy = val(1.0f) +
in[
"subsurface_anisotropy"];
676 NodeItem n_subsurface_thin_walled_reflection = n_subsurface_thin_walled_reflection_bsdf *
677 n_subsurface_thin_walled_brdf_factor;
678 NodeItem n_subsurface_thin_walled_transmission = n_subsurface_thin_walled_transmission_bsdf *
679 n_one_plus_subsurface_scatter_anisotropy;
680 NodeItem n_subsurface_thin_walled_mix = val(0.5f).mix(n_subsurface_thin_walled_reflection,
681 n_subsurface_thin_walled_transmission);
684 NodeItem n_subsurface_selector_mix =
in[
"geometry_thin_walled"]
685 .convert(NodeItem::Type::Float)
686 .mix(n_subsurface_bsdf,
687 n_subsurface_thin_walled_mix);
689 NodeItem n_sheen_bsdf = create_node(
"sheen_bsdf",
690 NodeItem::Type::BSDF,
691 {{
"weight",
in[
"sheen"]},
692 {
"color",
in[
"sheen_tint"]},
693 {
"roughness",
in[
"sheen_roughness"]},
694 {
"normal", normal}});
696 NodeItem n_diffuse_bsdf = create_node(
"oren_nayar_diffuse_bsdf",
697 NodeItem::Type::BSDF,
698 {{
"color", base_color.max(val(0.0f)) ^ n_coat_gamma},
699 {
"roughness", diffuse_roughness},
700 {
"weight", val(1.0f)},
701 {
"normal", normal}});
703 NodeItem n_subsurface_mix =
in[
"subsurface"].mix(n_diffuse_bsdf, n_subsurface_selector_mix);
705 NodeItem n_sheen_layer = create_node(
706 "layer", NodeItem::Type::BSDF, {{
"top", n_sheen_bsdf}, {
"base", n_subsurface_mix}});
708 NodeItem n_transmission_mix =
in[
"transmission"].mix(n_sheen_layer, n_transmission_bsdf);
710 NodeItem n_specular_layer = create_node(
711 "layer", NodeItem::Type::BSDF, {{
"top", n_specular_bsdf}, {
"base", n_transmission_mix}});
713 NodeItem n_metalness_mix =
in[
"metallic"].mix(n_specular_layer, n_metal_bsdf);
715 NodeItem n_thin_film_layer = create_node(
716 "layer", NodeItem::Type::BSDF, {{
"top", n_thin_film_bsdf}, {
"base", n_metalness_mix}});
718 NodeItem n_coat_attenuation = coat.mix(val(MaterialX::Color3(1.0f, 1.0f, 1.0f)),
721 res = create_node(
"layer",
722 NodeItem::Type::BSDF,
723 {{
"top", n_coat_bsdf}, {
"base", n_thin_film_layer * n_coat_attenuation}});
727 case NodeItem::Type::EDF: {
728 auto in = edf_inputs();
730 "uniform_edf", NodeItem::Type::EDF, {{
"color",
in[
"emission_color"] *
in[
"emission"]}});
734 case NodeItem::Type::SurfaceShader: {
735 auto in = bsdf_inputs();
736 auto e_in = edf_inputs();
737 in.insert(e_in.begin(), e_in.end());
739 NodeItem base_color =
in[
"base_color"];
741 NodeItem anisotropy =
in[
"anisotropic"];
742 NodeItem tangent =
in[
"tangent"];
745 anisotropy = anisotropy * val(0.7f);
749 NodeItem
rotation = -((
in[
"anisotropic_rotation"] * val(360.0f)) + val(90.0f));
753 NodeItem normal =
in[
"normal"];
755 const std::string world =
"world";
757 create_node(
"normal", NodeItem::Type::Vector3, {{
"space", val(world)}}).
normalize();
761 const std::string world =
"world";
763 create_node(
"tangent", NodeItem::Type::Vector3, {{
"space", val(world)}}).
normalize();
766 NodeItem n_tangent_rotate_normalize = tangent.rotate(rotation, normal).normalize();
767 tangent = anisotropy.if_else(
768 NodeItem::CompareOp::Greater, val(0.0f), n_tangent_rotate_normalize, tangent);
772 NodeItem thin_film_thickness =
in[
"thin_film_thickness"] * val(0.001f);
773 NodeItem thin_film_weight = thin_film_thickness.if_else(
774 NodeItem::CompareOp::Greater, val(0.0f), val(1.0f), val(0.0f));
780 NodeItem specular_weight =
in[
"specular"] * val(2.0f);
782 res = create_node(
"open_pbr_surface",
783 NodeItem::Type::SurfaceShader,
784 {{
"base_weight", val(1.0f)},
785 {
"base_color", base_color},
786 {
"base_diffuse_roughness",
in[
"diffuse_roughness"]},
787 {
"base_metalness",
in[
"metallic"]},
788 {
"specular_weight", specular_weight},
789 {
"specular_color",
in[
"specular_tint"]},
790 {
"specular_roughness",
in[
"roughness"]},
791 {
"specular_ior",
in[
"ior"]},
792 {
"specular_roughness_anisotropy", anisotropy},
793 {
"transmission_weight",
in[
"transmission"]},
794 {
"transmission_color", base_color},
795 {
"subsurface_weight",
in[
"subsurface"]},
796 {
"subsurface_color", base_color},
797 {
"subsurface_radius_scale",
in[
"subsurface_radius"]},
798 {
"subsurface_radius",
in[
"subsurface_scale"]},
799 {
"subsurface_scatter_anisotropy",
in[
"subsurface_anisotropy"]},
800 {
"fuzz_weight",
in[
"sheen"]},
801 {
"fuzz_color",
in[
"sheen_tint"]},
802 {
"fuzz_roughness",
in[
"sheen_roughness"]},
803 {
"coat_weight",
in[
"coat"]},
804 {
"coat_color",
in[
"coat_tint"]},
805 {
"coat_roughness",
in[
"coat_roughness"]},
806 {
"coat_ior",
in[
"coat_ior"]},
810 {
"emission_luminance",
in[
"emission"]},
811 {
"emission_color",
in[
"emission_color"]},
812 {
"thin_film_weight", thin_film_weight},
813 {
"thin_film_thickness", thin_film_thickness},
814 {
"thin_film_ior",
in[
"thin_film_IOR"]},
815 {
"geometry_normal",
in[
"normal"]},
816 {
"geometry_coat_normal",
in[
"coat_normal"]},
817 {
"geometry_tangent", tangent},
818 {
"geometry_opacity",
in[
"alpha"]},
819 {
"geometry_thin_walled",
in[
"geometry_thin_walled"]}});
823 case NodeItem::Type::SurfaceOpacity: {
824 res = get_input_value(
"Alpha", NodeItem::Type::Float);