Blender V5.3
shader_nodes.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include "shader_nodes.h"
6
8#include "kernel/svm/types.h"
9#include "kernel/types.h"
10
11#include "scene/constant_fold.h"
12#include "scene/film.h"
13#include "scene/image.h"
14#include "scene/image_sky.h"
15#include "scene/integrator.h"
16#include "scene/light.h"
17#include "scene/mesh.h"
18#include "scene/osl.h"
19#include "scene/scene.h"
20#include "scene/shader_nodes.h"
21#include "scene/svm.h"
22
23#include "sky_hosek.h"
24#include "sky_nishita.h"
25
26#include "util/colorspace.h"
27#include "util/log.h"
28#include "util/math_base.h"
29#include "util/math_float3.h"
30#include "util/string.h"
31#include "util/transform.h"
32
40
41#include <cassert>
42#include <limits>
43#include <mutex>
44
46
47/* Texture Mapping */
48
49#define TEXTURE_MAPPING_DEFINE(TextureNode) \
50 SOCKET_POINT(tex_mapping.translation, "Translation", zero_float3()); \
51 SOCKET_VECTOR(tex_mapping.rotation, "Rotation", zero_float3()); \
52 SOCKET_VECTOR(tex_mapping.scale, "Scale", one_float3()); \
53\
54 SOCKET_VECTOR(tex_mapping.min, "Min", make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX)); \
55 SOCKET_VECTOR(tex_mapping.max, "Max", make_float3(FLT_MAX, FLT_MAX, FLT_MAX)); \
56 SOCKET_BOOLEAN(tex_mapping.use_minmax, "Use Min Max", false); \
57\
58 static NodeEnum mapping_axis_enum; \
59 mapping_axis_enum.insert("none", TextureMapping::NONE); \
60 mapping_axis_enum.insert("x", TextureMapping::X); \
61 mapping_axis_enum.insert("y", TextureMapping::Y); \
62 mapping_axis_enum.insert("z", TextureMapping::Z); \
63 SOCKET_ENUM(tex_mapping.x_mapping, "x_mapping", mapping_axis_enum, TextureMapping::X); \
64 SOCKET_ENUM(tex_mapping.y_mapping, "y_mapping", mapping_axis_enum, TextureMapping::Y); \
65 SOCKET_ENUM(tex_mapping.z_mapping, "z_mapping", mapping_axis_enum, TextureMapping::Z); \
66\
67 static NodeEnum mapping_type_enum; \
68 mapping_type_enum.insert("point", TextureMapping::POINT); \
69 mapping_type_enum.insert("texture", TextureMapping::TEXTURE); \
70 mapping_type_enum.insert("vector", TextureMapping::VECTOR); \
71 mapping_type_enum.insert("normal", TextureMapping::NORMAL); \
72 SOCKET_ENUM(tex_mapping.type, "Type", mapping_type_enum, TextureMapping::TEXTURE); \
73\
74 static NodeEnum mapping_projection_enum; \
75 mapping_projection_enum.insert("flat", TextureMapping::FLAT); \
76 mapping_projection_enum.insert("cube", TextureMapping::CUBE); \
77 mapping_projection_enum.insert("tube", TextureMapping::TUBE); \
78 mapping_projection_enum.insert("sphere", TextureMapping::SPHERE); \
79 SOCKET_ENUM(tex_mapping.projection, "Projection", mapping_projection_enum, TextureMapping::FLAT);
80
82
84{
86
87 if (x_mapping != NONE) {
88 mmat[0][x_mapping - 1] = 1.0f;
89 }
90 if (y_mapping != NONE) {
91 mmat[1][y_mapping - 1] = 1.0f;
92 }
93 if (z_mapping != NONE) {
94 mmat[2][z_mapping - 1] = 1.0f;
95 }
96
97 float3 scale_clamped = scale;
98
99 if (type == TEXTURE || type == NORMAL) {
100 /* keep matrix invertible */
101 if (fabsf(scale.x) < 1e-5f) {
102 scale_clamped.x = signf(scale.x) * 1e-5f;
103 }
104 if (fabsf(scale.y) < 1e-5f) {
105 scale_clamped.y = signf(scale.y) * 1e-5f;
106 }
107 if (fabsf(scale.z) < 1e-5f) {
108 scale_clamped.z = signf(scale.z) * 1e-5f;
109 }
110 }
111
112 const Transform smat = transform_scale(scale_clamped);
113 const Transform rmat = transform_euler(rotation);
115
116 Transform mat;
117
118 switch (type) {
119 case TEXTURE:
120 /* inverse transform on texture coordinate gives
121 * forward transform on texture */
122 mat = tmat * rmat * smat;
123 mat = transform_inverse(mat);
124 break;
125 case POINT:
126 /* full transform */
127 mat = tmat * rmat * smat;
128 break;
129 case VECTOR:
130 /* no translation for vectors */
131 mat = rmat * smat;
132 break;
133 case NORMAL:
134 /* no translation for normals, and inverse transpose */
135 mat = rmat * smat;
137 break;
138 }
139
140 /* projection last */
141 mat = mat * mmat;
142
143 return mat;
144}
145
147{
148 if (translation != zero_float3()) {
149 return false;
150 }
151 if (rotation != zero_float3()) {
152 return false;
153 }
154 if (scale != one_float3()) {
155 return false;
156 }
157
158 if (x_mapping != X || y_mapping != Y || z_mapping != Z) {
159 return false;
160 }
161 if (use_minmax) {
162 return false;
163 }
164
165 return true;
166}
167
169 const SVMStackOffset offset_in,
170 const SVMStackOffset offset_out,
172{
173 const Transform tfm = compute_transform();
174 compiler.add_node(node,
175 NODE_TEXTURE_MAPPING,
177 .vec_offset = offset_in,
178 .out_offset = offset_out,
179 .tfm = tfm,
180 });
181
182 if (use_minmax) {
183 compiler.add_node(nullptr,
184 NODE_MIN_MAX,
186 .vec_offset = offset_out,
187 .out_offset = offset_out,
188 .mn = min,
189 .mx = max,
190 });
191 }
192
193 if (type == NORMAL) {
194 compiler.add_node(node,
195 NODE_VECTOR_MATH,
197 .math_type = NODE_VECTOR_MATH_NORMALIZE,
198 .a = compiler.input_float3_from_offset(offset_out),
199 .b = {},
200 .c = {},
201 .param1 = {},
202 .value_offset = SVM_STACK_INVALID,
203 .vector_offset = offset_out,
204 });
205 }
206}
207
208/* Convenience function for texture nodes, allocating stack space to output
209 * a modified vector and returning its offset */
211 ShaderInput *vector_in,
213{
214 if (!skip()) {
215 const SVMStackOffset offset_in = compiler.stack_assign(vector_in);
216 assert(vector_in->type() == SocketType::VECTOR || vector_in->type() == SocketType::POINT);
217 const SVMStackOffset offset_out = compiler.stack_find_offset(vector_in);
218
219 compile(compiler, offset_in, offset_out, node);
220
221 return offset_out;
222 }
223
224 return compiler.stack_assign(vector_in);
225}
226
228 ShaderInput *vector_in,
229 const SVMStackOffset vector_offset)
230{
231 if (!skip()) {
232 compiler.stack_clear_offset(vector_in, vector_offset);
233 }
234}
235
237{
238 if (!skip()) {
239 compiler.parameter("mapping", compute_transform());
240 compiler.parameter("use_mapping", 1);
241 }
242}
243
244/* Image Texture */
245
247{
248 NodeType *type = NodeType::add("image_texture", create, NodeType::SHADER);
249
251
252 SOCKET_STRING(filename, "Filename", ustring());
254
255 static NodeEnum alpha_type_enum;
256 alpha_type_enum.insert("auto", IMAGE_ALPHA_AUTO);
257 alpha_type_enum.insert("unassociated", IMAGE_ALPHA_UNASSOCIATED);
258 alpha_type_enum.insert("associated", IMAGE_ALPHA_ASSOCIATED);
259 alpha_type_enum.insert("channel_packed", IMAGE_ALPHA_CHANNEL_PACKED);
260 alpha_type_enum.insert("ignore", IMAGE_ALPHA_IGNORE);
261 SOCKET_ENUM(alpha_type, "Alpha Type", alpha_type_enum, IMAGE_ALPHA_AUTO);
262
263 static NodeEnum interpolation_enum;
264 interpolation_enum.insert("closest", INTERPOLATION_CLOSEST);
265 interpolation_enum.insert("linear", INTERPOLATION_LINEAR);
266 interpolation_enum.insert("cubic", INTERPOLATION_CUBIC);
267 interpolation_enum.insert("smart", INTERPOLATION_SMART);
268 SOCKET_ENUM(interpolation, "Interpolation", interpolation_enum, INTERPOLATION_LINEAR);
269
270 static NodeEnum extension_enum;
271 extension_enum.insert("periodic", EXTENSION_REPEAT);
272 extension_enum.insert("clamp", EXTENSION_EXTEND);
273 extension_enum.insert("black", EXTENSION_CLIP);
274 extension_enum.insert("mirror", EXTENSION_MIRROR);
275 SOCKET_ENUM(extension, "Extension", extension_enum, EXTENSION_REPEAT);
276
277 static NodeEnum projection_enum;
278 projection_enum.insert("flat", NODE_IMAGE_PROJ_FLAT);
279 projection_enum.insert("box", NODE_IMAGE_PROJ_BOX);
280 projection_enum.insert("sphere", NODE_IMAGE_PROJ_SPHERE);
281 projection_enum.insert("tube", NODE_IMAGE_PROJ_TUBE);
282 SOCKET_ENUM(projection, "Projection", projection_enum, NODE_IMAGE_PROJ_FLAT);
283
284 SOCKET_FLOAT(projection_blend, "Projection Blend", 0.0f);
285
286 SOCKET_INT_ARRAY(tiles, "Tiles", array<int>());
287 SOCKET_BOOLEAN(animated, "Animated", false);
288
290 SOCKET_IN_COLOR(missing, "Missing", IMAGE_MISSING_RGB);
291 SOCKET_IN_FLOAT(missing_alpha, "Missing Alpha", 1.0f);
292
293 SOCKET_OUT_COLOR(color, "Color");
294 SOCKET_OUT_FLOAT(alpha, "Alpha");
295
296 return type;
297}
298
299ImageTextureNode::ImageTextureNode() : ImageSlotTextureNode(get_node_type())
300{
302 animated = false;
303}
304
306{
308 node->handle = handle;
309 return node;
310}
311
313{
314 ImageParams params;
315 params.animated = animated;
316 params.interpolation = interpolation;
317 params.extension = extension;
318 params.alpha_type = alpha_type;
319 params.colorspace = colorspace;
320 return params;
321}
322
324{
325 /* Box projection computes its own UVs that always lie in the
326 * 1001 tile, so there's no point in loading any others. */
327 if (projection == NODE_IMAGE_PROJ_BOX) {
328 if (tiles.size()) {
329 tiles.clear();
330 tiles.push_back_slow(1001);
331 }
332 return;
333 }
334
335 if (!scene->params.background) {
336 /* During interactive renders, all tiles are loaded.
337 * While we could support updating this when UVs change, that could lead
338 * to annoying interruptions when loading images while editing UVs. */
339 return;
340 }
341
342 /* Only check UVs for tile culling when using tiles. */
343 if (tiles.size() == 0) {
344 return;
345 }
346
347 ShaderInput *vector_in = input("Vector");
348 ustring attribute;
349 if (vector_in->link) {
350 ShaderNode *node = vector_in->link->parent;
351 if (node->type == UVMapNode::get_node_type()) {
352 UVMapNode *uvmap = (UVMapNode *)node;
353 attribute = uvmap->get_attribute();
354 }
355 else if (node->type == TextureCoordinateNode::get_node_type()) {
356 if (vector_in->link != node->output("UV")) {
357 return;
358 }
359 }
360 else {
361 return;
362 }
363 }
364
365 unordered_set<int> used_tiles;
366 /* TODO(lukas): This is quite inefficient. A fairly simple improvement would
367 * be to have a cache in each mesh that is indexed by attribute.
368 * Additionally, building a graph-to-meshes list once could help. */
369 for (Geometry *geom : scene->geometry) {
370 for (Node *node : geom->get_used_shaders()) {
371 Shader *shader = static_cast<Shader *>(node);
372 if (shader->graph.get() == graph) {
373 geom->get_uv_tiles(attribute, used_tiles);
374 }
375 }
376 }
377
378 array<int> new_tiles;
379 for (const int tile : tiles) {
380 if (used_tiles.contains(tile)) {
381 new_tiles.push_back_slow(tile);
382 }
383 }
384 tiles.steal_data(new_tiles);
385}
386
388{
389#ifdef WITH_PTEX
390 /* todo: avoid loading other texture coordinates when using ptex,
391 * and hide texture coordinate socket in the UI */
392 if (shader->has_surface_link() && string_endswith(filename, ".ptx")) {
393 /* ptex */
396 }
397#endif
398
400}
401
403{
404 if (projection != NODE_IMAGE_PROJ_BOX) {
405 return NODE_TEX_IMAGE;
406 }
407 return NODE_TEX_IMAGE_BOX;
408}
409
411{
412 if (handle.empty()) {
413 ImageManager *image_manager = compiler.scene->image_manager.get();
414 const bool use_cache = image_manager->get_use_texture_cache();
415
416 if (!use_cache) {
417 cull_tiles(compiler.scene, compiler.current_graph);
418 }
419
420 handle = image_manager->add_image(filename.string(), image_params(), tiles);
421
422 if (use_cache && !tiles.empty() && !image_manager->get_auto_texture_cache()) {
423 if (!handle.all_udim_tiled(compiler.progress)) {
424 cull_tiles(compiler.scene, compiler.current_graph);
425 handle = image_manager->add_image(filename.string(), image_params(), tiles);
426 }
427 }
428 }
429
430 const ImageMetaData metadata = handle.metadata(compiler.progress);
431 if (metadata.has_tiles_and_mipmaps && compiler.scene->image_manager->get_use_texture_cache()) {
433 }
434}
435
437{
438 ShaderInput *vector_in = input("Vector");
439 ShaderOutput *alpha_out = output("Alpha");
440
441 update_images(compiler);
442
443 /* All tiles have the same metadata. */
444 const ImageMetaData metadata = handle.metadata(compiler.progress);
445 const bool compress_as_srgb = metadata.is_compressible_as_srgb;
446
447 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, this);
448 uint flags = 0;
449
450 if (compress_as_srgb) {
452 }
453 if (!alpha_out->links.empty()) {
454 const bool unassociate_alpha = !(ColorSpaceManager::colorspace_is_data(colorspace) ||
455 alpha_type == IMAGE_ALPHA_CHANNEL_PACKED ||
456 alpha_type == IMAGE_ALPHA_IGNORE);
457
458 if (unassociate_alpha) {
460 }
461 }
462
463 if (projection != NODE_IMAGE_PROJ_BOX) {
464 compiler.add_node(this,
465 NODE_TEX_IMAGE,
466 SVMNodeTexImage{
467 .id = handle.kernel_id(),
468 .projection = uint(projection),
469 .missing = compiler.input_float3("Missing"),
470 .missing_alpha = compiler.input_float("Missing Alpha"),
471 .flags = uint8_t(flags),
472 .co = vector_offset,
473 .out_offset = compiler.output("Color"),
474 .alpha_offset = compiler.output("Alpha"),
475 });
476 }
477 else {
478 compiler.add_node(this,
479 NODE_TEX_IMAGE_BOX,
480 SVMNodeTexImageBox{
481 .id = handle.kernel_id(),
482 .blend = projection_blend,
483 .missing = compiler.input_float3("Missing"),
484 .missing_alpha = compiler.input_float("Missing Alpha"),
485 .flags = uint8_t(flags),
486 .co = vector_offset,
487 .out_offset = compiler.output("Color"),
488 .alpha_offset = compiler.output("Alpha"),
489 });
490 }
491
492 tex_mapping.compile_end(compiler, vector_in, vector_offset);
493}
494
496{
497
498 tex_mapping.compile(compiler);
499
500 if (handle.empty()) {
501 cull_tiles(compiler.scene, compiler.current_graph);
502 ImageManager *image_manager = compiler.scene->image_manager.get();
503 const bool use_cache = image_manager->get_use_texture_cache();
504
505 if (!use_cache) {
506 cull_tiles(compiler.scene, compiler.current_graph);
507 }
508
509 handle = image_manager->add_image(filename.string(), image_params(), tiles);
510
511 if (use_cache && !tiles.empty() && !image_manager->get_auto_texture_cache()) {
512 if (!handle.all_udim_tiled(*compiler.progress)) {
513 cull_tiles(compiler.scene, compiler.current_graph);
514 handle = image_manager->add_image(filename.string(), image_params(), tiles);
515 }
516 }
517 }
518
519 const ImageMetaData metadata = handle.metadata(*compiler.progress);
520 const bool is_float = metadata.is_float();
521 const bool compress_as_srgb = metadata.is_compressible_as_srgb;
522
523 compiler.parameter_texture("filename", handle);
524
525 const bool unassociate_alpha = !(ColorSpaceManager::colorspace_is_data(colorspace) ||
526 alpha_type == IMAGE_ALPHA_CHANNEL_PACKED ||
527 alpha_type == IMAGE_ALPHA_IGNORE);
528
529 compiler.parameter(this, "projection");
530 compiler.parameter(this, "projection_blend");
531 compiler.parameter("compress_as_srgb", compress_as_srgb);
532 compiler.parameter("ignore_alpha", alpha_type == IMAGE_ALPHA_IGNORE);
533 compiler.parameter("unassociate_alpha", !output("Alpha")->links.empty() && unassociate_alpha);
534 compiler.parameter("is_float", is_float);
535 compiler.parameter(this, "interpolation");
536 compiler.parameter(this, "extension");
537
538 compiler.add(this, "node_image_texture");
539}
540
541/* Environment Texture */
542
544{
545 NodeType *type = NodeType::add("environment_texture", create, NodeType::SHADER);
546
548
549 SOCKET_STRING(filename, "Filename", ustring());
551
552 static NodeEnum alpha_type_enum;
553 alpha_type_enum.insert("auto", IMAGE_ALPHA_AUTO);
554 alpha_type_enum.insert("unassociated", IMAGE_ALPHA_UNASSOCIATED);
555 alpha_type_enum.insert("associated", IMAGE_ALPHA_ASSOCIATED);
556 alpha_type_enum.insert("channel_packed", IMAGE_ALPHA_CHANNEL_PACKED);
557 alpha_type_enum.insert("ignore", IMAGE_ALPHA_IGNORE);
558 SOCKET_ENUM(alpha_type, "Alpha Type", alpha_type_enum, IMAGE_ALPHA_AUTO);
559
560 static NodeEnum interpolation_enum;
561 interpolation_enum.insert("closest", INTERPOLATION_CLOSEST);
562 interpolation_enum.insert("linear", INTERPOLATION_LINEAR);
563 interpolation_enum.insert("cubic", INTERPOLATION_CUBIC);
564 interpolation_enum.insert("smart", INTERPOLATION_SMART);
565 SOCKET_ENUM(interpolation, "Interpolation", interpolation_enum, INTERPOLATION_LINEAR);
566
567 static NodeEnum projection_enum;
568 projection_enum.insert("equirectangular", NODE_ENVIRONMENT_EQUIRECTANGULAR);
569 projection_enum.insert("mirror_ball", NODE_ENVIRONMENT_MIRROR_BALL);
570 SOCKET_ENUM(projection, "Projection", projection_enum, NODE_ENVIRONMENT_EQUIRECTANGULAR);
571
572 SOCKET_BOOLEAN(animated, "Animated", false);
573
575 SOCKET_IN_COLOR(missing, "Missing", IMAGE_MISSING_RGB);
576 SOCKET_IN_FLOAT(missing_alpha, "Missing Alpha", 1.0f);
577
578 SOCKET_OUT_COLOR(color, "Color");
579 SOCKET_OUT_FLOAT(alpha, "Alpha");
580
581 return type;
582}
583
584EnvironmentTextureNode::EnvironmentTextureNode() : ImageSlotTextureNode(get_node_type())
585{
587 animated = false;
588}
589
591{
593 node->handle = handle;
594 return node;
595}
596
598{
599 ImageParams params;
600 params.animated = animated;
601 params.interpolation = interpolation;
603 params.alpha_type = alpha_type;
604 params.colorspace = colorspace;
605 return params;
606}
607
609{
610#ifdef WITH_PTEX
611 if (shader->has_surface_link() && string_endswith(filename, ".ptx")) {
612 /* ptex */
615 }
616#endif
617
619}
620
622{
623 if (handle.empty()) {
624 ImageManager *image_manager = compiler.scene->image_manager.get();
625 handle = image_manager->add_image(filename.string(), image_params());
626 }
627
628 const ImageMetaData metadata = handle.metadata(compiler.progress);
629 if (metadata.has_tiles_and_mipmaps && compiler.scene->image_manager->get_use_texture_cache()) {
631 }
632}
633
635{
636 ShaderInput *vector_in = input("Vector");
637
638 update_images(compiler);
639
640 const ImageMetaData metadata = handle.metadata(compiler.progress);
641 const bool compress_as_srgb = metadata.is_compressible_as_srgb;
642
643 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, this);
644 uint flags = 0;
645
646 if (compress_as_srgb) {
648 }
649
650 compiler.add_node(this,
651 NODE_TEX_ENVIRONMENT,
652 SVMNodeTexEnvironment{
653 .id = handle.kernel_id(),
654 .projection = projection,
655 .missing = compiler.input_float3("Missing"),
656 .missing_alpha = compiler.input_float("Missing Alpha"),
657 .flags = uint8_t(flags),
658 .co = vector_offset,
659 .out_offset = compiler.output("Color"),
660 .alpha_offset = compiler.output("Alpha"),
661 });
662
663 tex_mapping.compile_end(compiler, vector_in, vector_offset);
664}
665
667{
668 if (handle.empty()) {
669 ImageManager *image_manager = compiler.scene->image_manager.get();
670 handle = image_manager->add_image(filename.string(), image_params());
671 }
672
673 tex_mapping.compile(compiler);
674
675 const ImageMetaData metadata = handle.metadata(*compiler.progress);
676 const bool is_float = metadata.is_float();
677 const bool compress_as_srgb = metadata.is_compressible_as_srgb;
678
679 compiler.parameter_texture("filename", handle);
680 compiler.parameter(this, "projection");
681 compiler.parameter(this, "interpolation");
682 compiler.parameter("compress_as_srgb", compress_as_srgb);
683 compiler.parameter("ignore_alpha", alpha_type == IMAGE_ALPHA_IGNORE);
684 compiler.parameter("is_float", is_float);
685 compiler.add(this, "node_environment_texture");
686}
687
688/* Sky Texture */
689
691{
692 return make_float2(acosf(dir.z), atan2f(dir.x, dir.y));
693}
694
695struct SunSky {
696 /* sun direction in spherical and cartesian */
697 float theta, phi;
698
699 /* Parameter */
701 float config_x[9], config_y[9], config_z[9], nishita_data[11];
702};
703
704/* Preetham model */
705static float sky_perez_function(const float lam[6], float theta, const float gamma)
706{
707 return (1.0f + lam[0] * expf(lam[1] / cosf(theta))) *
708 (1.0f + lam[2] * expf(lam[3] * gamma) + lam[4] * cosf(gamma) * cosf(gamma));
709}
710
712 const float3 dir,
713 const float turbidity)
714{
715 /*
716 * We re-use the SunSky struct of the new model, to avoid extra variables
717 * zenith_Y/x/y is now radiance_x/y/z
718 * perez_Y/x/y is now config_x/y/z
719 */
720
721 const float2 spherical = sky_spherical_coordinates(dir);
722 const float theta = spherical.x;
723 const float phi = spherical.y;
724
725 sunsky->theta = theta;
726 sunsky->phi = phi;
727
728 const float theta2 = theta * theta;
729 const float theta3 = theta2 * theta;
730 const float T = turbidity;
731 const float T2 = T * T;
732
733 const float chi = (4.0f / 9.0f - T / 120.0f) * (M_PI_F - 2.0f * theta);
734 sunsky->radiance_x = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f;
735 sunsky->radiance_x *= 0.06f;
736
737 sunsky->radiance_y = (0.00166f * theta3 - 0.00375f * theta2 + 0.00209f * theta) * T2 +
738 (-0.02903f * theta3 + 0.06377f * theta2 - 0.03202f * theta + 0.00394f) * T +
739 (0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * theta + 0.25886f);
740
741 sunsky->radiance_z = (0.00275f * theta3 - 0.00610f * theta2 + 0.00317f * theta) * T2 +
742 (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * theta + 0.00516f) * T +
743 (0.15346f * theta3 - 0.26756f * theta2 + 0.06670f * theta + 0.26688f);
744
745 sunsky->config_x[0] = (0.1787f * T - 1.4630f);
746 sunsky->config_x[1] = (-0.3554f * T + 0.4275f);
747 sunsky->config_x[2] = (-0.0227f * T + 5.3251f);
748 sunsky->config_x[3] = (0.1206f * T - 2.5771f);
749 sunsky->config_x[4] = (-0.0670f * T + 0.3703f);
750
751 sunsky->config_y[0] = (-0.0193f * T - 0.2592f);
752 sunsky->config_y[1] = (-0.0665f * T + 0.0008f);
753 sunsky->config_y[2] = (-0.0004f * T + 0.2125f);
754 sunsky->config_y[3] = (-0.0641f * T - 0.8989f);
755 sunsky->config_y[4] = (-0.0033f * T + 0.0452f);
756
757 sunsky->config_z[0] = (-0.0167f * T - 0.2608f);
758 sunsky->config_z[1] = (-0.0950f * T + 0.0092f);
759 sunsky->config_z[2] = (-0.0079f * T + 0.2102f);
760 sunsky->config_z[3] = (-0.0441f * T - 1.6537f);
761 sunsky->config_z[4] = (-0.0109f * T + 0.0529f);
762
763 /* unused for old sky model */
764 for (int i = 5; i < 9; i++) {
765 sunsky->config_x[i] = 0.0f;
766 sunsky->config_y[i] = 0.0f;
767 sunsky->config_z[i] = 0.0f;
768 }
769
770 sunsky->radiance_x /= sky_perez_function(sunsky->config_x, 0, theta);
771 sunsky->radiance_y /= sky_perez_function(sunsky->config_y, 0, theta);
772 sunsky->radiance_z /= sky_perez_function(sunsky->config_z, 0, theta);
773}
774
775/* Hosek / Wilkie */
777 const float3 dir,
778 float turbidity,
779 const float ground_albedo)
780{
781 /* Calculate Sun Direction and save coordinates */
782 const float2 spherical = sky_spherical_coordinates(dir);
783 float theta = spherical.x;
784 const float phi = spherical.y;
785
786 /* Clamp Turbidity */
787 turbidity = clamp(turbidity, 0.0f, 10.0f);
788
789 /* Clamp to Horizon */
790 theta = clamp(theta, 0.0f, M_PI_2_F);
791
792 sunsky->theta = theta;
793 sunsky->phi = phi;
794
795 const float solarElevation = M_PI_2_F - theta;
796
797 /* Initialize Sky Model */
798 SKY_ArHosekSkyModelState *sky_state;
800 (double)turbidity, (double)ground_albedo, (double)solarElevation);
801
802 /* Copy values from sky_state to SunSky */
803 for (int i = 0; i < 9; ++i) {
804 sunsky->config_x[i] = (float)sky_state->configs[0][i];
805 sunsky->config_y[i] = (float)sky_state->configs[1][i];
806 sunsky->config_z[i] = (float)sky_state->configs[2][i];
807 }
808 sunsky->radiance_x = (float)sky_state->radiances[0];
809 sunsky->radiance_y = (float)sky_state->radiances[1];
810 sunsky->radiance_z = (float)sky_state->radiances[2];
811
812 /* Free sky_state */
814}
815
816/* Nishita improved */
818 bool multiple_scattering,
819 bool sun_disc,
820 const float sun_size,
821 const float sun_intensity,
822 const float sun_elevation,
823 const float sun_rotation,
824 const float altitude,
825 const float air_density,
826 const float aerosol_density,
827 const float ozone_density)
828{
829 /* Sample 2 Sun pixels */
830 float pixel_bottom[3];
831 float pixel_top[3];
832
833 if (multiple_scattering) {
835 sun_size,
836 altitude,
837 air_density,
838 aerosol_density,
839 ozone_density,
840 pixel_bottom,
841 pixel_top);
842 }
843 else {
845 sun_elevation, sun_size, altitude, air_density, aerosol_density, pixel_bottom, pixel_top);
846 }
847
848 float earth_intersection_angle = SKY_earth_intersection_angle(altitude);
849
850 /* Send data to sky.h */
851 sunsky->nishita_data[0] = pixel_bottom[0];
852 sunsky->nishita_data[1] = pixel_bottom[1];
853 sunsky->nishita_data[2] = pixel_bottom[2];
854 sunsky->nishita_data[3] = pixel_top[0];
855 sunsky->nishita_data[4] = pixel_top[1];
856 sunsky->nishita_data[5] = pixel_top[2];
857 sunsky->nishita_data[6] = sun_elevation;
858 sunsky->nishita_data[7] = sun_rotation;
859 sunsky->nishita_data[8] = sun_disc ? sun_size : -1.0f;
860 sunsky->nishita_data[9] = sun_intensity;
861 sunsky->nishita_data[10] = -earth_intersection_angle;
862}
863
865{
866 const float angular_diameter = get_sun_size();
867 float pix_bottom[3];
868 float pix_top[3];
869
870 if (sky_type == NODE_SKY_SINGLE_SCATTERING) {
872 angular_diameter,
873 altitude,
874 air_density,
875 aerosol_density,
876 pix_bottom,
877 pix_top);
878 }
879 else {
881 angular_diameter,
882 altitude,
883 air_density,
884 aerosol_density,
885 ozone_density,
886 pix_bottom,
887 pix_top);
888 }
889
890 /* Sample center of Sun. */
891 const float3 pixel_bottom = make_float3(pix_bottom[0], pix_bottom[1], pix_bottom[2]);
892 const float3 pixel_top = make_float3(pix_top[0], pix_top[1], pix_top[2]);
893 float3 xyz = interp(pixel_bottom, pixel_top, 0.5f) * sun_intensity;
894
895 /* We first approximate the Sun's contribution by
896 * multiplying the evaluated point by the square of the angular diameter.
897 * Then we scale the approximation using a piecewise function (determined empirically). */
898 float sun_contribution = average(xyz) * sqr(angular_diameter);
899
900 const float first_point = 0.8f / 180.0f * M_PI_F;
901 const float second_point = 1.0f / 180.0f * M_PI_F;
902 const float third_point = M_PI_2_F;
903 if (angular_diameter < first_point) {
904 sun_contribution *= 1.0f;
905 }
906 else if (angular_diameter < second_point) {
907 const float diff = angular_diameter - first_point;
908 const float slope = (0.8f - 1.0f) / (second_point - first_point);
909 sun_contribution *= 1.0f + slope * diff;
910 }
911 else {
912 const float diff = angular_diameter - 1.0f / 180.0f * M_PI_F;
913 const float slope = (0.45f - 0.8f) / (third_point - second_point);
914 sun_contribution *= 0.8f + slope * diff;
915 }
916
917 return sun_contribution;
918}
919
921{
922 NodeType *type = NodeType::add("sky_texture", create, NodeType::SHADER);
924 static NodeEnum type_enum;
925 type_enum.insert("preetham", NODE_SKY_PREETHAM);
926 type_enum.insert("hosek_wilkie", NODE_SKY_HOSEK);
927 type_enum.insert("single_scattering", NODE_SKY_SINGLE_SCATTERING);
928 type_enum.insert("multiple_scattering", NODE_SKY_MULTIPLE_SCATTERING);
929 SOCKET_ENUM(sky_type, "Type", type_enum, NODE_SKY_MULTIPLE_SCATTERING);
930
931 /* Nishita parameters. */
932 SOCKET_BOOLEAN(sun_disc, "Sun Disc", true);
933 SOCKET_FLOAT(sun_size, "Sun Size", 0.009512f);
934 SOCKET_FLOAT(sun_intensity, "Sun Intensity", 1.0f);
935 SOCKET_FLOAT(sun_elevation, "Sun Elevation", 15.0f * M_PI_F / 180.0f);
936 SOCKET_FLOAT(sun_rotation, "Sun Rotation", 0.0f);
937 SOCKET_FLOAT(altitude, "Altitude", 100.0f);
938 SOCKET_FLOAT(air_density, "Air", 1.0f);
939 SOCKET_FLOAT(aerosol_density, "Aerosol", 1.0f);
940 SOCKET_FLOAT(ozone_density, "Ozone", 1.0f);
942 SOCKET_OUT_COLOR(color, "Color");
943
944 /* Legacy parameters. */
945 SOCKET_VECTOR(sun_direction, "Sun Direction", make_float3(0.0f, 0.0f, 1.0f));
946 SOCKET_FLOAT(turbidity, "Turbidity", 2.2f);
947 SOCKET_FLOAT(ground_albedo, "Ground Albedo", 0.3f);
948
949 return type;
950}
951
952SkyTextureNode::SkyTextureNode() : TextureNode(get_node_type()) {}
953
955{
956 /* Patch Sun position so users are able to animate the daylight cycle while keeping the shading
957 * code simple. */
958 float new_sun_elevation = sun_elevation;
959 float new_sun_rotation = sun_rotation;
960
961 /* Wrap `new_sun_elevation` into [-2PI..2PI] range. */
962 new_sun_elevation = fmodf(new_sun_elevation, M_2PI_F);
963 /* Wrap `new_sun_elevation` into [-PI..PI] range. */
964 if (fabsf(new_sun_elevation) >= M_PI_F) {
965 new_sun_elevation -= copysignf(2.0f, new_sun_elevation) * M_PI_F;
966 }
967 /* Wrap `new_sun_elevation` into [-PI/2..PI/2] range while keeping the same absolute position. */
968 if (new_sun_elevation >= M_PI_2_F || new_sun_elevation <= -M_PI_2_F) {
969 new_sun_elevation = copysignf(M_PI_F, new_sun_elevation) - new_sun_elevation;
970 new_sun_rotation += M_PI_F;
971 }
972
973 /* Wrap `new_sun_rotation` into [-2PI..2PI] range. */
974 new_sun_rotation = fmodf(new_sun_rotation, M_2PI_F);
975 /* Wrap `new_sun_rotation` into [0..2PI] range. */
976 if (new_sun_rotation < 0.0f) {
977 new_sun_rotation += M_2PI_F;
978 }
979 new_sun_rotation = M_2PI_F - new_sun_rotation;
980
981 sun_elevation = new_sun_elevation;
982 sun_rotation = new_sun_rotation;
983
984 if (is_modified()) {
985 handle.clear();
986 }
987}
988
990{
991 ShaderInput *vector_in = input("Vector");
992 SunSky sunsky = {};
993
994 if (sky_type == NODE_SKY_PREETHAM) {
996 }
997 else if (sky_type == NODE_SKY_HOSEK) {
998 sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo);
999 }
1000 else {
1002 sky_type == NODE_SKY_MULTIPLE_SCATTERING,
1003 sun_disc,
1004 get_sun_size(),
1005 sun_intensity,
1006 sun_elevation,
1007 sun_rotation,
1008 altitude,
1009 air_density,
1010 aerosol_density,
1011 ozone_density);
1012 /* Sky texture image parameters */
1013 ImageManager *image_manager = compiler.scene->image_manager.get();
1014 ImageParams impar;
1017
1018 /* Precompute sky texture */
1019 if (handle.empty()) {
1020 unique_ptr<SkyLoader> loader = make_unique<SkyLoader>(sky_type ==
1022 sun_elevation,
1023 altitude,
1024 air_density,
1025 aerosol_density,
1026 ozone_density);
1027 handle = image_manager->add_image(std::move(loader), impar);
1028 }
1029 }
1030
1031 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1032
1033 compiler.add_node(this,
1034 NODE_TEX_SKY,
1035 SVMNodeTexSky{
1036 .sky_type = sky_type,
1037 .dir_offset = vector_offset,
1038 .out_offset = compiler.output("Color"),
1039 });
1040 if (sky_type == NODE_SKY_PREETHAM || sky_type == NODE_SKY_HOSEK) {
1041 SVMNodeTexSkyPreethamData preetham_data = {};
1042 preetham_data.phi = sunsky.phi;
1043 preetham_data.theta = sunsky.theta;
1044 preetham_data.radiance_x = sunsky.radiance_x;
1045 preetham_data.radiance_y = sunsky.radiance_y;
1046 preetham_data.radiance_z = sunsky.radiance_z;
1047 memcpy(preetham_data.config_x, sunsky.config_x, sizeof(preetham_data.config_x));
1048 memcpy(preetham_data.config_y, sunsky.config_y, sizeof(preetham_data.config_y));
1049 memcpy(preetham_data.config_z, sunsky.config_z, sizeof(preetham_data.config_z));
1050 compiler.add_node_data(preetham_data);
1051 }
1052 else {
1053 compiler.add_node_data(SVMNodeTexSkyNishitaData{
1054 .pixel_bottom_x = sunsky.nishita_data[0],
1055 .pixel_bottom_y = sunsky.nishita_data[1],
1056 .pixel_bottom_z = sunsky.nishita_data[2],
1057 .pixel_top_x = sunsky.nishita_data[3],
1058 .pixel_top_y = sunsky.nishita_data[4],
1059 .pixel_top_z = sunsky.nishita_data[5],
1060 .sun_elevation = sunsky.nishita_data[6],
1061 .sun_rotation = sunsky.nishita_data[7],
1062 .angular_diameter = sunsky.nishita_data[8],
1063 .sun_intensity = sunsky.nishita_data[9],
1064 .earth_intersection_angle = sunsky.nishita_data[10],
1065 .texture_id = uint(handle.kernel_id()),
1066 });
1067 }
1068
1069 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1070}
1071
1073{
1074 tex_mapping.compile(compiler);
1075 SunSky sunsky = {};
1076
1077 if (sky_type == NODE_SKY_PREETHAM) {
1079 }
1080 else if (sky_type == NODE_SKY_HOSEK) {
1081 sky_texture_precompute_hosek(&sunsky, sun_direction, turbidity, ground_albedo);
1082 }
1083 else {
1085 sky_type == NODE_SKY_MULTIPLE_SCATTERING,
1086 sun_disc,
1087 get_sun_size(),
1088 sun_intensity,
1089 sun_elevation,
1090 sun_rotation,
1091 altitude,
1092 air_density,
1093 aerosol_density,
1094 ozone_density);
1095 /* Sky texture image parameters */
1096 ImageManager *image_manager = compiler.scene->image_manager.get();
1097 ImageParams impar;
1100
1101 /* Precompute sky texture */
1102 {
1103 unique_ptr<SkyLoader> loader = make_unique<SkyLoader>(sky_type ==
1105 sun_elevation,
1106 altitude,
1107 air_density,
1108 aerosol_density,
1109 ozone_density);
1110 handle = image_manager->add_image(std::move(loader), impar);
1111 }
1112
1113 compiler.parameter_texture("filename", handle);
1114 }
1115
1116 compiler.parameter(this, "sky_type");
1117 compiler.parameter("theta", sunsky.theta);
1118 compiler.parameter("phi", sunsky.phi);
1119 compiler.parameter_color("radiance",
1120 make_float3(sunsky.radiance_x, sunsky.radiance_y, sunsky.radiance_z));
1121 compiler.parameter_array("config_x", sunsky.config_x, 9);
1122 compiler.parameter_array("config_y", sunsky.config_y, 9);
1123 compiler.parameter_array("config_z", sunsky.config_z, 9);
1124 compiler.parameter_array("nishita_data", sunsky.nishita_data, 11);
1125 compiler.add(this, "node_sky_texture");
1126}
1127
1128/* Gradient Texture */
1129
1131{
1132 NodeType *type = NodeType::add("gradient_texture", create, NodeType::SHADER);
1133
1135
1136 static NodeEnum type_enum;
1137 type_enum.insert("linear", NODE_BLEND_LINEAR);
1138 type_enum.insert("quadratic", NODE_BLEND_QUADRATIC);
1139 type_enum.insert("easing", NODE_BLEND_EASING);
1140 type_enum.insert("diagonal", NODE_BLEND_DIAGONAL);
1141 type_enum.insert("radial", NODE_BLEND_RADIAL);
1142 type_enum.insert("quadratic_sphere", NODE_BLEND_QUADRATIC_SPHERE);
1143 type_enum.insert("spherical", NODE_BLEND_SPHERICAL);
1144 SOCKET_ENUM(gradient_type, "Type", type_enum, NODE_BLEND_LINEAR);
1145
1147
1148 SOCKET_OUT_COLOR(color, "Color");
1149 SOCKET_OUT_FLOAT(fac, "Fac");
1150
1151 return type;
1152}
1153
1154GradientTextureNode::GradientTextureNode() : TextureNode(get_node_type()) {}
1155
1157{
1158 ShaderInput *vector_in = input("Vector");
1159
1160 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1161 compiler.add_node(this,
1162 NODE_TEX_GRADIENT,
1163 SVMNodeTexGradient{
1164 .gradient_type = gradient_type,
1165 .co = vector_offset,
1166 .fac_offset = compiler.output("Fac"),
1167 .color_offset = compiler.output("Color"),
1168 });
1169
1170 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1171}
1172
1174{
1175 tex_mapping.compile(compiler);
1176
1177 compiler.parameter(this, "gradient_type");
1178 compiler.add(this, "node_gradient_texture");
1179}
1180
1181/* Noise Texture */
1182
1184{
1185 NodeType *type = NodeType::add("noise_texture", create, NodeType::SHADER);
1186
1188
1189 static NodeEnum dimensions_enum;
1190 dimensions_enum.insert("1D", 1);
1191 dimensions_enum.insert("2D", 2);
1192 dimensions_enum.insert("3D", 3);
1193 dimensions_enum.insert("4D", 4);
1194 SOCKET_ENUM(dimensions, "Dimensions", dimensions_enum, 3);
1195
1196 static NodeEnum type_enum;
1197 type_enum.insert("multifractal", NODE_NOISE_MULTIFRACTAL);
1198 type_enum.insert("fBM", NODE_NOISE_FBM);
1199 type_enum.insert("hybrid_multifractal", NODE_NOISE_HYBRID_MULTIFRACTAL);
1200 type_enum.insert("ridged_multifractal", NODE_NOISE_RIDGED_MULTIFRACTAL);
1201 type_enum.insert("hetero_terrain", NODE_NOISE_HETERO_TERRAIN);
1202 SOCKET_ENUM(type, "Type", type_enum, NODE_NOISE_FBM);
1203
1204 SOCKET_BOOLEAN(use_normalize, "Normalize", true);
1205
1207 SOCKET_IN_FLOAT(w, "W", 0.0f);
1208 SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
1209 SOCKET_IN_FLOAT(detail, "Detail", 2.0f);
1210 SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
1211 SOCKET_IN_FLOAT(lacunarity, "Lacunarity", 2.0f);
1212 SOCKET_IN_FLOAT(offset, "Offset", 0.0f);
1213 SOCKET_IN_FLOAT(gain, "Gain", 1.0f);
1214 SOCKET_IN_FLOAT(distortion, "Distortion", 0.0f);
1215
1216 SOCKET_OUT_FLOAT(fac, "Fac");
1217 SOCKET_OUT_COLOR(color, "Color");
1218
1219 return type;
1220}
1221
1222NoiseTextureNode::NoiseTextureNode() : TextureNode(get_node_type()) {}
1223
1225{
1226 ShaderInput *vector_in = input("Vector");
1227
1228 const SVMStackOffset vector_stack_offset = tex_mapping.compile_begin(
1229 compiler, vector_in, nullptr);
1230 compiler.add_node(this,
1231 NODE_TEX_NOISE,
1232 SVMNodeTexNoise{
1233 .dimensions = uint(dimensions),
1234 .noise_type = type,
1235 .normalize = uint(use_normalize),
1236 .w = compiler.input_float("W"),
1237 .scale = compiler.input_float("Scale"),
1238 .detail = compiler.input_float("Detail"),
1239 .roughness = compiler.input_float("Roughness"),
1240 .lacunarity = compiler.input_float("Lacunarity"),
1241 .offset = compiler.input_float("Offset"),
1242 .gain = compiler.input_float("Gain"),
1243 .distortion = compiler.input_float("Distortion"),
1244 .vector = vector_stack_offset,
1245 .value_offset = compiler.output("Fac"),
1246 .color_offset = compiler.output("Color"),
1247 });
1248
1249 tex_mapping.compile_end(compiler, vector_in, vector_stack_offset);
1250}
1251
1253{
1254 tex_mapping.compile(compiler);
1255 compiler.parameter(this, "dimensions");
1256 compiler.parameter(this, "type");
1257 compiler.parameter(this, "use_normalize");
1258 compiler.add(this, "node_noise_texture");
1259}
1260
1261/* Gabor Texture */
1262
1264{
1265 NodeType *type = NodeType::add("gabor_texture", create, NodeType::SHADER);
1266
1268
1269 static NodeEnum type_enum;
1270 type_enum.insert("2D", NODE_GABOR_TYPE_2D);
1271 type_enum.insert("3D", NODE_GABOR_TYPE_3D);
1272 SOCKET_ENUM(type, "Type", type_enum, NODE_GABOR_TYPE_2D);
1273
1275 SOCKET_IN_FLOAT(scale, "Scale", 5.0f);
1276 SOCKET_IN_FLOAT(frequency, "Frequency", 2.0f);
1277 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 1.0f);
1278 SOCKET_IN_FLOAT(orientation_2d, "Orientation 2D", M_PI_F / 4.0f);
1279 SOCKET_IN_VECTOR(orientation_3d, "Orientation 3D", make_float3(M_SQRT2_F, M_SQRT2_F, 0.0f));
1280
1281 SOCKET_OUT_FLOAT(value, "Value");
1282 SOCKET_OUT_FLOAT(phase, "Phase");
1283 SOCKET_OUT_FLOAT(intensity, "Intensity");
1284
1285 return type;
1286}
1287
1288GaborTextureNode::GaborTextureNode() : TextureNode(get_node_type()) {}
1289
1291{
1292 ShaderInput *vector_in = input("Vector");
1293
1294 const SVMStackOffset vector_stack_offset = tex_mapping.compile_begin(
1295 compiler, vector_in, nullptr);
1296 compiler.add_node(this,
1297 NODE_TEX_GABOR,
1298 SVMNodeTexGabor{
1299 .gabor_type = type,
1300 .orientation_3d = compiler.input_float3("Orientation 3D"),
1301 .scale = compiler.input_float("Scale"),
1302 .frequency = compiler.input_float("Frequency"),
1303 .anisotropy = compiler.input_float("Anisotropy"),
1304 .orientation_2d = compiler.input_float("Orientation 2D"),
1305 .coordinates = vector_stack_offset,
1306 .value_offset = compiler.output("Value"),
1307 .phase_offset = compiler.output("Phase"),
1308 .intensity_offset = compiler.output("Intensity"),
1309 });
1310
1311 tex_mapping.compile_end(compiler, vector_in, vector_stack_offset);
1312}
1313
1315{
1316 tex_mapping.compile(compiler);
1317 compiler.parameter(this, "type");
1318 compiler.add(this, "node_gabor_texture");
1319}
1320
1321/* Voronoi Texture */
1322
1324{
1325 NodeType *type = NodeType::add("voronoi_texture", create, NodeType::SHADER);
1326
1328
1329 static NodeEnum dimensions_enum;
1330 dimensions_enum.insert("1D", 1);
1331 dimensions_enum.insert("2D", 2);
1332 dimensions_enum.insert("3D", 3);
1333 dimensions_enum.insert("4D", 4);
1334 SOCKET_ENUM(dimensions, "Dimensions", dimensions_enum, 3);
1335
1336 static NodeEnum metric_enum;
1337 metric_enum.insert("euclidean", NODE_VORONOI_EUCLIDEAN);
1338 metric_enum.insert("manhattan", NODE_VORONOI_MANHATTAN);
1339 metric_enum.insert("chebychev", NODE_VORONOI_CHEBYCHEV);
1340 metric_enum.insert("minkowski", NODE_VORONOI_MINKOWSKI);
1341 SOCKET_ENUM(metric, "Distance Metric", metric_enum, NODE_VORONOI_EUCLIDEAN);
1342
1343 static NodeEnum feature_enum;
1344 feature_enum.insert("f1", NODE_VORONOI_F1);
1345 feature_enum.insert("f2", NODE_VORONOI_F2);
1346 feature_enum.insert("smooth_f1", NODE_VORONOI_SMOOTH_F1);
1347 feature_enum.insert("distance_to_edge", NODE_VORONOI_DISTANCE_TO_EDGE);
1348 feature_enum.insert("n_sphere_radius", NODE_VORONOI_N_SPHERE_RADIUS);
1349 SOCKET_ENUM(feature, "Feature", feature_enum, NODE_VORONOI_F1);
1350
1351 SOCKET_BOOLEAN(use_normalize, "Normalize", false);
1352
1354 SOCKET_IN_FLOAT(w, "W", 0.0f);
1355 SOCKET_IN_FLOAT(scale, "Scale", 5.0f);
1356 SOCKET_IN_FLOAT(detail, "Detail", 0.0f);
1357 SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
1358 SOCKET_IN_FLOAT(lacunarity, "Lacunarity", 2.0f);
1359 SOCKET_IN_FLOAT(smoothness, "Smoothness", 5.0f);
1360 SOCKET_IN_FLOAT(exponent, "Exponent", 0.5f);
1361 SOCKET_IN_FLOAT(randomness, "Randomness", 1.0f);
1362
1363 SOCKET_OUT_FLOAT(distance, "Distance");
1364 SOCKET_OUT_COLOR(color, "Color");
1365 SOCKET_OUT_POINT(position, "Position");
1366 SOCKET_OUT_FLOAT(w, "W");
1367 SOCKET_OUT_FLOAT(radius, "Radius");
1368
1369 return type;
1370}
1371
1372VoronoiTextureNode::VoronoiTextureNode() : TextureNode(get_node_type()) {}
1373
1375{
1376 ShaderInput *vector_in = input("Vector");
1377
1378 const SVMStackOffset vector_stack_offset = tex_mapping.compile_begin(
1379 compiler, vector_in, nullptr);
1380 compiler.add_node(this,
1381 NODE_TEX_VORONOI,
1382 SVMNodeTexVoronoi{
1383 .dimensions = uint(dimensions),
1384 .feature = feature,
1385 .metric = metric,
1386 .w = compiler.input_float("W"),
1387 .scale = compiler.input_float("Scale"),
1388 .detail = compiler.input_float("Detail"),
1389 .roughness = compiler.input_float("Roughness"),
1390 .lacunarity = compiler.input_float("Lacunarity"),
1391 .smoothness = compiler.input_float("Smoothness"),
1392 .exponent = compiler.input_float("Exponent"),
1393 .randomness = compiler.input_float("Randomness"),
1394 .normalize = use_normalize,
1395 .coord = vector_stack_offset,
1396 .distance_offset = compiler.output("Distance"),
1397 .color_offset = compiler.output("Color"),
1398 .position_offset = compiler.output("Position"),
1399 .w_out_offset = compiler.output("W"),
1400 .radius_offset = compiler.output("Radius"),
1401 });
1402 tex_mapping.compile_end(compiler, vector_in, vector_stack_offset);
1403}
1404
1406{
1407 tex_mapping.compile(compiler);
1408
1409 compiler.parameter(this, "dimensions");
1410 compiler.parameter(this, "feature");
1411 compiler.parameter(this, "metric");
1412 compiler.parameter(this, "use_normalize");
1413 compiler.add(this, "node_voronoi_texture");
1414}
1415
1416/* IES Light */
1417
1419{
1420 NodeType *type = NodeType::add("ies_light", create, NodeType::SHADER);
1421
1423
1424 SOCKET_STRING(ies, "IES", ustring());
1425 SOCKET_STRING(filename, "File Name", ustring());
1426
1427 SOCKET_IN_FLOAT(strength, "Strength", 1.0f);
1429
1430 SOCKET_OUT_FLOAT(fac, "Fac");
1431
1432 return type;
1433}
1434
1435IESLightNode::IESLightNode() : TextureNode(get_node_type())
1436{
1437 light_manager = nullptr;
1438 slot = -1;
1439}
1440
1442{
1443 IESLightNode *node = graph->create_node<IESLightNode>(*this);
1444
1445 node->light_manager = nullptr;
1446 node->slot = -1;
1447
1448 return node;
1449}
1450
1452{
1453 if (light_manager) {
1454 light_manager->remove_ies(slot);
1455 }
1456}
1457
1458void IESLightNode::get_slot()
1459{
1460 assert(light_manager);
1461
1462 if (slot == -1) {
1463 if (ies.empty()) {
1464 slot = light_manager->add_ies_from_file(filename.string());
1465 }
1466 else {
1467 slot = light_manager->add_ies(ies.string(), true);
1468 }
1469 }
1470}
1471
1472void IESLightNode::compile(SVMCompiler &compiler)
1473{
1474 light_manager = compiler.scene->light_manager.get();
1475 get_slot();
1476 ShaderInput *vector_in = input("Vector");
1477
1478 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1479 compiler.add_node(this,
1480 NODE_IES,
1481 SVMNodeIES{
1482 .strength = compiler.input_float("Strength"),
1483 .slot = uint(slot),
1484 .vector_offset = vector_offset,
1485 .fac_offset = compiler.output("Fac"),
1486 });
1487
1488 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1489}
1490
1491void IESLightNode::compile(OSLCompiler &compiler)
1492{
1493 light_manager = compiler.scene->light_manager.get();
1494 get_slot();
1495
1496 tex_mapping.compile(compiler);
1497
1498 compiler.parameter_texture_ies("filename", slot);
1499 compiler.add(this, "node_ies_light");
1500}
1501
1502/* White Noise Texture */
1503
1505{
1506 NodeType *type = NodeType::add("white_noise_texture", create, NodeType::SHADER);
1507
1508 static NodeEnum dimensions_enum;
1509 dimensions_enum.insert("1D", 1);
1510 dimensions_enum.insert("2D", 2);
1511 dimensions_enum.insert("3D", 3);
1512 dimensions_enum.insert("4D", 4);
1513 SOCKET_ENUM(dimensions, "Dimensions", dimensions_enum, 3);
1514
1515 SOCKET_IN_POINT(vector, "Vector", zero_float3());
1516 SOCKET_IN_FLOAT(w, "W", 0.0f);
1517
1518 SOCKET_OUT_FLOAT(value, "Value");
1519 SOCKET_OUT_COLOR(color, "Color");
1520
1521 return type;
1522}
1523
1524WhiteNoiseTextureNode::WhiteNoiseTextureNode() : ShaderNode(get_node_type()) {}
1525
1527{
1528 compiler.add_node(this,
1529 NODE_TEX_WHITE_NOISE,
1530 SVMNodeTexWhiteNoise{
1531 .dimensions = uint(dimensions),
1532 .vector = compiler.input_float3("Vector"),
1533 .w = compiler.input_float("W"),
1534 .value_offset = compiler.output("Value"),
1535 .color_offset = compiler.output("Color"),
1536 });
1537}
1538
1540{
1541 compiler.parameter(this, "dimensions");
1542 compiler.add(this, "node_white_noise_texture");
1543}
1544
1545/* Wave Texture */
1546
1548{
1549 NodeType *type = NodeType::add("wave_texture", create, NodeType::SHADER);
1550
1552
1553 static NodeEnum type_enum;
1554 type_enum.insert("bands", NODE_WAVE_BANDS);
1555 type_enum.insert("rings", NODE_WAVE_RINGS);
1556 SOCKET_ENUM(wave_type, "Type", type_enum, NODE_WAVE_BANDS);
1557
1558 static NodeEnum bands_direction_enum;
1559 bands_direction_enum.insert("x", NODE_WAVE_BANDS_DIRECTION_X);
1560 bands_direction_enum.insert("y", NODE_WAVE_BANDS_DIRECTION_Y);
1561 bands_direction_enum.insert("z", NODE_WAVE_BANDS_DIRECTION_Z);
1562 bands_direction_enum.insert("diagonal", NODE_WAVE_BANDS_DIRECTION_DIAGONAL);
1564 bands_direction, "Bands Direction", bands_direction_enum, NODE_WAVE_BANDS_DIRECTION_X);
1565
1566 static NodeEnum rings_direction_enum;
1567 rings_direction_enum.insert("x", NODE_WAVE_RINGS_DIRECTION_X);
1568 rings_direction_enum.insert("y", NODE_WAVE_RINGS_DIRECTION_Y);
1569 rings_direction_enum.insert("z", NODE_WAVE_RINGS_DIRECTION_Z);
1570 rings_direction_enum.insert("spherical", NODE_WAVE_RINGS_DIRECTION_SPHERICAL);
1572 rings_direction, "Rings Direction", rings_direction_enum, NODE_WAVE_BANDS_DIRECTION_X);
1573
1574 static NodeEnum profile_enum;
1575 profile_enum.insert("sine", NODE_WAVE_PROFILE_SIN);
1576 profile_enum.insert("saw", NODE_WAVE_PROFILE_SAW);
1577 profile_enum.insert("tri", NODE_WAVE_PROFILE_TRI);
1578 SOCKET_ENUM(profile, "Profile", profile_enum, NODE_WAVE_PROFILE_SIN);
1579
1581 SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
1582 SOCKET_IN_FLOAT(distortion, "Distortion", 0.0f);
1583 SOCKET_IN_FLOAT(detail, "Detail", 2.0f);
1584 SOCKET_IN_FLOAT(detail_scale, "Detail Scale", 0.0f);
1585 SOCKET_IN_FLOAT(detail_roughness, "Detail Roughness", 0.5f);
1586 SOCKET_IN_FLOAT(phase, "Phase Offset", 0.0f);
1587 SOCKET_OUT_COLOR(color, "Color");
1588 SOCKET_OUT_FLOAT(fac, "Fac");
1589
1590 return type;
1591}
1592
1593WaveTextureNode::WaveTextureNode() : TextureNode(get_node_type()) {}
1594
1596{
1597 ShaderInput *vector_in = input("Vector");
1598
1599 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1600 compiler.add_node(this,
1601 NODE_TEX_WAVE,
1602 SVMNodeTexWave{
1603 .wave_type = wave_type,
1604 .bands_direction = bands_direction,
1605 .rings_direction = rings_direction,
1606 .profile = profile,
1607 .scale = compiler.input_float("Scale"),
1608 .distortion = compiler.input_float("Distortion"),
1609 .detail = compiler.input_float("Detail"),
1610 .dscale = compiler.input_float("Detail Scale"),
1611 .droughness = compiler.input_float("Detail Roughness"),
1612 .phase = compiler.input_float("Phase Offset"),
1613 .co = vector_offset,
1614 .color_offset = compiler.output("Color"),
1615 .fac_offset = compiler.output("Fac"),
1616 });
1617
1618 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1619}
1620
1622{
1623 tex_mapping.compile(compiler);
1624
1625 compiler.parameter(this, "wave_type");
1626 compiler.parameter(this, "bands_direction");
1627 compiler.parameter(this, "rings_direction");
1628 compiler.parameter(this, "profile");
1629
1630 compiler.add(this, "node_wave_texture");
1631}
1632
1633/* Magic Texture */
1634
1636{
1637 NodeType *type = NodeType::add("magic_texture", create, NodeType::SHADER);
1638
1640
1641 SOCKET_INT(depth, "Depth", 2);
1642
1644 SOCKET_IN_FLOAT(scale, "Scale", 5.0f);
1645 SOCKET_IN_FLOAT(distortion, "Distortion", 1.0f);
1646
1647 SOCKET_OUT_COLOR(color, "Color");
1648 SOCKET_OUT_FLOAT(fac, "Fac");
1649
1650 return type;
1651}
1652
1653MagicTextureNode::MagicTextureNode() : TextureNode(get_node_type()) {}
1654
1656{
1657 ShaderInput *vector_in = input("Vector");
1658
1659 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1660 compiler.add_node(this,
1661 NODE_TEX_MAGIC,
1662 SVMNodeTexMagic{
1663 .scale = compiler.input_float("Scale"),
1664 .distortion = compiler.input_float("Distortion"),
1665 .depth = uint8_t(depth),
1666 .co = vector_offset,
1667 .color_offset = compiler.output("Color"),
1668 .fac_offset = compiler.output("Fac"),
1669 });
1670
1671 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1672}
1673
1675{
1676 tex_mapping.compile(compiler);
1677
1678 compiler.parameter(this, "depth");
1679 compiler.add(this, "node_magic_texture");
1680}
1681
1682/* Checker Texture */
1683
1685{
1686 NodeType *type = NodeType::add("checker_texture", create, NodeType::SHADER);
1687
1689
1691 SOCKET_IN_COLOR(color1, "Color1", zero_float3());
1692 SOCKET_IN_COLOR(color2, "Color2", zero_float3());
1693 SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
1694
1695 SOCKET_OUT_COLOR(color, "Color");
1696 SOCKET_OUT_FLOAT(fac, "Fac");
1697
1698 return type;
1699}
1700
1701CheckerTextureNode::CheckerTextureNode() : TextureNode(get_node_type()) {}
1702
1704{
1705 ShaderInput *vector_in = input("Vector");
1706
1707 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1708 compiler.add_node(this,
1709 NODE_TEX_CHECKER,
1710 SVMNodeTexChecker{
1711 .color1 = compiler.input_float3("Color1"),
1712 .color2 = compiler.input_float3("Color2"),
1713 .scale = compiler.input_float("Scale"),
1714 .co = vector_offset,
1715 .color_offset = compiler.output("Color"),
1716 .fac_offset = compiler.output("Fac"),
1717 });
1718
1719 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1720}
1721
1723{
1724 tex_mapping.compile(compiler);
1725
1726 compiler.add(this, "node_checker_texture");
1727}
1728
1729/* Brick Texture */
1730
1732{
1733 NodeType *type = NodeType::add("brick_texture", create, NodeType::SHADER);
1734
1736
1737 SOCKET_FLOAT(offset, "Offset", 0.5f);
1738 SOCKET_INT(offset_frequency, "Offset Frequency", 2);
1739 SOCKET_FLOAT(squash, "Squash", 1.0f);
1740 SOCKET_INT(squash_frequency, "Squash Frequency", 2);
1741
1743
1744 SOCKET_IN_COLOR(color1, "Color1", zero_float3());
1745 SOCKET_IN_COLOR(color2, "Color2", zero_float3());
1746 SOCKET_IN_COLOR(mortar, "Mortar", zero_float3());
1747 SOCKET_IN_FLOAT(scale, "Scale", 5.0f);
1748 SOCKET_IN_FLOAT(mortar_size, "Mortar Size", 0.02f);
1749 SOCKET_IN_FLOAT(mortar_smooth, "Mortar Smooth", 0.0f);
1750 SOCKET_IN_FLOAT(bias, "Bias", 0.0f);
1751 SOCKET_IN_FLOAT(brick_width, "Brick Width", 0.5f);
1752 SOCKET_IN_FLOAT(row_height, "Row Height", 0.25f);
1753
1754 SOCKET_OUT_COLOR(color, "Color");
1755 SOCKET_OUT_FLOAT(fac, "Fac");
1756
1757 return type;
1758}
1759
1760BrickTextureNode::BrickTextureNode() : TextureNode(get_node_type()) {}
1761
1763{
1764 ShaderInput *vector_in = input("Vector");
1765
1766 const SVMStackOffset vector_offset = tex_mapping.compile_begin(compiler, vector_in, nullptr);
1767 compiler.add_node(this,
1768 NODE_TEX_BRICK,
1769 SVMNodeTexBrick{
1770 .color1 = compiler.input_float3("Color1"),
1771 .color2 = compiler.input_float3("Color2"),
1772 .mortar = compiler.input_float3("Mortar"),
1773 .scale = compiler.input_float("Scale"),
1774 .mortar_size = compiler.input_float("Mortar Size"),
1775 .bias = compiler.input_float("Bias"),
1776 .brick_width = compiler.input_float("Brick Width"),
1777 .row_height = compiler.input_float("Row Height"),
1778 .mortar_smooth = compiler.input_float("Mortar Smooth"),
1779 .offset_amount = offset,
1780 .squash_amount = squash,
1781 .offset_frequency = uint8_t(offset_frequency),
1782 .squash_frequency = uint8_t(squash_frequency),
1783 .co = vector_offset,
1784 .color_offset = compiler.output("Color"),
1785 .fac_offset = compiler.output("Fac"),
1786 });
1787
1788 tex_mapping.compile_end(compiler, vector_in, vector_offset);
1789}
1790
1792{
1793 tex_mapping.compile(compiler);
1794
1795 compiler.parameter(this, "offset");
1796 compiler.parameter(this, "offset_frequency");
1797 compiler.parameter(this, "squash");
1798 compiler.parameter(this, "squash_frequency");
1799 compiler.add(this, "node_brick_texture");
1800}
1801
1802/* Normal */
1803
1805{
1806 NodeType *type = NodeType::add("normal", create, NodeType::SHADER);
1807
1808 SOCKET_VECTOR(direction, "direction", zero_float3());
1809
1810 SOCKET_IN_NORMAL(normal, "Normal", zero_float3());
1811
1812 SOCKET_OUT_NORMAL(normal, "Normal");
1813 SOCKET_OUT_FLOAT(dot, "Dot");
1814
1815 return type;
1816}
1817
1818NormalNode::NormalNode() : ShaderNode(get_node_type()) {}
1819
1820void NormalNode::compile(SVMCompiler &compiler)
1821{
1822 compiler.add_node(this,
1823 NODE_NORMAL,
1824 SVMNodeNormal{
1825 .in_normal = compiler.input_float3("Normal"),
1826 .out_normal_offset = compiler.output("Normal"),
1827 .out_dot_offset = compiler.output("Dot"),
1828 .direction_x = direction.x,
1829 .direction_y = direction.y,
1830 .direction_z = direction.z,
1831 });
1832}
1833
1834void NormalNode::compile(OSLCompiler &compiler)
1835{
1836 compiler.parameter(this, "direction");
1837 compiler.add(this, "node_normal");
1838}
1839
1840/* Mapping */
1841
1843{
1844 NodeType *type = NodeType::add("mapping", create, NodeType::SHADER);
1845
1846 static NodeEnum type_enum;
1847 type_enum.insert("point", NODE_MAPPING_TYPE_POINT);
1848 type_enum.insert("texture", NODE_MAPPING_TYPE_TEXTURE);
1849 type_enum.insert("vector", NODE_MAPPING_TYPE_VECTOR);
1850 type_enum.insert("normal", NODE_MAPPING_TYPE_NORMAL);
1851 SOCKET_ENUM(mapping_type, "Type", type_enum, NODE_MAPPING_TYPE_POINT);
1852
1853 SOCKET_IN_POINT(vector, "Vector", zero_float3());
1854 SOCKET_IN_POINT(location, "Location", zero_float3());
1855 SOCKET_IN_POINT(rotation, "Rotation", zero_float3());
1856 SOCKET_IN_POINT(scale, "Scale", one_float3());
1857
1858 SOCKET_OUT_POINT(vector, "Vector");
1859
1860 return type;
1861}
1862
1863MappingNode::MappingNode() : ShaderNode(get_node_type()) {}
1864
1866{
1867 if (folder.all_inputs_constant()) {
1868 const float3 result = svm_mapping(mapping_type, vector, location, rotation, scale);
1869 folder.make_constant(result);
1870 }
1871 else {
1872 folder.fold_mapping(mapping_type);
1873 }
1874}
1875
1876void MappingNode::compile(SVMCompiler &compiler)
1877{
1878 compiler.add_node(this,
1879 NODE_MAPPING,
1881 .mapping_type = mapping_type,
1882 .vector = compiler.input_float3("Vector"),
1883 .location = compiler.input_float3("Location"),
1884 .rotation = compiler.input_float3("Rotation"),
1885 .scale = compiler.input_float3("Scale"),
1886 .result_offset = compiler.output("Vector"),
1887 });
1888}
1889
1890void MappingNode::compile(OSLCompiler &compiler)
1891{
1892 compiler.parameter(this, "mapping_type");
1893 compiler.add(this, "node_mapping");
1894}
1895
1896/* RGBToBW */
1897
1899{
1900 NodeType *type = NodeType::add("rgb_to_bw", create, NodeType::SHADER);
1901
1902 SOCKET_IN_COLOR(color, "Color", zero_float3());
1903 SOCKET_OUT_FLOAT(val, "Val");
1904
1905 return type;
1906}
1907
1908RGBToBWNode::RGBToBWNode() : ShaderNode(get_node_type()) {}
1909
1911{
1912 if (folder.all_inputs_constant()) {
1913 const float val = folder.scene->shader_manager->linear_rgb_to_gray(color);
1914 folder.make_constant(val);
1915 }
1916}
1917
1918void RGBToBWNode::compile(SVMCompiler &compiler)
1919{
1920 compiler.add_node(this,
1921 NODE_CONVERT,
1923 .convert_type = NODE_CONVERT_CF,
1924 .from_offset = compiler.input_link("Color"),
1925 .to_offset = compiler.output("Val"),
1926 });
1927}
1928
1929void RGBToBWNode::compile(OSLCompiler &compiler)
1930{
1931 compiler.add(this, "node_rgb_to_bw");
1932}
1933
1934/* Convert */
1935
1936const NodeType *(&ConvertNode::get_node_types()) [ConvertNode::MAX_TYPE][ConvertNode::MAX_TYPE] {
1937 static const NodeType *node_types[MAX_TYPE][MAX_TYPE];
1938 static std::once_flag node_types_flag;
1939
1940 std::call_once(node_types_flag, [&] {
1941 const int num_types = 8;
1942 const SocketType::Type types[num_types] = {SocketType::FLOAT,
1950
1951 for (size_t i = 0; i < num_types; i++) {
1952 const SocketType::Type from = types[i];
1953 const ustring from_name(SocketType::type_name(from));
1954 const ustring from_value_name("value_" + from_name.string());
1955
1956 for (size_t j = 0; j < num_types; j++) {
1957 const SocketType::Type to = types[j];
1958 const ustring to_name(SocketType::type_name(to));
1959 const ustring to_value_name("value_" + to_name.string());
1960
1961 const string node_name = "convert_" + from_name.string() + "_to_" + to_name.string();
1962 NodeType *type = NodeType::add(node_name.c_str(), create, NodeType::SHADER);
1963
1964 type->register_input(from_value_name,
1965 from_value_name,
1966 from,
1967 SOCKET_OFFSETOF(ConvertNode, value_float),
1969 nullptr,
1970 nullptr,
1972 type->register_output(to_value_name, to_value_name, to);
1973
1974 assert(from < MAX_TYPE);
1975 assert(to < MAX_TYPE);
1976
1977 node_types[from][to] = type;
1978 }
1979 }
1980 });
1981
1982 return node_types;
1983}
1984
1985bool ConvertNode::register_on_init = NodeType::register_on_init([] {
1986 ConvertNode::get_node_types();
1987 return static_cast<const NodeType *>(nullptr);
1988});
1989
1990unique_ptr<Node> ConvertNode::create(const NodeType *type)
1991{
1992 return make_unique<ConvertNode>(type->inputs[0].type, type->outputs[0].type);
1993}
1994
1996 : ShaderNode(get_node_types()[from_][to_])
1997{
1998 from = from_;
1999 to = to_;
2000
2001 if (from == to) {
2003 }
2004 else if (autoconvert) {
2006 }
2007}
2008
2009/* Union usage requires a manual copy constructor. */
2011 : ShaderNode(other),
2012 from(other.from),
2013 to(other.to),
2014 value_color(other.value_color),
2015 value_string(other.value_string)
2016{
2017}
2018
2020{
2021 /* proxy nodes should have been removed at this point */
2023
2024 if (folder.all_inputs_constant()) {
2025 if (from == SocketType::FLOAT || from == SocketType::INT) {
2026 float val = value_float;
2027 if (from == SocketType::INT) {
2028 val = value_int;
2029 }
2030 if (SocketType::is_float3(to)) {
2031 folder.make_constant(make_float3(val, val, val));
2032 }
2033 else if (to == SocketType::INT) {
2034 folder.make_constant((int)val);
2035 }
2036 else if (to == SocketType::FLOAT) {
2037 folder.make_constant(val);
2038 }
2039 }
2040 else if (SocketType::is_float3(from)) {
2041 if (to == SocketType::FLOAT || to == SocketType::INT) {
2042 float val;
2043 if (from == SocketType::COLOR) {
2044 /* color to scalar */
2045 val = folder.scene->shader_manager->linear_rgb_to_gray(value_color);
2046 }
2047 else {
2048 /* vector/point/normal to scalar */
2049 val = average(value_vector);
2050 }
2051 if (to == SocketType::INT) {
2052 folder.make_constant((int)val);
2053 }
2054 else if (to == SocketType::FLOAT) {
2055 folder.make_constant(val);
2056 }
2057 }
2058 else if (SocketType::is_float3(to)) {
2059 folder.make_constant(value_color);
2060 }
2061 }
2062 }
2063 else {
2064 ShaderInput *in = inputs[0];
2065 ShaderNode *prev = in->link->parent;
2066
2067 /* no-op conversion of A to B to A */
2068 if (prev->type == get_node_types()[to][from]) {
2069 ShaderInput *prev_in = prev->inputs[0];
2070
2072 prev_in->link)
2073 {
2074 folder.bypass(prev_in->link);
2075 }
2076 }
2077 }
2078}
2079
2081{
2082 if (from == SocketType::FLOAT) {
2083 if (to == SocketType::INT) {
2084 /* float to int */
2085 return NODE_CONVERT_FI;
2086 }
2087 /* float to float3 */
2088 return NODE_CONVERT_FV;
2089 }
2090 if (from == SocketType::INT) {
2091 if (to == SocketType::FLOAT) {
2092 /* int to float */
2093 return NODE_CONVERT_IF;
2094 }
2095 /* int to vector/point/normal */
2096 return NODE_CONVERT_IV;
2097 }
2098 if (to == SocketType::FLOAT) {
2099 if (from == SocketType::COLOR) {
2100 /* color to float */
2101 return NODE_CONVERT_CF;
2102 }
2103 /* vector/point/normal to float */
2104 return NODE_CONVERT_VF;
2105 }
2106 if (to == SocketType::INT) {
2107 if (from == SocketType::COLOR) {
2108 /* color to int */
2109 return NODE_CONVERT_CI;
2110 }
2111 /* vector/point/normal to int */
2112 return NODE_CONVERT_VI;
2113 }
2114 return NODE_CONVERT_NONE;
2115}
2116
2117void ConvertNode::compile(SVMCompiler &compiler)
2118{
2119 /* proxy nodes should have been removed at this point */
2121
2122 ShaderInput *in = inputs[0];
2123 ShaderOutput *out = outputs[0];
2124
2125 const NodeConvert cvt_type = convert_type();
2126 if (cvt_type != NODE_CONVERT_NONE) {
2127 compiler.add_node(this,
2128 NODE_CONVERT,
2130 .convert_type = cvt_type,
2131 .from_offset = compiler.input_link(in->name().c_str()),
2132 .to_offset = compiler.output(out->name().c_str()),
2133 });
2134 }
2135 else {
2136 /* float3 to float3 */
2137 if (in->link) {
2138 /* no op in SVM */
2139 compiler.stack_link(in, out);
2140 }
2141 else {
2142 /* set 0,0,0 value */
2143 compiler.add_value_node(this, value_color, compiler.output(out->name().c_str()));
2144 }
2145 }
2146}
2147
2148void ConvertNode::compile(OSLCompiler &compiler)
2149{
2150 /* proxy nodes should have been removed at this point */
2152
2153 if (from == SocketType::FLOAT) {
2154 compiler.add(this, "node_convert_from_float");
2155 }
2156 else if (from == SocketType::INT) {
2157 compiler.add(this, "node_convert_from_int");
2158 }
2159 else if (from == SocketType::COLOR) {
2160 compiler.add(this, "node_convert_from_color");
2161 }
2162 else if (from == SocketType::VECTOR) {
2163 compiler.add(this, "node_convert_from_vector");
2164 }
2165 else if (from == SocketType::POINT) {
2166 compiler.add(this, "node_convert_from_point");
2167 }
2168 else if (from == SocketType::NORMAL) {
2169 compiler.add(this, "node_convert_from_normal");
2170 }
2171 else {
2172 assert(0);
2173 }
2174}
2175
2176/* Base type for all closure-type nodes */
2177
2182
2184{
2185 /* detect if anything is plugged into the normal input besides the default */
2186 ShaderInput *normal_in = input("Normal");
2187 return (normal_in && normal_in->link &&
2189}
2190
2191/* BSDF Closure */
2192
2193BsdfNode::BsdfNode(const NodeType *node_type) : BsdfBaseNode(node_type) {}
2194
2195void BsdfNode::compile(SVMCompiler & /*compiler*/)
2196{
2197 assert(false);
2198}
2199
2200template<typename T> void BsdfNode::compile(SVMCompiler &compiler, const T &data)
2201{
2202 ShaderInput *color_in = input("Color");
2203
2204 if (color_in->link) {
2205 compiler.add_node(this,
2206 NODE_CLOSURE_WEIGHT,
2208 .weight_offset = compiler.input_link("Color"),
2209 });
2210 }
2211 else {
2212 compiler.add_node(this,
2213 NODE_CLOSURE_SET_WEIGHT,
2214 SVMNodeClosureSetWeight{
2215 .rgb = color,
2216 });
2217 }
2218
2219 compiler.add_bsdf_node(
2220 SVMNodeClosureBsdf{
2221 .closure_type = closure,
2222 .mix_weight_offset = compiler.closure_mix_weight_offset(),
2223 },
2224 data);
2225}
2226
2227void BsdfNode::compile(OSLCompiler & /*compiler*/)
2228{
2229 assert(0);
2230}
2231
2232/* Metallic BSDF Closure */
2233
2235{
2236 NodeType *type = NodeType::add("metallic_bsdf", create, NodeType::SHADER);
2237
2238 SOCKET_IN_COLOR(color, "Base Color", make_float3(0.617f, 0.577f, 0.540f));
2240 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2241
2242 static NodeEnum distribution_enum;
2243 distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_ID);
2244 distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_ID);
2245 distribution_enum.insert("multi_ggx", CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID);
2247 distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID);
2248
2249 static NodeEnum fresnel_type_enum;
2250 fresnel_type_enum.insert("f82", CLOSURE_BSDF_F82_CONDUCTOR);
2251 fresnel_type_enum.insert("physical_conductor", CLOSURE_BSDF_PHYSICAL_CONDUCTOR);
2252 SOCKET_ENUM(fresnel_type, "fresnel_type", fresnel_type_enum, CLOSURE_BSDF_F82_CONDUCTOR);
2253
2254 SOCKET_IN_COLOR(edge_tint, "Edge Tint", make_float3(0.695f, 0.726f, 0.770f));
2255
2256 SOCKET_IN_VECTOR(ior, "IOR", make_float3(2.757f, 2.513f, 2.231f));
2257 SOCKET_IN_VECTOR(k, "Extinction", make_float3(3.867f, 3.404f, 3.009f));
2258
2260
2261 SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
2262 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
2263 SOCKET_IN_FLOAT(rotation, "Rotation", 0.0f);
2264
2265 SOCKET_IN_FLOAT(thin_film_thickness, "Thin Film Thickness", 0.0f);
2266 SOCKET_IN_FLOAT(thin_film_ior, "Thin Film IOR", 1.33f);
2267
2268 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2269
2270 return type;
2271}
2272
2273MetallicBsdfNode::MetallicBsdfNode() : BsdfNode(get_node_type())
2274{
2276}
2277
2279{
2280 /* Keep in sync with the thresholds in OSL's node_conductor_bsdf and SVM's
2281 * svm_node_metallic_bsdf. */
2282 return (!input("Anisotropy")->link && fabsf(anisotropy) <= 1e-4f);
2283}
2284
2286{
2287 if (shader->has_surface_link()) {
2288 if (!input("Tangent")->link && !is_isotropic()) {
2290 }
2291 }
2292
2294}
2295
2297{
2298 /* If the anisotropy is close enough to zero, fall back to the isotropic case. */
2299 if (is_isotropic()) {
2300 disconnect_unused_input("Tangent");
2301 }
2302}
2303
2305{
2306 compiler.add_bsdf_node(
2308 .closure_type = fresnel_type,
2309 .mix_weight_offset = compiler.closure_mix_weight_offset(),
2310 },
2311 SVMNodeMetallicBsdfData{
2312 .distribution = distribution,
2313 .base_ior = fresnel_type == CLOSURE_BSDF_PHYSICAL_CONDUCTOR ?
2314 compiler.input_float3("IOR") :
2315 compiler.input_float3("Base Color"),
2316 .edge_tint_k = fresnel_type == CLOSURE_BSDF_PHYSICAL_CONDUCTOR ?
2317 compiler.input_float3("Extinction") :
2318 compiler.input_float3("Edge Tint"),
2319 .roughness = compiler.input_float("Roughness"),
2320 .anisotropy = compiler.input_float("Anisotropy"),
2321 .rotation = compiler.input_float("Rotation"),
2322 .thin_film_thickness = compiler.input_float("Thin Film Thickness"),
2323 .thin_film_ior = compiler.input_float("Thin Film IOR"),
2324 .normal_offset = compiler.input_link("Normal"),
2325 .tangent_offset = compiler.input_link("Tangent"),
2326 });
2327}
2328
2330{
2331 compiler.parameter(this, "distribution");
2332 compiler.parameter(this, "fresnel_type");
2333 compiler.add(this, "node_metallic_bsdf");
2334}
2335
2336/* Glossy BSDF Closure */
2337
2339{
2340 NodeType *type = NodeType::add("glossy_bsdf", create, NodeType::SHADER);
2341
2342 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2344 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2345
2346 static NodeEnum distribution_enum;
2347 distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_ID);
2348 distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_ID);
2349 distribution_enum.insert("ashikhmin_shirley", CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID);
2350 distribution_enum.insert("multi_ggx", CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID);
2351 SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_ID);
2352
2354
2355 SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
2356 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
2357 SOCKET_IN_FLOAT(rotation, "Rotation", 0.0f);
2358
2359 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2360
2361 return type;
2362}
2363
2364GlossyBsdfNode::GlossyBsdfNode() : BsdfNode(get_node_type())
2365{
2367}
2368
2370{
2371 /* Keep in sync with the thresholds in OSL's node_glossy_bsdf and SVM's svm_node_closure_bsdf.
2372 */
2373 return (!input("Anisotropy")->link && fabsf(anisotropy) <= 1e-4f);
2374}
2375
2377{
2378 if (shader->has_surface_link()) {
2379 if (!input("Tangent")->link && !is_isotropic()) {
2381 }
2382 }
2383
2385}
2386
2388{
2389 /* If the anisotropy is close enough to zero, fall back to the isotropic case. */
2390 if (is_isotropic()) {
2391 disconnect_unused_input("Tangent");
2392 }
2393}
2394
2396{
2397 closure = distribution;
2398
2399 /* TODO: Just use weight for legacy MultiGGX? Would also simplify OSL. */
2400 BsdfNode::compile(compiler,
2403 compiler.input_float3("Color") :
2405 .roughness = compiler.input_float("Roughness"),
2406 .anisotropy = compiler.input_float("Anisotropy"),
2407 .rotation = compiler.input_float("Rotation"),
2408 .normal_offset = compiler.input_link("Normal"),
2409 .tangent_offset = compiler.input_link("Tangent"),
2410 });
2411}
2412
2414{
2415 compiler.parameter(this, "distribution");
2416 compiler.add(this, "node_glossy_bsdf");
2417}
2418
2419/* Glass BSDF Closure */
2420
2422{
2423 NodeType *type = NodeType::add("glass_bsdf", create, NodeType::SHADER);
2424
2425 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2427 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2428
2429 static NodeEnum distribution_enum;
2430 distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID);
2431 distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
2432 distribution_enum.insert("multi_ggx", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
2434 distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
2435
2437
2438 SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f);
2439 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
2440 SOCKET_IN_FLOAT(rotation, "Rotation", 0.0f);
2441 SOCKET_IN_FLOAT(IOR, "IOR", 1.5f);
2442
2443 SOCKET_IN_FLOAT(thin_film_thickness, "Thin Film Thickness", 0.0f);
2444 SOCKET_IN_FLOAT(thin_film_ior, "Thin Film IOR", 1.33f);
2445
2446 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2447
2448 return type;
2449}
2450
2451GlassBsdfNode::GlassBsdfNode() : BsdfNode(get_node_type())
2452{
2454}
2455
2457{
2458 /* Keep in sync with the thresholds in OSL's node_glass_bsdf and SVM's svm_node_closure_bsdf. */
2459 return (!input("Anisotropy")->link && fabsf(anisotropy) <= 1e-4f);
2460}
2461
2463{
2464 if (shader->has_surface_link()) {
2465 if (!input("Tangent")->link && !is_isotropic()) {
2467 }
2468 }
2469
2471}
2472
2474{
2475 /* If the anisotropy is close enough to zero, fall back to the isotropic case. */
2476 if (is_isotropic()) {
2477 disconnect_unused_input("Tangent");
2478 }
2479}
2480
2481void GlassBsdfNode::compile(SVMCompiler &compiler)
2482{
2483 closure = distribution;
2484 BsdfNode::compile(compiler,
2486 .color = compiler.input_float3("Color"),
2487 .roughness = compiler.input_float("Roughness"),
2488 .anisotropy = compiler.input_float("Anisotropy"),
2489 .rotation = compiler.input_float("Rotation"),
2490 .ior = compiler.input_float("IOR"),
2491 .thin_film_thickness = compiler.input_float("Thin Film Thickness"),
2492 .thin_film_ior = compiler.input_float("Thin Film IOR"),
2493 .normal_offset = compiler.input_link("Normal"),
2494 .tangent_offset = compiler.input_link("Tangent"),
2495 });
2496}
2497
2498void GlassBsdfNode::compile(OSLCompiler &compiler)
2499{
2500 compiler.parameter(this, "distribution");
2501 compiler.add(this, "node_glass_bsdf");
2502}
2503
2504/* Refraction BSDF Closure */
2505
2507{
2508 NodeType *type = NodeType::add("refraction_bsdf", create, NodeType::SHADER);
2509
2510 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2512 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2513
2514 static NodeEnum distribution_enum;
2515 distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID);
2516 distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID);
2518 distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID);
2519
2520 SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f);
2521 SOCKET_IN_FLOAT(IOR, "IOR", 0.3f);
2522
2523 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2524
2525 return type;
2526}
2527
2528RefractionBsdfNode::RefractionBsdfNode() : BsdfNode(get_node_type())
2529{
2531}
2532
2534{
2535 closure = distribution;
2536 BsdfNode::compile(compiler,
2537 SVMNodeRefractionBsdfData{
2538 .roughness = compiler.input_float("Roughness"),
2539 .ior = compiler.input_float("IOR"),
2540 .normal_offset = compiler.input_link("Normal"),
2541 });
2542}
2543
2545{
2546 compiler.parameter(this, "distribution");
2547 compiler.add(this, "node_refraction_bsdf");
2548}
2549
2550/* Toon BSDF Closure */
2551
2553{
2554 NodeType *type = NodeType::add("toon_bsdf", create, NodeType::SHADER);
2555
2556 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2558 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2559
2560 static NodeEnum component_enum;
2561 component_enum.insert("diffuse", CLOSURE_BSDF_DIFFUSE_TOON_ID);
2562 component_enum.insert("glossy", CLOSURE_BSDF_GLOSSY_TOON_ID);
2563 SOCKET_ENUM(component, "Component", component_enum, CLOSURE_BSDF_DIFFUSE_TOON_ID);
2564 SOCKET_IN_FLOAT(size, "Size", 0.5f);
2565 SOCKET_IN_FLOAT(smooth, "Smooth", 0.0f);
2566
2567 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2568
2569 return type;
2570}
2571
2572ToonBsdfNode::ToonBsdfNode() : BsdfNode(get_node_type())
2573{
2575}
2576
2577void ToonBsdfNode::compile(SVMCompiler &compiler)
2578{
2579 closure = component;
2580 BsdfNode::compile(compiler,
2581 SVMNodeToonBsdfData{
2582 .size = compiler.input_float("Size"),
2583 .smooth = compiler.input_float("Smooth"),
2584 .normal_offset = compiler.input_link("Normal"),
2585 });
2586}
2587
2588void ToonBsdfNode::compile(OSLCompiler &compiler)
2589{
2590 compiler.parameter(this, "component");
2591 compiler.add(this, "node_toon_bsdf");
2592}
2593
2594/* Sheen BSDF Closure */
2595
2597{
2598 NodeType *type = NodeType::add("sheen_bsdf", create, NodeType::SHADER);
2599
2600 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2602 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2603 SOCKET_IN_FLOAT(roughness, "Roughness", 1.0f);
2604
2605 static NodeEnum distribution_enum;
2606 distribution_enum.insert("ashikhmin", CLOSURE_BSDF_ASHIKHMIN_VELVET_ID);
2607 distribution_enum.insert("microfiber", CLOSURE_BSDF_SHEEN_ID);
2608 SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_SHEEN_ID);
2609
2610 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2611
2612 return type;
2613}
2614
2615SheenBsdfNode::SheenBsdfNode() : BsdfNode(get_node_type())
2616{
2617 closure = CLOSURE_BSDF_SHEEN_ID;
2618}
2619
2620void SheenBsdfNode::compile(SVMCompiler &compiler)
2621{
2622 closure = distribution;
2623 BsdfNode::compile(compiler,
2624 SVMNodeSimpleBsdfData{
2625 .param1 = compiler.input_float("Roughness"),
2626 .normal_offset = compiler.input_link("Normal"),
2627 });
2628}
2629
2630void SheenBsdfNode::compile(OSLCompiler &compiler)
2631{
2632 compiler.parameter(this, "distribution");
2633 compiler.add(this, "node_sheen_bsdf");
2634}
2635
2636/* Diffuse BSDF Closure */
2637
2639{
2640 NodeType *type = NodeType::add("diffuse_bsdf", create, NodeType::SHADER);
2641
2642 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2644 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2645 SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f);
2646
2647 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2648
2649 return type;
2650}
2651
2652DiffuseBsdfNode::DiffuseBsdfNode() : BsdfNode(get_node_type())
2653{
2654 closure = CLOSURE_BSDF_DIFFUSE_ID;
2655}
2656
2658{
2659 BsdfNode::compile(compiler,
2660 SVMNodeDiffuseBsdfData{.color = compiler.input_float3("Color"),
2661 .roughness = compiler.input_float("Roughness"),
2662 .normal_offset = compiler.input_link("Normal")});
2663}
2664
2666{
2667 compiler.add(this, "node_diffuse_bsdf");
2668}
2669
2670/* Disney principled BSDF Closure */
2672{
2673 NodeType *type = NodeType::add("principled_bsdf", create, NodeType::SHADER);
2674
2675 static NodeEnum distribution_enum;
2676 distribution_enum.insert("ggx", CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID);
2677 distribution_enum.insert("multi_ggx", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
2679 distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID);
2680
2681 static NodeEnum subsurface_method_enum;
2682 subsurface_method_enum.insert("burley", CLOSURE_BSSRDF_BURLEY_ID);
2683 subsurface_method_enum.insert("random_walk", CLOSURE_BSSRDF_RANDOM_WALK_ID);
2684 subsurface_method_enum.insert("random_walk_skin", CLOSURE_BSSRDF_RANDOM_WALK_SKIN_ID);
2685 subsurface_method_enum.insert("random_walk_legacy", CLOSURE_BSSRDF_RANDOM_WALK_LEGACY_ID);
2686 SOCKET_ENUM(subsurface_method,
2687 "Subsurface Method",
2688 subsurface_method_enum,
2690
2691 SOCKET_IN_COLOR(base_color, "Base Color", make_float3(0.8f, 0.8f, 0.8f))
2692 SOCKET_IN_FLOAT(metallic, "Metallic", 0.0f);
2693 SOCKET_IN_FLOAT(roughness, "Roughness", 0.5f);
2694 SOCKET_IN_FLOAT(ior, "IOR", 1.5f);
2695 SOCKET_IN_FLOAT(alpha, "Alpha", 1.0f);
2696 /* FIXME: `SOCKET_IN_BOOLEAN()` doesn't pass the value correctly, need investigation. */
2697 SOCKET_IN_INT(thin_wall, "Thin Wall", int(false));
2699
2700 SOCKET_IN_FLOAT(diffuse_roughness, "Diffuse Roughness", 0.0f);
2701
2702 SOCKET_IN_FLOAT(subsurface_weight, "Subsurface Weight", 0.0f);
2703 SOCKET_IN_FLOAT(subsurface_scale, "Subsurface Scale", 0.005f);
2704 SOCKET_IN_VECTOR(subsurface_radius, "Subsurface Radius", make_float3(1.0f, 0.2f, 0.1f));
2705 SOCKET_IN_FLOAT(subsurface_ior, "Subsurface IOR", 1.4f);
2706 SOCKET_IN_FLOAT(subsurface_anisotropy, "Subsurface Anisotropy", 0.0f);
2707
2708 SOCKET_IN_FLOAT(specular_ior_level, "Specular IOR Level", 0.5f);
2709 SOCKET_IN_COLOR(specular_tint, "Specular Tint", one_float3());
2710 SOCKET_IN_FLOAT(anisotropic, "Anisotropic", 0.0f);
2711 SOCKET_IN_FLOAT(anisotropic_rotation, "Anisotropic Rotation", 0.0f);
2713
2714 SOCKET_IN_FLOAT(transmission_weight, "Transmission Weight", 0.0f);
2715 SOCKET_IN_FLOAT(transmission_dispersion_scale, "Transmission Dispersion Scale", 0.0f);
2717 transmission_dispersion_abbe_number, "Transmission Dispersion Abbe Number", 20.0f);
2718
2719 SOCKET_IN_FLOAT(sheen_weight, "Sheen Weight", 0.0f);
2720 SOCKET_IN_FLOAT(sheen_roughness, "Sheen Roughness", 0.5f);
2721 SOCKET_IN_COLOR(sheen_tint, "Sheen Tint", one_float3());
2722
2723 SOCKET_IN_FLOAT(coat_weight, "Coat Weight", 0.0f);
2724 SOCKET_IN_FLOAT(coat_roughness, "Coat Roughness", 0.03f);
2725 SOCKET_IN_FLOAT(coat_ior, "Coat IOR", 1.5f);
2726 SOCKET_IN_COLOR(coat_tint, "Coat Tint", one_float3());
2727 SOCKET_IN_NORMAL(coat_normal, "Coat Normal", zero_float3(), SocketType::LINK_NORMAL);
2728
2729 SOCKET_IN_COLOR(emission_color, "Emission Color", one_float3());
2730 SOCKET_IN_FLOAT(emission_strength, "Emission Strength", 0.0f);
2731
2732 SOCKET_IN_FLOAT(thin_film_thickness, "Thin Film Thickness", 0.0f);
2733 SOCKET_IN_FLOAT(thin_film_ior, "Thin Film IOR", 1.33f);
2734
2735 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2736
2737 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2738
2739 return type;
2740}
2741
2742PrincipledBsdfNode::PrincipledBsdfNode() : BsdfBaseNode(get_node_type())
2743{
2746}
2747
2749{
2750 if (!has_surface_emission()) {
2751 /* Emission will be zero, so optimize away any connected emission input. */
2752 disconnect_unused_input("Emission Color");
2753 disconnect_unused_input("Emission Strength");
2754 }
2755
2756 if (is_thin_wall()) {
2757 disconnect_unused_input("Subsurface Radius");
2758 disconnect_unused_input("Subsurface Scale");
2759 disconnect_unused_input("Subsurface IOR");
2760 }
2761 else if (!has_surface_bssrdf()) {
2762 disconnect_unused_input("Subsurface Weight");
2763 disconnect_unused_input("Subsurface Radius");
2764 disconnect_unused_input("Subsurface Scale");
2765 disconnect_unused_input("Subsurface IOR");
2766 disconnect_unused_input("Subsurface Anisotropy");
2767 }
2768
2769 if (!has_nonzero_weight("Coat Weight")) {
2770 disconnect_unused_input("Coat Weight");
2771 disconnect_unused_input("Coat IOR");
2772 disconnect_unused_input("Coat Roughness");
2773 disconnect_unused_input("Coat Tint");
2774 }
2775
2776 if (!has_nonzero_weight("Sheen Weight")) {
2777 disconnect_unused_input("Sheen Weight");
2778 disconnect_unused_input("Sheen Roughness");
2779 disconnect_unused_input("Sheen Tint");
2780 }
2781
2782 if (!has_nonzero_weight("Anisotropic")) {
2783 disconnect_unused_input("Anisotropic");
2784 disconnect_unused_input("Anisotropic Rotation");
2785 disconnect_unused_input("Tangent");
2786 }
2787
2788 if (!has_nonzero_weight("Thin Film Thickness")) {
2789 disconnect_unused_input("Thin Film Thickness");
2790 disconnect_unused_input("Thin Film IOR");
2791 }
2792
2793 if (!has_nonzero_weight("Transmission Weight")) {
2794 disconnect_unused_input("Transmission Dispersion Scale");
2795 disconnect_unused_input("Transmission Dispersion Abbe Number");
2796 }
2797}
2798
2800{
2801 if (input("Alpha")->link != nullptr || alpha < (1.0f - CLOSURE_WEIGHT_CUTOFF)) {
2802 return true;
2803 }
2804
2805 /* Smooth thin glass are treated as transparent for non-camera rays. */
2806 if ((input("Thin Wall")->link || thin_wall) && has_nonzero_weight("Transmission Weight")) {
2807 if (input("Roughness")->link || input("IOR")->link) {
2808 return true;
2809 }
2810
2811 const float transmission_alpha = bsdf_thin_glass_transmission_alpha(sqr(roughness), ior);
2812 return alpha_is_almost_specular(transmission_alpha, transmission_alpha);
2813 }
2814
2815 return false;
2816}
2817
2819{
2820 return (input("Thin Wall")->link == nullptr) && thin_wall;
2821}
2822
2824{
2825 return (input("Emission Color")->link != nullptr ||
2826 reduce_max(emission_color) > CLOSURE_WEIGHT_CUTOFF) &&
2827 (input("Emission Strength")->link != nullptr ||
2828 emission_strength > CLOSURE_WEIGHT_CUTOFF);
2829}
2830
2832{
2833 return (input("Subsurface Weight")->link != nullptr ||
2834 subsurface_weight > CLOSURE_WEIGHT_CUTOFF) &&
2835 (input("Subsurface Scale")->link != nullptr || subsurface_scale != 0.0f);
2836}
2837
2839{
2840 if (is_thin_wall()) {
2841 /* Subsurface in thin-walled mode is approximated via diffuse lobes, it doesn't contain real
2842 * subsurface. */
2843 return false;
2844 }
2845
2847}
2848
2850{
2851 return has_nonzero_weight("Transmission Dispersion Scale") &&
2852 has_nonzero_weight("Transmission Weight");
2853}
2854
2856{
2857 ShaderInput *weight_in = input(name);
2858 if (weight_in == nullptr) {
2859 return true;
2860 }
2861 if (weight_in->link != nullptr) {
2862 return true;
2863 }
2864 return (get_float(weight_in->socket_type) >= CLOSURE_WEIGHT_CUTOFF);
2865}
2866
2868{
2869 if (shader->has_surface_link()) {
2870
2871 if (!input("Tangent")->link) {
2873 }
2874 }
2875
2877}
2878
2880{
2881 SVMStackOffset tangent_offset = SVM_STACK_INVALID;
2882 if (has_nonzero_weight("Anisotropic")) {
2883 tangent_offset = compiler.input_link("Tangent");
2884 }
2885
2886 compiler.add_bsdf_node(
2887 SVMNodeClosureBsdf{
2888 .closure_type = closure,
2889 .mix_weight_offset = compiler.closure_mix_weight_offset(),
2890 },
2891 SVMNodePrincipledBsdfData{
2892 .distribution = distribution,
2893 .ior = compiler.input_float("IOR"),
2894 .roughness = compiler.input_float("Roughness"),
2895 /* Weights. */
2896 .sheen_weight = compiler.input_float("Sheen Weight"),
2897 .coat_weight = compiler.input_float("Coat Weight"),
2898 .metallic = compiler.input_float("Metallic"),
2899 .transmission_weight = compiler.input_float("Transmission Weight"),
2900 .subsurface_weight = compiler.input_float("Subsurface Weight"),
2901 /* Base. */
2902 .base_color = compiler.input_float3("Base Color"),
2903 .alpha = compiler.input_float("Alpha"),
2904 .diffuse_roughness = compiler.input_float("Diffuse Roughness"),
2905 /* Normals and tangents. */
2906 .normal_offset = compiler.input_link("Normal"),
2907 .tangent_offset = tangent_offset,
2908 .coat_normal_offset = compiler.input_link("Coat Normal"),
2909 /* Specular. */
2910 .specular_tint = compiler.input_float3("Specular Tint"),
2911 .specular_ior_level = compiler.input_float("Specular IOR Level"),
2912 .anisotropic = compiler.input_float("Anisotropic"),
2913 .anisotropic_rotation = compiler.input_float("Anisotropic Rotation"),
2914 /* Transmission. */
2915 .transmission_dispersion_scale = compiler.input_float("Transmission Dispersion Scale"),
2916 .transmission_dispersion_abbe_number = compiler.input_float(
2917 "Transmission Dispersion Abbe Number"),
2918 /* Emission. */
2919 .emission_color = compiler.input_float3("Emission Color"),
2920 .emission_strength = compiler.input_float("Emission Strength"),
2921 /* Sheen. */
2922 .sheen_tint = compiler.input_float3("Sheen Tint"),
2923 .sheen_roughness = compiler.input_float("Sheen Roughness"),
2924 /* Coat. */
2925 .coat_tint = compiler.input_float3("Coat Tint"),
2926 .coat_roughness = compiler.input_float("Coat Roughness"),
2927 .coat_ior = compiler.input_float("Coat IOR"),
2928 /* Subsurface. */
2929 .subsurface_method = subsurface_method,
2930 .subsurface_radius = compiler.input_float3("Subsurface Radius"),
2931 .subsurface_scale = compiler.input_float("Subsurface Scale"),
2932 .subsurface_ior = compiler.input_float("Subsurface IOR"),
2933 .subsurface_anisotropy = compiler.input_float("Subsurface Anisotropy"),
2934 /* Thin film. */
2935 .thin_film_thickness = compiler.input_float("Thin Film Thickness"),
2936 .thin_film_ior = compiler.input_float("Thin Film IOR"),
2937 /* Thin wall. */
2938 .thin_wall = compiler.input_int("Thin Wall"),
2939 });
2940}
2941
2943{
2944 compiler.parameter(this, "distribution");
2945 compiler.parameter(this, "subsurface_method");
2946 compiler.add(this, "node_principled_bsdf");
2947}
2948
2953
2954/* Translucent BSDF Closure */
2955
2957{
2958 NodeType *type = NodeType::add("translucent_bsdf", create, NodeType::SHADER);
2959
2960 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
2962 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2963
2964 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2965
2966 return type;
2967}
2968
2969TranslucentBsdfNode::TranslucentBsdfNode() : BsdfNode(get_node_type())
2970{
2972}
2973
2975{
2976 BsdfNode::compile(compiler,
2977 SVMNodeSimpleBsdfData{
2978 .normal_offset = compiler.input_link("Normal"),
2979 });
2980}
2981
2983{
2984 compiler.add(this, "node_translucent_bsdf");
2985}
2986
2987/* Transparent BSDF Closure */
2988
2990{
2991 NodeType *type = NodeType::add("transparent_bsdf", create, NodeType::SHADER);
2992
2993 SOCKET_IN_COLOR(color, "Color", one_float3());
2994 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
2995
2996 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
2997
2998 return type;
2999}
3000
3001TransparentBsdfNode::TransparentBsdfNode() : BsdfNode(get_node_type())
3002{
3004}
3005
3007{
3008 BsdfNode::compile(compiler, SVMNodeSimpleBsdfData{});
3009}
3010
3012{
3013 compiler.add(this, "node_transparent_bsdf");
3014}
3015
3016/* Ray Portal BSDF Closure */
3017
3019{
3020 NodeType *type = NodeType::add("ray_portal_bsdf", create, NodeType::SHADER);
3021
3022 SOCKET_IN_COLOR(color, "Color", one_float3());
3023 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3024
3026 SOCKET_IN_VECTOR(direction, "Direction", zero_float3());
3027
3028 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
3029
3030 return type;
3031}
3032
3033RayPortalBsdfNode::RayPortalBsdfNode() : BsdfNode(get_node_type())
3034{
3036}
3037
3039{
3040 BsdfNode::compile(compiler,
3041 SVMNodeRayPortalBsdfData{
3042 .direction = compiler.input_float3("Direction"),
3043 .position_offset = compiler.input_link("Position"),
3044 });
3045}
3046
3048{
3049 compiler.add(this, "node_ray_portal_bsdf");
3050}
3051
3052/* Subsurface Scattering Closure */
3053
3055{
3056 NodeType *type = NodeType::add("subsurface_scattering", create, NodeType::SHADER);
3057
3058 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
3060 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3061
3062 static NodeEnum method_enum;
3063 method_enum.insert("burley", CLOSURE_BSSRDF_BURLEY_ID);
3064 method_enum.insert("random_walk", CLOSURE_BSSRDF_RANDOM_WALK_ID);
3065 method_enum.insert("random_walk_skin", CLOSURE_BSSRDF_RANDOM_WALK_SKIN_ID);
3066 method_enum.insert("random_walk_legacy", CLOSURE_BSSRDF_RANDOM_WALK_LEGACY_ID);
3067 SOCKET_ENUM(method, "Method", method_enum, CLOSURE_BSSRDF_RANDOM_WALK_ID);
3068
3069 SOCKET_IN_FLOAT(scale, "Scale", 0.005f);
3070 SOCKET_IN_VECTOR(radius, "Radius", make_float3(1.0f, 0.2f, 0.1f));
3071
3072 SOCKET_IN_FLOAT(subsurface_ior, "IOR", 1.4f);
3073 SOCKET_IN_FLOAT(subsurface_roughness, "Roughness", 1.0f);
3074 SOCKET_IN_FLOAT(subsurface_anisotropy, "Anisotropy", 0.0f);
3075
3076 SOCKET_OUT_CLOSURE(BSSRDF, "BSSRDF");
3077
3078 return type;
3079}
3080
3081SubsurfaceScatteringNode::SubsurfaceScatteringNode() : BsdfNode(get_node_type())
3082{
3083 closure = method;
3084}
3085
3087{
3088 closure = method;
3089 BsdfNode::compile(compiler,
3090 SVMNodeBssrdfData{
3091 .radius = compiler.input_float3("Radius"),
3092 .scale = compiler.input_float("Scale"),
3093 .ior = compiler.input_float("IOR"),
3094 .anisotropy = compiler.input_float("Anisotropy"),
3095 .roughness = compiler.input_float("Roughness"),
3096 .normal_offset = compiler.input_link("Normal"),
3097 });
3098}
3099
3101{
3102 closure = method;
3103 compiler.parameter(this, "method");
3104 compiler.add(this, "node_subsurface_scattering");
3105}
3106
3108{
3109 /* detect if anything is plugged into the normal input besides the default */
3110 ShaderInput *normal_in = input("Normal");
3111 return (normal_in->link &&
3113}
3114
3115/* Emissive Closure */
3116
3118{
3119 NodeType *type = NodeType::add("emission", create, NodeType::SHADER);
3120
3121 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
3122 SOCKET_IN_FLOAT(strength, "Strength", 10.0f);
3123 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3124 SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3125
3126 SOCKET_OUT_CLOSURE(emission, "Emission");
3127
3128 return type;
3129}
3130
3131EmissionNode::EmissionNode() : ShaderNode(get_node_type()) {}
3132
3133void EmissionNode::compile(SVMCompiler &compiler)
3134{
3135 ShaderInput *color_in = input("Color");
3136 ShaderInput *strength_in = input("Strength");
3137
3138 if (color_in->link || strength_in->link) {
3139 compiler.add_node(this,
3140 NODE_EMISSION_WEIGHT,
3141 SVMNodeEmissionWeight{
3142 .color = compiler.input_float3("Color"),
3143 .strength = compiler.input_float("Strength"),
3144 });
3145 }
3146 else {
3147 const float3 w = color * strength;
3148 compiler.add_node(this,
3149 NODE_CLOSURE_SET_WEIGHT,
3150 SVMNodeClosureSetWeight{
3151 .rgb = w,
3152 });
3153 }
3154
3155 compiler.add_node(this,
3156 NODE_CLOSURE_EMISSION,
3157 SVMNodeClosureEmission{
3158 .mix_weight_offset = compiler.closure_mix_weight_offset(),
3159 });
3160}
3161
3162void EmissionNode::compile(OSLCompiler &compiler)
3163{
3164 compiler.add(this, "node_emission");
3165}
3166
3168{
3169
3170 if ((!input("Color")->link && color == zero_float3()) ||
3171 (!input("Strength")->link && strength == 0.0f))
3172 {
3173 folder.discard();
3174 }
3175}
3176
3177/* Background Closure */
3178
3180{
3181 NodeType *type = NodeType::add("background_shader", create, NodeType::SHADER);
3182
3183 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
3184 SOCKET_IN_FLOAT(strength, "Strength", 1.0f);
3185 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3186
3187 SOCKET_OUT_CLOSURE(background, "Background");
3188
3189 return type;
3190}
3191
3192BackgroundNode::BackgroundNode() : ShaderNode(get_node_type()) {}
3193
3195{
3196 ShaderInput *color_in = input("Color");
3197 ShaderInput *strength_in = input("Strength");
3198
3199 if (color_in->link || strength_in->link) {
3200 compiler.add_node(this,
3201 NODE_EMISSION_WEIGHT,
3202 SVMNodeEmissionWeight{
3203 .color = compiler.input_float3("Color"),
3204 .strength = compiler.input_float("Strength"),
3205 });
3206 }
3207 else {
3208 const float3 w = color * strength;
3209 compiler.add_node(this,
3210 NODE_CLOSURE_SET_WEIGHT,
3211 SVMNodeClosureSetWeight{
3212 .rgb = w,
3213 });
3214 }
3215
3216 compiler.add_node(this,
3217 NODE_CLOSURE_BACKGROUND,
3218 SVMNodeClosureBackground{
3219 .mix_weight_offset = compiler.closure_mix_weight_offset(),
3220 });
3221}
3222
3224{
3225 compiler.add(this, "node_background");
3226}
3227
3229{
3230
3231 if ((!input("Color")->link && color == zero_float3()) ||
3232 (!input("Strength")->link && strength == 0.0f))
3233 {
3234 folder.discard();
3235 }
3236}
3237
3238/* Holdout Closure */
3239
3241{
3242 NodeType *type = NodeType::add("holdout", create, NodeType::SHADER);
3243
3244 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3245 SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3246
3247 SOCKET_OUT_CLOSURE(holdout, "Holdout");
3248
3249 return type;
3250}
3251
3252HoldoutNode::HoldoutNode() : ShaderNode(get_node_type()) {}
3253
3254void HoldoutNode::compile(SVMCompiler &compiler)
3255{
3256 const float3 value = one_float3();
3257 compiler.add_node(this,
3258 NODE_CLOSURE_SET_WEIGHT,
3259 SVMNodeClosureSetWeight{
3260 .rgb = value,
3261 });
3262 compiler.add_node(this,
3263 NODE_CLOSURE_HOLDOUT,
3264 SVMNodeClosureHoldout{
3265 .mix_weight_offset = compiler.closure_mix_weight_offset(),
3266 });
3267}
3268
3269void HoldoutNode::compile(OSLCompiler &compiler)
3270{
3271 compiler.add(this, "node_holdout");
3272}
3273
3274/* Ambient Occlusion */
3275
3277{
3278 NodeType *type = NodeType::add("ambient_occlusion", create, NodeType::SHADER);
3279
3280 SOCKET_INT(samples, "Samples", 16);
3281
3282 SOCKET_IN_COLOR(color, "Color", one_float3());
3283 SOCKET_IN_FLOAT(distance, "Distance", 1.0f);
3285
3286 SOCKET_BOOLEAN(inside, "Inside", false);
3287 SOCKET_BOOLEAN(only_local, "Only Local", false);
3288
3289 SOCKET_OUT_COLOR(color, "Color");
3290 SOCKET_OUT_FLOAT(ao, "AO");
3291
3292 return type;
3293}
3294
3295AmbientOcclusionNode::AmbientOcclusionNode() : ShaderNode(get_node_type()) {}
3296
3298{
3299 ShaderInput *distance_in = input("Distance");
3300
3301 int flags = (inside ? NODE_AO_INSIDE : 0) | (only_local ? NODE_AO_ONLY_LOCAL : 0);
3302
3303 if (!distance_in->link && distance == 0.0f) {
3304 flags |= NODE_AO_GLOBAL_RADIUS;
3305 }
3306
3307 compiler.add_node(this,
3308 NODE_AMBIENT_OCCLUSION,
3309 SVMNodeAmbientOcclusion{
3310 .color = compiler.input_float3("Color"),
3311 .dist = compiler.input_float("Distance"),
3312 .flags = uint8_t(flags),
3313 .samples = uint8_t(samples),
3314 .normal_offset = compiler.input_link("Normal"),
3315 .out_ao_offset = compiler.output("AO"),
3316 .out_color_offset = compiler.output("Color"),
3317 });
3318}
3319
3321{
3322 compiler.parameter(this, "samples");
3323 compiler.parameter(this, "inside");
3324 compiler.parameter(this, "only_local");
3325 compiler.add(this, "node_ambient_occlusion");
3326}
3327
3328/* Volume Closure */
3329
3334
3336 ShaderInput *density,
3337 ShaderInput *param1,
3338 ShaderInput *param2)
3339{
3340 ShaderInput *color_in = input("Color");
3341
3342 if (color_in->link) {
3343 compiler.add_node(this,
3344 NODE_CLOSURE_WEIGHT,
3346 .weight_offset = compiler.input_link("Color"),
3347 });
3348 }
3349 else {
3350 compiler.add_node(this,
3351 NODE_CLOSURE_SET_WEIGHT,
3353 .rgb = color,
3354 });
3355 }
3356
3357 /* Density and mix weight need to be stored the same way for all volume closures since there's
3358 * a shortcut code path if we only need the extinction value. */
3359 const SVMStackOffset mix_weight_ofs = compiler.closure_mix_weight_offset();
3360
3361 compiler.add_node(
3362 this,
3363 NODE_CLOSURE_VOLUME,
3365 .closure_type = closure,
3366 .density = (density) ? compiler.input_float(density->name().c_str()) : SVMInputFloat{0},
3367 .param1 = (param1) ? compiler.input_float(param1->name().c_str()) : SVMInputFloat{0},
3368 .param_extra = (param2) ? compiler.input_float(param2->name().c_str()) :
3369 SVMInputFloat{0},
3370 .mix_weight_offset = mix_weight_ofs,
3371 });
3372}
3373
3374void VolumeNode::compile(SVMCompiler &compiler)
3375{
3376 compile(compiler, nullptr, nullptr, nullptr);
3377}
3378
3379void VolumeNode::compile(OSLCompiler & /*compiler*/)
3380{
3381 assert(0);
3382}
3383
3384/* Absorption Volume Closure */
3385
3387{
3388 NodeType *type = NodeType::add("absorption_volume", create, NodeType::SHADER);
3389
3390 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
3391 SOCKET_IN_FLOAT(density, "Density", 1.0f);
3392 SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3393
3394 SOCKET_OUT_CLOSURE(volume, "Volume");
3395
3396 return type;
3397}
3398
3399AbsorptionVolumeNode::AbsorptionVolumeNode() : VolumeNode(get_node_type())
3400{
3402}
3403
3405{
3406 VolumeNode::compile(compiler, input("Density"));
3407}
3408
3410{
3411 compiler.add(this, "node_absorption_volume");
3412}
3413
3414/* Scatter Volume Closure */
3415
3417{
3418 NodeType *type = NodeType::add("scatter_volume", create, NodeType::SHADER);
3419
3420 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
3421 SOCKET_IN_FLOAT(density, "Density", 1.0f);
3422 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
3423 SOCKET_IN_FLOAT(IOR, "IOR", 1.33f);
3424 SOCKET_IN_FLOAT(backscatter, "Backscatter", 0.1f);
3425 SOCKET_IN_FLOAT(alpha, "Alpha", 0.5f);
3426 SOCKET_IN_FLOAT(diameter, "Diameter", 20.0f);
3427
3428 static NodeEnum phase_enum;
3429 phase_enum.insert("Henyey-Greenstein", CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID);
3430 phase_enum.insert("Fournier-Forand", CLOSURE_VOLUME_FOURNIER_FORAND_ID);
3431 phase_enum.insert("Draine", CLOSURE_VOLUME_DRAINE_ID);
3432 phase_enum.insert("Rayleigh", CLOSURE_VOLUME_RAYLEIGH_ID);
3433 phase_enum.insert("Mie", CLOSURE_VOLUME_MIE_ID);
3434 SOCKET_ENUM(phase, "Phase", phase_enum, CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID);
3435
3436 SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3437
3438 SOCKET_OUT_CLOSURE(volume, "Volume");
3439
3440 return type;
3441}
3442
3447
3449{
3451}
3452
3454{
3455 closure = phase;
3456
3457 switch (phase) {
3459 VolumeNode::compile(compiler, input("Density"), input("Anisotropy"));
3460 break;
3462 VolumeNode::compile(compiler, input("Density"), input("IOR"), input("Backscatter"));
3463 break;
3465 VolumeNode::compile(compiler, input("Density"));
3466 break;
3468 VolumeNode::compile(compiler, input("Density"), input("Anisotropy"), input("Alpha"));
3469 break;
3471 VolumeNode::compile(compiler, input("Density"), input("Diameter"));
3472 break;
3473 default:
3474 assert(false);
3475 break;
3476 }
3477}
3478
3480{
3481 compiler.parameter(this, "phase");
3482 compiler.add(this, "node_scatter_volume");
3483}
3484
3485/* Volume Coefficients Closure */
3486
3488{
3489 NodeType *type = NodeType::add("volume_coefficients", create, NodeType::SHADER);
3490
3491 SOCKET_IN_VECTOR(scatter_coeffs, "Scatter Coefficients", make_float3(1.0f, 1.0f, 1.0f));
3492 SOCKET_IN_VECTOR(absorption_coeffs, "Absorption Coefficients", make_float3(1.0f, 1.0f, 1.0f));
3493 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
3494 SOCKET_IN_FLOAT(IOR, "IOR", 1.33f);
3495 SOCKET_IN_FLOAT(backscatter, "Backscatter", 0.1f);
3496 SOCKET_IN_FLOAT(alpha, "Alpha", 0.5f);
3497 SOCKET_IN_FLOAT(diameter, "Diameter", 20.0f);
3498 SOCKET_IN_VECTOR(emission_coeffs, "Emission Coefficients", make_float3(0.0f, 0.0f, 0.0f));
3499
3500 static NodeEnum phase_enum;
3501 phase_enum.insert("Henyey-Greenstein", CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID);
3502 phase_enum.insert("Fournier-Forand", CLOSURE_VOLUME_FOURNIER_FORAND_ID);
3503 phase_enum.insert("Draine", CLOSURE_VOLUME_DRAINE_ID);
3504 phase_enum.insert("Rayleigh", CLOSURE_VOLUME_RAYLEIGH_ID);
3505 phase_enum.insert("Mie", CLOSURE_VOLUME_MIE_ID);
3506 SOCKET_ENUM(phase, "Phase", phase_enum, CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID);
3507
3508 SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3509
3510 SOCKET_OUT_CLOSURE(volume, "Volume");
3511
3512 return type;
3513}
3514
3515VolumeCoefficientsNode::VolumeCoefficientsNode() : ScatterVolumeNode(get_node_type())
3516{
3518}
3519
3521{
3522 closure = phase;
3523 const char *param1 = nullptr;
3524 const char *param2 = nullptr;
3525
3526 switch (phase) {
3528 param1 = "Anisotropy";
3529 break;
3531 param1 = "IOR";
3532 param2 = "Backscatter";
3533 break;
3535 break;
3537 param1 = "Anisotropy";
3538 param2 = "Alpha";
3539 break;
3541 param1 = "Diameter";
3542 break;
3543 default:
3544 assert(false);
3545 break;
3546 }
3547
3548 if (input("Scatter Coefficients")->link) {
3549 compiler.add_node(this,
3550 NODE_CLOSURE_WEIGHT,
3551 SVMNodeClosureWeight{
3552 .weight_offset = compiler.input_link("Scatter Coefficients"),
3553 });
3554 }
3555 else {
3556 compiler.add_node(this,
3557 NODE_CLOSURE_SET_WEIGHT,
3558 SVMNodeClosureSetWeight{
3559 .rgb = scatter_coeffs,
3560 });
3561 }
3562
3563 const SVMStackOffset mix_weight_ofs = compiler.closure_mix_weight_offset();
3564
3565 compiler.add_node(this,
3566 NODE_VOLUME_COEFFICIENTS,
3567 SVMNodeVolumeCoefficients{
3568 .closure_type = closure,
3569 .absorption_coeffs = compiler.input_float3("Absorption Coefficients"),
3570 .emission_coeffs = compiler.input_float3("Emission Coefficients"),
3571 .param1 = (param1) ? compiler.input_float(param1) : SVMInputFloat{0},
3572 .param_extra = (param2) ? compiler.input_float(param2) : SVMInputFloat{0},
3573 .mix_weight_offset = mix_weight_ofs,
3574 });
3575}
3576
3578{
3579 compiler.parameter(this, "phase");
3580 compiler.add(this, "node_volume_coefficients");
3581}
3582
3583/* Principled Volume Closure */
3584
3586{
3587 NodeType *type = NodeType::add("principled_volume", create, NodeType::SHADER);
3588
3589 SOCKET_IN_STRING(density_attribute, "Density Attribute", ustring());
3590 SOCKET_IN_STRING(color_attribute, "Color Attribute", ustring());
3591 SOCKET_IN_STRING(temperature_attribute, "Temperature Attribute", ustring());
3592
3593 SOCKET_IN_COLOR(color, "Color", make_float3(0.5f, 0.5f, 0.5f));
3594 SOCKET_IN_FLOAT(density, "Density", 1.0f);
3595 SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f);
3596 SOCKET_IN_COLOR(absorption_color, "Absorption Color", zero_float3());
3597 SOCKET_IN_FLOAT(emission_strength, "Emission Strength", 0.0f);
3598 SOCKET_IN_COLOR(emission_color, "Emission Color", one_float3());
3599 SOCKET_IN_FLOAT(blackbody_intensity, "Blackbody Intensity", 0.0f);
3600 SOCKET_IN_COLOR(blackbody_tint, "Blackbody Tint", one_float3());
3601 SOCKET_IN_FLOAT(temperature, "Temperature", 1000.0f);
3602 SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3603
3604 SOCKET_OUT_CLOSURE(volume, "Volume");
3605
3606 return type;
3607}
3608
3609PrincipledVolumeNode::PrincipledVolumeNode() : VolumeNode(get_node_type())
3610{
3612 density_attribute = ustring("density");
3613 temperature_attribute = ustring("temperature");
3614}
3615
3617{
3618 if (shader->has_volume) {
3619
3620 if (input("Density")->link || density > 0.0f) {
3621 attributes->add_name_or_standard(density_attribute);
3622 attributes->add_name_or_standard(color_attribute);
3623 }
3624
3625 if (input("Blackbody Intensity")->link || blackbody_intensity > 0.0f) {
3626 attributes->add_name_or_standard(temperature_attribute);
3627 }
3628
3630 }
3631
3633}
3634
3636{
3637 ShaderInput *color_in = input("Color");
3638
3639 if (color_in->link) {
3640 compiler.add_node(this,
3641 NODE_CLOSURE_WEIGHT,
3643 .weight_offset = compiler.input_link("Color"),
3644 });
3645 }
3646 else {
3647 compiler.add_node(this,
3648 NODE_CLOSURE_SET_WEIGHT,
3649 SVMNodeClosureSetWeight{
3650 .rgb = color,
3651 });
3652 }
3653
3654 compiler.add_node(
3655 this,
3656 NODE_PRINCIPLED_VOLUME,
3657 SVMNodePrincipledVolume{
3658 .absorption_color = compiler.input_float3("Absorption Color"),
3659 .emission_color = compiler.input_float3("Emission Color"),
3660 .blackbody_tint = compiler.input_float3("Blackbody Tint"),
3661 .density = compiler.input_float("Density"),
3662 .anisotropy = compiler.input_float("Anisotropy"),
3663 .emission = compiler.input_float("Emission Strength"),
3664 .blackbody = compiler.input_float("Blackbody Intensity"),
3665 .temperature = compiler.input_float("Temperature"),
3666 .attr_density = (int)compiler.attribute_standard(density_attribute),
3667 .attr_color = (int)compiler.attribute_standard(color_attribute),
3668 .attr_temperature = (int)compiler.attribute_standard(temperature_attribute),
3669 .mix_weight_offset = compiler.closure_mix_weight_offset(),
3670 });
3671}
3672
3674{
3675 density_attribute = Attribute::osl_name(density_attribute);
3676 color_attribute = Attribute::osl_name(color_attribute);
3677 temperature_attribute = Attribute::osl_name(temperature_attribute);
3678
3679 compiler.add(this, "node_principled_volume");
3680}
3681
3682/* Principled Hair BSDF Closure */
3683
3685{
3686 NodeType *type = NodeType::add("principled_hair_bsdf", create, NodeType::SHADER);
3687
3688 /* Scattering models. */
3689 static NodeEnum model_enum;
3690 model_enum.insert("Chiang", NODE_PRINCIPLED_HAIR_CHIANG);
3691 model_enum.insert("Huang", NODE_PRINCIPLED_HAIR_HUANG);
3692 SOCKET_ENUM(model, "Model", model_enum, NODE_PRINCIPLED_HAIR_HUANG);
3693
3694 /* Color parametrization specified as enum. */
3695 static NodeEnum parametrization_enum;
3696 parametrization_enum.insert("Direct coloring", NODE_PRINCIPLED_HAIR_REFLECTANCE);
3697 parametrization_enum.insert("Melanin concentration", NODE_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION);
3698 parametrization_enum.insert("Absorption coefficient", NODE_PRINCIPLED_HAIR_DIRECT_ABSORPTION);
3700 parametrization, "Parametrization", parametrization_enum, NODE_PRINCIPLED_HAIR_REFLECTANCE);
3701
3702 /* Initialize sockets to their default values. */
3703 SOCKET_IN_COLOR(color, "Color", make_float3(0.017513f, 0.005763f, 0.002059f));
3704 SOCKET_IN_FLOAT(melanin, "Melanin", 0.8f);
3705 SOCKET_IN_FLOAT(melanin_redness, "Melanin Redness", 1.0f);
3706 SOCKET_IN_COLOR(tint, "Tint", make_float3(1.f, 1.f, 1.f));
3708 absorption_coefficient, "Absorption Coefficient", make_float3(0.245531f, 0.52f, 1.365f));
3709
3710 SOCKET_IN_FLOAT(aspect_ratio, "Aspect Ratio", 0.85f);
3711
3712 SOCKET_IN_FLOAT(offset, "Offset", 2.f * M_PI_F / 180.f);
3713 SOCKET_IN_FLOAT(roughness, "Roughness", 0.3f);
3714 SOCKET_IN_FLOAT(radial_roughness, "Radial Roughness", 0.3f);
3715 SOCKET_IN_FLOAT(coat, "Coat", 0.0f);
3716 SOCKET_IN_FLOAT(ior, "IOR", 1.55f);
3717
3718 SOCKET_IN_FLOAT(random_roughness, "Random Roughness", 0.0f);
3719 SOCKET_IN_FLOAT(random_color, "Random Color", 0.0f);
3720 SOCKET_IN_FLOAT(random, "Random", 0.0f);
3721
3722 SOCKET_IN_FLOAT(R, "R lobe", 1.0f);
3723 SOCKET_IN_FLOAT(TT, "TT lobe", 1.0f);
3724 SOCKET_IN_FLOAT(TRT, "TRT lobe", 1.0f);
3725
3726 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3727
3728 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
3729
3730 return type;
3731}
3732
3733PrincipledHairBsdfNode::PrincipledHairBsdfNode() : BsdfBaseNode(get_node_type())
3734{
3736}
3737
3738/* Treat hair as transparent if the hit is outside of the projected width. */
3740{
3741 if (model == NODE_PRINCIPLED_HAIR_HUANG) {
3742 if (aspect_ratio != 1.0f || input("Aspect Ratio")->link) {
3743 return true;
3744 }
3745 }
3746 return false;
3747}
3748
3750{
3752 /* Make sure we have the normal for elliptical cross section tracking. */
3754 }
3755
3756 if (!input("Random")->link) {
3757 /* Enable retrieving Hair Info -> Random if Random isn't linked. */
3759 }
3761}
3762
3763/* Prepares the input data for the SVM shader. */
3765{
3766 const bool is_huang = (model == NODE_PRINCIPLED_HAIR_HUANG);
3768 compiler.add_node(this,
3769 NODE_CLOSURE_SET_WEIGHT,
3771 .rgb = one_float3(),
3772 });
3773
3774 ShaderInput *random_in = input("Random");
3775 const int attr_random = random_in->link ? SVM_STACK_INVALID :
3777
3778 /* Encode all parameters into data nodes. */
3779 compiler.add_bsdf_node(
3780 SVMNodeClosureBsdf{
3781 .closure_type = closure,
3782 .mix_weight_offset = compiler.closure_mix_weight_offset(),
3783 },
3784 SVMNodePrincipledHairBsdfData{
3785 .parametrization = parametrization,
3786 .color = compiler.input_float3("Color"),
3787 .tint = compiler.input_float3("Tint"),
3788 .absorption_coefficient = compiler.input_float3("Absorption Coefficient"),
3789 .roughness = compiler.input_float("Roughness"),
3790 .random_roughness = compiler.input_float("Random Roughness"),
3791 .offset = compiler.input_float("Offset"),
3792 .ior = compiler.input_float("IOR"),
3793 .random = compiler.input_float("Random"),
3794 .melanin = compiler.input_float("Melanin"),
3795 .melanin_redness = compiler.input_float("Melanin Redness"),
3796 .coat = compiler.input_float("Coat"),
3797 .aspect_ratio = compiler.input_float("Aspect Ratio"),
3798 .radial_roughness = compiler.input_float("Radial Roughness"),
3799 .random_color = compiler.input_float("Random Color"),
3800 .R = compiler.input_float("R lobe"),
3801 .TT = compiler.input_float("TT lobe"),
3802 .TRT = compiler.input_float("TRT lobe"),
3803 .attr_random = attr_random,
3804 .attr_normal = is_huang ? (int)compiler.attribute(ATTR_STD_VERTEX_NORMAL) : 0,
3805 });
3806}
3807
3808/* Prepares the input data for the OSL shader. */
3810{
3811 compiler.parameter(this, "model");
3812 compiler.parameter(this, "parametrization");
3813 compiler.add(this, "node_principled_hair_bsdf");
3814}
3815
3816/* Hair BSDF Closure */
3817
3819{
3820 NodeType *type = NodeType::add("hair_bsdf", create, NodeType::SHADER);
3821
3822 SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f));
3823 SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL);
3824
3825 static NodeEnum component_enum;
3826 component_enum.insert("reflection", CLOSURE_BSDF_HAIR_REFLECTION_ID);
3827 component_enum.insert("transmission", CLOSURE_BSDF_HAIR_TRANSMISSION_ID);
3828 SOCKET_ENUM(component, "Component", component_enum, CLOSURE_BSDF_HAIR_REFLECTION_ID);
3829 SOCKET_IN_FLOAT(offset, "Offset", 0.0f);
3830 SOCKET_IN_FLOAT(roughness_u, "RoughnessU", 0.2f);
3831 SOCKET_IN_FLOAT(roughness_v, "RoughnessV", 0.2f);
3832 SOCKET_IN_VECTOR(tangent, "Tangent", zero_float3());
3833
3834 SOCKET_OUT_CLOSURE(BSDF, "BSDF");
3835
3836 return type;
3837}
3838
3839HairBsdfNode::HairBsdfNode() : BsdfNode(get_node_type())
3840{
3842}
3843
3844void HairBsdfNode::compile(SVMCompiler &compiler)
3845{
3846 closure = component;
3847
3848 BsdfNode::compile(compiler,
3849 SVMNodeHairBsdfData{
3850 .roughness1 = compiler.input_float("RoughnessU"),
3851 .roughness2 = compiler.input_float("RoughnessV"),
3852 .offset = compiler.input_float("Offset"),
3853 .tangent_offset = compiler.input_link("Tangent"),
3854 });
3855}
3856
3857void HairBsdfNode::compile(OSLCompiler &compiler)
3858{
3859 compiler.parameter(this, "component");
3860 compiler.add(this, "node_hair_bsdf");
3861}
3862
3863/* Geometry */
3864
3866{
3867 NodeType *type = NodeType::add("geometry", create, NodeType::SHADER);
3868
3869 SOCKET_OUT_POINT(position, "Position");
3870 SOCKET_OUT_NORMAL(normal, "Normal");
3871 SOCKET_OUT_NORMAL(tangent, "Tangent");
3872 SOCKET_OUT_NORMAL(true_normal, "True Normal");
3873 SOCKET_OUT_VECTOR(incoming, "Incoming");
3874 SOCKET_OUT_POINT(parametric, "Parametric");
3875 SOCKET_OUT_FLOAT(backfacing, "Backfacing");
3876 SOCKET_OUT_FLOAT(pointiness, "Pointiness");
3877 SOCKET_OUT_FLOAT(random_per_island, "Random Per Island");
3878
3879 return type;
3880}
3881
3882GeometryNode::GeometryNode() : ShaderNode(get_node_type())
3883{
3884 special_type = SHADER_SPECIAL_TYPE_GEOMETRY;
3885}
3886
3888{
3889 if (shader->has_surface_link()) {
3890 if (!output("Tangent")->links.empty()) {
3892 }
3893 if (!output("Pointiness")->links.empty()) {
3895 }
3896 if (!output("Random Per Island")->links.empty()) {
3898 }
3899 }
3900
3902}
3903
3905{
3906 return NODE_GEOMETRY;
3907}
3908
3910{
3911 switch (bump) {
3912 case SHADER_BUMP_DX:
3913 return NODE_BUMP_OFFSET_DX;
3914 case SHADER_BUMP_DY:
3915 return NODE_BUMP_OFFSET_DY;
3916 default:
3918 }
3919}
3920
3921void GeometryNode::compile(SVMCompiler &compiler)
3922{
3924 const bool use_derivative = need_derivatives() || (bump != SHADER_BUMP_NONE);
3925 const uint8_t store_derivatives = need_derivatives();
3926 ShaderOutput *out;
3927
3928 out = output("Position");
3929 if (!out->links.empty()) {
3930 compiler.add_node(this,
3931 NODE_GEOMETRY,
3932 SVMNodeGeometry{
3933 .geom_type = NODE_GEOM_P,
3934 .bump_offset = bump_offset,
3935 .store_derivatives = store_derivatives,
3936 .out_offset = compiler.output("Position"),
3937 .bump_filter_width = bump_filter_width,
3938 },
3939 use_derivative);
3940 }
3941
3942 /* Currently no bump offset is supported for Normal, Tangent, True Normal, and Incoming. */
3943 out = output("Normal");
3944 if (!out->links.empty()) {
3945 compiler.add_node(this,
3946 NODE_GEOMETRY,
3947 SVMNodeGeometry{
3948 .geom_type = NODE_GEOM_N,
3949 .bump_offset = NODE_BUMP_OFFSET_CENTER,
3950 .store_derivatives = store_derivatives,
3951 .out_offset = compiler.output("Normal"),
3952 .bump_filter_width = bump_filter_width,
3953 });
3954 }
3955
3956 out = output("Tangent");
3957 if (!out->links.empty()) {
3958 compiler.add_node(this,
3959 NODE_GEOMETRY,
3960 SVMNodeGeometry{
3961 .geom_type = NODE_GEOM_T,
3962 .bump_offset = NODE_BUMP_OFFSET_CENTER,
3963 .store_derivatives = store_derivatives,
3964 .out_offset = compiler.output("Tangent"),
3965 .bump_filter_width = bump_filter_width,
3966 },
3967 use_derivative);
3968 }
3969
3970 out = output("True Normal");
3971 if (!out->links.empty()) {
3972 compiler.add_node(this,
3973 NODE_GEOMETRY,
3974 SVMNodeGeometry{
3975 .geom_type = NODE_GEOM_Ng,
3976 .bump_offset = NODE_BUMP_OFFSET_CENTER,
3977 .store_derivatives = store_derivatives,
3978 .out_offset = compiler.output("True Normal"),
3979 .bump_filter_width = bump_filter_width,
3980 },
3981 use_derivative);
3982 }
3983
3984 out = output("Incoming");
3985 if (!out->links.empty()) {
3986 compiler.add_node(this,
3987 NODE_GEOMETRY,
3988 SVMNodeGeometry{
3989 .geom_type = NODE_GEOM_I,
3990 .bump_offset = NODE_BUMP_OFFSET_CENTER,
3991 .store_derivatives = store_derivatives,
3992 .out_offset = compiler.output("Incoming"),
3993 .bump_filter_width = bump_filter_width,
3994 },
3995 use_derivative);
3996 }
3997
3998 out = output("Parametric");
3999 if (!out->links.empty()) {
4000 compiler.add_node(this,
4001 NODE_GEOMETRY,
4002 SVMNodeGeometry{
4003 .geom_type = NODE_GEOM_uv,
4004 .bump_offset = bump_offset,
4005 .store_derivatives = store_derivatives,
4006 .out_offset = compiler.output("Parametric"),
4007 .bump_filter_width = bump_filter_width,
4008 },
4009 use_derivative);
4010 }
4011
4012 out = output("Backfacing");
4013 if (!out->links.empty()) {
4014 compiler.add_node(this,
4015 NODE_LIGHT_PATH,
4016 SVMNodeLightPath{
4017 .path_type = NODE_LP_backfacing,
4018 .out_offset = compiler.output("Backfacing"),
4019 });
4020 }
4021
4022 out = output("Pointiness");
4023 if (!out->links.empty()) {
4024 if (compiler.output_type() != SHADER_TYPE_VOLUME) {
4025 compiler.add_node(this,
4026 NODE_ATTR,
4027 SVMNodeAttr{
4028 .attr = int(ATTR_STD_POINTINESS),
4029 .missing = SVMInputFloat3{{0}, {0}, {0}},
4030 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
4031 .out_offset = compiler.output("Pointiness"),
4032 .output_type = NODE_ATTR_OUTPUT_FLOAT,
4033 .bump_offset = bump_offset,
4034 .store_derivatives = store_derivatives,
4035 .bump_filter_width = bump_filter_width,
4036 },
4037 use_derivative);
4038 }
4039 else {
4040 compiler.add_value_node(this, 0.0f, compiler.output("Pointiness"));
4041 }
4042 }
4043
4044 out = output("Random Per Island");
4045 if (!out->links.empty()) {
4046 if (compiler.output_type() != SHADER_TYPE_VOLUME) {
4047 compiler.add_node(this,
4048 NODE_ATTR,
4049 SVMNodeAttr{
4050 .attr = int(ATTR_STD_RANDOM_PER_ISLAND),
4051 .missing = SVMInputFloat3{{0}, {0}, {0}},
4052 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
4053 .out_offset = compiler.output("Random Per Island"),
4054 .output_type = NODE_ATTR_OUTPUT_FLOAT,
4055 .bump_offset = bump_offset,
4056 .store_derivatives = store_derivatives,
4057 .bump_filter_width = bump_filter_width,
4058 },
4059 use_derivative);
4060 }
4061 else {
4062 compiler.add_value_node(this, 0.0f, compiler.output("Random Per Island"));
4063 }
4064 }
4065}
4066
4067void GeometryNode::compile(OSLCompiler &compiler)
4068{
4069 if (bump == SHADER_BUMP_DX) {
4070 compiler.parameter("bump_offset", "dx");
4071 }
4072 else if (bump == SHADER_BUMP_DY) {
4073 compiler.parameter("bump_offset", "dy");
4074 }
4075 else {
4076 compiler.parameter("bump_offset", "center");
4077 }
4078 compiler.parameter("bump_filter_width", bump_filter_width);
4079
4080 compiler.add(this, "node_geometry");
4081}
4082
4083/* TextureCoordinate */
4084
4086{
4087 NodeType *type = NodeType::add("texture_coordinate", create, NodeType::SHADER);
4088
4089 SOCKET_BOOLEAN(from_dupli, "From Dupli", false);
4090 SOCKET_BOOLEAN(use_transform, "Use Transform", false);
4091 SOCKET_TRANSFORM(ob_tfm, "Object Transform", transform_identity());
4092
4093 SOCKET_OUT_POINT(generated, "Generated");
4094 SOCKET_OUT_NORMAL(normal, "Normal");
4095 SOCKET_OUT_POINT(UV, "UV");
4096 SOCKET_OUT_POINT(object, "Object");
4097 SOCKET_OUT_POINT(camera, "Camera");
4098 SOCKET_OUT_POINT(window, "Window");
4099 SOCKET_OUT_NORMAL(reflection, "Reflection");
4100
4101 return type;
4102}
4103
4104TextureCoordinateNode::TextureCoordinateNode() : ShaderNode(get_node_type()) {}
4105
4107{
4108 if (shader->has_surface_link()) {
4109 if (!from_dupli) {
4110 if (!output("Generated")->links.empty()) {
4112 }
4113 if (!output("UV")->links.empty()) {
4115 }
4116 }
4117 }
4118
4119 if (shader->has_volume) {
4120 if (!from_dupli) {
4121 if (!output("Generated")->links.empty()) {
4123 }
4124 }
4125 }
4126
4128}
4129
4131{
4132 return NODE_TEX_COORD;
4133}
4134
4136{
4138 const bool use_derivative = need_derivatives() || (bump != SHADER_BUMP_NONE);
4139 const bool store_derivatives = need_derivatives();
4141
4142 out = output("Generated");
4143 if (!out->links.empty()) {
4144 if (compiler.background) {
4145 compiler.add_node(this,
4146 NODE_GEOMETRY,
4148 .geom_type = NODE_GEOM_P,
4149 .bump_offset = bump_offset,
4150 .store_derivatives = store_derivatives,
4151 .out_offset = compiler.output("Generated"),
4152 .bump_filter_width = bump_filter_width,
4153 },
4154 use_derivative);
4155 }
4156 else {
4157 if (from_dupli) {
4158 /* Dupli generated coordinates are constant, no bump offset. */
4159 compiler.add_node(this,
4160 NODE_TEX_COORD,
4161 SVMNodeTexCoord{
4162 .texco_type = NODE_TEXCO_DUPLI_GENERATED,
4163 .bump_offset = NODE_BUMP_OFFSET_CENTER,
4164 .store_derivatives = store_derivatives,
4165 .out_offset = compiler.output("Generated"),
4166 .bump_filter_width = bump_filter_width,
4167 },
4168 use_derivative);
4169 }
4170 else if (compiler.output_type() == SHADER_TYPE_VOLUME) {
4171 compiler.add_node(this,
4172 NODE_TEX_COORD,
4173 SVMNodeTexCoord{
4174 .texco_type = NODE_TEXCO_VOLUME_GENERATED,
4175 .bump_offset = bump_offset,
4176 .store_derivatives = store_derivatives,
4177 .out_offset = compiler.output("Generated"),
4178 .bump_filter_width = bump_filter_width,
4179 },
4180 use_derivative);
4181 }
4182 else {
4183 compiler.add_node(this,
4184 NODE_ATTR,
4185 SVMNodeAttr{
4186 .attr = int(compiler.attribute(ATTR_STD_GENERATED)),
4187 .missing = SVMInputFloat3{{0}, {0}, {0}},
4188 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
4189 .out_offset = compiler.output("Generated"),
4190 .output_type = NODE_ATTR_OUTPUT_FLOAT3,
4191 .bump_offset = bump_offset,
4192 .store_derivatives = store_derivatives,
4193 .bump_filter_width = bump_filter_width,
4194 },
4195 use_derivative);
4196 }
4197 }
4198 }
4199
4200 out = output("Normal");
4201 if (!out->links.empty()) {
4202 compiler.add_node(this,
4203 NODE_TEX_COORD,
4204 SVMNodeTexCoord{
4205 .texco_type = NODE_TEXCO_NORMAL,
4206 .bump_offset = bump_offset,
4207 .store_derivatives = store_derivatives,
4208 .out_offset = compiler.output("Normal"),
4209 .bump_filter_width = bump_filter_width,
4210 },
4211 use_derivative);
4212 }
4213
4214 out = output("UV");
4215 if (!out->links.empty()) {
4216 if (from_dupli) {
4217 /* Dupli UV coordinates aren't constant, no bump offset. */
4218 compiler.add_node(this,
4219 NODE_TEX_COORD,
4220 SVMNodeTexCoord{
4221 .texco_type = NODE_TEXCO_DUPLI_UV,
4222 .bump_offset = NODE_BUMP_OFFSET_CENTER,
4223 .store_derivatives = store_derivatives,
4224 .out_offset = compiler.output("UV"),
4225 .bump_filter_width = bump_filter_width,
4226 },
4227 use_derivative);
4228 }
4229 else {
4230 compiler.add_node(this,
4231 NODE_ATTR,
4232 SVMNodeAttr{
4233 .attr = int(compiler.attribute(ATTR_STD_UV)),
4234 .missing = SVMInputFloat3{{0}, {0}, {0}},
4235 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
4236 .out_offset = compiler.output("UV"),
4237 .output_type = NODE_ATTR_OUTPUT_FLOAT3,
4238 .bump_offset = bump_offset,
4239 .store_derivatives = store_derivatives,
4240 .bump_filter_width = bump_filter_width,
4241 },
4242 use_derivative);
4243 }
4244 }
4245
4246 out = output("Object");
4247 if (!out->links.empty()) {
4248 compiler.add_node(
4249 this,
4250 NODE_TEX_COORD,
4251 SVMNodeTexCoord{
4252 .texco_type = (use_transform) ? NODE_TEXCO_OBJECT_WITH_TRANSFORM : NODE_TEXCO_OBJECT,
4253 .bump_offset = bump_offset,
4254 .store_derivatives = store_derivatives,
4255 .out_offset = compiler.output("Object"),
4257 },
4258 use_derivative);
4259 if (use_transform) {
4260 const PackedTransform ob_itfm = transform_inverse(ob_tfm);
4261 compiler.add_node_data(ob_itfm);
4262 }
4263 }
4264
4265 out = output("Camera");
4266 if (!out->links.empty()) {
4267 compiler.add_node(this,
4268 NODE_TEX_COORD,
4269 SVMNodeTexCoord{
4270 .texco_type = NODE_TEXCO_CAMERA,
4271 .bump_offset = bump_offset,
4272 .store_derivatives = store_derivatives,
4273 .out_offset = compiler.output("Camera"),
4274 .bump_filter_width = bump_filter_width,
4275 },
4276 use_derivative);
4277 }
4278
4279 out = output("Window");
4280 if (!out->links.empty()) {
4281 compiler.add_node(this,
4282 NODE_TEX_COORD,
4283 SVMNodeTexCoord{
4284 .texco_type = NODE_TEXCO_WINDOW,
4285 .bump_offset = bump_offset,
4286 .store_derivatives = store_derivatives,
4287 .out_offset = compiler.output("Window"),
4288 .bump_filter_width = bump_filter_width,
4289 },
4290 use_derivative);
4291 }
4292
4293 /* Reflection currently does not support bump offset. */
4294 out = output("Reflection");
4295 if (!out->links.empty()) {
4296 if (compiler.background) {
4297 compiler.add_node(this,
4298 NODE_GEOMETRY,
4299 SVMNodeGeometry{
4300 .geom_type = NODE_GEOM_I,
4301 .bump_offset = NODE_BUMP_OFFSET_CENTER,
4302 .store_derivatives = store_derivatives,
4303 .out_offset = compiler.output("Reflection"),
4304 .bump_filter_width = bump_filter_width,
4305 },
4306 use_derivative);
4307 }
4308 else {
4309 compiler.add_node(this,
4310 NODE_TEX_COORD,
4311 SVMNodeTexCoord{
4312 .texco_type = NODE_TEXCO_REFLECTION,
4313 .bump_offset = NODE_BUMP_OFFSET_CENTER,
4314 .store_derivatives = store_derivatives,
4315 .out_offset = compiler.output("Reflection"),
4316 .bump_filter_width = bump_filter_width,
4317 },
4318 use_derivative);
4319 }
4320 }
4321}
4322
4323void TextureCoordinateNode::compile(OSLCompiler &compiler)
4324{
4325 if (bump == SHADER_BUMP_DX) {
4326 compiler.parameter("bump_offset", "dx");
4327 }
4328 else if (bump == SHADER_BUMP_DY) {
4329 compiler.parameter("bump_offset", "dy");
4330 }
4331 else {
4332 compiler.parameter("bump_offset", "center");
4333 }
4334 compiler.parameter("bump_filter_width", bump_filter_width);
4335
4336 if (compiler.background) {
4337 compiler.parameter("is_background", true);
4338 }
4339 if (compiler.output_type() == SHADER_TYPE_VOLUME) {
4340 compiler.parameter("is_volume", true);
4341 }
4342 compiler.parameter(this, "use_transform");
4343 const Transform ob_itfm = transform_inverse(ob_tfm);
4344 compiler.parameter("object_itfm", ob_itfm);
4345
4346 compiler.parameter(this, "from_dupli");
4347
4348 compiler.add(this, "node_texture_coordinate");
4349}
4350
4351/* UV Map */
4352
4354{
4355 NodeType *type = NodeType::add("uvmap", create, NodeType::SHADER);
4356
4357 SOCKET_STRING(attribute, "attribute", ustring());
4358 SOCKET_IN_BOOLEAN(from_dupli, "from dupli", false);
4359
4360 SOCKET_OUT_POINT(UV, "UV");
4361
4362 return type;
4363}
4364
4365UVMapNode::UVMapNode() : ShaderNode(get_node_type()) {}
4366
4368{
4369 if (shader->has_surface) {
4370 if (!from_dupli) {
4371 if (!output("UV")->links.empty()) {
4372 if (!attribute.empty()) {
4374 }
4375 else {
4377 }
4378 }
4379 }
4380 }
4381
4383}
4384
4386{
4387 return NODE_TEX_COORD;
4388}
4389
4390void UVMapNode::compile(SVMCompiler &compiler)
4391{
4393 const bool use_derivative = need_derivatives() || (bump != SHADER_BUMP_NONE);
4394 const bool store_derivatives = need_derivatives();
4395 ShaderOutput *out = output("UV");
4396
4397 if (!out->links.empty()) {
4398 if (from_dupli) {
4399 /* Dupli UV coordinates are constant, no bump offset. */
4400 compiler.add_node(this,
4401 NODE_TEX_COORD,
4403 .texco_type = NODE_TEXCO_DUPLI_UV,
4404 .bump_offset = NODE_BUMP_OFFSET_CENTER,
4405 .store_derivatives = store_derivatives,
4406 .out_offset = compiler.output("UV"),
4407 .bump_filter_width = bump_filter_width,
4408 },
4409 use_derivative);
4410 }
4411 else {
4412 int attr;
4413 if (!attribute.empty()) {
4414 attr = compiler.attribute(attribute);
4415 }
4416 else {
4417 attr = compiler.attribute(ATTR_STD_UV);
4418 }
4419
4420 compiler.add_node(this,
4421 NODE_ATTR,
4422 SVMNodeAttr{
4423 .attr = attr,
4424 .missing = SVMInputFloat3{{0}, {0}, {0}},
4425 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
4426 .out_offset = compiler.output("UV"),
4427 .output_type = NODE_ATTR_OUTPUT_FLOAT3,
4428 .bump_offset = bump_offset,
4429 .store_derivatives = store_derivatives,
4430 .bump_filter_width = bump_filter_width,
4431 },
4432 use_derivative);
4433 }
4434 }
4435}
4436
4437void UVMapNode::compile(OSLCompiler &compiler)
4438{
4439 if (bump == SHADER_BUMP_DX) {
4440 compiler.parameter("bump_offset", "dx");
4441 }
4442 else if (bump == SHADER_BUMP_DY) {
4443 compiler.parameter("bump_offset", "dy");
4444 }
4445 else {
4446 compiler.parameter("bump_offset", "center");
4447 }
4448 compiler.parameter("bump_filter_width", bump_filter_width);
4449
4450 compiler.parameter(this, "from_dupli");
4451 compiler.parameter(this, "attribute");
4452 compiler.add(this, "node_uv_map");
4453}
4454
4455/* Light Path */
4456
4458{
4459 NodeType *type = NodeType::add("light_path", create, NodeType::SHADER);
4460
4461 SOCKET_OUT_FLOAT(is_camera_ray, "Is Camera Ray");
4462 SOCKET_OUT_FLOAT(is_shadow_ray, "Is Shadow Ray");
4463 SOCKET_OUT_FLOAT(is_diffuse_ray, "Is Diffuse Ray");
4464 SOCKET_OUT_FLOAT(is_glossy_ray, "Is Glossy Ray");
4465 SOCKET_OUT_FLOAT(is_singular_ray, "Is Singular Ray");
4466 SOCKET_OUT_FLOAT(is_reflection_ray, "Is Reflection Ray");
4467 SOCKET_OUT_FLOAT(is_transmission_ray, "Is Transmission Ray");
4468 SOCKET_OUT_FLOAT(is_volume_scatter_ray, "Is Volume Scatter Ray");
4469 SOCKET_OUT_FLOAT(ray_length, "Ray Length");
4470 SOCKET_OUT_FLOAT(ray_depth, "Ray Depth");
4471 SOCKET_OUT_FLOAT(diffuse_depth, "Diffuse Depth");
4472 SOCKET_OUT_FLOAT(glossy_depth, "Glossy Depth");
4473 SOCKET_OUT_FLOAT(transparent_depth, "Transparent Depth");
4474 SOCKET_OUT_FLOAT(transmission_depth, "Transmission Depth");
4475 SOCKET_OUT_FLOAT(portal_depth, "Portal Depth");
4476
4477 return type;
4478}
4479
4480LightPathNode::LightPathNode() : ShaderNode(get_node_type())
4481{
4482 special_type = SHADER_SPECIAL_TYPE_LIGHT_PATH;
4483}
4484
4485void LightPathNode::compile(SVMCompiler &compiler)
4486{
4487 ShaderOutput *out;
4488
4489 out = output("Is Camera Ray");
4490 if (!out->links.empty()) {
4491 compiler.add_node(this,
4492 NODE_LIGHT_PATH,
4493 SVMNodeLightPath{
4494 .path_type = NODE_LP_camera,
4495 .out_offset = compiler.output("Is Camera Ray"),
4496 });
4497 }
4498
4499 out = output("Is Shadow Ray");
4500 if (!out->links.empty()) {
4501 compiler.add_node(this,
4502 NODE_LIGHT_PATH,
4503 SVMNodeLightPath{
4504 .path_type = NODE_LP_shadow,
4505 .out_offset = compiler.output("Is Shadow Ray"),
4506 });
4507 }
4508
4509 out = output("Is Diffuse Ray");
4510 if (!out->links.empty()) {
4511 compiler.add_node(this,
4512 NODE_LIGHT_PATH,
4513 SVMNodeLightPath{
4514 .path_type = NODE_LP_diffuse,
4515 .out_offset = compiler.output("Is Diffuse Ray"),
4516 });
4517 }
4518
4519 out = output("Is Glossy Ray");
4520 if (!out->links.empty()) {
4521 compiler.add_node(this,
4522 NODE_LIGHT_PATH,
4523 SVMNodeLightPath{
4524 .path_type = NODE_LP_glossy,
4525 .out_offset = compiler.output("Is Glossy Ray"),
4526 });
4527 }
4528
4529 out = output("Is Singular Ray");
4530 if (!out->links.empty()) {
4531 compiler.add_node(this,
4532 NODE_LIGHT_PATH,
4533 SVMNodeLightPath{
4534 .path_type = NODE_LP_singular,
4535 .out_offset = compiler.output("Is Singular Ray"),
4536 });
4537 }
4538
4539 out = output("Is Reflection Ray");
4540 if (!out->links.empty()) {
4541 compiler.add_node(this,
4542 NODE_LIGHT_PATH,
4543 SVMNodeLightPath{
4544 .path_type = NODE_LP_reflection,
4545 .out_offset = compiler.output("Is Reflection Ray"),
4546 });
4547 }
4548
4549 out = output("Is Transmission Ray");
4550 if (!out->links.empty()) {
4551 compiler.add_node(this,
4552 NODE_LIGHT_PATH,
4553 SVMNodeLightPath{
4554 .path_type = NODE_LP_transmission,
4555 .out_offset = compiler.output("Is Transmission Ray"),
4556 });
4557 }
4558
4559 out = output("Is Volume Scatter Ray");
4560 if (!out->links.empty()) {
4561 compiler.add_node(this,
4562 NODE_LIGHT_PATH,
4563 SVMNodeLightPath{
4564 .path_type = NODE_LP_volume_scatter,
4565 .out_offset = compiler.output("Is Volume Scatter Ray"),
4566 });
4567 }
4568
4569 out = output("Ray Length");
4570 if (!out->links.empty()) {
4571 compiler.add_node(this,
4572 NODE_LIGHT_PATH,
4573 SVMNodeLightPath{
4574 .path_type = NODE_LP_ray_length,
4575 .out_offset = compiler.output("Ray Length"),
4576 });
4577 }
4578
4579 out = output("Ray Depth");
4580 if (!out->links.empty()) {
4581 compiler.add_node(this,
4582 NODE_LIGHT_PATH,
4583 SVMNodeLightPath{
4584 .path_type = NODE_LP_ray_depth,
4585 .out_offset = compiler.output("Ray Depth"),
4586 });
4587 }
4588
4589 out = output("Diffuse Depth");
4590 if (!out->links.empty()) {
4591 compiler.add_node(this,
4592 NODE_LIGHT_PATH,
4593 SVMNodeLightPath{
4594 .path_type = NODE_LP_ray_diffuse,
4595 .out_offset = compiler.output("Diffuse Depth"),
4596 });
4597 }
4598
4599 out = output("Glossy Depth");
4600 if (!out->links.empty()) {
4601 compiler.add_node(this,
4602 NODE_LIGHT_PATH,
4603 SVMNodeLightPath{
4604 .path_type = NODE_LP_ray_glossy,
4605 .out_offset = compiler.output("Glossy Depth"),
4606 });
4607 }
4608
4609 out = output("Transparent Depth");
4610 if (!out->links.empty()) {
4611 compiler.add_node(this,
4612 NODE_LIGHT_PATH,
4613 SVMNodeLightPath{
4614 .path_type = NODE_LP_ray_transparent,
4615 .out_offset = compiler.output("Transparent Depth"),
4616 });
4617 }
4618
4619 out = output("Transmission Depth");
4620 if (!out->links.empty()) {
4621 compiler.add_node(this,
4622 NODE_LIGHT_PATH,
4623 SVMNodeLightPath{
4624 .path_type = NODE_LP_ray_transmission,
4625 .out_offset = compiler.output("Transmission Depth"),
4626 });
4627 }
4628
4629 out = output("Portal Depth");
4630 if (!out->links.empty()) {
4631 compiler.add_node(this,
4632 NODE_LIGHT_PATH,
4633 SVMNodeLightPath{
4634 .path_type = NODE_LP_ray_portal,
4635 .out_offset = compiler.output("Portal Depth"),
4636 });
4637 }
4638}
4639
4640void LightPathNode::compile(OSLCompiler &compiler)
4641{
4642 compiler.add(this, "node_light_path");
4643}
4644
4645/* Light Falloff */
4646
4648{
4649 NodeType *type = NodeType::add("light_falloff", create, NodeType::SHADER);
4650
4651 SOCKET_IN_FLOAT(strength, "Strength", 100.0f);
4652 SOCKET_IN_FLOAT(smooth, "Smooth", 0.0f);
4653
4654 SOCKET_OUT_FLOAT(quadratic, "Quadratic");
4655 SOCKET_OUT_FLOAT(linear, "Linear");
4656 SOCKET_OUT_FLOAT(constant, "Constant");
4657
4658 return type;
4659}
4660
4661LightFalloffNode::LightFalloffNode() : ShaderNode(get_node_type()) {}
4662
4664{
4665 ShaderOutput *out = output("Quadratic");
4666 if (!out->links.empty()) {
4667 compiler.add_node(this,
4668 NODE_LIGHT_FALLOFF,
4669 SVMNodeLightFalloff{
4670 .falloff_type = NODE_LIGHT_FALLOFF_QUADRATIC,
4671 .strength = compiler.input_float("Strength"),
4672 .smooth = compiler.input_float("Smooth"),
4673 .out_offset = compiler.output("Quadratic"),
4674 });
4675 }
4676
4677 out = output("Linear");
4678 if (!out->links.empty()) {
4679 compiler.add_node(this,
4680 NODE_LIGHT_FALLOFF,
4681 SVMNodeLightFalloff{
4682 .falloff_type = NODE_LIGHT_FALLOFF_LINEAR,
4683 .strength = compiler.input_float("Strength"),
4684 .smooth = compiler.input_float("Smooth"),
4685 .out_offset = compiler.output("Linear"),
4686 });
4687 }
4688
4689 out = output("Constant");
4690 if (!out->links.empty()) {
4691 compiler.add_node(this,
4692 NODE_LIGHT_FALLOFF,
4693 SVMNodeLightFalloff{
4694 .falloff_type = NODE_LIGHT_FALLOFF_CONSTANT,
4695 .strength = compiler.input_float("Strength"),
4696 .smooth = compiler.input_float("Smooth"),
4697 .out_offset = compiler.output("Constant"),
4698 });
4699 }
4700}
4701
4703{
4704 compiler.add(this, "node_light_falloff");
4705}
4706
4707/* Object Info */
4708
4710{
4711 NodeType *type = NodeType::add("object_info", create, NodeType::SHADER);
4712
4713 SOCKET_OUT_VECTOR(location, "Location");
4714 SOCKET_OUT_COLOR(color, "Color");
4715 SOCKET_OUT_FLOAT(alpha, "Alpha");
4716 SOCKET_OUT_FLOAT(object_index, "Object Index");
4717 SOCKET_OUT_FLOAT(material_index, "Material Index");
4718 SOCKET_OUT_FLOAT(random, "Random");
4719
4720 return type;
4721}
4722
4723ObjectInfoNode::ObjectInfoNode() : ShaderNode(get_node_type()) {}
4724
4726{
4727 ShaderOutput *out = output("Location");
4728 if (!out->links.empty()) {
4729 compiler.add_node(this,
4730 NODE_OBJECT_INFO,
4731 SVMNodeObjectInfo{
4732 .info_type = NODE_INFO_OB_LOCATION,
4733 .out_offset = compiler.output("Location"),
4734 });
4735 }
4736
4737 out = output("Color");
4738 if (!out->links.empty()) {
4739 compiler.add_node(this,
4740 NODE_OBJECT_INFO,
4741 SVMNodeObjectInfo{
4742 .info_type = NODE_INFO_OB_COLOR,
4743 .out_offset = compiler.output("Color"),
4744 });
4745 }
4746
4747 out = output("Alpha");
4748 if (!out->links.empty()) {
4749 compiler.add_node(this,
4750 NODE_OBJECT_INFO,
4751 SVMNodeObjectInfo{
4752 .info_type = NODE_INFO_OB_ALPHA,
4753 .out_offset = compiler.output("Alpha"),
4754 });
4755 }
4756
4757 out = output("Object Index");
4758 if (!out->links.empty()) {
4759 compiler.add_node(this,
4760 NODE_OBJECT_INFO,
4761 SVMNodeObjectInfo{
4762 .info_type = NODE_INFO_OB_INDEX,
4763 .out_offset = compiler.output("Object Index"),
4764 });
4765 }
4766
4767 out = output("Material Index");
4768 if (!out->links.empty()) {
4769 compiler.add_node(this,
4770 NODE_OBJECT_INFO,
4771 SVMNodeObjectInfo{
4772 .info_type = NODE_INFO_MAT_INDEX,
4773 .out_offset = compiler.output("Material Index"),
4774 });
4775 }
4776
4777 out = output("Random");
4778 if (!out->links.empty()) {
4779 compiler.add_node(this,
4780 NODE_OBJECT_INFO,
4781 SVMNodeObjectInfo{
4782 .info_type = NODE_INFO_OB_RANDOM,
4783 .out_offset = compiler.output("Random"),
4784 });
4785 }
4786}
4787
4789{
4790 compiler.add(this, "node_object_info");
4791}
4792
4793/* Particle Info */
4794
4796{
4797 NodeType *type = NodeType::add("particle_info", create, NodeType::SHADER);
4798
4799 SOCKET_OUT_FLOAT(index, "Index");
4800 SOCKET_OUT_FLOAT(random, "Random");
4801 SOCKET_OUT_FLOAT(age, "Age");
4802 SOCKET_OUT_FLOAT(lifetime, "Lifetime");
4803 SOCKET_OUT_POINT(location, "Location");
4804#if 0 /* not yet supported */
4805 SOCKET_OUT_QUATERNION(rotation, "Rotation");
4806#endif
4807 SOCKET_OUT_FLOAT(size, "Size");
4808 SOCKET_OUT_VECTOR(velocity, "Velocity");
4809 SOCKET_OUT_VECTOR(angular_velocity, "Angular Velocity");
4810
4811 return type;
4812}
4813
4814ParticleInfoNode::ParticleInfoNode() : ShaderNode(get_node_type()) {}
4815
4817{
4818 if (!output("Index")->links.empty()) {
4820 }
4821 if (!output("Random")->links.empty()) {
4823 }
4824 if (!output("Age")->links.empty()) {
4826 }
4827 if (!output("Lifetime")->links.empty()) {
4829 }
4830 if (!output("Location")->links.empty()) {
4832 }
4833#if 0 /* not yet supported */
4834 if (!output("Rotation")->links.empty()) {
4836 }
4837#endif
4838 if (!output("Size")->links.empty()) {
4840 }
4841 if (!output("Velocity")->links.empty()) {
4843 }
4844 if (!output("Angular Velocity")->links.empty()) {
4846 }
4847
4849}
4850
4852{
4854
4855 out = output("Index");
4856 if (!out->links.empty()) {
4857 compiler.add_node(this,
4858 NODE_PARTICLE_INFO,
4860 .info_type = NODE_INFO_PAR_INDEX,
4861 .out_offset = compiler.output("Index"),
4862 });
4863 }
4864
4865 out = output("Random");
4866 if (!out->links.empty()) {
4867 compiler.add_node(this,
4868 NODE_PARTICLE_INFO,
4869 SVMNodeParticleInfo{
4870 .info_type = NODE_INFO_PAR_RANDOM,
4871 .out_offset = compiler.output("Random"),
4872 });
4873 }
4874
4875 out = output("Age");
4876 if (!out->links.empty()) {
4877 compiler.add_node(this,
4878 NODE_PARTICLE_INFO,
4879 SVMNodeParticleInfo{
4880 .info_type = NODE_INFO_PAR_AGE,
4881 .out_offset = compiler.output("Age"),
4882 });
4883 }
4884
4885 out = output("Lifetime");
4886 if (!out->links.empty()) {
4887 compiler.add_node(this,
4888 NODE_PARTICLE_INFO,
4889 SVMNodeParticleInfo{
4890 .info_type = NODE_INFO_PAR_LIFETIME,
4891 .out_offset = compiler.output("Lifetime"),
4892 });
4893 }
4894
4895 out = output("Location");
4896 if (!out->links.empty()) {
4897 compiler.add_node(this,
4898 NODE_PARTICLE_INFO,
4899 SVMNodeParticleInfo{
4900 .info_type = NODE_INFO_PAR_LOCATION,
4901 .out_offset = compiler.output("Location"),
4902 });
4903 }
4904
4905 /* quaternion data is not yet supported by Cycles */
4906#if 0
4907 out = output("Rotation");
4908 if (!out->links.empty()) {
4909 compiler.add_node(this, NODE_PARTICLE_INFO,
4910 SVMNodeParticleInfo{
4911 .info_type = NODE_INFO_PAR_ROTATION,
4912 .out_offset = compiler.output("Rotation"),
4913 });
4914 }
4915#endif
4916
4917 out = output("Size");
4918 if (!out->links.empty()) {
4919 compiler.add_node(this,
4920 NODE_PARTICLE_INFO,
4921 SVMNodeParticleInfo{
4922 .info_type = NODE_INFO_PAR_SIZE,
4923 .out_offset = compiler.output("Size"),
4924 });
4925 }
4926
4927 out = output("Velocity");
4928 if (!out->links.empty()) {
4929 compiler.add_node(this,
4930 NODE_PARTICLE_INFO,
4931 SVMNodeParticleInfo{
4932 .info_type = NODE_INFO_PAR_VELOCITY,
4933 .out_offset = compiler.output("Velocity"),
4934 });
4935 }
4936
4937 out = output("Angular Velocity");
4938 if (!out->links.empty()) {
4939 compiler.add_node(this,
4940 NODE_PARTICLE_INFO,
4941 SVMNodeParticleInfo{
4942 .info_type = NODE_INFO_PAR_ANGULAR_VELOCITY,
4943 .out_offset = compiler.output("Angular Velocity"),
4944 });
4945 }
4946}
4947
4949{
4950 compiler.add(this, "node_particle_info");
4951}
4952
4953/* Hair Info */
4954
4956{
4957 NodeType *type = NodeType::add("hair_info", create, NodeType::SHADER);
4958
4959 SOCKET_OUT_FLOAT(is_strand, "Is Strand");
4960 SOCKET_OUT_FLOAT(intercept, "Intercept");
4961 SOCKET_OUT_FLOAT(size, "Length");
4962 SOCKET_OUT_FLOAT(thickness, "Thickness");
4963 SOCKET_OUT_NORMAL(tangent_normal, "Tangent Normal");
4964 SOCKET_OUT_FLOAT(index, "Random");
4965
4966 return type;
4967}
4968
4969HairInfoNode::HairInfoNode() : ShaderNode(get_node_type()) {}
4970
4972{
4973 if (shader->has_surface_link()) {
4974
4975 if (!output("Intercept")->links.empty()) {
4977 }
4978
4979 if (!output("Length")->links.empty()) {
4981 }
4982
4983 if (!output("Random")->links.empty()) {
4985 }
4986 }
4987
4989}
4990
4991void HairInfoNode::compile(SVMCompiler &compiler)
4992{
4994
4995 out = output("Is Strand");
4996 if (!out->links.empty()) {
4997 compiler.add_node(this,
4998 NODE_HAIR_INFO,
5000 .info_type = NODE_INFO_CURVE_IS_STRAND,
5001 .out_offset = compiler.output("Is Strand"),
5002 });
5003 }
5004
5005 out = output("Intercept");
5006 if (!out->links.empty()) {
5007 compiler.add_node(this,
5008 NODE_ATTR,
5009 SVMNodeAttr{
5010 .attr = int(compiler.attribute(ATTR_STD_CURVE_INTERCEPT)),
5011 .missing = SVMInputFloat3{{0}, {0}, {0}},
5012 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
5013 .out_offset = compiler.output("Intercept"),
5014 .output_type = NODE_ATTR_OUTPUT_FLOAT,
5015 });
5016 }
5017
5018 out = output("Length");
5019 if (!out->links.empty()) {
5020 compiler.add_node(this,
5021 NODE_ATTR,
5022 SVMNodeAttr{
5023 .attr = int(compiler.attribute(ATTR_STD_CURVE_LENGTH)),
5024 .missing = SVMInputFloat3{{0}, {0}, {0}},
5025 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
5026 .out_offset = compiler.output("Length"),
5027 .output_type = NODE_ATTR_OUTPUT_FLOAT,
5028 });
5029 }
5030
5031 out = output("Thickness");
5032 if (!out->links.empty()) {
5033 compiler.add_node(this,
5034 NODE_HAIR_INFO,
5035 SVMNodeHairInfo{
5036 .info_type = NODE_INFO_CURVE_THICKNESS,
5037 .out_offset = compiler.output("Thickness"),
5038 });
5039 }
5040
5041 out = output("Tangent Normal");
5042 if (!out->links.empty()) {
5043 compiler.add_node(this,
5044 NODE_HAIR_INFO,
5045 SVMNodeHairInfo{
5046 .info_type = NODE_INFO_CURVE_TANGENT_NORMAL,
5047 .out_offset = compiler.output("Tangent Normal"),
5048 });
5049 }
5050
5051 out = output("Random");
5052 if (!out->links.empty()) {
5053 compiler.add_node(this,
5054 NODE_ATTR,
5055 SVMNodeAttr{
5056 .attr = int(compiler.attribute(ATTR_STD_CURVE_RANDOM)),
5057 .missing = SVMInputFloat3{{0}, {0}, {0}},
5058 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
5059 .out_offset = compiler.output("Random"),
5060 .output_type = NODE_ATTR_OUTPUT_FLOAT,
5061 });
5062 }
5063}
5064
5065void HairInfoNode::compile(OSLCompiler &compiler)
5066{
5067 compiler.add(this, "node_hair_info");
5068}
5069
5070/* Point Info */
5071
5073{
5074 NodeType *type = NodeType::add("point_info", create, NodeType::SHADER);
5075
5076 SOCKET_OUT_POINT(position, "Position");
5077 SOCKET_OUT_FLOAT(radius, "Radius");
5078 SOCKET_OUT_FLOAT(random, "Random");
5079
5080 return type;
5081}
5082
5083PointInfoNode::PointInfoNode() : ShaderNode(get_node_type()) {}
5084
5086{
5087 if (shader->has_surface_link()) {
5088 if (!output("Random")->links.empty()) {
5090 }
5091 }
5092
5094}
5095
5096void PointInfoNode::compile(SVMCompiler &compiler)
5097{
5099
5100 out = output("Position");
5101 if (!out->links.empty()) {
5102 compiler.add_node(this,
5103 NODE_POINT_INFO,
5105 .info_type = NODE_INFO_POINT_POSITION,
5106 .out_offset = compiler.output("Position"),
5107 });
5108 }
5109
5110 out = output("Radius");
5111 if (!out->links.empty()) {
5112 compiler.add_node(this,
5113 NODE_POINT_INFO,
5114 SVMNodePointInfo{
5115 .info_type = NODE_INFO_POINT_RADIUS,
5116 .out_offset = compiler.output("Radius"),
5117 });
5118 }
5119
5120 out = output("Random");
5121 if (!out->links.empty()) {
5122 compiler.add_node(this,
5123 NODE_ATTR,
5124 SVMNodeAttr{
5125 .attr = int(compiler.attribute(ATTR_STD_POINT_RANDOM)),
5126 .missing = SVMInputFloat3{{0}, {0}, {0}},
5127 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
5128 .out_offset = compiler.output("Random"),
5129 .output_type = NODE_ATTR_OUTPUT_FLOAT,
5130 });
5131 }
5132}
5133
5134void PointInfoNode::compile(OSLCompiler &compiler)
5135{
5136 compiler.add(this, "node_point_info");
5137}
5138
5139/* Volume Info */
5140
5142{
5143 NodeType *type = NodeType::add("volume_info", create, NodeType::SHADER);
5144
5145 SOCKET_OUT_COLOR(color, "Color");
5146 SOCKET_OUT_FLOAT(density, "Density");
5147 SOCKET_OUT_FLOAT(flame, "Flame");
5148 SOCKET_OUT_FLOAT(temperature, "Temperature");
5149
5150 return type;
5151}
5152
5153VolumeInfoNode::VolumeInfoNode() : ShaderNode(get_node_type()) {}
5154
5155/* The requested attributes are not updated after node expansion.
5156 * So we explicitly request the required attributes.
5157 */
5159{
5160 if (shader->has_volume) {
5161 if (!output("Color")->links.empty()) {
5163 }
5164 if (!output("Density")->links.empty()) {
5166 }
5167 if (!output("Flame")->links.empty()) {
5169 }
5170 if (!output("Temperature")->links.empty()) {
5172 }
5174 }
5176}
5177
5179{
5180 ShaderOutput *color_out = output("Color");
5181 if (!color_out->links.empty()) {
5182 AttributeNode *attr = graph->create_node<AttributeNode>();
5183 attr->set_attribute(ustring("color"));
5184 graph->relink(color_out, attr->output("Color"));
5185 }
5186
5187 ShaderOutput *density_out = output("Density");
5188 if (!density_out->links.empty()) {
5189 AttributeNode *attr = graph->create_node<AttributeNode>();
5190 attr->set_attribute(ustring("density"));
5191 graph->relink(density_out, attr->output("Fac"));
5192 }
5193
5194 ShaderOutput *flame_out = output("Flame");
5195 if (!flame_out->links.empty()) {
5196 AttributeNode *attr = graph->create_node<AttributeNode>();
5197 attr->set_attribute(ustring("flame"));
5198 graph->relink(flame_out, attr->output("Fac"));
5199 }
5200
5201 ShaderOutput *temperature_out = output("Temperature");
5202 if (!temperature_out->links.empty()) {
5203 AttributeNode *attr = graph->create_node<AttributeNode>();
5204 attr->set_attribute(ustring("temperature"));
5205 graph->relink(temperature_out, attr->output("Fac"));
5206 }
5207}
5208
5209void VolumeInfoNode::compile(SVMCompiler & /*compiler*/) {}
5210
5211void VolumeInfoNode::compile(OSLCompiler & /*compiler*/) {}
5212
5214{
5215 NodeType *type = NodeType::add("vertex_color", create, NodeType::SHADER);
5216
5217 SOCKET_STRING(layer_name, "Layer Name", ustring());
5218 SOCKET_OUT_COLOR(color, "Color");
5219 SOCKET_OUT_FLOAT(alpha, "Alpha");
5220
5221 return type;
5222}
5223
5224VertexColorNode::VertexColorNode() : ShaderNode(get_node_type()) {}
5225
5227{
5228 if (!(output("Color")->links.empty() && output("Alpha")->links.empty())) {
5229 if (!layer_name.empty()) {
5230 attributes->add_name_or_standard(layer_name);
5231 }
5232 else {
5234 }
5235 }
5237}
5238
5240{
5241 /* Replace with an attribute node, which has the same functionality. */
5242 ShaderOutput *color_out = output("Color");
5243 ShaderOutput *alpha_out = output("Alpha");
5244 if (color_out->links.empty() && alpha_out->links.empty()) {
5245 return;
5246 }
5247
5248 AttributeNode *attr = graph->create_node<AttributeNode>();
5249 attr->set_attribute(
5250 layer_name.empty() ? ustring(Attribute::standard_name(ATTR_STD_VERTEX_COLOR)) : layer_name);
5251 attr->set_missing(zero_float3());
5252 attr->set_missing_alpha(0.0f);
5253
5254 graph->relink(color_out, attr->output("Color"));
5255 graph->relink(alpha_out, attr->output("Alpha"));
5256}
5257
5258void VertexColorNode::compile(SVMCompiler & /*compiler*/) {}
5259
5260void VertexColorNode::compile(OSLCompiler & /*compiler*/) {}
5261
5262/* Value */
5263
5265{
5266 NodeType *type = NodeType::add("value", create, NodeType::SHADER);
5267
5268 SOCKET_FLOAT(value, "Value", 0.0f);
5269 SOCKET_OUT_FLOAT(value, "Value");
5270
5271 return type;
5272}
5273
5274ValueNode::ValueNode() : ShaderNode(get_node_type()) {}
5275
5277{
5278 folder.make_constant(value);
5279}
5280
5281void ValueNode::compile(SVMCompiler &compiler)
5282{
5283 compiler.add_value_node(this, value, compiler.output("Value"));
5284}
5285
5286void ValueNode::compile(OSLCompiler &compiler)
5287{
5288 compiler.parameter("value_value", value);
5289 compiler.add(this, "node_value");
5290}
5291
5292/* Color */
5293
5295{
5296 NodeType *type = NodeType::add("color", create, NodeType::SHADER);
5297
5298 SOCKET_COLOR(value, "Value", zero_float3());
5299 SOCKET_OUT_COLOR(color, "Color");
5300
5301 return type;
5302}
5303
5304ColorNode::ColorNode() : ShaderNode(get_node_type()) {}
5305
5307{
5308 folder.make_constant(value);
5309}
5310
5311void ColorNode::compile(SVMCompiler &compiler)
5312{
5313 ShaderOutput *color_out = output("Color");
5314
5315 if (!color_out->links.empty()) {
5316 compiler.add_value_node(this, value, compiler.output("Color"));
5317 }
5318}
5319
5320void ColorNode::compile(OSLCompiler &compiler)
5321{
5322 compiler.parameter_color("color_value", value);
5323
5324 compiler.add(this, "node_value");
5325}
5326
5327/* Add Closure */
5328
5330{
5331 NodeType *type = NodeType::add("add_closure", create, NodeType::SHADER);
5332
5333 SOCKET_IN_CLOSURE(closure1, "Closure1");
5334 SOCKET_IN_CLOSURE(closure2, "Closure2");
5335 SOCKET_OUT_CLOSURE(closure, "Closure");
5336
5337 return type;
5338}
5339
5340AddClosureNode::AddClosureNode() : ShaderNode(get_node_type())
5341{
5343}
5344
5345void AddClosureNode::compile(SVMCompiler & /*compiler*/)
5346{
5347 /* handled in the SVM compiler */
5348}
5349
5351{
5352 compiler.add(this, "node_add_closure");
5353}
5354
5356{
5357 ShaderInput *closure1_in = input("Closure1");
5358 ShaderInput *closure2_in = input("Closure2");
5359
5360 /* remove useless add closures nodes */
5361 if (!closure1_in->link) {
5362 folder.bypass_or_discard(closure2_in);
5363 }
5364 else if (!closure2_in->link) {
5365 folder.bypass_or_discard(closure1_in);
5366 }
5367}
5368
5369/* Mix Closure */
5370
5372{
5373 NodeType *type = NodeType::add("mix_closure", create, NodeType::SHADER);
5374
5375 SOCKET_IN_FLOAT(fac, "Fac", 0.5f);
5376 SOCKET_IN_CLOSURE(closure1, "Closure1");
5377 SOCKET_IN_CLOSURE(closure2, "Closure2");
5378
5379 SOCKET_OUT_CLOSURE(closure, "Closure");
5380
5381 return type;
5382}
5383
5384MixClosureNode::MixClosureNode() : ShaderNode(get_node_type())
5385{
5387}
5388
5389void MixClosureNode::compile(SVMCompiler & /*compiler*/)
5390{
5391 /* handled in the SVM compiler */
5392}
5393
5395{
5396 compiler.add(this, "node_mix_closure");
5397}
5398
5400{
5401 ShaderInput *closure1_in = input("Closure1");
5402 ShaderInput *closure2_in = input("Closure2");
5403
5404 /* remove useless mix closures nodes */
5405 if (closure1_in->link == closure2_in->link) {
5406 folder.bypass_or_discard(closure1_in);
5407 }
5408 /* remove unused mix closure input when factor is 0.0 or 1.0
5409 * check for closure links and make sure factor link is disconnected */
5410 else if (!input("Fac")->link) {
5411 /* factor 0.0 */
5412 if (fac <= 0.0f) {
5413 folder.bypass_or_discard(closure1_in);
5414 }
5415 /* factor 1.0 */
5416 else if (fac >= 1.0f) {
5417 folder.bypass_or_discard(closure2_in);
5418 }
5419 }
5420}
5421
5422/* Mix Closure */
5423
5425{
5426 NodeType *type = NodeType::add("mix_closure_weight", create, NodeType::SHADER);
5427
5428 SOCKET_IN_FLOAT(weight, "Weight", 1.0f);
5429 SOCKET_IN_FLOAT(fac, "Fac", 1.0f);
5430
5431 SOCKET_OUT_FLOAT(weight1, "Weight1");
5432 SOCKET_OUT_FLOAT(weight2, "Weight2");
5433
5434 return type;
5435}
5436
5437MixClosureWeightNode::MixClosureWeightNode() : ShaderNode(get_node_type()) {}
5438
5440{
5441 compiler.add_node(this,
5442 NODE_MIX_CLOSURE,
5443 SVMNodeMixClosure{
5444 .fac = compiler.input_float("Fac"),
5445 .in_weight_offset = compiler.input_link("Weight"),
5446 .weight1_offset = compiler.output("Weight1"),
5447 .weight2_offset = compiler.output("Weight2"),
5448 });
5449}
5450
5451void MixClosureWeightNode::compile(OSLCompiler & /*compiler*/)
5452{
5453 assert(0);
5454}
5455
5456/* Invert */
5457
5459{
5460 NodeType *type = NodeType::add("invert", create, NodeType::SHADER);
5461
5462 SOCKET_IN_FLOAT(fac, "Fac", 1.0f);
5463 SOCKET_IN_COLOR(color, "Color", zero_float3());
5464
5465 SOCKET_OUT_COLOR(color, "Color");
5466
5467 return type;
5468}
5469
5470InvertNode::InvertNode() : ShaderNode(get_node_type()) {}
5471
5473{
5474 ShaderInput *color_in = input("Color");
5475
5476 if (!input("Fac")->link) {
5477 /* evaluate fully constant node */
5478 if (!color_in->link) {
5479 folder.make_constant(interp(color, one_float3() - color, fac));
5480 }
5481 /* remove no-op node */
5482 else if (fac == 0.0f) {
5483 folder.bypass(color_in->link);
5484 }
5485 }
5486}
5487
5488void InvertNode::compile(SVMCompiler &compiler)
5489{
5490 compiler.add_node(this,
5491 NODE_INVERT,
5493 .color = compiler.input_float3("Color"),
5494 .fac = compiler.input_float("Fac"),
5495 .out_offset = compiler.output("Color"),
5496 });
5497}
5498
5499void InvertNode::compile(OSLCompiler &compiler)
5500{
5501 compiler.add(this, "node_invert");
5502}
5503
5504/* Mix */
5505
5507{
5508 NodeType *type = NodeType::add("mix", create, NodeType::SHADER);
5509
5510 static NodeEnum type_enum;
5511 type_enum.insert("mix", NODE_MIX_BLEND);
5512 type_enum.insert("add", NODE_MIX_ADD);
5513 type_enum.insert("multiply", NODE_MIX_MUL);
5514 type_enum.insert("screen", NODE_MIX_SCREEN);
5515 type_enum.insert("overlay", NODE_MIX_OVERLAY);
5516 type_enum.insert("subtract", NODE_MIX_SUB);
5517 type_enum.insert("divide", NODE_MIX_DIV);
5518 type_enum.insert("difference", NODE_MIX_DIFF);
5519 type_enum.insert("darken", NODE_MIX_DARK);
5520 type_enum.insert("lighten", NODE_MIX_LIGHT);
5521 type_enum.insert("dodge", NODE_MIX_DODGE);
5522 type_enum.insert("burn", NODE_MIX_BURN);
5523 type_enum.insert("hue", NODE_MIX_HUE);
5524 type_enum.insert("saturation", NODE_MIX_SAT);
5525 type_enum.insert("value", NODE_MIX_VAL);
5526 type_enum.insert("color", NODE_MIX_COL);
5527 type_enum.insert("soft_light", NODE_MIX_SOFT);
5528 type_enum.insert("linear_light", NODE_MIX_LINEAR);
5529 type_enum.insert("exclusion", NODE_MIX_EXCLUSION);
5530 SOCKET_ENUM(mix_type, "Type", type_enum, NODE_MIX_BLEND);
5531
5532 SOCKET_BOOLEAN(use_clamp, "Use Clamp", false);
5533
5534 SOCKET_IN_FLOAT(fac, "Fac", 0.5f);
5535 SOCKET_IN_COLOR(color1, "Color1", zero_float3());
5536 SOCKET_IN_COLOR(color2, "Color2", zero_float3());
5537
5538 SOCKET_OUT_COLOR(color, "Color");
5539
5540 return type;
5541}
5542
5543MixNode::MixNode() : ShaderNode(get_node_type()) {}
5544
5545void MixNode::compile(SVMCompiler &compiler)
5546{
5547 const SVMStackOffset color_offset = compiler.output("Color");
5548
5549 compiler.add_node(this,
5550 NODE_MIX,
5551 SVMNodeMix{
5552 .mix_type = mix_type,
5553 .c1 = compiler.input_float3("Color1"),
5554 .c2 = compiler.input_float3("Color2"),
5555 .fac = compiler.input_float("Fac"),
5556 .result_offset = color_offset,
5557 });
5558
5559 if (use_clamp) {
5560 compiler.add_node(this,
5561 NODE_MIX,
5562 SVMNodeMix{
5563 .mix_type = NODE_MIX_CLAMP,
5564 .c1 = compiler.input_float3_from_offset(color_offset),
5565 .c2 = SVMInputFloat3{{0}, {0}, {0}},
5566 .fac = SVMInputFloat{0},
5567 .result_offset = color_offset,
5568 });
5569 }
5570}
5571
5572void MixNode::compile(OSLCompiler &compiler)
5573{
5574 compiler.parameter(this, "mix_type");
5575 compiler.parameter(this, "use_clamp");
5576 compiler.add(this, "node_mix");
5577}
5578
5580{
5581 if (folder.all_inputs_constant()) {
5582 folder.make_constant_clamp(svm_mix_clamped_factor(mix_type, fac, color1, color2), use_clamp);
5583 }
5584 else {
5585 folder.fold_mix(mix_type, use_clamp);
5586 }
5587}
5588
5590{
5591 switch (mix_type) {
5592 case NODE_MIX_BLEND:
5593 case NODE_MIX_ADD:
5594 case NODE_MIX_MUL:
5595 case NODE_MIX_SUB:
5596 break;
5597 default:
5598 return false;
5599 }
5600 return use_clamp == false && input("Factor")->link == nullptr;
5601}
5602
5603/* Mix Color */
5604
5606{
5607 NodeType *type = NodeType::add("mix_color", create, NodeType::SHADER);
5608
5609 static NodeEnum type_enum;
5610 type_enum.insert("mix", NODE_MIX_BLEND);
5611 type_enum.insert("add", NODE_MIX_ADD);
5612 type_enum.insert("multiply", NODE_MIX_MUL);
5613 type_enum.insert("screen", NODE_MIX_SCREEN);
5614 type_enum.insert("overlay", NODE_MIX_OVERLAY);
5615 type_enum.insert("subtract", NODE_MIX_SUB);
5616 type_enum.insert("divide", NODE_MIX_DIV);
5617 type_enum.insert("difference", NODE_MIX_DIFF);
5618 type_enum.insert("darken", NODE_MIX_DARK);
5619 type_enum.insert("lighten", NODE_MIX_LIGHT);
5620 type_enum.insert("dodge", NODE_MIX_DODGE);
5621 type_enum.insert("burn", NODE_MIX_BURN);
5622 type_enum.insert("hue", NODE_MIX_HUE);
5623 type_enum.insert("saturation", NODE_MIX_SAT);
5624 type_enum.insert("value", NODE_MIX_VAL);
5625 type_enum.insert("color", NODE_MIX_COL);
5626 type_enum.insert("soft_light", NODE_MIX_SOFT);
5627 type_enum.insert("linear_light", NODE_MIX_LINEAR);
5628 type_enum.insert("exclusion", NODE_MIX_EXCLUSION);
5629 SOCKET_ENUM(blend_type, "Type", type_enum, NODE_MIX_BLEND);
5630
5631 SOCKET_IN_FLOAT(fac, "Factor", 0.5f);
5632 SOCKET_IN_COLOR(a, "A", zero_float3());
5633 SOCKET_IN_COLOR(b, "B", zero_float3());
5634 SOCKET_BOOLEAN(use_clamp_result, "Use Clamp Result", false);
5635 SOCKET_BOOLEAN(use_clamp, "Use Clamp", true);
5636
5637 SOCKET_OUT_COLOR(result, "Result");
5638
5639 return type;
5640}
5641
5642MixColorNode::MixColorNode() : ShaderNode(get_node_type()) {}
5643
5644void MixColorNode::compile(SVMCompiler &compiler)
5645{
5646 compiler.add_node(this,
5647 NODE_MIX_COLOR,
5648 SVMNodeMixColor{
5649 .blend_type = blend_type,
5650 .a = compiler.input_float3("A"),
5651 .b = compiler.input_float3("B"),
5652 .fac = compiler.input_float("Factor"),
5653 .use_clamp = use_clamp,
5654 .use_clamp_result = use_clamp_result,
5655 .result_offset = compiler.output("Result"),
5656 });
5657}
5658
5659void MixColorNode::compile(OSLCompiler &compiler)
5660{
5661 compiler.parameter(this, "blend_type");
5662 compiler.parameter(this, "use_clamp");
5663 compiler.parameter(this, "use_clamp_result");
5664 compiler.add(this, "node_mix_color");
5665}
5666
5668{
5669 if (folder.all_inputs_constant()) {
5670 if (use_clamp) {
5671 fac = clamp(fac, 0.0f, 1.0f);
5672 }
5673 folder.make_constant_clamp(svm_mix(blend_type, fac, a, b), use_clamp_result);
5674 }
5675 else {
5676 folder.fold_mix_color(blend_type, use_clamp, use_clamp_result);
5677 }
5678}
5679
5681{
5682 switch (blend_type) {
5683 case NODE_MIX_BLEND:
5684 case NODE_MIX_ADD:
5685 case NODE_MIX_MUL:
5686 case NODE_MIX_SUB:
5687 break;
5688 default:
5689 return false;
5690 }
5691 return use_clamp == false && use_clamp_result == false && input("Factor")->link == nullptr;
5692}
5693
5694/* Mix Float */
5695
5697{
5698 NodeType *type = NodeType::add("mix_float", create, NodeType::SHADER);
5699
5700 SOCKET_IN_FLOAT(fac, "Factor", 0.5f);
5701 SOCKET_IN_FLOAT(a, "A", 0.0f);
5702 SOCKET_IN_FLOAT(b, "B", 0.0f);
5703 SOCKET_BOOLEAN(use_clamp, "Use Clamp", true);
5704 SOCKET_OUT_FLOAT(result, "Result");
5705
5706 return type;
5707}
5708
5709MixFloatNode::MixFloatNode() : ShaderNode(get_node_type()) {}
5710
5711void MixFloatNode::compile(SVMCompiler &compiler)
5712{
5713 compiler.add_node(this,
5714 NODE_MIX_FLOAT,
5715 SVMNodeMixFloat{
5716 .fac = compiler.input_float("Factor"),
5717 .a = compiler.input_float("A"),
5718 .b = compiler.input_float("B"),
5719 .use_clamp = use_clamp,
5720 .result_offset = compiler.output("Result"),
5721 });
5722}
5723
5724void MixFloatNode::compile(OSLCompiler &compiler)
5725{
5726 compiler.parameter(this, "use_clamp");
5727 compiler.add(this, "node_mix_float");
5728}
5729
5731{
5732 if (folder.all_inputs_constant()) {
5733 if (use_clamp) {
5734 fac = clamp(fac, 0.0f, 1.0f);
5735 }
5736 folder.make_constant(a * (1 - fac) + b * fac);
5737 }
5738 else {
5739 folder.fold_mix_float(use_clamp, false);
5740 }
5741}
5742
5744{
5745 return use_clamp == false && input("Factor")->link == nullptr;
5746}
5747
5748/* Mix Vector */
5749
5751{
5752 NodeType *type = NodeType::add("mix_vector", create, NodeType::SHADER);
5753
5754 SOCKET_IN_FLOAT(fac, "Factor", 0.5f);
5755 SOCKET_IN_VECTOR(a, "A", zero_float3());
5757 SOCKET_BOOLEAN(use_clamp, "Use Clamp", true);
5758
5759 SOCKET_OUT_VECTOR(result, "Result");
5760
5761 return type;
5762}
5763
5764MixVectorNode::MixVectorNode() : ShaderNode(get_node_type()) {}
5765
5766void MixVectorNode::compile(SVMCompiler &compiler)
5767{
5768 compiler.add_node(this,
5769 NODE_MIX_VECTOR,
5770 SVMNodeMixVector{
5771 .a = compiler.input_float3("A"),
5772 .b = compiler.input_float3("B"),
5773 .fac = compiler.input_float("Factor"),
5774 .use_clamp = use_clamp,
5775 .result_offset = compiler.output("Result"),
5776 });
5777}
5778
5779void MixVectorNode::compile(OSLCompiler &compiler)
5780{
5781 compiler.parameter(this, "use_clamp");
5782 compiler.add(this, "node_mix_vector");
5783}
5784
5786{
5787 if (folder.all_inputs_constant()) {
5788 if (use_clamp) {
5789 fac = clamp(fac, 0.0f, 1.0f);
5790 }
5791 folder.make_constant(a * (one_float3() - fac) + b * fac);
5792 }
5793 else {
5794 folder.fold_mix_color(NODE_MIX_BLEND, use_clamp, false);
5795 }
5796}
5797
5799{
5800 return use_clamp == false && input("Factor")->link == nullptr;
5801}
5802
5803/* Mix Vector Non Uniform */
5804
5806{
5807 NodeType *type = NodeType::add("mix_vector_non_uniform", create, NodeType::SHADER);
5808
5809 SOCKET_IN_VECTOR(fac, "Factor", make_float3(0.5f, 0.5f, 0.5f));
5810 SOCKET_IN_VECTOR(a, "A", zero_float3());
5812 SOCKET_BOOLEAN(use_clamp, "Use Clamp", true);
5813
5814 SOCKET_OUT_VECTOR(result, "Result");
5815
5816 return type;
5817}
5818
5819MixVectorNonUniformNode::MixVectorNonUniformNode() : ShaderNode(get_node_type()) {}
5820
5822{
5823 compiler.add_node(this,
5824 NODE_MIX_VECTOR_NON_UNIFORM,
5825 SVMNodeMixVectorNonUniform{
5826 .a = compiler.input_float3("A"),
5827 .b = compiler.input_float3("B"),
5828 .fac = compiler.input_float3("Factor"),
5829 .use_clamp = use_clamp,
5830 .result_offset = compiler.output("Result"),
5831 });
5832}
5833
5835{
5836 compiler.parameter(this, "use_clamp");
5837 compiler.add(this, "node_mix_vector_non_uniform");
5838}
5839
5841{
5842 if (folder.all_inputs_constant()) {
5843 if (use_clamp) {
5844 fac = saturate(fac);
5845 }
5846 folder.make_constant(a * (one_float3() - fac) + b * fac);
5847 }
5848}
5849
5851{
5852 return use_clamp == false && input("Factor")->link == nullptr;
5853}
5854
5855/* Combine Color */
5856
5858{
5859 NodeType *type = NodeType::add("combine_color", create, NodeType::SHADER);
5860
5861 static NodeEnum type_enum;
5862 type_enum.insert("rgb", NODE_COMBSEP_COLOR_RGB);
5863 type_enum.insert("hsv", NODE_COMBSEP_COLOR_HSV);
5864 type_enum.insert("hsl", NODE_COMBSEP_COLOR_HSL);
5865 SOCKET_ENUM(color_type, "Type", type_enum, NODE_COMBSEP_COLOR_RGB);
5866
5867 SOCKET_IN_FLOAT(r, "Red", 0.0f);
5868 SOCKET_IN_FLOAT(g, "Green", 0.0f);
5869 SOCKET_IN_FLOAT(b, "Blue", 0.0f);
5870
5871 SOCKET_OUT_COLOR(color, "Color");
5872
5873 return type;
5874}
5875
5876CombineColorNode::CombineColorNode() : ShaderNode(get_node_type()) {}
5877
5879{
5880 if (folder.all_inputs_constant()) {
5881 folder.make_constant(svm_combine_color(color_type, make_float3(r, g, b)));
5882 }
5883}
5884
5886{
5887 compiler.add_node(this,
5888 NODE_COMBINE_COLOR,
5890 .color_type = color_type,
5891 .red = compiler.input_float("Red"),
5892 .green = compiler.input_float("Green"),
5893 .blue = compiler.input_float("Blue"),
5894 .color_offset = compiler.output("Color"),
5895 });
5896}
5897
5899{
5900 compiler.parameter(this, "color_type");
5901 compiler.add(this, "node_combine_color");
5902}
5903
5904/* Combine XYZ */
5905
5907{
5908 NodeType *type = NodeType::add("combine_xyz", create, NodeType::SHADER);
5909
5910 SOCKET_IN_FLOAT(x, "X", 0.0f);
5911 SOCKET_IN_FLOAT(y, "Y", 0.0f);
5912 SOCKET_IN_FLOAT(z, "Z", 0.0f);
5913
5914 SOCKET_OUT_VECTOR(vector, "Vector");
5915
5916 return type;
5917}
5918
5919CombineXYZNode::CombineXYZNode() : ShaderNode(get_node_type()) {}
5920
5922{
5923 if (folder.all_inputs_constant()) {
5924 folder.make_constant(make_float3(x, y, z));
5925 }
5926}
5927
5929{
5930 const SVMStackOffset vector_out = compiler.output("Vector");
5931 compiler.add_node(this,
5932 NODE_COMBINE_VECTOR,
5934 .in = compiler.input_float("X"),
5935 .vector_index = 0,
5936 .out_offset = vector_out,
5937 });
5938 compiler.add_node(this,
5939 NODE_COMBINE_VECTOR,
5940 SVMNodeCombineVector{
5941 .in = compiler.input_float("Y"),
5942 .vector_index = 1,
5943 .out_offset = vector_out,
5944 });
5945 compiler.add_node(this,
5946 NODE_COMBINE_VECTOR,
5947 SVMNodeCombineVector{
5948 .in = compiler.input_float("Z"),
5949 .vector_index = 2,
5950 .out_offset = vector_out,
5951 });
5952}
5953
5955{
5956 compiler.add(this, "node_combine_xyz");
5957}
5958
5959/* Gamma */
5960
5962{
5963 NodeType *type = NodeType::add("gamma", create, NodeType::SHADER);
5964
5965 SOCKET_IN_COLOR(color, "Color", zero_float3());
5966 SOCKET_IN_FLOAT(gamma, "Gamma", 1.0f);
5967 SOCKET_OUT_COLOR(color, "Color");
5968
5969 return type;
5970}
5971
5972GammaNode::GammaNode() : ShaderNode(get_node_type()) {}
5973
5975{
5976 if (folder.all_inputs_constant()) {
5977 folder.make_constant(svm_math_gamma_color(color, gamma));
5978 }
5979 else {
5980 ShaderInput *color_in = input("Color");
5981 ShaderInput *gamma_in = input("Gamma");
5982
5983 /* 1 ^ X == X ^ 0 == 1 */
5984 if (folder.is_one(color_in) || folder.is_zero(gamma_in)) {
5985 folder.make_one();
5986 }
5987 /* X ^ 1 == X */
5988 else if (folder.is_one(gamma_in)) {
5989 folder.try_bypass_or_make_constant(color_in, false);
5990 }
5991 }
5992}
5993
5994void GammaNode::compile(SVMCompiler &compiler)
5995{
5996 compiler.add_node(this,
5997 NODE_GAMMA,
5999 .color = compiler.input_float3("Color"),
6000 .gamma = compiler.input_float("Gamma"),
6001 .out_offset = compiler.output("Color"),
6002 });
6003}
6004
6005void GammaNode::compile(OSLCompiler &compiler)
6006{
6007 compiler.add(this, "node_gamma");
6008}
6009
6010/* Bright Contrast */
6011
6013{
6014 NodeType *type = NodeType::add("brightness_contrast", create, NodeType::SHADER);
6015
6016 SOCKET_IN_COLOR(color, "Color", zero_float3());
6017 SOCKET_IN_FLOAT(bright, "Bright", 0.0f);
6018 SOCKET_IN_FLOAT(contrast, "Contrast", 0.0f);
6019
6020 SOCKET_OUT_COLOR(color, "Color");
6021
6022 return type;
6023}
6024
6025BrightContrastNode::BrightContrastNode() : ShaderNode(get_node_type()) {}
6026
6028{
6029 if (folder.all_inputs_constant()) {
6030 folder.make_constant(svm_brightness_contrast(color, bright, contrast));
6031 }
6032}
6033
6035{
6036 compiler.add_node(this,
6037 NODE_BRIGHTCONTRAST,
6039 .color = compiler.input_float3("Color"),
6040 .bright = compiler.input_float("Bright"),
6041 .contrast = compiler.input_float("Contrast"),
6042 .out_offset = compiler.output("Color"),
6043 });
6044}
6045
6047{
6048 compiler.add(this, "node_brightness");
6049}
6050
6051/* Separate Color */
6052
6054{
6055 NodeType *type = NodeType::add("separate_color", create, NodeType::SHADER);
6056
6057 static NodeEnum type_enum;
6058 type_enum.insert("rgb", NODE_COMBSEP_COLOR_RGB);
6059 type_enum.insert("hsv", NODE_COMBSEP_COLOR_HSV);
6060 type_enum.insert("hsl", NODE_COMBSEP_COLOR_HSL);
6061 SOCKET_ENUM(color_type, "Type", type_enum, NODE_COMBSEP_COLOR_RGB);
6062
6063 SOCKET_IN_COLOR(color, "Color", zero_float3());
6064
6065 SOCKET_OUT_FLOAT(r, "Red");
6066 SOCKET_OUT_FLOAT(g, "Green");
6067 SOCKET_OUT_FLOAT(b, "Blue");
6068
6069 return type;
6070}
6071
6072SeparateColorNode::SeparateColorNode() : ShaderNode(get_node_type()) {}
6073
6075{
6076 if (folder.all_inputs_constant()) {
6077 float3 col = svm_separate_color(color_type, color);
6078
6079 for (int channel = 0; channel < 3; channel++) {
6080 if (outputs[channel] == folder.output) {
6081 folder.make_constant(col[channel]);
6082 return;
6083 }
6084 }
6085 }
6086}
6087
6089{
6090 compiler.add_node(this,
6091 NODE_SEPARATE_COLOR,
6093 .color_type = color_type,
6094 .color = compiler.input_float3("Color"),
6095 .red_offset = compiler.output("Red"),
6096 .green_offset = compiler.output("Green"),
6097 .blue_offset = compiler.output("Blue"),
6098 });
6099}
6100
6102{
6103 compiler.parameter(this, "color_type");
6104 compiler.add(this, "node_separate_color");
6105}
6106
6107/* Separate XYZ */
6108
6110{
6111 NodeType *type = NodeType::add("separate_xyz", create, NodeType::SHADER);
6112
6113 SOCKET_IN_COLOR(vector, "Vector", zero_float3());
6114
6115 SOCKET_OUT_FLOAT(x, "X");
6116 SOCKET_OUT_FLOAT(y, "Y");
6117 SOCKET_OUT_FLOAT(z, "Z");
6118
6119 return type;
6120}
6121
6122SeparateXYZNode::SeparateXYZNode() : ShaderNode(get_node_type()) {}
6123
6125{
6126 if (folder.all_inputs_constant()) {
6127 for (int channel = 0; channel < 3; channel++) {
6128 if (outputs[channel] == folder.output) {
6129 folder.make_constant(vector[channel]);
6130 return;
6131 }
6132 }
6133 }
6134}
6135
6137{
6138 const SVMInputFloat3 vector_in = compiler.input_float3("Vector");
6139 compiler.add_node(this,
6140 NODE_SEPARATE_VECTOR,
6142 .vector = vector_in,
6143 .vector_index = 0,
6144 .out_offset = compiler.output("X"),
6145 });
6146 compiler.add_node(this,
6147 NODE_SEPARATE_VECTOR,
6148 SVMNodeSeparateVector{
6149 .vector = vector_in,
6150 .vector_index = 1,
6151 .out_offset = compiler.output("Y"),
6152 });
6153 compiler.add_node(this,
6154 NODE_SEPARATE_VECTOR,
6155 SVMNodeSeparateVector{
6156 .vector = vector_in,
6157 .vector_index = 2,
6158 .out_offset = compiler.output("Z"),
6159 });
6160}
6161
6163{
6164 compiler.add(this, "node_separate_xyz");
6165}
6166
6167/* Get Vector Component */
6168
6170{
6171 NodeType *type = NodeType::add("get_vector_component", create, NodeType::SHADER);
6172
6173 SOCKET_IN_VECTOR(vector, "Vector", zero_float3());
6174 SOCKET_IN_INT(index, "Index", 0);
6175
6176 SOCKET_OUT_FLOAT(value, "Value");
6177
6178 return type;
6179}
6180
6181GetVectorComponentNode::GetVectorComponentNode() : ShaderNode(get_node_type()) {}
6182
6184{
6185 if (folder.all_inputs_constant()) {
6186 folder.make_constant(index >= 0 && index <= 2 ? vector[index] : 0.0f);
6187 }
6188}
6189
6191{
6192 compiler.add_node(this,
6193 NODE_GET_VECTOR_COMPONENT,
6195 .vector = compiler.input_float3("Vector"),
6196 .index = compiler.input_int("Index"),
6197 .out_offset = compiler.output("Value"),
6198 });
6199}
6200
6202{
6203 compiler.add(this, "node_get_vector_component");
6204}
6205
6206/* Hue/Saturation/Value */
6207
6209{
6210 NodeType *type = NodeType::add("hsv", create, NodeType::SHADER);
6211
6212 SOCKET_IN_FLOAT(hue, "Hue", 0.5f);
6213 SOCKET_IN_FLOAT(saturation, "Saturation", 1.0f);
6214 SOCKET_IN_FLOAT(value, "Value", 1.0f);
6215 SOCKET_IN_FLOAT(fac, "Fac", 1.0f);
6216 SOCKET_IN_COLOR(color, "Color", zero_float3());
6217
6218 SOCKET_OUT_COLOR(color, "Color");
6219
6220 return type;
6221}
6222
6223HSVNode::HSVNode() : ShaderNode(get_node_type()) {}
6224
6225void HSVNode::compile(SVMCompiler &compiler)
6226{
6227 compiler.add_node(this,
6228 NODE_HSV,
6229 SVMNodeHSV{
6230 .color = compiler.input_float3("Color"),
6231 .hue = compiler.input_float("Hue"),
6232 .sat = compiler.input_float("Saturation"),
6233 .val = compiler.input_float("Value"),
6234 .fac = compiler.input_float("Fac"),
6235 .out_color_offset = compiler.output("Color"),
6236 });
6237}
6238
6239void HSVNode::compile(OSLCompiler &compiler)
6240{
6241 compiler.add(this, "node_hsv");
6242}
6243
6244/* Attribute */
6245
6247{
6248 NodeType *type = NodeType::add("attribute", create, NodeType::SHADER);
6249
6250 SOCKET_STRING(attribute, "Attribute", ustring());
6251 SOCKET_IN_COLOR(missing, "Missing", zero_float3());
6252 SOCKET_IN_FLOAT(missing_alpha, "Missing Alpha", 1.0f);
6253
6254 SOCKET_OUT_COLOR(color, "Color");
6255 SOCKET_OUT_VECTOR(vector, "Vector");
6256 SOCKET_OUT_FLOAT(fac, "Fac");
6257 SOCKET_OUT_FLOAT(alpha, "Alpha");
6258
6259 return type;
6260}
6261
6262AttributeNode::AttributeNode() : ShaderNode(get_node_type()) {}
6263
6265{
6266
6267 if (!output("Color")->links.empty() || !output("Vector")->links.empty() ||
6268 !output("Fac")->links.empty() || !output("Alpha")->links.empty())
6269 {
6271 }
6272
6273 if (shader->has_volume) {
6275 }
6276
6278}
6279
6281{
6282 return NODE_ATTR;
6283}
6284
6285void AttributeNode::compile(SVMCompiler &compiler)
6286{
6288 const bool use_derivative = need_derivatives() || (bump != SHADER_BUMP_NONE);
6289 const bool store_derivatives = need_derivatives();
6290 ShaderOutput *color_out = output("Color");
6291 ShaderOutput *vector_out = output("Vector");
6292 ShaderOutput *fac_out = output("Fac");
6293 ShaderOutput *alpha_out = output("Alpha");
6294 const int attr = compiler.attribute_standard(attribute);
6295 const float bump_filter_or_stochastic = (compiler.output_type() == SHADER_TYPE_VOLUME) ?
6298
6299 if (!color_out->links.empty() || !vector_out->links.empty()) {
6300 if (!color_out->links.empty()) {
6301 compiler.add_node(this,
6302 NODE_ATTR,
6304 .attr = attr,
6305 .missing = compiler.input_float3("Missing"),
6306 .missing_alpha = compiler.input_float("Missing Alpha"),
6307 .out_offset = compiler.output("Color"),
6308 .output_type = NODE_ATTR_OUTPUT_FLOAT3,
6309 .bump_offset = bump_offset,
6310 .store_derivatives = store_derivatives,
6311 .bump_filter_width = bump_filter_or_stochastic,
6312 },
6313 use_derivative);
6314 }
6315 if (!vector_out->links.empty()) {
6316 compiler.add_node(this,
6317 NODE_ATTR,
6318 SVMNodeAttr{
6319 .attr = attr,
6320 .missing = compiler.input_float3("Missing"),
6321 .missing_alpha = compiler.input_float("Missing Alpha"),
6322 .out_offset = compiler.output("Vector"),
6323 .output_type = NODE_ATTR_OUTPUT_FLOAT3,
6324 .bump_offset = bump_offset,
6325 .store_derivatives = store_derivatives,
6326 .bump_filter_width = bump_filter_or_stochastic,
6327 },
6328 use_derivative);
6329 }
6330 }
6331
6332 if (!fac_out->links.empty()) {
6333 compiler.add_node(this,
6334 NODE_ATTR,
6335 SVMNodeAttr{
6336 .attr = attr,
6337 .missing = compiler.input_float3("Missing"),
6338 .missing_alpha = compiler.input_float("Missing Alpha"),
6339 .out_offset = compiler.output("Fac"),
6340 .output_type = NODE_ATTR_OUTPUT_FLOAT,
6341 .bump_offset = bump_offset,
6342 .store_derivatives = store_derivatives,
6343 .bump_filter_width = bump_filter_or_stochastic,
6344 },
6345 use_derivative);
6346 }
6347
6348 if (!alpha_out->links.empty()) {
6349 compiler.add_node(this,
6350 NODE_ATTR,
6351 SVMNodeAttr{
6352 .attr = attr,
6353 .missing = compiler.input_float3("Missing"),
6354 .missing_alpha = compiler.input_float("Missing Alpha"),
6355 .out_offset = compiler.output("Alpha"),
6356 .output_type = NODE_ATTR_OUTPUT_FLOAT_ALPHA,
6357 .bump_offset = bump_offset,
6358 .store_derivatives = store_derivatives,
6359 .bump_filter_width = bump_filter_or_stochastic,
6360 },
6361 use_derivative);
6362 }
6363}
6364
6365void AttributeNode::compile(OSLCompiler &compiler)
6366{
6367 if (bump == SHADER_BUMP_DX) {
6368 compiler.parameter("bump_offset", "dx");
6369 }
6370 else if (bump == SHADER_BUMP_DY) {
6371 compiler.parameter("bump_offset", "dy");
6372 }
6373 else {
6374 compiler.parameter("bump_offset", "center");
6375 }
6376 compiler.parameter("bump_filter_width", bump_filter_width);
6377
6378 compiler.parameter_attribute("name", attribute);
6379
6380 compiler.add(this, "node_attribute");
6381}
6382
6383/* Camera */
6384
6386{
6387 NodeType *type = NodeType::add("camera_info", create, NodeType::SHADER);
6388
6389 SOCKET_OUT_VECTOR(view_vector, "View Vector");
6390 SOCKET_OUT_FLOAT(view_z_depth, "View Z Depth");
6391 SOCKET_OUT_FLOAT(view_distance, "View Distance");
6392
6393 return type;
6394}
6395
6396CameraNode::CameraNode() : ShaderNode(get_node_type()) {}
6397
6398void CameraNode::compile(SVMCompiler &compiler)
6399{
6400 compiler.add_node(this,
6401 NODE_CAMERA,
6402 SVMNodeCamera{
6403 .vector_offset = compiler.output("View Vector"),
6404 .zdepth_offset = compiler.output("View Z Depth"),
6405 .distance_offset = compiler.output("View Distance"),
6406 });
6407}
6408
6409void CameraNode::compile(OSLCompiler &compiler)
6410{
6411 compiler.add(this, "node_camera");
6412}
6413
6414/* Fresnel */
6415
6417{
6418 NodeType *type = NodeType::add("fresnel", create, NodeType::SHADER);
6419
6422 SOCKET_IN_FLOAT(IOR, "IOR", 1.5f);
6423
6424 SOCKET_OUT_FLOAT(fac, "Fac");
6425
6426 return type;
6427}
6428
6429FresnelNode::FresnelNode() : ShaderNode(get_node_type()) {}
6430
6431void FresnelNode::compile(SVMCompiler &compiler)
6432{
6433 compiler.add_node(this,
6434 NODE_FRESNEL,
6435 SVMNodeFresnel{
6436 .ior = compiler.input_float("IOR"),
6437 .normal_offset = compiler.input_link("Normal"),
6438 .out_offset = compiler.output("Fac"),
6439 });
6440}
6441
6442void FresnelNode::compile(OSLCompiler &compiler)
6443{
6444 compiler.add(this, "node_fresnel");
6445}
6446
6447/* Layer Weight */
6448
6450{
6451 NodeType *type = NodeType::add("layer_weight", create, NodeType::SHADER);
6452
6455 SOCKET_IN_FLOAT(blend, "Blend", 0.5f);
6456
6457 SOCKET_OUT_FLOAT(fresnel, "Fresnel");
6458 SOCKET_OUT_FLOAT(facing, "Facing");
6459
6460 return type;
6461}
6462
6463LayerWeightNode::LayerWeightNode() : ShaderNode(get_node_type()) {}
6464
6466{
6467 ShaderOutput *fresnel_out = output("Fresnel");
6468 ShaderOutput *facing_out = output("Facing");
6469
6470 if (!fresnel_out->links.empty()) {
6471 compiler.add_node(this,
6472 NODE_LAYER_WEIGHT,
6473 SVMNodeLayerWeight{
6474 .weight_type = NODE_LAYER_WEIGHT_FRESNEL,
6475 .blend = compiler.input_float("Blend"),
6476 .normal_offset = compiler.input_link("Normal"),
6477 .out_offset = compiler.output("Fresnel"),
6478 });
6479 }
6480
6481 if (!facing_out->links.empty()) {
6482 compiler.add_node(this,
6483 NODE_LAYER_WEIGHT,
6484 SVMNodeLayerWeight{
6485 .weight_type = NODE_LAYER_WEIGHT_FACING,
6486 .blend = compiler.input_float("Blend"),
6487 .normal_offset = compiler.input_link("Normal"),
6488 .out_offset = compiler.output("Facing"),
6489 });
6490 }
6491}
6492
6494{
6495 compiler.add(this, "node_layer_weight");
6496}
6497
6498/* Wireframe */
6499
6501{
6502 NodeType *type = NodeType::add("wireframe", create, NodeType::SHADER);
6503
6504 SOCKET_BOOLEAN(use_pixel_size, "Use Pixel Size", false);
6505 SOCKET_IN_FLOAT(size, "Size", 0.01f);
6506 SOCKET_OUT_FLOAT(fac, "Fac");
6507
6508 return type;
6509}
6510
6511WireframeNode::WireframeNode() : ShaderNode(get_node_type()) {}
6512
6513void WireframeNode::compile(SVMCompiler &compiler)
6514{
6516 if (bump == SHADER_BUMP_DX) {
6517 bump_offset = NODE_BUMP_OFFSET_DX;
6518 }
6519 else if (bump == SHADER_BUMP_DY) {
6520 bump_offset = NODE_BUMP_OFFSET_DY;
6521 }
6522 compiler.add_node(this,
6523 NODE_WIREFRAME,
6524 SVMNodeWireframe{
6525 .in_size = compiler.input_float("Size"),
6526 .bump_filter_width = bump_filter_width,
6527 .use_pixel_size = use_pixel_size,
6528 .bump_offset = bump_offset,
6529 .out_fac_offset = compiler.output("Fac"),
6530 });
6531}
6532
6533void WireframeNode::compile(OSLCompiler &compiler)
6534{
6535 if (bump == SHADER_BUMP_DX) {
6536 compiler.parameter("bump_offset", "dx");
6537 }
6538 else if (bump == SHADER_BUMP_DY) {
6539 compiler.parameter("bump_offset", "dy");
6540 }
6541 else {
6542 compiler.parameter("bump_offset", "center");
6543 }
6544 compiler.parameter("bump_filter_width", bump_filter_width);
6545
6546 compiler.parameter(this, "use_pixel_size");
6547 compiler.add(this, "node_wireframe");
6548}
6549
6550/* Wavelength */
6551
6553{
6554 NodeType *type = NodeType::add("wavelength", create, NodeType::SHADER);
6555
6556 SOCKET_IN_FLOAT(wavelength, "Wavelength", 500.0f);
6557 SOCKET_OUT_COLOR(color, "Color");
6558
6559 return type;
6560}
6561
6562WavelengthNode::WavelengthNode() : ShaderNode(get_node_type()) {}
6563
6565{
6566 compiler.add_node(this,
6567 NODE_WAVELENGTH,
6568 SVMNodeWavelength{
6569 .wavelength = compiler.input_float("Wavelength"),
6570 .color_offset = compiler.output("Color"),
6571 });
6572}
6573
6575{
6576 compiler.add(this, "node_wavelength");
6577}
6578
6579/* Blackbody */
6580
6582{
6583 NodeType *type = NodeType::add("blackbody", create, NodeType::SHADER);
6584
6585 SOCKET_IN_FLOAT(temperature, "Temperature", 1200.0f);
6586 SOCKET_OUT_COLOR(color, "Color");
6587
6588 return type;
6589}
6590
6591BlackbodyNode::BlackbodyNode() : ShaderNode(get_node_type()) {}
6592
6594{
6595 if (folder.all_inputs_constant()) {
6596 const float3 rgb_rec709 = svm_math_blackbody_color_rec709(temperature);
6597 const float3 rgb = folder.scene->shader_manager->rec709_to_scene_linear(rgb_rec709);
6598 folder.make_constant(max(rgb, zero_float3()));
6599 }
6600}
6601
6602void BlackbodyNode::compile(SVMCompiler &compiler)
6603{
6604 compiler.add_node(this,
6605 NODE_BLACKBODY,
6607 .temperature = compiler.input_float("Temperature"),
6608 .color_offset = compiler.output("Color"),
6609 });
6610}
6611
6612void BlackbodyNode::compile(OSLCompiler &compiler)
6613{
6614 compiler.add(this, "node_blackbody");
6615}
6616
6617/* Output */
6618
6620{
6621 NodeType *type = NodeType::add("output", create, NodeType::SHADER);
6622
6623 SOCKET_IN_CLOSURE(surface, "Surface");
6624 SOCKET_IN_CLOSURE(volume, "Volume");
6625 SOCKET_IN_VECTOR(displacement, "Displacement", zero_float3());
6626 SOCKET_IN_NORMAL(normal, "Normal", zero_float3());
6627
6628 return type;
6629}
6630
6631OutputNode::OutputNode() : ShaderNode(get_node_type())
6632{
6633 special_type = SHADER_SPECIAL_TYPE_OUTPUT;
6634}
6635
6636void OutputNode::compile(SVMCompiler &compiler)
6637{
6638 if (compiler.output_type() == SHADER_TYPE_DISPLACEMENT) {
6639 ShaderInput *displacement_in = input("Displacement");
6640
6641 if (displacement_in->link) {
6642 compiler.add_node(this,
6643 NODE_SET_DISPLACEMENT,
6644 SVMNodeSetDisplacement{.fac_offset = compiler.input_link("Displacement")});
6645 }
6646 }
6647}
6648
6649void OutputNode::compile(OSLCompiler &compiler)
6650{
6651 if (compiler.output_type() == SHADER_TYPE_SURFACE) {
6652 compiler.add(this, "node_output_surface");
6653 }
6654 else if (compiler.output_type() == SHADER_TYPE_VOLUME) {
6655 compiler.add(this, "node_output_volume");
6656 }
6657 else if (compiler.output_type() == SHADER_TYPE_DISPLACEMENT) {
6658 compiler.add(this, "node_output_displacement");
6659 }
6660}
6661
6662/* Map Range Node */
6663
6665{
6666 NodeType *type = NodeType::add("map_range", create, NodeType::SHADER);
6667
6668 static NodeEnum type_enum;
6669 type_enum.insert("linear", NODE_MAP_RANGE_LINEAR);
6670 type_enum.insert("stepped", NODE_MAP_RANGE_STEPPED);
6671 type_enum.insert("smoothstep", NODE_MAP_RANGE_SMOOTHSTEP);
6672 type_enum.insert("smootherstep", NODE_MAP_RANGE_SMOOTHERSTEP);
6673 SOCKET_ENUM(range_type, "Type", type_enum, NODE_MAP_RANGE_LINEAR);
6674
6675 SOCKET_IN_FLOAT(value, "Value", 1.0f);
6676 SOCKET_IN_FLOAT(from_min, "From Min", 0.0f);
6677 SOCKET_IN_FLOAT(from_max, "From Max", 1.0f);
6678 SOCKET_IN_FLOAT(to_min, "To Min", 0.0f);
6679 SOCKET_IN_FLOAT(to_max, "To Max", 1.0f);
6680 SOCKET_IN_FLOAT(steps, "Steps", 4.0f);
6681 SOCKET_IN_BOOLEAN(clamp, "Clamp", false);
6682
6683 SOCKET_OUT_FLOAT(result, "Result");
6684
6685 return type;
6686}
6687
6688MapRangeNode::MapRangeNode() : ShaderNode(get_node_type()) {}
6689
6691{
6692 if (clamp) {
6693 ShaderOutput *result_out = output("Result");
6694 if (!result_out->links.empty()) {
6695 ClampNode *clamp_node = graph->create_node<ClampNode>();
6696 clamp_node->set_clamp_type(NODE_CLAMP_RANGE);
6697 graph->relink(result_out, clamp_node->output("Result"));
6698 graph->connect(result_out, clamp_node->input("Value"));
6699 if (input("To Min")->link) {
6700 graph->connect(input("To Min")->link, clamp_node->input("Min"));
6701 }
6702 else {
6703 clamp_node->set_min(to_min);
6704 }
6705 if (input("To Max")->link) {
6706 graph->connect(input("To Max")->link, clamp_node->input("Max"));
6707 }
6708 else {
6709 clamp_node->set_max(to_max);
6710 }
6711 }
6712 }
6713}
6714
6716{
6717 if (range_type != NODE_MAP_RANGE_LINEAR) {
6718 return false;
6719 }
6720 return input("To Min")->link == nullptr && input("To Max")->link == nullptr &&
6721 input("To Min")->link == nullptr && input("To Max")->link == nullptr;
6722}
6723
6724void MapRangeNode::compile(SVMCompiler &compiler)
6725{
6726 compiler.add_node(this,
6727 NODE_MAP_RANGE,
6729 .range_type = range_type,
6730 .value = compiler.input_float("Value"),
6731 .from_min = compiler.input_float("From Min"),
6732 .from_max = compiler.input_float("From Max"),
6733 .to_min = compiler.input_float("To Min"),
6734 .to_max = compiler.input_float("To Max"),
6735 .steps = compiler.input_float("Steps"),
6736 .result_offset = compiler.output("Result"),
6737 });
6738}
6739
6740void MapRangeNode::compile(OSLCompiler &compiler)
6741{
6742 compiler.parameter(this, "range_type");
6743 compiler.add(this, "node_map_range");
6744}
6745
6746/* Vector Map Range Node */
6747
6749{
6750 NodeType *type = NodeType::add("vector_map_range", create, NodeType::SHADER);
6751
6752 static NodeEnum type_enum;
6753 type_enum.insert("linear", NODE_MAP_RANGE_LINEAR);
6754 type_enum.insert("stepped", NODE_MAP_RANGE_STEPPED);
6755 type_enum.insert("smoothstep", NODE_MAP_RANGE_SMOOTHSTEP);
6756 type_enum.insert("smootherstep", NODE_MAP_RANGE_SMOOTHERSTEP);
6757 SOCKET_ENUM(range_type, "Type", type_enum, NODE_MAP_RANGE_LINEAR);
6758
6759 SOCKET_IN_VECTOR(vector, "Vector", zero_float3());
6760 SOCKET_IN_VECTOR(from_min, "From_Min_FLOAT3", zero_float3());
6761 SOCKET_IN_VECTOR(from_max, "From_Max_FLOAT3", one_float3());
6762 SOCKET_IN_VECTOR(to_min, "To_Min_FLOAT3", zero_float3());
6763 SOCKET_IN_VECTOR(to_max, "To_Max_FLOAT3", one_float3());
6764 SOCKET_IN_VECTOR(steps, "Steps_FLOAT3", make_float3(4.0f));
6765 SOCKET_BOOLEAN(use_clamp, "Use Clamp", false);
6766
6767 SOCKET_OUT_VECTOR(vector, "Vector");
6768
6769 return type;
6770}
6771
6772VectorMapRangeNode::VectorMapRangeNode() : ShaderNode(get_node_type()) {}
6773
6775
6777{
6778 if (range_type != NODE_MAP_RANGE_LINEAR) {
6779 return false;
6780 }
6781 return input("From_Min_FLOAT3")->link == nullptr && input("From_Max_FLOAT3")->link == nullptr &&
6782 input("To_Min_FLOAT3")->link == nullptr && input("To_Max_FLOAT3")->link == nullptr;
6783}
6784
6786{
6787 compiler.add_node(this,
6788 NODE_VECTOR_MAP_RANGE,
6790 .range_type = range_type,
6791 .use_clamp = use_clamp,
6792 .value = compiler.input_float3("Vector"),
6793 .from_min = compiler.input_float3("From_Min_FLOAT3"),
6794 .from_max = compiler.input_float3("From_Max_FLOAT3"),
6795 .to_min = compiler.input_float3("To_Min_FLOAT3"),
6796 .to_max = compiler.input_float3("To_Max_FLOAT3"),
6797 .steps = compiler.input_float3("Steps_FLOAT3"),
6798 .result_offset = compiler.output("Vector"),
6799 });
6800}
6801
6803{
6804 compiler.parameter(this, "range_type");
6805 compiler.parameter(this, "use_clamp");
6806 compiler.add(this, "node_vector_map_range");
6807}
6808
6809/* Clamp Node */
6810
6812{
6813 NodeType *type = NodeType::add("clamp", create, NodeType::SHADER);
6814
6815 static NodeEnum type_enum;
6816 type_enum.insert("minmax", NODE_CLAMP_MINMAX);
6817 type_enum.insert("range", NODE_CLAMP_RANGE);
6818 SOCKET_ENUM(clamp_type, "Type", type_enum, NODE_CLAMP_MINMAX);
6819
6820 SOCKET_IN_FLOAT(value, "Value", 1.0f);
6821 SOCKET_IN_FLOAT(min, "Min", 0.0f);
6822 SOCKET_IN_FLOAT(max, "Max", 1.0f);
6823
6824 SOCKET_OUT_FLOAT(result, "Result");
6825
6826 return type;
6827}
6828
6829ClampNode::ClampNode() : ShaderNode(get_node_type()) {}
6830
6832{
6833 if (folder.all_inputs_constant()) {
6834 if (clamp_type == NODE_CLAMP_RANGE && (min > max)) {
6835 folder.make_constant(clamp(value, max, min));
6836 }
6837 else {
6838 folder.make_constant(clamp(value, min, max));
6839 }
6840 }
6841}
6842
6843void ClampNode::compile(SVMCompiler &compiler)
6844{
6845 compiler.add_node(this,
6846 NODE_CLAMP,
6848 .clamp_type = clamp_type,
6849 .min = compiler.input_float("Min"),
6850 .max = compiler.input_float("Max"),
6851 .value = compiler.input_float("Value"),
6852 .result_offset = compiler.output("Result"),
6853 });
6854}
6855
6856void ClampNode::compile(OSLCompiler &compiler)
6857{
6858 compiler.parameter(this, "clamp_type");
6859 compiler.add(this, "node_clamp");
6860}
6861
6862/* AOV Output */
6863
6865{
6866 NodeType *type = NodeType::add("aov_output", create, NodeType::SHADER);
6867
6868 SOCKET_IN_COLOR(color, "Color", zero_float3());
6869 SOCKET_IN_FLOAT(value, "Value", 0.0f);
6870
6871 SOCKET_STRING(name, "AOV Name", ustring(""));
6872
6873 return type;
6874}
6875
6876OutputAOVNode::OutputAOVNode() : ShaderNode(get_node_type())
6877{
6878 special_type = SHADER_SPECIAL_TYPE_OUTPUT_AOV;
6879 offset = -1;
6880}
6881
6883{
6884 offset = scene->film->get_aov_offset(scene, name.string(), is_color);
6885
6886 if (offset == -1 || is_color) {
6887 input("Value")->disconnect();
6888 }
6889 if (offset == -1 || !is_color) {
6890 input("Color")->disconnect();
6891 }
6892}
6893
6894void OutputAOVNode::compile(SVMCompiler &compiler)
6895{
6896 assert(offset >= 0);
6897
6898 if (is_color) {
6899 compiler.add_node(this,
6900 NODE_AOV_COLOR,
6902 .aov_offset = offset,
6903 .color = compiler.input_float3("Color"),
6904 });
6905 }
6906 else {
6907 compiler.add_node(this,
6908 NODE_AOV_VALUE,
6909 SVMNodeAOVValue{
6910 .aov_offset = offset,
6911 .value = compiler.input_float("Value"),
6912 });
6913 }
6914}
6915
6916void OutputAOVNode::compile(OSLCompiler & /*compiler*/)
6917{
6918 /* TODO */
6919}
6920
6921/* Math */
6922
6924{
6925 NodeType *type = NodeType::add("math", create, NodeType::SHADER);
6926
6927 static NodeEnum type_enum;
6928 type_enum.insert("add", NODE_MATH_ADD);
6929 type_enum.insert("subtract", NODE_MATH_SUBTRACT);
6930 type_enum.insert("multiply", NODE_MATH_MULTIPLY);
6931 type_enum.insert("divide", NODE_MATH_DIVIDE);
6932 type_enum.insert("multiply_add", NODE_MATH_MULTIPLY_ADD);
6933 type_enum.insert("sine", NODE_MATH_SINE);
6934 type_enum.insert("cosine", NODE_MATH_COSINE);
6935 type_enum.insert("tangent", NODE_MATH_TANGENT);
6936 type_enum.insert("sinh", NODE_MATH_SINH);
6937 type_enum.insert("cosh", NODE_MATH_COSH);
6938 type_enum.insert("tanh", NODE_MATH_TANH);
6939 type_enum.insert("arcsine", NODE_MATH_ARCSINE);
6940 type_enum.insert("arccosine", NODE_MATH_ARCCOSINE);
6941 type_enum.insert("arctangent", NODE_MATH_ARCTANGENT);
6942 type_enum.insert("power", NODE_MATH_POWER);
6943 type_enum.insert("logarithm", NODE_MATH_LOGARITHM);
6944 type_enum.insert("minimum", NODE_MATH_MINIMUM);
6945 type_enum.insert("maximum", NODE_MATH_MAXIMUM);
6946 type_enum.insert("round", NODE_MATH_ROUND);
6947 type_enum.insert("less_than", NODE_MATH_LESS_THAN);
6948 type_enum.insert("greater_than", NODE_MATH_GREATER_THAN);
6949 type_enum.insert("modulo", NODE_MATH_MODULO);
6950 type_enum.insert("floored_modulo", NODE_MATH_FLOORED_MODULO);
6951 type_enum.insert("absolute", NODE_MATH_ABSOLUTE);
6952 type_enum.insert("arctan2", NODE_MATH_ARCTAN2);
6953 type_enum.insert("floor", NODE_MATH_FLOOR);
6954 type_enum.insert("ceil", NODE_MATH_CEIL);
6955 type_enum.insert("fraction", NODE_MATH_FRACTION);
6956 type_enum.insert("trunc", NODE_MATH_TRUNC);
6957 type_enum.insert("snap", NODE_MATH_SNAP);
6958 type_enum.insert("wrap", NODE_MATH_WRAP);
6959 type_enum.insert("pingpong", NODE_MATH_PINGPONG);
6960 type_enum.insert("sqrt", NODE_MATH_SQRT);
6961 type_enum.insert("inversesqrt", NODE_MATH_INV_SQRT);
6962 type_enum.insert("sign", NODE_MATH_SIGN);
6963 type_enum.insert("exponent", NODE_MATH_EXPONENT);
6964 type_enum.insert("radians", NODE_MATH_RADIANS);
6965 type_enum.insert("degrees", NODE_MATH_DEGREES);
6966 type_enum.insert("smoothmin", NODE_MATH_SMOOTH_MIN);
6967 type_enum.insert("smoothmax", NODE_MATH_SMOOTH_MAX);
6968 type_enum.insert("compare", NODE_MATH_COMPARE);
6969 SOCKET_ENUM(math_type, "Type", type_enum, NODE_MATH_ADD);
6970
6971 SOCKET_BOOLEAN(use_clamp, "Use Clamp", false);
6972
6973 SOCKET_IN_FLOAT(value1, "Value1", 0.5f);
6974 SOCKET_IN_FLOAT(value2, "Value2", 0.5f);
6975 SOCKET_IN_FLOAT(value3, "Value3", 0.0f);
6976
6977 SOCKET_OUT_FLOAT(value, "Value");
6978
6979 return type;
6980}
6981
6982MathNode::MathNode() : ShaderNode(get_node_type()) {}
6983
6985{
6986 if (use_clamp) {
6987 ShaderOutput *result_out = output("Value");
6988 if (!result_out->links.empty()) {
6989 ClampNode *clamp_node = graph->create_node<ClampNode>();
6990 clamp_node->set_clamp_type(NODE_CLAMP_MINMAX);
6991 clamp_node->set_min(0.0f);
6992 clamp_node->set_max(1.0f);
6993 graph->relink(result_out, clamp_node->output("Result"));
6994 graph->connect(result_out, clamp_node->input("Value"));
6995 }
6996 }
6997}
6998
7000{
7001 if (folder.all_inputs_constant()) {
7002 folder.make_constant(svm_math(math_type, value1, value2, value3));
7003 }
7004 else {
7005 folder.fold_math(math_type);
7006 }
7007}
7008
7010{
7011 switch (math_type) {
7012 case NODE_MATH_ADD:
7013 case NODE_MATH_SUBTRACT:
7014 case NODE_MATH_MULTIPLY:
7016 break;
7017 case NODE_MATH_DIVIDE:
7018 return input("Value2")->link == nullptr;
7019 default:
7020 return false;
7021 }
7022
7023 int num_variable_inputs = 0;
7024 for (ShaderInput *input : inputs) {
7025 num_variable_inputs += (input->link) ? 1 : 0;
7026 }
7027 return num_variable_inputs <= 1;
7028}
7029
7030void MathNode::compile(SVMCompiler &compiler)
7031{
7032 compiler.add_node(this,
7033 NODE_MATH,
7035 .math_type = math_type,
7036 .value1 = compiler.input_float("Value1"),
7037 .value2 = compiler.input_float("Value2"),
7038 .value3 = compiler.input_float("Value3"),
7039 .result_offset = compiler.output("Value"),
7040 });
7041}
7042
7043void MathNode::compile(OSLCompiler &compiler)
7044{
7045 compiler.parameter(this, "math_type");
7046 compiler.add(this, "node_math");
7047}
7048
7049/* Boolean Math */
7050
7052{
7053 NodeType *type = NodeType::add("boolean_math", create, NodeType::SHADER);
7054
7055 static NodeEnum type_enum;
7056 type_enum.insert("and", NODE_BOOLEAN_MATH_AND);
7057 type_enum.insert("or", NODE_BOOLEAN_MATH_OR);
7058 type_enum.insert("not", NODE_BOOLEAN_MATH_NOT);
7059 type_enum.insert("nand", NODE_BOOLEAN_MATH_NAND);
7060 type_enum.insert("nor", NODE_BOOLEAN_MATH_NOR);
7061 type_enum.insert("xnor", NODE_BOOLEAN_MATH_XNOR);
7062 type_enum.insert("xor", NODE_BOOLEAN_MATH_XOR);
7063 type_enum.insert("imply", NODE_BOOLEAN_MATH_IMPLY);
7064 type_enum.insert("nimply", NODE_BOOLEAN_MATH_NIMPLY);
7065 SOCKET_ENUM(math_type, "Type", type_enum, NODE_BOOLEAN_MATH_AND);
7066
7067 SOCKET_IN_INT(boolean1, "Boolean1", 0);
7068 SOCKET_IN_INT(boolean2, "Boolean2", 0);
7069
7070 SOCKET_OUT_INT(boolean, "Boolean");
7071
7072 return type;
7073}
7074
7075BooleanMathNode::BooleanMathNode() : ShaderNode(get_node_type()) {}
7076
7078{
7079 /* In the future this could constant fold for e.g. the AND operation when the first input is
7080 * false, even if the second input is not constant.*/
7081 if (folder.all_inputs_constant()) {
7082 folder.make_constant(svm_boolean_math(math_type, boolean1, boolean2));
7083 }
7084}
7085
7087{
7088 compiler.add_node(this,
7089 NODE_BOOLEAN_MATH,
7091 .math_type = math_type,
7092 .value1 = compiler.input_int("Boolean1"),
7093 .value2 = compiler.input_int("Boolean2"),
7094 .result_offset = compiler.output("Boolean"),
7095 });
7096}
7097
7099{
7100 compiler.parameter(this, "math_type");
7101 compiler.add(this, "node_boolean_math");
7102}
7103
7104/* Integer Math */
7105
7107{
7108 NodeType *type = NodeType::add("integer_math", create, NodeType::SHADER);
7109
7110 static NodeEnum type_enum;
7111 type_enum.insert("add", NODE_INTEGER_MATH_ADD);
7112 type_enum.insert("subtract", NODE_INTEGER_MATH_SUBTRACT);
7113 type_enum.insert("multiply", NODE_INTEGER_MATH_MULTIPLY);
7114 type_enum.insert("divide", NODE_INTEGER_MATH_DIVIDE);
7115 type_enum.insert("multiply_add", NODE_INTEGER_MATH_MULTIPLY_ADD);
7116 type_enum.insert("power", NODE_INTEGER_MATH_POWER);
7117 type_enum.insert("floored_modulo", NODE_INTEGER_MATH_FLOORED_MODULO);
7118 type_enum.insert("absolute", NODE_INTEGER_MATH_ABSOLUTE);
7119 type_enum.insert("minimum", NODE_INTEGER_MATH_MINIMUM);
7120 type_enum.insert("maximum", NODE_INTEGER_MATH_MAXIMUM);
7121 type_enum.insert("gcd", NODE_INTEGER_MATH_GCD);
7122 type_enum.insert("lcm", NODE_INTEGER_MATH_LCM);
7123 type_enum.insert("negate", NODE_INTEGER_MATH_NEGATE);
7124 type_enum.insert("sign", NODE_INTEGER_MATH_SIGN);
7125 type_enum.insert("divide_floor", NODE_INTEGER_MATH_DIVIDE_FLOOR);
7126 type_enum.insert("divide_ceil", NODE_INTEGER_MATH_DIVIDE_CEIL);
7127 type_enum.insert("divide_round", NODE_INTEGER_MATH_DIVIDE_ROUND);
7128 type_enum.insert("modulo", NODE_INTEGER_MATH_MODULO);
7129 SOCKET_ENUM(math_type, "Type", type_enum, NODE_INTEGER_MATH_ADD);
7130
7131 SOCKET_IN_INT(value1, "Value1", 0);
7132 SOCKET_IN_INT(value2, "Value2", 0);
7133 SOCKET_IN_INT(value3, "Value3", 0);
7134
7135 SOCKET_OUT_INT(value, "Value");
7136
7137 return type;
7138}
7139
7140IntegerMathNode::IntegerMathNode() : ShaderNode(get_node_type()) {}
7141
7143{
7144 if (folder.all_inputs_constant()) {
7145 folder.make_constant(svm_integer_math(math_type, value1, value2, value3));
7146 }
7147}
7148
7150{
7151 compiler.add_node(this,
7152 NODE_INTEGER_MATH,
7154 .math_type = math_type,
7155 .value1 = compiler.input_int("Value1"),
7156 .value2 = compiler.input_int("Value2"),
7157 .value3 = compiler.input_int("Value3"),
7158 .result_offset = compiler.output("Value"),
7159 });
7160}
7161
7163{
7164 compiler.parameter(this, "math_type");
7165 compiler.add(this, "node_integer_math");
7166}
7167
7168/* VectorMath */
7169
7171{
7172 NodeType *type = NodeType::add("vector_math", create, NodeType::SHADER);
7173
7174 static NodeEnum type_enum;
7175 type_enum.insert("add", NODE_VECTOR_MATH_ADD);
7176 type_enum.insert("subtract", NODE_VECTOR_MATH_SUBTRACT);
7177 type_enum.insert("multiply", NODE_VECTOR_MATH_MULTIPLY);
7178 type_enum.insert("divide", NODE_VECTOR_MATH_DIVIDE);
7179
7180 type_enum.insert("cross_product", NODE_VECTOR_MATH_CROSS_PRODUCT);
7181 type_enum.insert("project", NODE_VECTOR_MATH_PROJECT);
7182 type_enum.insert("reflect", NODE_VECTOR_MATH_REFLECT);
7183 type_enum.insert("refract", NODE_VECTOR_MATH_REFRACT);
7184 type_enum.insert("faceforward", NODE_VECTOR_MATH_FACEFORWARD);
7185 type_enum.insert("multiply_add", NODE_VECTOR_MATH_MULTIPLY_ADD);
7186
7187 type_enum.insert("dot_product", NODE_VECTOR_MATH_DOT_PRODUCT);
7188
7189 type_enum.insert("distance", NODE_VECTOR_MATH_DISTANCE);
7190 type_enum.insert("length", NODE_VECTOR_MATH_LENGTH);
7191 type_enum.insert("scale", NODE_VECTOR_MATH_SCALE);
7192 type_enum.insert("normalize", NODE_VECTOR_MATH_NORMALIZE);
7193
7194 type_enum.insert("snap", NODE_VECTOR_MATH_SNAP);
7195 type_enum.insert("round", NODE_VECTOR_MATH_ROUND);
7196 type_enum.insert("floor", NODE_VECTOR_MATH_FLOOR);
7197 type_enum.insert("ceil", NODE_VECTOR_MATH_CEIL);
7198 type_enum.insert("modulo", NODE_VECTOR_MATH_MODULO);
7199 type_enum.insert("wrap", NODE_VECTOR_MATH_WRAP);
7200 type_enum.insert("fraction", NODE_VECTOR_MATH_FRACTION);
7201 type_enum.insert("absolute", NODE_VECTOR_MATH_ABSOLUTE);
7202 type_enum.insert("power", NODE_VECTOR_MATH_POWER);
7203 type_enum.insert("sign", NODE_VECTOR_MATH_SIGN);
7204 type_enum.insert("minimum", NODE_VECTOR_MATH_MINIMUM);
7205 type_enum.insert("maximum", NODE_VECTOR_MATH_MAXIMUM);
7206
7207 type_enum.insert("sine", NODE_VECTOR_MATH_SINE);
7208 type_enum.insert("cosine", NODE_VECTOR_MATH_COSINE);
7209 type_enum.insert("tangent", NODE_VECTOR_MATH_TANGENT);
7210 SOCKET_ENUM(math_type, "Type", type_enum, NODE_VECTOR_MATH_ADD);
7211
7212 SOCKET_IN_VECTOR(vector1, "Vector1", zero_float3());
7213 SOCKET_IN_VECTOR(vector2, "Vector2", zero_float3());
7214 SOCKET_IN_VECTOR(vector3, "Vector3", zero_float3());
7215 SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
7216
7217 SOCKET_OUT_FLOAT(value, "Value");
7218 SOCKET_OUT_VECTOR(vector, "Vector");
7219
7220 return type;
7221}
7222
7223VectorMathNode::VectorMathNode() : ShaderNode(get_node_type()) {}
7224
7226{
7227 float value = 0.0f;
7229
7230 if (folder.all_inputs_constant()) {
7231 svm_vector_math(&value, &vector, math_type, vector1, vector2, vector3, scale);
7232 if (folder.output == output("Value")) {
7233 folder.make_constant(value);
7234 }
7235 else if (folder.output == output("Vector")) {
7236 folder.make_constant(vector);
7237 }
7238 }
7239 else {
7240 folder.fold_vector_math(math_type);
7241 }
7242}
7243
7245{
7246 switch (math_type) {
7251 break;
7253 return input("Vector2")->link == nullptr;
7254 default:
7255 return false;
7256 }
7257
7258 int num_variable_inputs = 0;
7259 for (ShaderInput *input : inputs) {
7260 num_variable_inputs += (input->link) ? 1 : 0;
7261 }
7262 return num_variable_inputs <= 1;
7263}
7264
7266{
7267 compiler.add_node(this,
7268 NODE_VECTOR_MATH,
7270 .math_type = math_type,
7271 .a = compiler.input_float3("Vector1"),
7272 .b = compiler.input_float3("Vector2"),
7273 .c = compiler.input_float3("Vector3"),
7274 .param1 = compiler.input_float("Scale"),
7275 .value_offset = compiler.output("Value"),
7276 .vector_offset = compiler.output("Vector"),
7277 });
7278}
7279
7281{
7282 compiler.parameter(this, "math_type");
7283 compiler.add(this, "node_vector_math");
7284}
7285
7286/* Vector Rotate */
7287
7289{
7290 NodeType *type = NodeType::add("vector_rotate", create, NodeType::SHADER);
7291
7292 static NodeEnum type_enum;
7293 type_enum.insert("axis", NODE_VECTOR_ROTATE_TYPE_AXIS);
7294 type_enum.insert("x_axis", NODE_VECTOR_ROTATE_TYPE_AXIS_X);
7295 type_enum.insert("y_axis", NODE_VECTOR_ROTATE_TYPE_AXIS_Y);
7296 type_enum.insert("z_axis", NODE_VECTOR_ROTATE_TYPE_AXIS_Z);
7297 type_enum.insert("euler_xyz", NODE_VECTOR_ROTATE_TYPE_EULER_XYZ);
7298 SOCKET_ENUM(rotate_type, "Type", type_enum, NODE_VECTOR_ROTATE_TYPE_AXIS);
7299
7300 SOCKET_BOOLEAN(invert, "Invert", false);
7301
7302 SOCKET_IN_VECTOR(vector, "Vector", zero_float3());
7303 SOCKET_IN_POINT(rotation, "Rotation", zero_float3());
7304 SOCKET_IN_POINT(center, "Center", zero_float3());
7305 SOCKET_IN_VECTOR(axis, "Axis", make_float3(0.0f, 0.0f, 1.0f));
7306 SOCKET_IN_FLOAT(angle, "Angle", 0.0f);
7307 SOCKET_OUT_VECTOR(vector, "Vector");
7308
7309 return type;
7310}
7311
7312VectorRotateNode::VectorRotateNode() : ShaderNode(get_node_type()) {}
7313
7315{
7316 compiler.add_node(this,
7317 NODE_VECTOR_ROTATE,
7318 SVMNodeVectorRotate{
7319 .rotate_type = rotate_type,
7320 .vector = compiler.input_float3("Vector"),
7321 .center = compiler.input_float3("Center"),
7322 .axis = compiler.input_float3("Axis"),
7323 .rotation = compiler.input_float3("Rotation"),
7324 .angle = compiler.input_float("Angle"),
7325 .invert = invert,
7326 .result_offset = compiler.output("Vector"),
7327 });
7328}
7329
7331{
7332 compiler.parameter(this, "rotate_type");
7333 compiler.parameter(this, "invert");
7334 compiler.add(this, "node_vector_rotate");
7335}
7336
7337/* VectorTransform */
7338
7340{
7341 NodeType *type = NodeType::add("vector_transform", create, NodeType::SHADER);
7342
7343 static NodeEnum type_enum;
7344 type_enum.insert("vector", NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
7345 type_enum.insert("point", NODE_VECTOR_TRANSFORM_TYPE_POINT);
7346 type_enum.insert("normal", NODE_VECTOR_TRANSFORM_TYPE_NORMAL);
7347 SOCKET_ENUM(transform_type, "Type", type_enum, NODE_VECTOR_TRANSFORM_TYPE_VECTOR);
7348
7349 static NodeEnum space_enum;
7353 SOCKET_ENUM(convert_from, "Convert From", space_enum, NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD);
7354 SOCKET_ENUM(convert_to, "Convert To", space_enum, NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT);
7355
7356 SOCKET_IN_VECTOR(vector, "Vector", zero_float3());
7357 SOCKET_OUT_VECTOR(vector, "Vector");
7358
7359 return type;
7360}
7361
7362VectorTransformNode::VectorTransformNode() : ShaderNode(get_node_type()) {}
7363
7365{
7366 compiler.add_node(this,
7367 NODE_VECTOR_TRANSFORM,
7368 SVMNodeVectorTransform{
7369 .transform_type = transform_type,
7370 .convert_from = convert_from,
7371 .convert_to = convert_to,
7372 .vector_in = compiler.input_float3("Vector"),
7373 .vector_out_offset = compiler.output("Vector"),
7374 });
7375}
7376
7378{
7379 compiler.parameter(this, "transform_type");
7380 compiler.parameter(this, "convert_from");
7381 compiler.parameter(this, "convert_to");
7382 compiler.add(this, "node_vector_transform");
7383}
7384
7385/* BumpNode */
7386
7388{
7389 NodeType *type = NodeType::add("bump", create, NodeType::SHADER);
7390
7391 SOCKET_BOOLEAN(invert, "Invert", false);
7392 SOCKET_BOOLEAN(use_object_space, "UseObjectSpace", false);
7393
7394 /* this input is used by the user, but after graph transform it is no longer
7395 * used and moved to sampler center/x/y instead */
7396 SOCKET_IN_FLOAT(height, "Height", 1.0f);
7397
7398 SOCKET_IN_FLOAT(sample_center, "SampleCenter", 0.0f);
7399 SOCKET_IN_FLOAT(sample_x, "SampleX", 0.0f);
7400 SOCKET_IN_FLOAT(sample_y, "SampleY", 0.0f);
7402 SOCKET_IN_FLOAT(strength, "Strength", 1.0f);
7403 SOCKET_IN_FLOAT(distance, "Distance", 0.1f);
7404 SOCKET_IN_FLOAT(filter_width, "Filter Width", 0.1f);
7405
7406 SOCKET_OUT_NORMAL(normal, "Normal");
7407
7408 return type;
7409}
7410
7411BumpNode::BumpNode() : ShaderNode(get_node_type())
7412{
7413 special_type = SHADER_SPECIAL_TYPE_BUMP;
7414}
7415
7416void BumpNode::compile(SVMCompiler &compiler)
7417{
7418 compiler.add_node(this,
7419 NODE_SET_BUMP,
7420 SVMNodeSetBump{.scale = compiler.input_float("Distance"),
7421 .strength = compiler.input_float("Strength"),
7422 .bump_filter_width = filter_width,
7423 .normal_offset = compiler.input_link("Normal"),
7424 .invert = invert,
7425 .use_object_space = use_object_space,
7426 .center_offset = compiler.input_link("SampleCenter"),
7427 .dx_offset = compiler.input_link("SampleX"),
7428 .dy_offset = compiler.input_link("SampleY"),
7429 .out_offset = compiler.output("Normal"),
7430 .bump_state_offset = compiler.get_bump_state_offset()});
7431}
7432
7433void BumpNode::compile(OSLCompiler &compiler)
7434{
7435 compiler.parameter(this, "invert");
7436 compiler.parameter(this, "use_object_space");
7437 compiler.add(this, "node_bump");
7438}
7439
7441{
7442 ShaderInput *normal_in = input("Normal");
7443
7444 if (input("Height")->link == nullptr) {
7445 if (normal_in->link == nullptr) {
7446 GeometryNode *geom = folder.graph->create_node<GeometryNode>();
7447 folder.bypass(geom->output("Normal"));
7448 }
7449 else {
7450 folder.bypass(normal_in->link);
7451 }
7452 }
7453
7454 /* TODO(sergey): Ignore bump with zero strength. */
7455}
7456
7457/* Curves node */
7458
7459CurvesNode::CurvesNode(const NodeType *node_type) : ShaderNode(node_type) {}
7460
7462{
7463
7464 /* evaluate fully constant node */
7465 if (folder.all_inputs_constant()) {
7466 if (curves.size() == 0) {
7467 return;
7468 }
7469
7470 float3 pos = (value - make_float3(min_x, min_x, min_x)) / (max_x - min_x);
7471 float3 result;
7472
7473 result[0] = rgb_ramp_lookup(curves.data(), pos[0], true, extrapolate, curves.size()).x;
7474 result[1] = rgb_ramp_lookup(curves.data(), pos[1], true, extrapolate, curves.size()).y;
7475 result[2] = rgb_ramp_lookup(curves.data(), pos[2], true, extrapolate, curves.size()).z;
7476
7477 folder.make_constant(interp(value, result, fac));
7478 }
7479 /* remove no-op node */
7480 else if (!input("Fac")->link && fac == 0.0f) {
7481 /* link is not null because otherwise all inputs are constant */
7482 folder.bypass(value_in->link);
7483 }
7484}
7485
7486void CurvesNode::compile(SVMCompiler &compiler, ShaderInput *value_in, ShaderOutput *value_out)
7487{
7488 if (curves.size() == 0) {
7489 return;
7490 }
7491
7492 compiler.add_node(this,
7493 NODE_CURVES,
7494 SVMNodeCurves{.color = compiler.input_float3(value_in->name().c_str()),
7495 .fac = compiler.input_float("Fac"),
7496 .min_x = min_x,
7497 .max_x = max_x,
7498 .table_size = uint(curves.size()),
7499 .extrapolate = extrapolate,
7500 .out_offset = compiler.output(value_out->name().c_str())});
7501 for (int i = 0; i < curves.size(); i++) {
7503 }
7504}
7505
7506void CurvesNode::compile(OSLCompiler &compiler, const char *name)
7507{
7508 if (curves.size() == 0) {
7509 return;
7510 }
7511
7512 compiler.parameter_color_array("ramp", curves);
7513 compiler.parameter(this, "min_x");
7514 compiler.parameter(this, "max_x");
7515 compiler.parameter(this, "extrapolate");
7516 compiler.add(this, name);
7517}
7518
7519void CurvesNode::compile(SVMCompiler & /*compiler*/)
7520{
7521 assert(0);
7522}
7523
7524void CurvesNode::compile(OSLCompiler & /*compiler*/)
7525{
7526 assert(0);
7527}
7528
7529/* RGBCurvesNode */
7530
7532{
7533 NodeType *type = NodeType::add("rgb_curves", create, NodeType::SHADER);
7534
7536 SOCKET_FLOAT(min_x, "Min X", 0.0f);
7537 SOCKET_FLOAT(max_x, "Max X", 1.0f);
7538 SOCKET_BOOLEAN(extrapolate, "Extrapolate", true);
7539
7540 SOCKET_IN_FLOAT(fac, "Fac", 0.0f);
7541 SOCKET_IN_COLOR(value, "Color", zero_float3());
7542
7543 SOCKET_OUT_COLOR(value, "Color");
7544
7545 return type;
7546}
7547
7548RGBCurvesNode::RGBCurvesNode() : CurvesNode(get_node_type()) {}
7549
7551{
7552 CurvesNode::constant_fold(folder, input("Color"));
7553}
7554
7555void RGBCurvesNode::compile(SVMCompiler &compiler)
7556{
7557 CurvesNode::compile(compiler, input("Color"), output("Color"));
7558}
7559
7560void RGBCurvesNode::compile(OSLCompiler &compiler)
7561{
7562 CurvesNode::compile(compiler, "node_rgb_curves");
7563}
7564
7565/* VectorCurvesNode */
7566
7568{
7569 NodeType *type = NodeType::add("vector_curves", create, NodeType::SHADER);
7570
7572 SOCKET_FLOAT(min_x, "Min X", 0.0f);
7573 SOCKET_FLOAT(max_x, "Max X", 1.0f);
7574 SOCKET_BOOLEAN(extrapolate, "Extrapolate", true);
7575
7576 SOCKET_IN_FLOAT(fac, "Fac", 0.0f);
7577 SOCKET_IN_VECTOR(value, "Vector", zero_float3());
7578
7579 SOCKET_OUT_VECTOR(value, "Vector");
7580
7581 return type;
7582}
7583
7584VectorCurvesNode::VectorCurvesNode() : CurvesNode(get_node_type()) {}
7585
7587{
7588 CurvesNode::constant_fold(folder, input("Vector"));
7589}
7590
7592{
7593 CurvesNode::compile(compiler, input("Vector"), output("Vector"));
7594}
7595
7597{
7598 CurvesNode::compile(compiler, "node_vector_curves");
7599}
7600
7601/* FloatCurveNode */
7602
7604{
7605 NodeType *type = NodeType::add("float_curve", create, NodeType::SHADER);
7606
7607 SOCKET_FLOAT_ARRAY(curve, "Curve", array<float>());
7608 SOCKET_FLOAT(min_x, "Min X", 0.0f);
7609 SOCKET_FLOAT(max_x, "Max X", 1.0f);
7610 SOCKET_BOOLEAN(extrapolate, "Extrapolate", true);
7611
7612 SOCKET_IN_FLOAT(fac, "Factor", 0.0f);
7613 SOCKET_IN_FLOAT(value, "Value", 0.0f);
7614
7615 SOCKET_OUT_FLOAT(value, "Value");
7616
7617 return type;
7618}
7619
7620FloatCurveNode::FloatCurveNode() : ShaderNode(get_node_type()) {}
7621
7623{
7624
7625 /* evaluate fully constant node */
7626 if (folder.all_inputs_constant()) {
7627 if (curve.size() == 0) {
7628 return;
7629 }
7630
7631 const float pos = (value - min_x) / (max_x - min_x);
7632 const float result = float_ramp_lookup(curve.data(), pos, true, extrapolate, curve.size());
7633
7634 folder.make_constant(value + fac * (result - value));
7635 }
7636 /* remove no-op node */
7637 else if (!input("Factor")->link && fac == 0.0f) {
7638 /* link is not null because otherwise all inputs are constant */
7639 folder.bypass(input("Value")->link);
7640 }
7641}
7642
7644{
7645 if (curve.size() == 0) {
7646 return;
7647 }
7648
7649 compiler.add_node(this,
7650 NODE_FLOAT_CURVE,
7651 SVMNodeFloatCurve{
7652 .fac = compiler.input_float("Factor"),
7653 .value_in = compiler.input_float("Value"),
7654 .min_x = min_x,
7655 .max_x = max_x,
7656 .table_size = uint(curve.size()),
7657 .extrapolate = extrapolate,
7658 .out_offset = compiler.output("Value"),
7659 });
7660 for (int i = 0; i < curve.size(); i++) {
7661 compiler.add_node_data_float(curve[i]);
7662 }
7663}
7664
7666{
7667 if (curve.size() == 0) {
7668 return;
7669 }
7670
7671 compiler.parameter_array("ramp", curve.data(), curve.size());
7672 compiler.parameter(this, "min_x");
7673 compiler.parameter(this, "max_x");
7674 compiler.parameter(this, "extrapolate");
7675 compiler.add(this, "node_float_curve");
7676}
7677
7678/* RGBRampNode */
7679
7681{
7682 NodeType *type = NodeType::add("rgb_ramp", create, NodeType::SHADER);
7683
7685 SOCKET_FLOAT_ARRAY(ramp_alpha, "Ramp Alpha", array<float>());
7686 SOCKET_BOOLEAN(interpolate, "Interpolate", true);
7687
7688 SOCKET_IN_FLOAT(fac, "Fac", 0.0f);
7689
7690 SOCKET_OUT_COLOR(color, "Color");
7691 SOCKET_OUT_FLOAT(alpha, "Alpha");
7692
7693 return type;
7694}
7695
7696RGBRampNode::RGBRampNode() : ShaderNode(get_node_type()) {}
7697
7699{
7700 if (ramp.size() == 0 || ramp.size() != ramp_alpha.size()) {
7701 return;
7702 }
7703
7704 if (folder.all_inputs_constant()) {
7705 const float f = clamp(fac, 0.0f, 1.0f) * (ramp.size() - 1);
7706
7707 /* clamp int as well in case of NaN */
7708 const int i = clamp((int)f, 0, ramp.size() - 1);
7709 const float t = f - (float)i;
7710
7711 const bool use_lerp = interpolate && t > 0.0f;
7712
7713 if (folder.output == output("Color")) {
7714 const float3 color = rgb_ramp_lookup(ramp.data(), fac, use_lerp, false, ramp.size());
7715 folder.make_constant(color);
7716 }
7717 else if (folder.output == output("Alpha")) {
7718 const float alpha = float_ramp_lookup(
7719 ramp_alpha.data(), fac, use_lerp, false, ramp_alpha.size());
7720 folder.make_constant(alpha);
7721 }
7722 }
7723}
7724
7725void RGBRampNode::compile(SVMCompiler &compiler)
7726{
7727 if (ramp.size() == 0 || ramp.size() != ramp_alpha.size()) {
7728 return;
7729 }
7730
7731 compiler.add_node(this,
7732 NODE_RGB_RAMP,
7733 SVMNodeRGBRamp{.table_size = uint(ramp.size()),
7734 .fac = compiler.input_float("Fac"),
7735 .interpolate = interpolate,
7736 .color_offset = compiler.output("Color"),
7737 .alpha_offset = compiler.output("Alpha")});
7738 for (int i = 0; i < ramp.size(); i++) {
7739 compiler.add_node_data_float4(make_float4(ramp[i], ramp_alpha[i]));
7740 }
7741}
7742
7743void RGBRampNode::compile(OSLCompiler &compiler)
7744{
7745 if (ramp.size() == 0 || ramp.size() != ramp_alpha.size()) {
7746 return;
7747 }
7748
7749 compiler.parameter_color_array("ramp_color", ramp);
7750 compiler.parameter_array("ramp_alpha", ramp_alpha.data(), ramp_alpha.size());
7751 compiler.parameter(this, "interpolate");
7752
7753 compiler.add(this, "node_rgb_ramp");
7754}
7755
7756/* Set Normal Node */
7757
7759{
7760 NodeType *type = NodeType::add("set_normal", create, NodeType::SHADER);
7761
7762 SOCKET_IN_VECTOR(direction, "Direction", zero_float3());
7763 SOCKET_OUT_NORMAL(normal, "Normal");
7764
7765 return type;
7766}
7767
7768SetNormalNode::SetNormalNode() : ShaderNode(get_node_type()) {}
7769
7770void SetNormalNode::compile(SVMCompiler &compiler)
7771{
7772 compiler.add_node(this,
7773 NODE_CLOSURE_SET_NORMAL,
7774 SVMNodeClosureSetNormal{
7775 .direction_offset = compiler.input_link("Direction"),
7776 .normal_offset = compiler.output("Normal"),
7777 });
7778}
7779
7780void SetNormalNode::compile(OSLCompiler &compiler)
7781{
7782 compiler.add(this, "node_set_normal");
7783}
7784
7785/* OSLNode */
7786
7787OSLNode::OSLNode() : ShaderNode(new NodeType(NodeType::SHADER))
7788{
7789 special_type = SHADER_SPECIAL_TYPE_OSL;
7790 has_emission = false;
7791}
7792
7794{
7795 delete type;
7796}
7797
7799{
7800 return OSLNode::create(graph, this->inputs.size(), this);
7801}
7802
7804{
7805 /* the added geometry node's attributes function unfortunately doesn't
7806 * request the need for ATTR_STD_GENERATED in-time somehow, so we request it
7807 * here if there are any sockets that have LINK_TANGENT or
7808 * LINK_TEXTURE_GENERATED flags */
7809 if (shader->has_surface_link()) {
7810 for (const ShaderInput *in : inputs) {
7811 if (!in->link && (in->flags() & SocketType::LINK_TANGENT ||
7813 {
7815 break;
7816 }
7817 }
7818 }
7819
7821}
7822
7823OSLNode *OSLNode::create(ShaderGraph *graph, const size_t num_inputs, const OSLNode *from)
7824{
7825 /* allocate space for the node itself and parameters, aligned to 16 bytes
7826 * assuming that's the most parameter types need */
7827 const size_t node_size = align_up(sizeof(OSLNode), 16);
7828 const size_t inputs_size = align_up(SocketType::max_size(), 16) * num_inputs;
7829
7830 char *node_memory = (char *)operator new(node_size + inputs_size);
7831 memset(node_memory, 0, node_size + inputs_size);
7832
7833 if (!from) {
7834 return graph->create_osl_node<OSLNode>(node_memory);
7835 }
7836 /* copy input default values and node type for cloning */
7837 memcpy(node_memory + node_size, (char *)from + node_size, inputs_size);
7838
7839 OSLNode *node = graph->create_osl_node<OSLNode>(node_memory, *from);
7840 node->type = new NodeType(*(from->type));
7841 return node;
7842}
7843
7845{
7846 /* pointer to default value storage, which is the same as our actual value */
7847 const size_t num_inputs = type->inputs.size();
7848 const size_t inputs_size = align_up(SocketType::max_size(), 16) * num_inputs;
7849 return (char *)this + align_up(sizeof(OSLNode), 16) + inputs_size;
7850}
7851
7852void OSLNode::add_input(ustring name, SocketType::Type socket_type, const int flags)
7853{
7854 char *memory = input_default_value();
7855 const size_t offset = memory - (char *)this;
7856 const_cast<NodeType *>(type)->register_input(
7857 name, name, socket_type, offset, memory, nullptr, nullptr, flags | SocketType::LINKABLE);
7858}
7859
7861{
7862 const_cast<NodeType *>(type)->register_output(name, name, socket_type);
7863}
7864
7865void OSLNode::compile(SVMCompiler & /*compiler*/)
7866{
7867 /* doesn't work for SVM, obviously ... */
7868}
7869
7870void OSLNode::compile(OSLCompiler &compiler)
7871{
7872 if (!filepath.empty()) {
7873 compiler.add(this, filepath.c_str(), true);
7874 }
7875 else {
7876 compiler.add(this, bytecode_hash.c_str(), false);
7877 }
7878}
7879
7880/* Normal Map */
7881
7883{
7884 NodeType *type = NodeType::add("normal_map", create, NodeType::SHADER);
7885
7886 static NodeEnum space_enum;
7887 space_enum.insert("tangent", NODE_NORMAL_MAP_TANGENT);
7888 space_enum.insert("object", NODE_NORMAL_MAP_OBJECT);
7889 space_enum.insert("world", NODE_NORMAL_MAP_WORLD);
7890 space_enum.insert("blender_object", NODE_NORMAL_MAP_BLENDER_OBJECT);
7891 space_enum.insert("blender_world", NODE_NORMAL_MAP_BLENDER_WORLD);
7892 SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_TANGENT);
7893
7894 static NodeEnum convention_enum;
7895 convention_enum.insert("opengl", NODE_NORMAL_MAP_CONVENTION_OPENGL);
7896 convention_enum.insert("directx", NODE_NORMAL_MAP_CONVENTION_DIRECTX);
7897 SOCKET_ENUM(convention, "Convention", convention_enum, NODE_NORMAL_MAP_CONVENTION_OPENGL);
7898
7899 static NodeEnum base_enum;
7900 base_enum.insert("original", NODE_NORMAL_MAP_BASE_ORIGINAL);
7901 base_enum.insert("displaced", NODE_NORMAL_MAP_BASE_DISPLACED);
7902 SOCKET_ENUM(base, "Base", base_enum, NODE_NORMAL_MAP_BASE_ORIGINAL);
7903
7904 SOCKET_STRING(attribute, "Attribute", ustring());
7905
7906 SOCKET_IN_FLOAT(strength, "Strength", 1.0f);
7907 SOCKET_IN_COLOR(color, "Color", make_float3(0.5f, 0.5f, 1.0f));
7908
7909 SOCKET_OUT_NORMAL(normal, "Normal");
7910
7911 return type;
7912}
7913
7914NormalMapNode::NormalMapNode() : ShaderNode(get_node_type()) {}
7915
7917{
7918 if (shader->has_surface_link() && space == NODE_NORMAL_MAP_TANGENT) {
7919 if (attribute.empty()) {
7920 /* We don't need the UV ourselves, but we need to compute the tangent from it. */
7922 if (base == NODE_NORMAL_MAP_BASE_DISPLACED) {
7925 }
7926 else {
7930 }
7931 }
7932 else {
7934 if (base == NODE_NORMAL_MAP_BASE_DISPLACED) {
7935 attributes->add(ustring((string(attribute.c_str()) + ".tangent").c_str()));
7936 attributes->add(ustring((string(attribute.c_str()) + ".tangent_sign").c_str()));
7937 }
7938 else {
7939 attributes->add(ustring((string(attribute.c_str()) + ".undisplaced_tangent").c_str()));
7940 attributes->add(
7941 ustring((string(attribute.c_str()) + ".undisplaced_tangent_sign").c_str()));
7943 }
7944 }
7945 }
7946
7948}
7949
7950void NormalMapNode::compile(SVMCompiler &compiler)
7951{
7952 int attr_id = 0;
7953 int attr_sign_id = 0;
7954
7955 if (space == NODE_NORMAL_MAP_TANGENT) {
7956 if (attribute.empty()) {
7957 if (base == NODE_NORMAL_MAP_BASE_DISPLACED) {
7958 attr_id = compiler.attribute(ATTR_STD_UV_TANGENT);
7959 attr_sign_id = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN);
7960 }
7961 else {
7962 attr_id = compiler.attribute(ATTR_STD_UV_TANGENT_UNDISPLACED);
7963 attr_sign_id = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN_UNDISPLACED);
7964 }
7965 }
7966 else {
7967 if (base == NODE_NORMAL_MAP_BASE_DISPLACED) {
7968 attr_id = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent").c_str()));
7969 attr_sign_id = compiler.attribute(
7970 ustring((string(attribute.c_str()) + ".tangent_sign").c_str()));
7971 }
7972 else {
7973 attr_id = compiler.attribute(
7974 ustring((string(attribute.c_str()) + ".undisplaced_tangent").c_str()));
7975 attr_sign_id = compiler.attribute(
7976 ustring((string(attribute.c_str()) + ".undisplaced_tangent_sign").c_str()));
7977 }
7978 }
7979 }
7980
7981 compiler.add_node(this,
7982 NODE_NORMAL_MAP,
7983 SVMNodeNormalMap{
7984 .space = space,
7985 .invert_green = (convention == NODE_NORMAL_MAP_CONVENTION_DIRECTX) ? 1 : 0,
7986 .use_original_base = (base == NODE_NORMAL_MAP_BASE_ORIGINAL) ? 1 : 0,
7987 .attr = attr_id,
7988 .attr_sign = attr_sign_id,
7989 .color = compiler.input_float3("Color"),
7990 .strength = compiler.input_float("Strength"),
7991 .normal_offset = compiler.output("Normal"),
7992 });
7993}
7994
7995void NormalMapNode::compile(OSLCompiler &compiler)
7996{
7997 if (space == NODE_NORMAL_MAP_TANGENT) {
7998 std::string attr_name, attr_sign_name;
7999
8000 if (attribute.empty()) {
8001 if (base == NODE_NORMAL_MAP_BASE_DISPLACED) {
8002 attr_name = "geom:tangent";
8003 attr_sign_name = "geom:tangent_sign";
8004 }
8005 else {
8006 attr_name = "geom:undisplaced_tangent";
8007 attr_sign_name = "geom:undisplaced_tangent_sign";
8008 }
8009 }
8010 else {
8011 if (base == NODE_NORMAL_MAP_BASE_DISPLACED) {
8012 attr_name = string(attribute.c_str()) + ".tangent";
8013 attr_sign_name = string(attribute.c_str()) + ".tangent_sign";
8014 }
8015 else {
8016 attr_name = string(attribute.c_str()) + ".undisplaced_tangent";
8017 attr_sign_name = string(attribute.c_str()) + ".undisplaced_tangent_sign";
8018 }
8019 }
8020
8021 compiler.parameter("attr_name", attr_name.c_str());
8022 compiler.parameter("attr_sign_name", attr_sign_name.c_str());
8023 }
8024
8025 compiler.parameter(this, "space");
8026 compiler.parameter(this, "convention");
8027 compiler.parameter(this, "base");
8028 compiler.add(this, "node_normal_map");
8029}
8030
8031/* Radial Tiling */
8032
8034{
8035 NodeType *type = NodeType::add("radial_tiling", create, NodeType::SHADER);
8036
8037 SOCKET_BOOLEAN(use_normalize, "Normalize", false);
8038 SOCKET_IN_POINT(vector, "Vector", zero_float3());
8039 SOCKET_IN_FLOAT(r_gon_sides, "Sides", 5.0f);
8040 SOCKET_IN_FLOAT(r_gon_roundness, "Roundness", 0.0f);
8041
8042 SOCKET_OUT_POINT(segment_coordinates, "Segment Coordinates");
8043 SOCKET_OUT_FLOAT(segment_id, "Segment ID");
8044 SOCKET_OUT_FLOAT(max_unit_parameter, "Segment Width");
8045 SOCKET_OUT_FLOAT(x_axis_A_angle_bisector, "Segment Rotation");
8046
8047 return type;
8048}
8049
8050RadialTilingNode::RadialTilingNode() : ShaderNode(get_node_type()) {}
8051
8053{
8054 compiler.add_node(this,
8055 NODE_RADIAL_TILING,
8056 SVMNodeRadialTiling{
8057 .vector = compiler.input_float3("Vector"),
8058 .r_gon_sides = compiler.input_float("Sides"),
8059 .r_gon_roundness = compiler.input_float("Roundness"),
8060 .normalize_r_gon_parameter = use_normalize,
8061 .segment_coordinates_offset = compiler.output("Segment Coordinates"),
8062 .segment_id_offset = compiler.output("Segment ID"),
8063 .max_unit_parameter_offset = compiler.output("Segment Width"),
8064 .x_axis_A_angle_bisector_offset = compiler.output("Segment Rotation"),
8065 });
8066}
8067
8069{
8070 compiler.parameter(this, "use_normalize");
8071 compiler.add(this, "node_radial_tiling");
8072}
8073
8074/* Tangent */
8075
8077{
8078 NodeType *type = NodeType::add("tangent", create, NodeType::SHADER);
8079
8080 static NodeEnum direction_type_enum;
8081 direction_type_enum.insert("radial", NODE_TANGENT_RADIAL);
8082 direction_type_enum.insert("uv_map", NODE_TANGENT_UVMAP);
8083 SOCKET_ENUM(direction_type, "Direction Type", direction_type_enum, NODE_TANGENT_RADIAL);
8084
8085 static NodeEnum axis_enum;
8086 axis_enum.insert("x", NODE_TANGENT_AXIS_X);
8087 axis_enum.insert("y", NODE_TANGENT_AXIS_Y);
8088 axis_enum.insert("z", NODE_TANGENT_AXIS_Z);
8089 SOCKET_ENUM(axis, "Axis", axis_enum, NODE_TANGENT_AXIS_X);
8090
8091 SOCKET_STRING(attribute, "Attribute", ustring());
8092
8093 SOCKET_OUT_NORMAL(tangent, "Tangent");
8094
8095 return type;
8096}
8097
8098TangentNode::TangentNode() : ShaderNode(get_node_type()) {}
8099
8101{
8102 if (shader->has_surface_link()) {
8103 if (direction_type == NODE_TANGENT_UVMAP) {
8104 if (attribute.empty()) {
8105 /* We don't need the UV ourselves, but we need to compute the tangent from it. */
8108 }
8109 else {
8111 attributes->add(ustring((string(attribute.c_str()) + ".tangent").c_str()));
8112 }
8113 }
8114 else {
8116 }
8117 }
8118
8120}
8121
8122void TangentNode::compile(SVMCompiler &compiler)
8123{
8124 int attr;
8125
8126 if (direction_type == NODE_TANGENT_UVMAP) {
8127 if (attribute.empty()) {
8128 attr = compiler.attribute(ATTR_STD_UV_TANGENT);
8129 }
8130 else {
8131 attr = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent").c_str()));
8132 }
8133 }
8134 else {
8135 attr = compiler.attribute(ATTR_STD_GENERATED);
8136 }
8137
8138 compiler.add_node(this,
8139 NODE_TANGENT,
8140 SVMNodeTangent{
8141 .direction_type = direction_type,
8142 .axis = axis,
8143 .attr = attr,
8144 .tangent_offset = compiler.output("Tangent"),
8145 });
8146}
8147
8148void TangentNode::compile(OSLCompiler &compiler)
8149{
8150 if (direction_type == NODE_TANGENT_UVMAP) {
8151 if (attribute.empty()) {
8152 compiler.parameter("attr_name", ustring("geom:tangent"));
8153 }
8154 else {
8155 compiler.parameter("attr_name", ustring((string(attribute.c_str()) + ".tangent").c_str()));
8156 }
8157 }
8158
8159 compiler.parameter(this, "direction_type");
8160 compiler.parameter(this, "axis");
8161 compiler.add(this, "node_tangent");
8162}
8163
8164/* Bevel */
8165
8167{
8168 NodeType *type = NodeType::add("bevel", create, NodeType::SHADER);
8169
8170 SOCKET_INT(samples, "Samples", 4);
8171
8172 SOCKET_IN_FLOAT(radius, "Radius", 0.05f);
8174
8175 SOCKET_OUT_NORMAL(bevel, "Normal");
8176
8177 return type;
8178}
8179
8180BevelNode::BevelNode() : ShaderNode(get_node_type()) {}
8181
8182void BevelNode::compile(SVMCompiler &compiler)
8183{
8184 compiler.add_node(this,
8185 NODE_BEVEL,
8186 SVMNodeBevel{
8187 .radius = compiler.input_float("Radius"),
8188 .num_samples = uint8_t(samples),
8189 .normal_offset = compiler.input_link("Normal"),
8190 .out_offset = compiler.output("Normal"),
8191 });
8192}
8193
8194void BevelNode::compile(OSLCompiler &compiler)
8195{
8196 compiler.parameter(this, "samples");
8197 compiler.add(this, "node_bevel");
8198}
8199
8200/* Displacement */
8201
8203{
8204 NodeType *type = NodeType::add("displacement", create, NodeType::SHADER);
8205
8206 static NodeEnum space_enum;
8207 space_enum.insert("object", NODE_NORMAL_MAP_OBJECT);
8208 space_enum.insert("world", NODE_NORMAL_MAP_WORLD);
8209
8210 SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_OBJECT);
8211
8212 SOCKET_IN_FLOAT(height, "Height", 0.0f);
8213 SOCKET_IN_FLOAT(midlevel, "Midlevel", 0.5f);
8214 SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
8216
8217 SOCKET_OUT_VECTOR(displacement, "Displacement");
8218
8219 return type;
8220}
8221
8222DisplacementNode::DisplacementNode() : ShaderNode(get_node_type()) {}
8223
8225{
8226 if (folder.all_inputs_constant()) {
8227 if ((height - midlevel == 0.0f) || (scale == 0.0f)) {
8228 folder.make_zero();
8229 }
8230 }
8231}
8232
8234{
8235 compiler.add_node(this,
8236 NODE_DISPLACEMENT,
8237 SVMNodeDisplacement{.space = space,
8238 .height = compiler.input_float("Height"),
8239 .midlevel = compiler.input_float("Midlevel"),
8240 .scale = compiler.input_float("Scale"),
8241 .normal_offset = compiler.input_link("Normal"),
8242 .out_offset = compiler.output("Displacement")});
8243}
8244
8246{
8247 compiler.parameter(this, "space");
8248 compiler.add(this, "node_displacement");
8249}
8250
8251/* Vector Displacement */
8252
8254{
8255 NodeType *type = NodeType::add("vector_displacement", create, NodeType::SHADER);
8256
8257 static NodeEnum space_enum;
8258 space_enum.insert("tangent", NODE_NORMAL_MAP_TANGENT);
8259 space_enum.insert("object", NODE_NORMAL_MAP_OBJECT);
8260 space_enum.insert("world", NODE_NORMAL_MAP_WORLD);
8261
8262 SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_TANGENT);
8263 SOCKET_STRING(attribute, "Attribute", ustring());
8264
8265 SOCKET_IN_COLOR(vector, "Vector", zero_float3());
8266 SOCKET_IN_FLOAT(midlevel, "Midlevel", 0.0f);
8267 SOCKET_IN_FLOAT(scale, "Scale", 1.0f);
8268
8269 SOCKET_OUT_VECTOR(displacement, "Displacement");
8270
8271 return type;
8272}
8273
8274VectorDisplacementNode::VectorDisplacementNode() : ShaderNode(get_node_type()) {}
8275
8277{
8278 if (folder.all_inputs_constant()) {
8279 if ((vector == zero_float3() && midlevel == 0.0f) || (scale == 0.0f)) {
8280 folder.make_zero();
8281 }
8282 }
8283}
8284
8286{
8287 if (shader->has_surface_link() && space == NODE_NORMAL_MAP_TANGENT) {
8288 if (attribute.empty()) {
8292 }
8293 else {
8295 attributes->add(ustring((string(attribute.c_str()) + ".undisplaced_tangent").c_str()));
8296 attributes->add(ustring((string(attribute.c_str()) + ".undisplaced_tangent_sign").c_str()));
8297 }
8298 }
8299
8301}
8302
8304{
8305 int attr = 0;
8306 int attr_sign = 0;
8307
8308 if (space == NODE_NORMAL_MAP_TANGENT) {
8309 if (attribute.empty()) {
8311 attr_sign = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN_UNDISPLACED);
8312 }
8313 else {
8314 attr = compiler.attribute(
8315 ustring((string(attribute.c_str()) + ".undisplaced_tangent").c_str()));
8316 attr_sign = compiler.attribute(
8317 ustring((string(attribute.c_str()) + ".undisplaced_tangent_sign").c_str()));
8318 }
8319 }
8320
8321 compiler.add_node(
8322 this,
8323 NODE_VECTOR_DISPLACEMENT,
8324 SVMNodeVectorDisplacement{.space = space,
8325 .vector = compiler.input_float3("Vector"),
8326 .midlevel = compiler.input_float("Midlevel"),
8327 .scale = compiler.input_float("Scale"),
8328 .attr = attr,
8329 .attr_sign = attr_sign,
8330 .displacement_offset = compiler.output("Displacement")});
8331}
8332
8334{
8335 if (space == NODE_NORMAL_MAP_TANGENT) {
8336 if (attribute.empty()) {
8337 compiler.parameter("attr_name", ustring("geom:undisplaced_tangent"));
8338 compiler.parameter("attr_sign_name", ustring("geom:undisplaced_tangent_sign"));
8339 }
8340 else {
8341 compiler.parameter("attr_name",
8342 ustring((string(attribute.c_str()) + ".undisplaced_tangent").c_str()));
8343 compiler.parameter(
8344 "attr_sign_name",
8345 ustring((string(attribute.c_str()) + ".undisplaced_tangent_sign").c_str()));
8346 }
8347 }
8348
8349 compiler.parameter(this, "space");
8350 compiler.add(this, "node_vector_displacement");
8351}
8352
8353/* Raycast */
8354
8356 const RaycastNode::AttributeOutputType attribute_output_type)
8357{
8358 switch (attribute_output_type) {
8360 return SocketType::VECTOR;
8362 return SocketType::FLOAT;
8364 return SocketType::FLOAT;
8365 }
8366 LOG_DFATAL << "Invalid attribute output type " << int(attribute_output_type);
8367 return SocketType::UNDEFINED;
8368}
8369
8371 const RaycastNode::AttributeOutputType attribute_output_type)
8372{
8373 switch (attribute_output_type) {
8380 }
8381 LOG_DFATAL << "Invalid attribute output type " << int(attribute_output_type);
8383}
8384
8386{
8387 NodeType *type = NodeType::add("raycast", create, NodeType::SHADER);
8388
8390 SOCKET_IN_NORMAL(direction, "Direction", zero_float3(), SocketType::LINK_NORMAL);
8391 SOCKET_IN_FLOAT(length, "Length", 1.0f);
8392
8393 SOCKET_OUT_FLOAT(is_hit, "Is Hit");
8394 SOCKET_OUT_FLOAT(is_self_hit, "Self Hit");
8395 SOCKET_OUT_FLOAT(hit_distance, "Hit Distance");
8396 SOCKET_OUT_POINT(hit_position, "Hit Position");
8397 SOCKET_OUT_NORMAL(hit_normal, "Hit Normal");
8398
8399 SOCKET_BOOLEAN(only_local, "Only Local", false);
8400
8401 return type;
8402}
8403
8405
8407 : ShaderNode(other),
8408 position(other.position),
8409 direction(other.direction),
8410 length(other.length),
8411 only_local(other.only_local)
8412{
8413 for (const AttributeOutput &other_attribute_output : other.attribute_outputs_) {
8414 /* The ShaderNode() is expected to only take care of sockets that are part of the node type. */
8415 assert(output(other_attribute_output.socket_id) == nullptr);
8416
8417 add_output_attribute_socket(other_attribute_output.attribute_name,
8418 other_attribute_output.attribute_output_type,
8419 other_attribute_output.socket_id);
8420 }
8421}
8422
8424{
8425 for (const AttributeOutput &attribute_output : attribute_outputs_) {
8426 attributes->add_name_or_standard(attribute_output.attribute_name);
8427 }
8428
8430}
8431
8432void RaycastNode::add_output_attribute_socket(const ustring attribute_name,
8433 const AttributeOutputType attribute_output_type,
8434 const ustring socket_id)
8435{
8436 const SocketType::Type type = get_socket_type(attribute_output_type);
8437 if (type == SocketType::UNDEFINED) {
8438 return;
8439 }
8440
8441 const AttributeOutput attribute_output = {
8442 .attribute_name = attribute_name,
8443 .attribute_output_type = attribute_output_type,
8444 .socket_id = socket_id,
8445 };
8446 attribute_outputs_.push_back(attribute_output);
8447
8448 auto socket_type = std::make_unique<SocketType>();
8449 socket_type->name = socket_id;
8450 socket_type->type = type;
8451 socket_type->flags = SocketType::LINKABLE;
8452 socket_type->ui_name = socket_id;
8453
8454 auto shader_output = std::make_unique<ShaderOutput>(*socket_type.get(), this);
8455 outputs.push_back(std::move(shader_output));
8456
8457 socket_types_.push_back(std::move(socket_type));
8458}
8459
8460void RaycastNode::compile(SVMCompiler &compiler)
8461{
8462 uint num_linked_attributes = 0;
8463 for (const auto &attribute_output : attribute_outputs_) {
8464 assert(num_linked_attributes < std::numeric_limits<uint16_t>::max() - 1);
8465 if (!output(attribute_output.socket_id)->links.empty()) {
8466 ++num_linked_attributes;
8467 }
8468 }
8469
8470 compiler.add_node(
8471 this,
8472 NODE_RAYCAST,
8473 SVMNodeRaycast{
8474 .position = compiler.input_float3("Position"),
8475 .direction = compiler.input_float3("Direction"),
8476 .distance = compiler.input_float("Length"),
8477 .bump_filter_width = (bump == SHADER_BUMP_CENTER) ? 0.0f : bump_filter_width,
8478 .only_local = only_local,
8479 .num_attributes = uint16_t(num_linked_attributes),
8480 .is_hit_offset = compiler.output("Is Hit"),
8481 .is_self_hit_offset = compiler.output("Self Hit"),
8482 .hit_distance_offset = compiler.output("Hit Distance"),
8483 .hit_position_offset = compiler.output("Hit Position"),
8484 .hit_normal_offset = compiler.output("Hit Normal"),
8485 });
8486
8487 for (const auto &attribute_output : attribute_outputs_) {
8488 ShaderOutput *shader_output = output(attribute_output.socket_id);
8489 if (shader_output->links.empty()) {
8490 continue;
8491 }
8492
8493 compiler.add_node(
8494 this,
8495 NODE_ATTR,
8496 SVMNodeAttr{
8497 .attr = int(compiler.attribute_standard(attribute_output.attribute_name)),
8498 .missing = SVMInputFloat3{{0}, {0}, {0}},
8499 .missing_alpha = SVMInputFloat{__float_as_uint(1.0f)},
8500 .out_offset = compiler.output(shader_output),
8501 .output_type = get_node_attribute_output_type(attribute_output.attribute_output_type),
8502 .bump_offset = NODE_BUMP_OFFSET_CENTER,
8503 .store_derivatives = false,
8504 .bump_filter_width = 0.0f,
8505 });
8506 }
8507}
8508
8509void RaycastNode::compile(OSLCompiler &compiler)
8510{
8511 /* Collect and pass the names of per-output-type attributes. */
8512 array<ustring> float_attribute_names;
8513 array<ustring> alpha_attribute_names;
8514 array<ustring> vector_attribute_names;
8515 for (const auto &attribute_output : attribute_outputs_) {
8516 switch (attribute_output.attribute_output_type) {
8517 case ATTR_OUTPUT_FLOAT:
8518 float_attribute_names.push_back_slow(attribute_output.attribute_name);
8519 break;
8521 alpha_attribute_names.push_back_slow(attribute_output.attribute_name);
8522 break;
8523 case ATTR_OUTPUT_FLOAT3:
8524 vector_attribute_names.push_back_slow(attribute_output.attribute_name);
8525 break;
8526 }
8527 }
8528 compiler.parameter_string_array("float_attribute_names", float_attribute_names);
8529 compiler.parameter_string_array("alpha_attribute_names", alpha_attribute_names);
8530 compiler.parameter_string_array("vector_attribute_names", vector_attribute_names);
8531
8532 compiler.parameter(this, "only_local");
8533 compiler.parameter("bump_filter_width", (bump == SHADER_BUMP_CENTER) ? 0.0f : bump_filter_width);
8534 compiler.add(this, "node_raycast");
8535
8536 int float_attr_index = 0;
8537 int alpha_attr_index = 0;
8538 int vector_attr_index = 0;
8539 for (const auto &attribute_output : attribute_outputs_) {
8540 switch (attribute_output.attribute_output_type) {
8541 case ATTR_OUTPUT_FLOAT:
8542 compiler.parameter("attribute_index", float_attr_index);
8543 compiler.add_output_converter(this,
8544 "node_raycast_attr_float",
8545 "float_attributes",
8546 "float_attributes",
8547 "value",
8548 attribute_output.socket_id);
8549 ++float_attr_index;
8550 break;
8552 compiler.parameter("attribute_index", alpha_attr_index);
8553 compiler.add_output_converter(this,
8554 "node_raycast_attr_float",
8555 "alpha_attributes",
8556 "float_attributes",
8557 "value",
8558 attribute_output.socket_id);
8559 ++alpha_attr_index;
8560 break;
8561 case ATTR_OUTPUT_FLOAT3:
8562 compiler.parameter("attribute_index", vector_attr_index);
8563 compiler.add_output_converter(this,
8564 "node_raycast_attr_vector",
8565 "vector_attributes",
8566 "vector_attributes",
8567 "value",
8568 attribute_output.socket_id);
8569 ++vector_attr_index;
8570 break;
8571 }
8572 }
8573}
8574
8575/* Scene Time */
8576
8578{
8579 NodeType *type = NodeType::add("scene_time", create, NodeType::SHADER);
8580
8581 SOCKET_OUT_FLOAT(seconds, "Seconds");
8582 SOCKET_OUT_FLOAT(frame, "Frame");
8583
8584 return type;
8585}
8586
8587SceneTimeNode::SceneTimeNode() : ShaderNode(get_node_type())
8588{
8589 special_type = SHADER_SPECIAL_TYPE_SCENE_TIME;
8590}
8591
8592void SceneTimeNode::compile(SVMCompiler &compiler)
8593{
8594 compiler.add_node(this,
8595 NODE_SCENE_TIME,
8596 SVMNodeSceneTime{.seconds_out = compiler.output("Seconds"),
8597 .frame_out = compiler.output("Frame")});
8598}
8599
8600void SceneTimeNode::compile(OSLCompiler &compiler)
8601{
8602 compiler.add(this, "node_scene_time");
8603}
8604
CCL_NAMESPACE_BEGIN ccl_device int svm_boolean_math(const NodeBooleanMathType type, const int a_int, const int b_int)
ccl_device_inline float bsdf_thin_glass_transmission_alpha(const float alpha, const float eta)
ccl_device_forceinline bool alpha_is_almost_specular(const float alpha_x, const float alpha_y)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
btScalar max
#define output
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
Definition btQuadWord.h:117
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void constant_fold(const ConstantFolder &folder) override
ShaderNodeType shader_node_type() const override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void add(ustring name)
void add_name_or_standard(ustring name)
static ustring osl_name(AttributeStandard std)
static const char * standard_name(AttributeStandard std)
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
ClosureType closure
bool has_bump() override
BsdfBaseNode(const NodeType *node_type)
BsdfNode(const NodeType *node_type)
void compile(SVMCompiler &compiler, const T &data)
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
static bool colorspace_is_data(ustring colorspace)
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
void make_one() const
void discard() const
void bypass(ShaderOutput *output) const
void bypass_or_discard(ShaderInput *input) const
void fold_mapping(NodeMappingType type) const
ShaderGraph *const graph
void fold_mix_float(bool clamp_factor, bool clamp) const
bool all_inputs_constant() const
bool try_bypass_or_make_constant(ShaderInput *input, bool clamp=false) const
void make_zero() const
bool is_zero(ShaderInput *input) const
bool is_one(ShaderInput *input) const
void fold_math(NodeMathType type) const
void make_constant(const float value) const
ShaderOutput *const output
void fold_mix(NodeMix type, bool clamp) const
void make_constant_clamp(const float value, bool clamp) const
void fold_vector_math(NodeVectorMathType type) const
void fold_mix_color(NodeMix type, bool clamp_factor, bool clamp) const
void constant_fold(const ConstantFolder &folder) override
ConvertNode(SocketType::Type from, SocketType::Type to, bool autoconvert=false)
NodeConvert convert_type()
void compile(SVMCompiler &compiler, ShaderInput *value_in, ShaderOutput *value_out)
CurvesNode(const NodeType *node_type)
void constant_fold(const ConstantFolder &folder, ShaderInput *value_in)
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
ShaderNode * clone(ShaderGraph *graph) const override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void update_images(const SVMCompiler &compiler) override
ImageParams image_params() const
int get_aov_offset(Scene *scene, string name, bool &is_color)
Definition film.cpp:492
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
ShaderNodeType shader_node_type() const override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
virtual void get_uv_tiles(ustring map, unordered_set< int > &tiles)=0
void constant_fold(const ConstantFolder &folder) override
void simplify_settings(Scene *scene) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void simplify_settings(Scene *scene) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
ShaderNode * clone(ShaderGraph *graph) const override
~IESLightNode() override
ImageMetaData metadata(Progress &progress)
bool empty() const
int kernel_id() const
bool all_udim_tiled(Progress &progress)
ImageHandle add_image(const string &filename, const ImageParams &params)
bool get_use_texture_cache() const
bool get_auto_texture_cache() const
bool has_tiles_and_mipmaps
bool is_float() const
bool is_compressible_as_srgb
ImageAlphaType alpha_type
InterpolationType interpolation
ExtensionType extension
void update_images(const SVMCompiler &compiler) override
ImageParams image_params() const
void cull_tiles(Scene *scene, ShaderGraph *graph)
ShaderNode * clone(ShaderGraph *graph) const override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
ShaderNodeType shader_node_type() const override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
int add_ies_from_file(const string &filename)
bool is_linear_operation() override
void expand(ShaderGraph *graph) override
void constant_fold(const ConstantFolder &folder) override
void expand(ShaderGraph *graph) override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void simplify_settings(Scene *scene) override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
bool is_linear_operation() override
void constant_fold(const ConstantFolder &folder) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void parameter_array(const char *name, const float f[], int arraylen)
Definition osl.cpp:1728
void add_output_converter(const ShaderNode *node, string_view converter_name, string_view node_output_parameter, string_view converter_input_parameter, string_view converter_output_parameter, string_view shader_output_parameter)
Definition osl.cpp:1699
void add(ShaderNode *node, const char *name, bool isfilepath=false)
Definition osl.cpp:1697
ShaderType output_type()
Definition scene/osl.h:194
void parameter_color_array(const char *name, const array< packed_float3 > &f)
Definition osl.cpp:1730
void parameter(ShaderNode *node, const char *name)
Definition osl.cpp:1708
bool background
Definition scene/osl.h:199
void parameter_texture(const char *name, const ImageHandle &handle)
Definition osl.cpp:1738
Progress * progress
Definition scene/osl.h:201
void parameter_texture_ies(const char *name, const int svm_slot)
Definition osl.cpp:1740
void parameter_string_array(const char *name, const array< ustring > &a)
Definition osl.cpp:1734
Scene * scene
Definition scene/osl.h:200
ShaderGraph * current_graph
Definition scene/osl.h:202
void parameter_attribute(const char *name, ustring s)
Definition osl.cpp:1736
void parameter_color(const char *name, const float3 f)
Definition osl.cpp:1712
string bytecode_hash
void add_input(ustring name, SocketType::Type type, const int flags=0)
static OSLNode * create(ShaderGraph *graph, const size_t num_inputs, const OSLNode *from=nullptr)
void add_output(ustring name, SocketType::Type type)
~OSLNode() override
ShaderNode * clone(ShaderGraph *graph) const override
char * input_default_value()
void attributes(Shader *shader, AttributeRequestSet *attributes) override
string filepath
void simplify_settings(Scene *scene) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
bool subsurface_has_positive_weight()
void attributes(Shader *shader, AttributeRequestSet *attributes) override
bool has_dispersion() override
bool has_surface_bssrdf() override
void simplify_settings(Scene *scene) override
bool has_nonzero_weight(const char *name)
bool has_surface_transparent() override
bool has_bssrdf_bump() override
bool has_surface_emission() override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
bool has_surface_transparent() override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
RaycastNode(const RaycastNode &other)
void global_attributes(Shader *shader, AttributeRequestSet *attributes) override
void add_output_attribute_socket(ustring attribute_name, AttributeOutputType attribute_output_type, ustring socket_id)
ShaderGraph * current_graph
Definition scene/svm.h:165
Progress & progress
Definition scene/svm.h:164
SVMStackOffset input_link(const char *name)
Definition svm.cpp:348
bool background
Definition scene/svm.h:167
SVMStackOffset output(const char *name)
Definition svm.cpp:360
SVMInputFloat input_float(const char *name)
Definition svm.cpp:310
void add_value_node(ShaderNode *shader_node, const float value, const int stack_offset)
Definition svm.cpp:480
void add_node_data(const T &data)
Definition scene/svm.h:128
void add_bsdf_node(const SVMNodeClosureBsdf &node, const T &data)
Definition scene/svm.h:119
SVMStackOffset stack_find_offset(const ShaderIO *io)
Definition svm.cpp:240
void add_node(ShaderNodeType type)
Definition svm.cpp:434
SVMStackOffset closure_mix_weight_offset()
Definition scene/svm.h:149
uint attribute_standard(ustring name)
Definition svm.cpp:546
void stack_link(ShaderInput *input, ShaderOutput *output)
Definition svm.cpp:371
ShaderType output_type()
Definition scene/svm.h:158
void add_node_data_float(const float f)
Definition svm.cpp:475
void add_node_data_float4(const float4 &f)
Definition svm.cpp:467
SVMInputInt input_int(const char *name)
Definition svm.cpp:300
uint attribute(ustring name)
Definition svm.cpp:536
SVMStackOffset get_bump_state_offset()
Definition scene/svm.h:153
SVMStackOffset stack_assign(ShaderInput *input)
Definition svm.cpp:254
Scene * scene
Definition scene/svm.h:163
SVMInputFloat3 input_float3(const char *name)
Definition svm.cpp:324
void stack_clear_offset(const ShaderIO *io, const SVMStackOffset offset)
Definition svm.cpp:245
SVMInputFloat3 input_float3_from_offset(SVMStackOffset offset)
Definition svm.cpp:343
ScatterVolumeNode(const NodeType *node_type)
bool background
Definition scene.h:91
Definition scene.h:133
Film * film
Definition scene.h:147
unique_ptr< LightManager > light_manager
Definition scene.h:167
SceneParams params
Definition scene.h:190
unique_ptr_vector< Geometry > geometry
Definition scene.h:161
unique_ptr< ShaderManager > shader_manager
Definition scene.h:169
unique_ptr< ImageManager > image_manager
Definition scene.h:166
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
T * create_node(Args &&...args)
void connect(ShaderOutput *from, ShaderInput *to)
void relink(ShaderInput *from, ShaderInput *to)
T * create_osl_node(void *node_memory, Args &&...args)
ustring name() const
const SocketType & socket_type
ShaderNode * parent
SocketType::Type type() const
void disconnect() override
ShaderOutput * link
ShaderInput * input(const char *name)
bool need_derivatives() const
ShaderNodeSpecialType special_type
void set_need_derivatives(const bool need_derivatives=true)
virtual void global_attributes(Shader *shader, AttributeRequestSet *attributes)
float bump_filter_width
void disconnect_unused_input(const char *name)
ShaderNode(const NodeType *type)
unique_ptr_vector< ShaderInput > inputs
ShaderBump bump
ShaderOutput * output(const char *name)
virtual void compile(SVMCompiler &compiler)=0
virtual void attributes(Shader *shader, AttributeRequestSet *attributes)
unique_ptr_vector< ShaderOutput > outputs
vector< ShaderInput * > links
bool has_surface_link() const
bool has_volume
bool has_surface
NODE_DECLARE unique_ptr< ShaderGraph > graph
float get_sun_size()
void simplify_settings(Scene *scene) override
ImageHandle handle
float get_sun_average_radiance()
bool has_bssrdf_bump() override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
ShaderNodeType shader_node_type() const override
SVMStackOffset compile_begin(SVMCompiler &compiler, ShaderInput *vector_in, ShaderNode *node)
Transform compute_transform()
Mapping x_mapping
void compile(SVMCompiler &compiler, const SVMStackOffset offset_in, const SVMStackOffset offset_out, ShaderNode *node)
Mapping z_mapping
Mapping y_mapping
void compile_end(SVMCompiler &compiler, ShaderInput *vector_in, const SVMStackOffset vector_offset)
TextureMapping tex_mapping
void attributes(Shader *shader, AttributeRequestSet *attributes) override
ShaderNodeType shader_node_type() const override
void constant_fold(const ConstantFolder &folder) override
void constant_fold(const ConstantFolder &folder) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
void expand(ShaderGraph *graph) override
void constant_fold(const ConstantFolder &folder) override
bool is_linear_operation() override
void expand(ShaderGraph *graph) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void attributes(Shader *shader, AttributeRequestSet *attributes) override
void expand(ShaderGraph *graph) override
ClosureType closure
void compile(SVMCompiler &compiler, ShaderInput *density, ShaderInput *param1=nullptr, ShaderInput *param2=nullptr)
VolumeNode(const NodeType *node_type)
void push_back_slow(const T &t)
void push_back(unique_ptr< T > &&value)
size_t size() const
ccl_device float3 svm_separate_color(NodeCombSepColorType type, const float3 color)
Definition color_util.h:396
ccl_device_noinline_cpu float3 svm_mix(NodeMix type, const float t, const float3 c1, const float3 c2)
Definition color_util.h:309
ccl_device float3 svm_combine_color(NodeCombSepColorType type, const float3 color)
Definition color_util.h:383
ccl_device_noinline_cpu float3 svm_mix_clamped_factor(NodeMix type, const float t, const float3 c1, const float3 c2)
Definition color_util.h:360
ccl_device_inline float3 svm_brightness_contrast(float3 color, const float brightness, const float contrast)
Definition color_util.h:369
CCL_NAMESPACE_BEGIN ustring u_colorspace_auto
#define M_PI_2_F
#define M_SQRT2_F
#define SVM_STACK_INVALID
#define expf(x)
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
#define fmodf(x, y)
#define acosf(x)
#define copysignf(x, y)
#define __float_as_uint(x)
#define __uint_as_float(x)
#define CLOSURE_WEIGHT_CUTOFF
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt)
Definition frames.inl:1166
#define assert(assertion)
#define position
#define index(i)
#define smooth
#define attribute(slot)
#define frequency(freq)
float dot(VecOp< float, D >, VecOp< float, D >) RET
float distance(float, float) RET
constexpr T clamp(T, U, U) RET
float length(VecOp< float, D >) RET
VecBase< float, 3 > float3
void camera(KernelGlobals &kg, const ShadingData &sd, float3 &outview, float &outdepth, float &outdist)
float sky_perez_function(float4 lam03, float lam4, float theta, float gamma)
float3 sky_spherical_coordinates(float3 dir)
float2x2 invert(float2x2 mat)
float3x3 scale(float3x3 mat, float2 scale)
Quaternion interpolate(Quaternion a, Quaternion b, float t)
float average(float2 a)
float reduce_max(float2 a)
ccl_device int svm_integer_math(const NodeIntegerMathType type, const int a, const int b, const int c)
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
const ccl_global KernelWorkTile * tile
@ NODE_INFO_POINT_RADIUS
@ NODE_INFO_POINT_POSITION
@ NODE_NORMAL_MAP_BASE_DISPLACED
@ NODE_NORMAL_MAP_BASE_ORIGINAL
@ NODE_VECTOR_TRANSFORM_TYPE_NORMAL
@ NODE_VECTOR_TRANSFORM_TYPE_VECTOR
@ NODE_VECTOR_TRANSFORM_TYPE_POINT
ShaderNodeType
@ NODE_COMBSEP_COLOR_RGB
@ NODE_COMBSEP_COLOR_HSV
@ NODE_COMBSEP_COLOR_HSL
NodeAttributeOutputType
@ NODE_ATTR_OUTPUT_FLOAT
@ NODE_ATTR_OUTPUT_FLOAT_ALPHA
@ NODE_ATTR_OUTPUT_FLOAT3
@ NODE_VECTOR_ROTATE_TYPE_AXIS
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Z
@ NODE_VECTOR_ROTATE_TYPE_AXIS_X
@ NODE_VECTOR_ROTATE_TYPE_EULER_XYZ
@ NODE_VECTOR_ROTATE_TYPE_AXIS_Y
@ NODE_AO_INSIDE
@ NODE_AO_GLOBAL_RADIUS
@ NODE_AO_ONLY_LOCAL
@ NODE_MAP_RANGE_STEPPED
@ NODE_MAP_RANGE_SMOOTHERSTEP
@ NODE_MAP_RANGE_SMOOTHSTEP
@ NODE_MAP_RANGE_LINEAR
@ NODE_GEOM_N
@ NODE_GEOM_T
@ NODE_GEOM_uv
@ NODE_GEOM_P
@ NODE_GEOM_Ng
@ NODE_GEOM_I
NodeBumpOffset
@ NODE_BUMP_OFFSET_DY
@ NODE_BUMP_OFFSET_CENTER
@ NODE_BUMP_OFFSET_DX
@ NODE_INFO_PAR_SIZE
@ NODE_INFO_PAR_LOCATION
@ NODE_INFO_PAR_RANDOM
@ NODE_INFO_PAR_VELOCITY
@ NODE_INFO_PAR_INDEX
@ NODE_INFO_PAR_ANGULAR_VELOCITY
@ NODE_INFO_PAR_AGE
@ NODE_INFO_PAR_LIFETIME
@ NODE_WAVE_BANDS
@ NODE_WAVE_RINGS
@ NODE_INFO_CURVE_IS_STRAND
@ NODE_INFO_CURVE_TANGENT_NORMAL
@ NODE_INFO_CURVE_THICKNESS
@ CLOSURE_VOLUME_RAYLEIGH_ID
@ CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID
@ CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID
@ CLOSURE_VOLUME_MIE_ID
@ CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID
@ CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID
@ CLOSURE_BSDF_DIFFUSE_ID
@ CLOSURE_BSSRDF_BURLEY_ID
@ CLOSURE_BSDF_PRINCIPLED_ID
@ CLOSURE_BSDF_SHEEN_ID
@ CLOSURE_BSDF_TRANSPARENT_ID
@ CLOSURE_BSDF_DIFFUSE_TOON_ID
@ CLOSURE_VOLUME_DRAINE_ID
@ CLOSURE_BSDF_MICROFACET_GGX_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID
@ CLOSURE_BSDF_HAIR_TRANSMISSION_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID
@ CLOSURE_VOLUME_FOURNIER_FORAND_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_ID
@ CLOSURE_BSDF_PHYSICAL_CONDUCTOR
@ CLOSURE_BSDF_HAIR_HUANG_ID
@ CLOSURE_BSDF_MICROFACET_BECKMANN_ID
@ CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID
@ CLOSURE_BSDF_F82_CONDUCTOR
@ CLOSURE_BSSRDF_RANDOM_WALK_LEGACY_ID
@ CLOSURE_BSDF_RAY_PORTAL_ID
@ CLOSURE_BSDF_GLOSSY_TOON_ID
@ CLOSURE_BSDF_HAIR_CHIANG_ID
@ CLOSURE_VOLUME_ABSORPTION_ID
@ CLOSURE_BSDF_HAIR_REFLECTION_ID
@ CLOSURE_BSSRDF_RANDOM_WALK_SKIN_ID
@ CLOSURE_BSDF_TRANSLUCENT_ID
@ CLOSURE_BSDF_ASHIKHMIN_VELVET_ID
@ NODE_BOOLEAN_MATH_IMPLY
@ NODE_BOOLEAN_MATH_AND
@ NODE_BOOLEAN_MATH_NAND
@ NODE_BOOLEAN_MATH_XOR
@ NODE_BOOLEAN_MATH_NOT
@ NODE_BOOLEAN_MATH_OR
@ NODE_BOOLEAN_MATH_NIMPLY
@ NODE_BOOLEAN_MATH_XNOR
@ NODE_BOOLEAN_MATH_NOR
@ SHADER_TYPE_SURFACE
@ SHADER_TYPE_VOLUME
@ SHADER_TYPE_DISPLACEMENT
@ NODE_VORONOI_SMOOTH_F1
@ NODE_VORONOI_N_SPHERE_RADIUS
@ NODE_VORONOI_F1
@ NODE_VORONOI_F2
@ NODE_VORONOI_DISTANCE_TO_EDGE
@ NODE_ENVIRONMENT_MIRROR_BALL
@ NODE_ENVIRONMENT_EQUIRECTANGULAR
@ NODE_BLEND_QUADRATIC
@ NODE_BLEND_DIAGONAL
@ NODE_BLEND_EASING
@ NODE_BLEND_RADIAL
@ NODE_BLEND_SPHERICAL
@ NODE_BLEND_QUADRATIC_SPHERE
@ NODE_BLEND_LINEAR
@ NODE_MATH_SINH
@ NODE_MATH_SMOOTH_MIN
@ NODE_MATH_TRUNC
@ NODE_MATH_COSH
@ NODE_MATH_SIGN
@ NODE_MATH_DEGREES
@ NODE_MATH_MODULO
@ NODE_MATH_ABSOLUTE
@ NODE_MATH_DIVIDE
@ NODE_MATH_SINE
@ NODE_MATH_FLOORED_MODULO
@ NODE_MATH_ARCTAN2
@ NODE_MATH_ARCCOSINE
@ NODE_MATH_MULTIPLY_ADD
@ NODE_MATH_POWER
@ NODE_MATH_WRAP
@ NODE_MATH_ARCTANGENT
@ NODE_MATH_MINIMUM
@ NODE_MATH_SQRT
@ NODE_MATH_CEIL
@ NODE_MATH_TANH
@ NODE_MATH_GREATER_THAN
@ NODE_MATH_ADD
@ NODE_MATH_FRACTION
@ NODE_MATH_EXPONENT
@ NODE_MATH_LESS_THAN
@ NODE_MATH_ARCSINE
@ NODE_MATH_MAXIMUM
@ NODE_MATH_LOGARITHM
@ NODE_MATH_COMPARE
@ NODE_MATH_INV_SQRT
@ NODE_MATH_MULTIPLY
@ NODE_MATH_PINGPONG
@ NODE_MATH_ROUND
@ NODE_MATH_FLOOR
@ NODE_MATH_SUBTRACT
@ NODE_MATH_COSINE
@ NODE_MATH_SNAP
@ NODE_MATH_TANGENT
@ NODE_MATH_SMOOTH_MAX
@ NODE_MATH_RADIANS
@ NODE_INTEGER_MATH_SIGN
@ NODE_INTEGER_MATH_ABSOLUTE
@ NODE_INTEGER_MATH_MODULO
@ NODE_INTEGER_MATH_POWER
@ NODE_INTEGER_MATH_MINIMUM
@ NODE_INTEGER_MATH_ADD
@ NODE_INTEGER_MATH_MULTIPLY_ADD
@ NODE_INTEGER_MATH_SUBTRACT
@ NODE_INTEGER_MATH_MULTIPLY
@ NODE_INTEGER_MATH_DIVIDE_FLOOR
@ NODE_INTEGER_MATH_DIVIDE_CEIL
@ NODE_INTEGER_MATH_NEGATE
@ NODE_INTEGER_MATH_MAXIMUM
@ NODE_INTEGER_MATH_GCD
@ NODE_INTEGER_MATH_LCM
@ NODE_INTEGER_MATH_FLOORED_MODULO
@ NODE_INTEGER_MATH_DIVIDE_ROUND
@ NODE_INTEGER_MATH_DIVIDE
NodeConvert
@ NODE_CONVERT_IF
@ NODE_CONVERT_CI
@ NODE_CONVERT_CF
@ NODE_CONVERT_NONE
@ NODE_CONVERT_VF
@ NODE_CONVERT_VI
@ NODE_CONVERT_FI
@ NODE_CONVERT_IV
@ NODE_CONVERT_FV
@ NODE_MIX_DIV
@ NODE_MIX_SOFT
@ NODE_MIX_CLAMP
@ NODE_MIX_COL
@ NODE_MIX_LIGHT
@ NODE_MIX_MUL
@ NODE_MIX_DIFF
@ NODE_MIX_BURN
@ NODE_MIX_SUB
@ NODE_MIX_LINEAR
@ NODE_MIX_DARK
@ NODE_MIX_SAT
@ NODE_MIX_EXCLUSION
@ NODE_MIX_SCREEN
@ NODE_MIX_HUE
@ NODE_MIX_BLEND
@ NODE_MIX_OVERLAY
@ NODE_MIX_DODGE
@ NODE_MIX_VAL
@ NODE_MIX_ADD
@ NODE_LIGHT_FALLOFF_QUADRATIC
@ NODE_LIGHT_FALLOFF_LINEAR
@ NODE_LIGHT_FALLOFF_CONSTANT
@ NODE_INFO_OB_INDEX
@ NODE_INFO_MAT_INDEX
@ NODE_INFO_OB_RANDOM
@ NODE_INFO_OB_COLOR
@ NODE_INFO_OB_LOCATION
@ NODE_INFO_OB_ALPHA
@ NODE_SKY_SINGLE_SCATTERING
@ NODE_SKY_PREETHAM
@ NODE_SKY_MULTIPLE_SCATTERING
@ NODE_SKY_HOSEK
@ NODE_PRINCIPLED_HAIR_CHIANG
@ NODE_PRINCIPLED_HAIR_HUANG
@ NODE_WAVE_PROFILE_TRI
@ NODE_WAVE_PROFILE_SIN
@ NODE_WAVE_PROFILE_SAW
@ NODE_IMAGE_COMPRESS_AS_SRGB
@ NODE_IMAGE_ALPHA_UNASSOCIATE
uint8_t SVMStackOffset
@ NODE_VORONOI_EUCLIDEAN
@ NODE_VORONOI_MANHATTAN
@ NODE_VORONOI_CHEBYCHEV
@ NODE_VORONOI_MINKOWSKI
@ NODE_LAYER_WEIGHT_FACING
@ NODE_LAYER_WEIGHT_FRESNEL
@ NODE_TANGENT_AXIS_Y
@ NODE_TANGENT_AXIS_X
@ NODE_TANGENT_AXIS_Z
@ NODE_PRINCIPLED_HAIR_REFLECTANCE
@ NODE_PRINCIPLED_HAIR_DIRECT_ABSORPTION
@ NODE_PRINCIPLED_HAIR_PIGMENT_CONCENTRATION
@ NODE_NOISE_FBM
@ NODE_NOISE_HYBRID_MULTIFRACTAL
@ NODE_NOISE_RIDGED_MULTIFRACTAL
@ NODE_NOISE_HETERO_TERRAIN
@ NODE_NOISE_MULTIFRACTAL
@ NODE_WAVE_BANDS_DIRECTION_Z
@ NODE_WAVE_BANDS_DIRECTION_DIAGONAL
@ NODE_WAVE_BANDS_DIRECTION_Y
@ NODE_WAVE_BANDS_DIRECTION_X
@ NODE_GABOR_TYPE_2D
@ NODE_GABOR_TYPE_3D
@ NODE_NORMAL_MAP_CONVENTION_DIRECTX
@ NODE_NORMAL_MAP_CONVENTION_OPENGL
@ NODE_TANGENT_RADIAL
@ NODE_TANGENT_UVMAP
@ NODE_VECTOR_MATH_NORMALIZE
@ NODE_VECTOR_MATH_LENGTH
@ NODE_VECTOR_MATH_SIGN
@ NODE_VECTOR_MATH_CROSS_PRODUCT
@ NODE_VECTOR_MATH_CEIL
@ NODE_VECTOR_MATH_MODULO
@ NODE_VECTOR_MATH_ADD
@ NODE_VECTOR_MATH_COSINE
@ NODE_VECTOR_MATH_REFLECT
@ NODE_VECTOR_MATH_WRAP
@ NODE_VECTOR_MATH_REFRACT
@ NODE_VECTOR_MATH_POWER
@ NODE_VECTOR_MATH_DOT_PRODUCT
@ NODE_VECTOR_MATH_ABSOLUTE
@ NODE_VECTOR_MATH_DIVIDE
@ NODE_VECTOR_MATH_TANGENT
@ NODE_VECTOR_MATH_DISTANCE
@ NODE_VECTOR_MATH_FLOOR
@ NODE_VECTOR_MATH_SNAP
@ NODE_VECTOR_MATH_SINE
@ NODE_VECTOR_MATH_FRACTION
@ NODE_VECTOR_MATH_PROJECT
@ NODE_VECTOR_MATH_MULTIPLY
@ NODE_VECTOR_MATH_ROUND
@ NODE_VECTOR_MATH_SCALE
@ NODE_VECTOR_MATH_MAXIMUM
@ NODE_VECTOR_MATH_FACEFORWARD
@ NODE_VECTOR_MATH_SUBTRACT
@ NODE_VECTOR_MATH_MULTIPLY_ADD
@ NODE_VECTOR_MATH_MINIMUM
@ NODE_CLAMP_RANGE
@ NODE_CLAMP_MINMAX
@ NODE_IMAGE_PROJ_SPHERE
@ NODE_IMAGE_PROJ_TUBE
@ NODE_IMAGE_PROJ_BOX
@ NODE_IMAGE_PROJ_FLAT
@ NODE_WAVE_RINGS_DIRECTION_Y
@ NODE_WAVE_RINGS_DIRECTION_SPHERICAL
@ NODE_WAVE_RINGS_DIRECTION_X
@ NODE_WAVE_RINGS_DIRECTION_Z
@ NODE_MAPPING_TYPE_POINT
@ NODE_MAPPING_TYPE_VECTOR
@ NODE_MAPPING_TYPE_TEXTURE
@ NODE_MAPPING_TYPE_NORMAL
@ NODE_TEXCO_VOLUME_GENERATED
@ NODE_TEXCO_REFLECTION
@ NODE_TEXCO_WINDOW
@ NODE_TEXCO_OBJECT
@ NODE_TEXCO_DUPLI_UV
@ NODE_TEXCO_OBJECT_WITH_TRANSFORM
@ NODE_TEXCO_DUPLI_GENERATED
@ NODE_TEXCO_CAMERA
@ NODE_TEXCO_NORMAL
@ NODE_NORMAL_MAP_TANGENT
@ NODE_NORMAL_MAP_WORLD
@ NODE_NORMAL_MAP_BLENDER_WORLD
@ NODE_NORMAL_MAP_BLENDER_OBJECT
@ NODE_NORMAL_MAP_OBJECT
@ NODE_LP_ray_depth
@ NODE_LP_shadow
@ NODE_LP_backfacing
@ NODE_LP_ray_glossy
@ NODE_LP_camera
@ NODE_LP_glossy
@ NODE_LP_transmission
@ NODE_LP_singular
@ NODE_LP_diffuse
@ NODE_LP_ray_diffuse
@ NODE_LP_volume_scatter
@ NODE_LP_ray_transmission
@ NODE_LP_ray_length
@ NODE_LP_ray_transparent
@ NODE_LP_reflection
@ NODE_LP_ray_portal
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD
@ NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA
@ ATTR_STD_CURVE_INTERCEPT
@ ATTR_STD_GENERATED_TRANSFORM
@ ATTR_STD_UV
@ ATTR_STD_VOLUME_TEMPERATURE
@ ATTR_STD_VERTEX_NORMAL
@ ATTR_STD_UV_TANGENT
@ ATTR_STD_POINT_RANDOM
@ ATTR_STD_VERTEX_COLOR
@ ATTR_STD_VOLUME_DENSITY
@ ATTR_STD_VOLUME_FLAME
@ ATTR_STD_PTEX_FACE_ID
@ ATTR_STD_VOLUME_COLOR
@ ATTR_STD_NORMAL_UNDISPLACED
@ ATTR_STD_UV_TANGENT_SIGN
@ ATTR_STD_CURVE_RANDOM
@ ATTR_STD_UV_TANGENT_SIGN_UNDISPLACED
@ ATTR_STD_UV_TANGENT_UNDISPLACED
@ ATTR_STD_PTEX_UV
@ ATTR_STD_POINTINESS
@ ATTR_STD_GENERATED
@ ATTR_STD_CURVE_LENGTH
@ ATTR_STD_RANDOM_PER_ISLAND
@ ATTR_STD_PARTICLE
#define LOG_DFATAL
Definition log.h:100
CCL_NAMESPACE_BEGIN ccl_device Float3Type svm_mapping(NodeMappingType type, const Float3Type vector, const float3 location, const float3 rotation, const float3 scale)
ccl_device_inline float signf(const float f)
Definition math_base.h:502
ccl_device_inline float interp(const float a, const float b, const float t)
Definition math_base.h:549
ccl_device_inline float3 one_float3()
Definition math_float3.h:26
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
ccl_device float svm_math(NodeMathType type, const float a, float b, const float c)
Definition math_util.h:121
ccl_device float3 svm_math_blackbody_color_rec709(const float t)
Definition math_util.h:211
ccl_device_inline float3 svm_math_gamma_color(float3 color, const float gamma)
Definition math_util.h:245
CCL_NAMESPACE_BEGIN ccl_device void svm_vector_math(ccl_private FloatType *value, ccl_private Float3Type *vector, NodeVectorMathType type, const Float3Type a, const Float3Type b, const Float3Type c, const FloatType param1)
Definition math_util.h:16
#define T
#define R
#define T2
Definition md5.cpp:21
#define IMAGE_MISSING_RGB
std::string filename(const std::string_view &str, size_t pos)
unsigned int uint
Definition BKE_text.h:55
unsigned short uint16_t
Definition BKE_text.h:80
BMesh const char void * data
unsigned char uint8_t
Definition BKE_text.h:79
#define vector3
color rgb_ramp_lookup(color ramp[], float at, int interpolate, int extrapolate)
static unordered_map< ustring, NodeType > & types()
#define SOCKET_IN_NORMAL(name, ui_name, default_value,...)
Definition node_type.h:373
#define SOCKET_OUT_POINT(name, ui_name)
Definition node_type.h:420
#define SOCKET_OUT_FLOAT(name, ui_name)
Definition node_type.h:408
#define SOCKET_OUT_INT(name, ui_name)
Definition node_type.h:404
#define SOCKET_OUT_COLOR(name, ui_name)
Definition node_type.h:412
#define SOCKET_FLOAT(name, ui_name, default_value,...)
Definition node_type.h:219
#define SOCKET_INT(name, ui_name, default_value,...)
Definition node_type.h:213
#define SOCKET_IN_COLOR(name, ui_name, default_value,...)
Definition node_type.h:349
#define SOCKET_FLOAT_ARRAY(name, ui_name, default_value,...)
Definition node_type.h:267
#define SOCKET_TRANSFORM(name, ui_name, default_value,...)
Definition node_type.h:233
#define SOCKET_OUT_NORMAL(name, ui_name)
Definition node_type.h:424
#define SOCKET_IN_FLOAT(name, ui_name, default_value,...)
Definition node_type.h:341
#define SOCKET_IN_CLOSURE(name, ui_name,...)
Definition node_type.h:389
#define SOCKET_OFFSETOF(T, name)
Definition node_type.h:194
#define SOCKET_INT_ARRAY(name, ui_name, default_value,...)
Definition node_type.h:265
#define SOCKET_VECTOR_ARRAY(name, ui_name, default_value,...)
Definition node_type.h:278
#define SOCKET_IN_VECTOR(name, ui_name, default_value,...)
Definition node_type.h:357
#define NODE_DEFINE(structname)
Definition node_type.h:157
#define SOCKET_VECTOR(name, ui_name, default_value,...)
Definition node_type.h:223
#define SOCKET_IN_POINT(name, ui_name, default_value,...)
Definition node_type.h:365
#define SOCKET_COLOR_ARRAY(name, ui_name, default_value,...)
Definition node_type.h:270
#define SOCKET_COLOR(name, ui_name, default_value,...)
Definition node_type.h:221
#define SOCKET_OUT_VECTOR(name, ui_name)
Definition node_type.h:416
#define SOCKET_IN_STRING(name, ui_name, default_value,...)
Definition node_type.h:381
#define SOCKET_BOOLEAN(name, ui_name, default_value,...)
Definition node_type.h:211
#define SOCKET_IN_BOOLEAN(name, ui_name, default_value,...)
Definition node_type.h:330
#define SOCKET_IN_INT(name, ui_name, default_value,...)
Definition node_type.h:338
#define SOCKET_STRING(name, ui_name, default_value,...)
Definition node_type.h:231
#define SOCKET_ENUM(name, ui_name, values, default_value,...)
Definition node_type.h:235
#define SOCKET_OUT_CLOSURE(name, ui_name)
Definition node_type.h:428
#define sqr
#define fabsf
#define M_2PI_F
#define make_float2
#define tanf
#define make_float4
#define M_PI_F
#define cosf
#define atan2f
ccl_device_inline float float_ramp_lookup(KernelGlobals kg, const int offset, float f, bool interpolate, bool extrapolate, const int table_size)
Definition ramp.h:19
@ SHADER_SPECIAL_TYPE_LIGHT_PATH
@ SHADER_SPECIAL_TYPE_PROXY
@ SHADER_SPECIAL_TYPE_GEOMETRY
@ SHADER_SPECIAL_TYPE_OUTPUT_AOV
@ SHADER_SPECIAL_TYPE_COMBINE_CLOSURE
@ SHADER_SPECIAL_TYPE_BUMP
@ SHADER_SPECIAL_TYPE_AUTOCONVERT
@ SHADER_SPECIAL_TYPE_SCENE_TIME
@ SHADER_SPECIAL_TYPE_OUTPUT
@ SHADER_SPECIAL_TYPE_CLOSURE
@ SHADER_SPECIAL_TYPE_OSL
ShaderBump
@ SHADER_BUMP_CENTER
@ SHADER_BUMP_DX
@ SHADER_BUMP_DY
@ SHADER_BUMP_NONE
static NodeBumpOffset shader_bump_to_node_bump_offset(ShaderBump bump)
static void sky_texture_precompute_hosek(SunSky *sunsky, const float3 dir, float turbidity, const float ground_albedo)
static NodeAttributeOutputType get_node_attribute_output_type(const RaycastNode::AttributeOutputType attribute_output_type)
static void sky_texture_precompute_preetham(SunSky *sunsky, const float3 dir, const float turbidity)
static void sky_texture_precompute_nishita(SunSky *sunsky, bool multiple_scattering, bool sun_disc, const float sun_size, const float sun_intensity, const float sun_elevation, const float sun_rotation, const float altitude, const float air_density, const float aerosol_density, const float ozone_density)
#define TEXTURE_MAPPING_DEFINE(TextureNode)
static SocketType::Type get_socket_type(const RaycastNode::AttributeOutputType attribute_output_type)
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
void SKY_arhosekskymodelstate_free(SKY_ArHosekSkyModelState *state)
SKY_ArHosekSkyModelState * SKY_arhosek_xyz_skymodelstate_alloc_init(const double turbidity, const double albedo, const double elevation)
float3 sun_direction(float sun_cos_theta)
Definition sky_math.h:457
void SKY_single_scattering_precompute_sun(float sun_elevation, float angular_diameter, float altitude, float air_density, float aerosol_density, float r_pixel_bottom[3], float r_pixel_top[3])
void SKY_multiple_scattering_precompute_sun(float sun_elevation, float angular_diameter, float altitude, float air_density, float aerosol_density, float ozone_density, float r_pixel_bottom[3], float r_pixel_top[3])
float SKY_earth_intersection_angle(float altitude)
#define saturate(a)
Definition smaa.cc:319
#define min(a, b)
Definition sort.cc:38
bool string_endswith(const string_view s, const string_view end)
Definition string.cpp:122
void insert(const char *x, const int y)
Definition node_enum.h:21
vector< SocketType, std::allocator< SocketType > > inputs
Definition node_type.h:131
NodeType(Type type=NONE, const NodeType *base=nullptr)
static NodeType * add(const char *name, CreateFunc create, Type type=NONE, const NodeType *base=nullptr)
void register_input(ustring name, ustring ui_name, SocketType::Type type, const int struct_offset, const void *default_value, const NodeEnum *enum_values=nullptr, const NodeType *node_type=nullptr, int flags=0, int extra_flags=0)
static bool register_on_init(const NodeType *(*init_func)())
void register_output(ustring name, ustring ui_name, SocketType::Type type)
vector< SocketType, std::allocator< SocketType > > outputs
Definition node_type.h:132
float get_float(const SocketType &input) const
const NodeType * type
Definition graph/node.h:179
ustring name
Definition graph/node.h:178
bool is_modified() const
SKY_ArHosekSkyModelConfiguration configs[11]
Definition sky_hosek.h:312
static size_t max_size()
Definition node_type.cpp:93
static bool is_float3(Type type)
static ustring type_name(Type type)
static void * zero_default_value()
Definition node_type.cpp:98
@ LINK_TEXTURE_UV
Definition node_type.h:73
@ LINK_TEXTURE_GENERATED
Definition node_type.h:71
@ LINK_TEXTURE_INCOMING
Definition node_type.h:74
@ LINK_POSITION
Definition node_type.h:77
float config_z[9]
float config_x[9]
float radiance_y
float radiance_z
float nishita_data[11]
float config_y[9]
float theta
float radiance_x
float x
float y
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
CCL_NAMESPACE_BEGIN Transform transform_transposed_inverse(const Transform &tfm)
Definition transform.cpp:15
ccl_device_inline Transform transform_identity()
Definition transform.h:355
ccl_device_inline Transform transform_scale(const float3 s)
Definition transform.h:313
ccl_device_inline Transform transform_inverse(const Transform tfm)
Definition transform.h:563
ccl_device_inline Transform transform_translate(const float3 t)
Definition transform.h:296
ccl_device_inline Transform transform_euler(const float3 euler)
Definition transform.h:348
ccl_device_inline size_t align_up(const size_t offset, const size_t alignment)
Definition types_base.h:48
@ IMAGE_ALPHA_ASSOCIATED
Definition types_image.h:63
@ IMAGE_ALPHA_CHANNEL_PACKED
Definition types_image.h:64
@ IMAGE_ALPHA_AUTO
Definition types_image.h:66
@ IMAGE_ALPHA_IGNORE
Definition types_image.h:65
@ IMAGE_ALPHA_UNASSOCIATED
Definition types_image.h:62
@ INTERPOLATION_LINEAR
Definition types_image.h:26
@ INTERPOLATION_SMART
Definition types_image.h:29
@ INTERPOLATION_CLOSEST
Definition types_image.h:27
@ INTERPOLATION_CUBIC
Definition types_image.h:28
@ EXTENSION_REPEAT
Definition types_image.h:82
@ EXTENSION_CLIP
Definition types_image.h:86
@ EXTENSION_EXTEND
Definition types_image.h:84
@ EXTENSION_MIRROR
Definition types_image.h:88
ustring u_colorspace_scene_linear