| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2013-08-18 14:16:15 +00:00
										 |  |  |  * Copyright 2011-2013 Blender Foundation | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-18 14:16:15 +00:00
										 |  |  |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
					
						
							|  |  |  |  * you may not use this file except in compliance with the License. | 
					
						
							|  |  |  |  * You may obtain a copy of the License at | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-18 14:16:15 +00:00
										 |  |  |  * http://www.apache.org/licenses/LICENSE-2.0
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2013-08-18 14:16:15 +00:00
										 |  |  |  * Unless required by applicable law or agreed to in writing, software | 
					
						
							|  |  |  |  * distributed under the License is distributed on an "AS IS" BASIS, | 
					
						
							|  |  |  |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
					
						
							|  |  |  |  * See the License for the specific language governing permissions and | 
					
						
							| 
									
										
										
										
											2014-12-25 02:50:24 +01:00
										 |  |  |  * limitations under the License. | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "image.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | #include "integrator.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | #include "nodes.h"
 | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | #include "scene.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | #include "svm.h"
 | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | #include "svm_color_util.h"
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | #include "svm_ramp_util.h"
 | 
					
						
							| 
									
										
										
										
											2014-10-26 19:40:04 +05:00
										 |  |  | #include "svm_math_util.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | #include "osl.h"
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | #include "constant_fold.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-13 13:40:48 +01:00
										 |  |  | #include "util_sky_model.h"
 | 
					
						
							| 
									
										
										
										
											2013-09-23 08:57:02 +00:00
										 |  |  | #include "util_foreach.h"
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | #include "util_transform.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CCL_NAMESPACE_BEGIN | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | /* Texture Mapping */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | #define TEXTURE_MAPPING_DEFINE(TextureNode) \
 | 
					
						
							|  |  |  | 	SOCKET_POINT(tex_mapping.translation, "Translation", make_float3(0.0f, 0.0f, 0.0f)); \ | 
					
						
							|  |  |  | 	SOCKET_VECTOR(tex_mapping.rotation, "Rotation", make_float3(0.0f, 0.0f, 0.0f));      \ | 
					
						
							|  |  |  | 	SOCKET_VECTOR(tex_mapping.scale, "Scale", make_float3(1.0f, 1.0f, 1.0f));            \ | 
					
						
							|  |  |  | 	\ | 
					
						
							|  |  |  | 	SOCKET_VECTOR(tex_mapping.min, "Min", make_float3(-FLT_MAX, -FLT_MAX, -FLT_MAX)); \ | 
					
						
							|  |  |  | 	SOCKET_VECTOR(tex_mapping.max, "Max", make_float3(FLT_MAX, FLT_MAX, FLT_MAX));    \ | 
					
						
							|  |  |  | 	SOCKET_BOOLEAN(tex_mapping.use_minmax, "Use Min Max", false);                     \ | 
					
						
							|  |  |  | 	\ | 
					
						
							|  |  |  | 	static NodeEnum mapping_axis_enum;                      \ | 
					
						
							|  |  |  | 	mapping_axis_enum.insert("none", TextureMapping::NONE); \ | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	mapping_axis_enum.insert("x", TextureMapping::X);       \ | 
					
						
							|  |  |  | 	mapping_axis_enum.insert("y", TextureMapping::Y);       \ | 
					
						
							|  |  |  | 	mapping_axis_enum.insert("z", TextureMapping::Z);       \ | 
					
						
							|  |  |  | 	SOCKET_ENUM(tex_mapping.x_mapping, "x_mapping", mapping_axis_enum, TextureMapping::X); \ | 
					
						
							|  |  |  | 	SOCKET_ENUM(tex_mapping.y_mapping, "y_mapping", mapping_axis_enum, TextureMapping::Y); \ | 
					
						
							|  |  |  | 	SOCKET_ENUM(tex_mapping.z_mapping, "z_mapping", mapping_axis_enum, TextureMapping::Z); \ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	\ | 
					
						
							|  |  |  | 	static NodeEnum mapping_type_enum;                            \ | 
					
						
							|  |  |  | 	mapping_type_enum.insert("point", TextureMapping::POINT);     \ | 
					
						
							|  |  |  | 	mapping_type_enum.insert("texture", TextureMapping::TEXTURE); \ | 
					
						
							|  |  |  | 	mapping_type_enum.insert("vector", TextureMapping::VECTOR);   \ | 
					
						
							|  |  |  | 	mapping_type_enum.insert("normal", TextureMapping::NORMAL);   \ | 
					
						
							|  |  |  | 	SOCKET_ENUM(tex_mapping.type, "Type", mapping_type_enum, TextureMapping::TEXTURE); \ | 
					
						
							|  |  |  | 	\ | 
					
						
							|  |  |  | 	static NodeEnum mapping_projection_enum;                                                \ | 
					
						
							|  |  |  | 	mapping_projection_enum.insert("flat", TextureMapping::FLAT);                           \ | 
					
						
							|  |  |  | 	mapping_projection_enum.insert("cube", TextureMapping::CUBE);                           \ | 
					
						
							|  |  |  | 	mapping_projection_enum.insert("tube", TextureMapping::TUBE);                           \ | 
					
						
							|  |  |  | 	mapping_projection_enum.insert("sphere", TextureMapping::SPHERE);                       \ | 
					
						
							|  |  |  | 	SOCKET_ENUM(tex_mapping.projection, "Projection", mapping_projection_enum, TextureMapping::FLAT); | 
					
						
							| 
									
										
										
										
											2016-05-19 11:35:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | TextureMapping::TextureMapping() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Transform TextureMapping::compute_transform() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	Transform mmat = transform_scale(make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(x_mapping != NONE) | 
					
						
							| 
									
										
										
										
											2011-11-04 20:58:00 +00:00
										 |  |  | 		mmat[0][x_mapping-1] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 	if(y_mapping != NONE) | 
					
						
							| 
									
										
										
										
											2011-11-04 20:58:00 +00:00
										 |  |  | 		mmat[1][y_mapping-1] = 1.0f; | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 	if(z_mapping != NONE) | 
					
						
							| 
									
										
										
										
											2011-11-04 20:58:00 +00:00
										 |  |  | 		mmat[2][z_mapping-1] = 1.0f; | 
					
						
							| 
									
										
										
										
											2013-09-25 20:28:49 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	float3 scale_clamped = scale; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(type == TEXTURE || type == NORMAL) { | 
					
						
							|  |  |  | 		/* keep matrix invertible */ | 
					
						
							|  |  |  | 		if(fabsf(scale.x) < 1e-5f) | 
					
						
							|  |  |  | 			scale_clamped.x = signf(scale.x)*1e-5f; | 
					
						
							|  |  |  | 		if(fabsf(scale.y) < 1e-5f) | 
					
						
							|  |  |  | 			scale_clamped.y = signf(scale.y)*1e-5f; | 
					
						
							|  |  |  | 		if(fabsf(scale.z) < 1e-5f) | 
					
						
							|  |  |  | 			scale_clamped.z = signf(scale.z)*1e-5f; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Transform smat = transform_scale(scale_clamped); | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 	Transform rmat = transform_euler(rotation); | 
					
						
							|  |  |  | 	Transform tmat = transform_translate(translation); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-25 20:28:49 +00:00
										 |  |  | 	Transform mat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch(type) { | 
					
						
							|  |  |  | 		case TEXTURE: | 
					
						
							|  |  |  | 			/* inverse transform on texture coordinate gives
 | 
					
						
							|  |  |  | 			 * forward transform on texture */ | 
					
						
							|  |  |  | 			mat = tmat*rmat*smat; | 
					
						
							|  |  |  | 			mat = transform_inverse(mat); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case POINT: | 
					
						
							|  |  |  | 			/* full transform */ | 
					
						
							|  |  |  | 			mat = tmat*rmat*smat; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case VECTOR: | 
					
						
							|  |  |  | 			/* no translation for vectors */ | 
					
						
							|  |  |  | 			mat = rmat*smat; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case NORMAL: | 
					
						
							|  |  |  | 			/* no translation for normals, and inverse transpose */ | 
					
						
							|  |  |  | 			mat = rmat*smat; | 
					
						
							|  |  |  | 			mat = transform_inverse(mat); | 
					
						
							|  |  |  | 			mat = transform_transpose(mat); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* projection last */ | 
					
						
							|  |  |  | 	mat = mat*mmat; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return mat; | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool TextureMapping::skip() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(translation != make_float3(0.0f, 0.0f, 0.0f)) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	if(rotation != make_float3(0.0f, 0.0f, 0.0f)) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	if(scale != make_float3(1.0f, 1.0f, 1.0f)) | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(x_mapping != X || y_mapping != Y || z_mapping != Z) | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | 	if(use_minmax) | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextureMapping::compile(SVMCompiler& compiler, int offset_in, int offset_out) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add_node(NODE_MAPPING, offset_in, offset_out); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Transform tfm = compute_transform(); | 
					
						
							|  |  |  | 	compiler.add_node(tfm.x); | 
					
						
							|  |  |  | 	compiler.add_node(tfm.y); | 
					
						
							|  |  |  | 	compiler.add_node(tfm.z); | 
					
						
							|  |  |  | 	compiler.add_node(tfm.w); | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(use_minmax) { | 
					
						
							|  |  |  | 		compiler.add_node(NODE_MIN_MAX, offset_out, offset_out); | 
					
						
							|  |  |  | 		compiler.add_node(float3_to_float4(min)); | 
					
						
							|  |  |  | 		compiler.add_node(float3_to_float4(max)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-09-25 20:28:49 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(type == NORMAL) { | 
					
						
							|  |  |  | 		compiler.add_node(NODE_VECTOR_MATH, NODE_VECTOR_MATH_NORMALIZE, offset_out, offset_out); | 
					
						
							|  |  |  | 		compiler.add_node(NODE_VECTOR_MATH, SVM_STACK_INVALID, offset_out); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | /* Convenience function for texture nodes, allocating stack space to output
 | 
					
						
							|  |  |  |  * a modified vector and returning its offset */ | 
					
						
							|  |  |  | int TextureMapping::compile_begin(SVMCompiler& compiler, ShaderInput *vector_in) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(!skip()) { | 
					
						
							|  |  |  | 		int offset_in = compiler.stack_assign(vector_in); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 		int offset_out = compiler.stack_find_offset(SocketType::VECTOR); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		compile(compiler, offset_in, offset_out); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return offset_out; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return compiler.stack_assign(vector_in); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextureMapping::compile_end(SVMCompiler& compiler, ShaderInput *vector_in, int vector_offset) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(!skip()) { | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 		compiler.stack_clear_offset(vector_in->type(), vector_offset); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | void TextureMapping::compile(OSLCompiler &compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(!skip()) { | 
					
						
							|  |  |  | 		Transform tfm = transform_transpose(compute_transform()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compiler.parameter("mapping", tfm); | 
					
						
							|  |  |  | 		compiler.parameter("use_mapping", 1); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Image Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ImageTextureNode) | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("image_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(ImageTextureNode); | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_STRING(filename, "Filename", ustring("")); | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum color_space_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	color_space_enum.insert("none", NODE_COLOR_SPACE_NONE); | 
					
						
							|  |  |  | 	color_space_enum.insert("color", NODE_COLOR_SPACE_COLOR); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(color_space, "Color Space", color_space_enum, NODE_COLOR_SPACE_COLOR); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_BOOLEAN(use_alpha, "Use Alpha", true); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum interpolation_enum; | 
					
						
							|  |  |  | 	interpolation_enum.insert("closest", INTERPOLATION_CLOSEST); | 
					
						
							|  |  |  | 	interpolation_enum.insert("linear", INTERPOLATION_LINEAR); | 
					
						
							|  |  |  | 	interpolation_enum.insert("cubic", INTERPOLATION_CUBIC); | 
					
						
							|  |  |  | 	interpolation_enum.insert("smart", INTERPOLATION_SMART); | 
					
						
							|  |  |  | 	SOCKET_ENUM(interpolation, "Interpolation", interpolation_enum, INTERPOLATION_LINEAR); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum extension_enum; | 
					
						
							|  |  |  | 	extension_enum.insert("periodic", EXTENSION_REPEAT); | 
					
						
							|  |  |  | 	extension_enum.insert("clamp", EXTENSION_EXTEND); | 
					
						
							|  |  |  | 	extension_enum.insert("black", EXTENSION_CLIP); | 
					
						
							|  |  |  | 	SOCKET_ENUM(extension, "Extension", extension_enum, EXTENSION_REPEAT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static NodeEnum projection_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	projection_enum.insert("flat", NODE_IMAGE_PROJ_FLAT); | 
					
						
							|  |  |  | 	projection_enum.insert("box", NODE_IMAGE_PROJ_BOX); | 
					
						
							|  |  |  | 	projection_enum.insert("sphere", NODE_IMAGE_PROJ_SPHERE); | 
					
						
							|  |  |  | 	projection_enum.insert("tube", NODE_IMAGE_PROJ_TUBE); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(projection, "Projection", projection_enum, NODE_IMAGE_PROJ_FLAT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_FLOAT(projection_blend, "Projection Blend", 0.0f); | 
					
						
							| 
									
										
										
										
											2015-10-08 03:31:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_UV); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(alpha, "Alpha"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | ImageTextureNode::ImageTextureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ImageSlotTextureNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	image_manager = NULL; | 
					
						
							|  |  |  | 	slot = -1; | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	is_float = -1; | 
					
						
							| 
									
										
										
										
											2013-02-14 21:40:29 +00:00
										 |  |  | 	is_linear = false; | 
					
						
							| 
									
										
										
										
											2013-01-30 13:42:12 +00:00
										 |  |  | 	builtin_data = NULL; | 
					
						
							| 
									
										
										
										
											2012-11-21 13:00:51 +00:00
										 |  |  | 	animated = false; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ImageTextureNode::~ImageTextureNode() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 	if(image_manager) { | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 		image_manager->remove_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                            builtin_data, | 
					
						
							|  |  |  | 		                            interpolation, | 
					
						
							|  |  |  | 		                            extension); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ShaderNode *ImageTextureNode::clone() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ImageTextureNode *node = new ImageTextureNode(*this); | 
					
						
							|  |  |  | 	node->image_manager = NULL; | 
					
						
							|  |  |  | 	node->slot = -1; | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	node->is_float = -1; | 
					
						
							| 
									
										
										
										
											2013-02-14 21:40:29 +00:00
										 |  |  | 	node->is_linear = false; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	return node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void ImageTextureNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2013-11-28 01:38:23 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef WITH_PTEX
 | 
					
						
							|  |  |  | 	/* todo: avoid loading other texture coordinates when using ptex,
 | 
					
						
							|  |  |  | 	 * and hide texture coordinate socket in the UI */ | 
					
						
							| 
									
										
										
										
											2015-03-28 00:15:15 +05:00
										 |  |  | 	if(shader->has_surface && string_endswith(filename, ".ptx")) { | 
					
						
							| 
									
										
										
										
											2013-11-28 01:38:23 +01:00
										 |  |  | 		/* ptex */ | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PTEX_FACE_ID); | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PTEX_UV); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2013-11-28 01:38:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void ImageTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	ShaderOutput *alpha_out = output("Alpha"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	image_manager = compiler.image_manager; | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	if(is_float == -1) { | 
					
						
							|  |  |  | 		bool is_float_bool; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 		slot = image_manager->add_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                                builtin_data, | 
					
						
							|  |  |  | 		                                animated, | 
					
						
							|  |  |  | 		                                0, | 
					
						
							|  |  |  | 		                                is_float_bool, | 
					
						
							|  |  |  | 		                                is_linear, | 
					
						
							|  |  |  | 		                                interpolation, | 
					
						
							|  |  |  | 		                                extension, | 
					
						
							|  |  |  | 		                                use_alpha); | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 		is_float = (int)is_float_bool; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(slot != -1) { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		int srgb = (is_linear || color_space != NODE_COLOR_SPACE_COLOR)? 0: 1; | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		if(projection != NODE_IMAGE_PROJ_BOX) { | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 			compiler.add_node(NODE_TEX_IMAGE, | 
					
						
							|  |  |  | 				slot, | 
					
						
							|  |  |  | 				compiler.encode_uchar4( | 
					
						
							|  |  |  | 					vector_offset, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 					compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 					compiler.stack_assign_if_linked(alpha_out), | 
					
						
							| 
									
										
										
										
											2015-01-21 22:44:30 +05:00
										 |  |  | 					srgb), | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 				projection); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			compiler.add_node(NODE_TEX_IMAGE_BOX, | 
					
						
							|  |  |  | 				slot, | 
					
						
							|  |  |  | 				compiler.encode_uchar4( | 
					
						
							|  |  |  | 					vector_offset, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 					compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 					compiler.stack_assign_if_linked(alpha_out), | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 					srgb), | 
					
						
							|  |  |  | 				__float_as_int(projection_blend)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-01-21 22:44:30 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* image not found */ | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		if(!color_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_V, compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2012-07-04 11:48:42 +00:00
										 |  |  | 			compiler.add_node(NODE_VALUE_V, make_float3(TEX_IMAGE_MISSING_R, | 
					
						
							|  |  |  | 			                                            TEX_IMAGE_MISSING_G, | 
					
						
							|  |  |  | 			                                            TEX_IMAGE_MISSING_B)); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(!alpha_out->links.empty()) | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_F, __float_as_int(TEX_IMAGE_MISSING_A), compiler.stack_assign(alpha_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ImageTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-21 13:05:10 +00:00
										 |  |  | 	ShaderOutput *alpha_out = output("Alpha"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	image_manager = compiler.image_manager; | 
					
						
							|  |  |  | 	if(is_float == -1) { | 
					
						
							|  |  |  | 		if(builtin_data == NULL) { | 
					
						
							| 
									
										
										
										
											2016-05-09 12:51:42 +02:00
										 |  |  | 			ImageManager::ImageDataType type; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 			type = image_manager->get_image_metadata(filename.string(), NULL, is_linear); | 
					
						
							| 
									
										
										
										
											2016-05-09 12:51:42 +02:00
										 |  |  | 			if(type == ImageManager::IMAGE_DATA_TYPE_FLOAT || type == ImageManager::IMAGE_DATA_TYPE_FLOAT4) | 
					
						
							|  |  |  | 				is_float = 1; | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			bool is_float_bool; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 			slot = image_manager->add_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 			                                builtin_data, | 
					
						
							|  |  |  | 			                                animated, | 
					
						
							|  |  |  | 			                                0, | 
					
						
							|  |  |  | 			                                is_float_bool, | 
					
						
							|  |  |  | 			                                is_linear, | 
					
						
							|  |  |  | 			                                interpolation, | 
					
						
							|  |  |  | 			                                extension, | 
					
						
							|  |  |  | 			                                use_alpha); | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 			is_float = (int)is_float_bool; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	if(slot == -1) { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.parameter(this, "filename"); | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* TODO(sergey): It's not so simple to pass custom attribute
 | 
					
						
							|  |  |  | 		 * to the texture() function in order to make builtin images | 
					
						
							|  |  |  | 		 * support more clear. So we use special file name which is | 
					
						
							|  |  |  | 		 * "@<slot_number>" and check whether file name matches this | 
					
						
							|  |  |  | 		 * mask in the OSLRenderServices::texture(). | 
					
						
							|  |  |  | 		 */ | 
					
						
							|  |  |  | 		compiler.parameter("filename", string_printf("@%d", slot).c_str()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(is_linear || color_space != NODE_COLOR_SPACE_COLOR) | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 		compiler.parameter("color_space", "linear"); | 
					
						
							| 
									
										
										
										
											2012-03-07 12:27:18 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("color_space", "sRGB"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "projection"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "projection_blend"); | 
					
						
							| 
									
										
										
										
											2016-06-19 17:54:01 +02:00
										 |  |  | 	compiler.parameter("is_float", is_float); | 
					
						
							| 
									
										
										
										
											2013-06-21 13:05:10 +00:00
										 |  |  | 	compiler.parameter("use_alpha", !alpha_out->links.empty()); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "interpolation"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "extension"); | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_image_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Environment Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(EnvironmentTextureNode) | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("environment_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(EnvironmentTextureNode); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_STRING(filename, "Filename", ustring("")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static NodeEnum color_space_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	color_space_enum.insert("none", NODE_COLOR_SPACE_NONE); | 
					
						
							|  |  |  | 	color_space_enum.insert("color", NODE_COLOR_SPACE_COLOR); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(color_space, "Color Space", color_space_enum, NODE_COLOR_SPACE_COLOR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_BOOLEAN(use_alpha, "Use Alpha", true); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum interpolation_enum; | 
					
						
							|  |  |  | 	interpolation_enum.insert("closest", INTERPOLATION_CLOSEST); | 
					
						
							|  |  |  | 	interpolation_enum.insert("linear", INTERPOLATION_LINEAR); | 
					
						
							|  |  |  | 	interpolation_enum.insert("cubic", INTERPOLATION_CUBIC); | 
					
						
							|  |  |  | 	interpolation_enum.insert("smart", INTERPOLATION_SMART); | 
					
						
							|  |  |  | 	SOCKET_ENUM(interpolation, "Interpolation", interpolation_enum, INTERPOLATION_LINEAR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static NodeEnum projection_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	projection_enum.insert("equirectangular", NODE_ENVIRONMENT_EQUIRECTANGULAR); | 
					
						
							|  |  |  | 	projection_enum.insert("mirror_ball", NODE_ENVIRONMENT_MIRROR_BALL); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(projection, "Projection", projection_enum, NODE_ENVIRONMENT_EQUIRECTANGULAR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_POSITION); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(alpha, "Alpha"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | EnvironmentTextureNode::EnvironmentTextureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ImageSlotTextureNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	image_manager = NULL; | 
					
						
							|  |  |  | 	slot = -1; | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	is_float = -1; | 
					
						
							| 
									
										
										
										
											2013-02-14 21:40:29 +00:00
										 |  |  | 	is_linear = false; | 
					
						
							| 
									
										
										
										
											2013-01-30 13:42:12 +00:00
										 |  |  | 	builtin_data = NULL; | 
					
						
							| 
									
										
										
										
											2012-11-21 13:00:51 +00:00
										 |  |  | 	animated = false; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EnvironmentTextureNode::~EnvironmentTextureNode() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 	if(image_manager) { | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 		image_manager->remove_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                            builtin_data, | 
					
						
							| 
									
										
										
										
											2015-10-08 03:31:15 +02:00
										 |  |  | 		                            interpolation, | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                            EXTENSION_REPEAT); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ShaderNode *EnvironmentTextureNode::clone() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	EnvironmentTextureNode *node = new EnvironmentTextureNode(*this); | 
					
						
							|  |  |  | 	node->image_manager = NULL; | 
					
						
							|  |  |  | 	node->slot = -1; | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	node->is_float = -1; | 
					
						
							| 
									
										
										
										
											2013-02-14 21:40:29 +00:00
										 |  |  | 	node->is_linear = false; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	return node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void EnvironmentTextureNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2013-11-28 01:38:23 +01:00
										 |  |  | { | 
					
						
							|  |  |  | #ifdef WITH_PTEX
 | 
					
						
							| 
									
										
										
										
											2015-03-28 00:15:15 +05:00
										 |  |  | 	if(shader->has_surface && string_endswith(filename, ".ptx")) { | 
					
						
							| 
									
										
										
										
											2013-11-28 01:38:23 +01:00
										 |  |  | 		/* ptex */ | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PTEX_FACE_ID); | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PTEX_UV); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2013-11-28 01:38:23 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void EnvironmentTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	ShaderOutput *alpha_out = output("Alpha"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	image_manager = compiler.image_manager; | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	if(slot == -1) { | 
					
						
							|  |  |  | 		bool is_float_bool; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 		slot = image_manager->add_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                                builtin_data, | 
					
						
							|  |  |  | 		                                animated, | 
					
						
							|  |  |  | 		                                0, | 
					
						
							|  |  |  | 		                                is_float_bool, | 
					
						
							|  |  |  | 		                                is_linear, | 
					
						
							| 
									
										
										
										
											2015-10-08 03:31:15 +02:00
										 |  |  | 		                                interpolation, | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                                EXTENSION_REPEAT, | 
					
						
							|  |  |  | 		                                use_alpha); | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 		is_float = (int)is_float_bool; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(slot != -1) { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		int srgb = (is_linear || color_space != NODE_COLOR_SPACE_COLOR)? 0: 1; | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-13 14:32:08 +00:00
										 |  |  | 		compiler.add_node(NODE_TEX_ENVIRONMENT, | 
					
						
							|  |  |  | 			slot, | 
					
						
							|  |  |  | 			compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 				vector_offset, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 				compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 				compiler.stack_assign_if_linked(alpha_out), | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 				srgb), | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			projection); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* image not found */ | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		if(!color_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_V, compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2012-07-04 11:48:42 +00:00
										 |  |  | 			compiler.add_node(NODE_VALUE_V, make_float3(TEX_IMAGE_MISSING_R, | 
					
						
							|  |  |  | 			                                            TEX_IMAGE_MISSING_G, | 
					
						
							|  |  |  | 			                                            TEX_IMAGE_MISSING_B)); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(!alpha_out->links.empty()) | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_F, __float_as_int(TEX_IMAGE_MISSING_A), compiler.stack_assign(alpha_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EnvironmentTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-06-21 13:05:10 +00:00
										 |  |  | 	ShaderOutput *alpha_out = output("Alpha"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	/* See comments in ImageTextureNode::compile about support
 | 
					
						
							|  |  |  | 	 * of builtin images. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2014-07-07 12:37:45 +06:00
										 |  |  | 	image_manager = compiler.image_manager; | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	if(is_float == -1) { | 
					
						
							|  |  |  | 		if(builtin_data == NULL) { | 
					
						
							| 
									
										
										
										
											2016-05-09 12:51:42 +02:00
										 |  |  | 			ImageManager::ImageDataType type; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 			type = image_manager->get_image_metadata(filename.string(), NULL, is_linear); | 
					
						
							| 
									
										
										
										
											2016-05-09 12:51:42 +02:00
										 |  |  | 			if(type == ImageManager::IMAGE_DATA_TYPE_FLOAT || type == ImageManager::IMAGE_DATA_TYPE_FLOAT4) | 
					
						
							|  |  |  | 				is_float = 1; | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			bool is_float_bool; | 
					
						
							| 
									
										
										
										
											2016-06-12 17:12:25 +02:00
										 |  |  | 			slot = image_manager->add_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 			                                builtin_data, | 
					
						
							|  |  |  | 			                                animated, | 
					
						
							|  |  |  | 			                                0, | 
					
						
							|  |  |  | 			                                is_float_bool, | 
					
						
							|  |  |  | 			                                is_linear, | 
					
						
							| 
									
										
										
										
											2015-10-08 03:31:15 +02:00
										 |  |  | 			                                interpolation, | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 			                                EXTENSION_REPEAT, | 
					
						
							|  |  |  | 			                                use_alpha); | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 			is_float = (int)is_float_bool; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	if(slot == -1) { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.parameter(this, "filename"); | 
					
						
							| 
									
										
										
										
											2014-06-12 13:26:48 +06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		compiler.parameter("filename", string_printf("@%d", slot).c_str()); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "projection"); | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(is_linear || color_space != NODE_COLOR_SPACE_COLOR) | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 		compiler.parameter("color_space", "linear"); | 
					
						
							| 
									
										
										
										
											2012-03-07 12:27:18 +00:00
										 |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("color_space", "sRGB"); | 
					
						
							| 
									
										
										
										
											2015-10-08 03:31:15 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "interpolation"); | 
					
						
							| 
									
										
										
										
											2016-06-22 16:10:10 +02:00
										 |  |  | 	compiler.parameter("is_float", is_float); | 
					
						
							| 
									
										
										
										
											2013-06-21 13:05:10 +00:00
										 |  |  | 	compiler.parameter("use_alpha", !alpha_out->links.empty()); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_environment_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Sky Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static float2 sky_spherical_coordinates(float3 dir) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return make_float2(acosf(dir.z), atan2f(dir.x, dir.y)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | typedef struct SunSky { | 
					
						
							|  |  |  | 	/* sun direction in spherical and cartesian */ | 
					
						
							|  |  |  | 	float theta, phi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Parameter */ | 
					
						
							|  |  |  | 	float radiance_x, radiance_y, radiance_z; | 
					
						
							|  |  |  | 	float config_x[9], config_y[9], config_z[9]; | 
					
						
							|  |  |  | } SunSky; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | /* Preetham model */ | 
					
						
							|  |  |  | static float sky_perez_function(float lam[6], float theta, float gamma) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return (1.0f + lam[0]*expf(lam[1]/cosf(theta))) * (1.0f + lam[2]*expf(lam[3]*gamma)  + lam[4]*cosf(gamma)*cosf(gamma)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void sky_texture_precompute_old(SunSky *sunsky, float3 dir, float turbidity) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							| 
									
										
										
										
											2016-07-02 10:02:04 +10:00
										 |  |  | 	 * We re-use the SunSky struct of the new model, to avoid extra variables | 
					
						
							|  |  |  | 	 * zenith_Y/x/y is now radiance_x/y/z | 
					
						
							|  |  |  | 	 * perez_Y/x/y is now config_x/y/z | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	float2 spherical = sky_spherical_coordinates(dir); | 
					
						
							|  |  |  | 	float theta = spherical.x; | 
					
						
							|  |  |  | 	float phi = spherical.y; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->theta = theta; | 
					
						
							|  |  |  | 	sunsky->phi = phi; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float theta2 = theta*theta; | 
					
						
							|  |  |  | 	float theta3 = theta2*theta; | 
					
						
							|  |  |  | 	float T = turbidity; | 
					
						
							|  |  |  | 	float T2 = T * T; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	float chi = (4.0f / 9.0f - T / 120.0f) * (M_PI_F - 2.0f * theta); | 
					
						
							|  |  |  | 	sunsky->radiance_x = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f; | 
					
						
							|  |  |  | 	sunsky->radiance_x *= 0.06f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->radiance_y = | 
					
						
							|  |  |  | 	(0.00166f * theta3 - 0.00375f * theta2 + 0.00209f * theta) * T2 + | 
					
						
							|  |  |  | 	(-0.02903f * theta3 + 0.06377f * theta2 - 0.03202f * theta + 0.00394f) * T + | 
					
						
							|  |  |  | 	(0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * theta + 0.25886f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->radiance_z = | 
					
						
							|  |  |  | 	(0.00275f * theta3 - 0.00610f * theta2 + 0.00317f * theta) * T2 + | 
					
						
							|  |  |  | 	(-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * theta  + 0.00516f) * T + | 
					
						
							|  |  |  | 	(0.15346f * theta3 - 0.26756f * theta2 + 0.06670f * theta  + 0.26688f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->config_x[0] = (0.1787f * T  - 1.4630f); | 
					
						
							|  |  |  | 	sunsky->config_x[1] = (-0.3554f * T  + 0.4275f); | 
					
						
							|  |  |  | 	sunsky->config_x[2] = (-0.0227f * T  + 5.3251f); | 
					
						
							|  |  |  | 	sunsky->config_x[3] = (0.1206f * T  - 2.5771f); | 
					
						
							|  |  |  | 	sunsky->config_x[4] = (-0.0670f * T  + 0.3703f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->config_y[0] = (-0.0193f * T  - 0.2592f); | 
					
						
							|  |  |  | 	sunsky->config_y[1] = (-0.0665f * T  + 0.0008f); | 
					
						
							|  |  |  | 	sunsky->config_y[2] = (-0.0004f * T  + 0.2125f); | 
					
						
							|  |  |  | 	sunsky->config_y[3] = (-0.0641f * T  - 0.8989f); | 
					
						
							|  |  |  | 	sunsky->config_y[4] = (-0.0033f * T  + 0.0452f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->config_z[0] = (-0.0167f * T  - 0.2608f); | 
					
						
							|  |  |  | 	sunsky->config_z[1] = (-0.0950f * T  + 0.0092f); | 
					
						
							|  |  |  | 	sunsky->config_z[2] = (-0.0079f * T  + 0.2102f); | 
					
						
							|  |  |  | 	sunsky->config_z[3] = (-0.0441f * T  - 1.6537f); | 
					
						
							|  |  |  | 	sunsky->config_z[4] = (-0.0109f * T  + 0.0529f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* unused for old sky model */ | 
					
						
							|  |  |  | 	for(int i = 5; i < 9; i++) { | 
					
						
							|  |  |  | 		sunsky->config_x[i] = 0.0f; | 
					
						
							|  |  |  | 		sunsky->config_y[i] = 0.0f; | 
					
						
							|  |  |  | 		sunsky->config_z[i] = 0.0f; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sunsky->radiance_x /= sky_perez_function(sunsky->config_x, 0, theta); | 
					
						
							|  |  |  | 	sunsky->radiance_y /= sky_perez_function(sunsky->config_y, 0, theta); | 
					
						
							|  |  |  | 	sunsky->radiance_z /= sky_perez_function(sunsky->config_z, 0, theta); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | /* Hosek / Wilkie */ | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | static void sky_texture_precompute_new(SunSky *sunsky, float3 dir, float turbidity, float ground_albedo) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-17 16:08:03 +00:00
										 |  |  | 	/* Calculate Sun Direction and save coordinates */ | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	float2 spherical = sky_spherical_coordinates(dir); | 
					
						
							|  |  |  | 	float theta = spherical.x; | 
					
						
							|  |  |  | 	float phi = spherical.y; | 
					
						
							| 
									
										
										
										
											2013-08-30 18:04:23 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-09-27 10:26:00 +00:00
										 |  |  | 	/* Clamp Turbidity */ | 
					
						
							|  |  |  | 	turbidity = clamp(turbidity, 0.0f, 10.0f);  | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-08-30 18:04:23 +00:00
										 |  |  | 	/* Clamp to Horizon */ | 
					
						
							|  |  |  | 	theta = clamp(theta, 0.0f, M_PI_2_F);  | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 	sunsky->theta = theta; | 
					
						
							|  |  |  | 	sunsky->phi = phi; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-22 19:11:26 +02:00
										 |  |  | 	float solarElevation = M_PI_2_F - theta; | 
					
						
							| 
									
										
										
										
											2013-08-17 16:08:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Initialize Sky Model */ | 
					
						
							|  |  |  | 	ArHosekSkyModelState *sky_state; | 
					
						
							| 
									
										
										
										
											2016-05-22 19:11:26 +02:00
										 |  |  | 	sky_state = arhosek_xyz_skymodelstate_alloc_init((double)turbidity, (double)ground_albedo, (double)solarElevation); | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Copy values from sky_state to SunSky */ | 
					
						
							| 
									
										
										
										
											2015-03-28 00:15:15 +05:00
										 |  |  | 	for(int i = 0; i < 9; ++i) { | 
					
						
							| 
									
										
										
										
											2014-05-03 07:22:14 +10:00
										 |  |  | 		sunsky->config_x[i] = (float)sky_state->configs[0][i]; | 
					
						
							|  |  |  | 		sunsky->config_y[i] = (float)sky_state->configs[1][i]; | 
					
						
							|  |  |  | 		sunsky->config_z[i] = (float)sky_state->configs[2][i]; | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-05-03 07:22:14 +10:00
										 |  |  | 	sunsky->radiance_x = (float)sky_state->radiances[0]; | 
					
						
							|  |  |  | 	sunsky->radiance_y = (float)sky_state->radiances[1]; | 
					
						
							|  |  |  | 	sunsky->radiance_z = (float)sky_state->radiances[2]; | 
					
						
							| 
									
										
										
										
											2013-08-17 16:08:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Free sky_state */ | 
					
						
							|  |  |  | 	arhosekskymodelstate_free(sky_state); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(SkyTextureNode) | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("sky_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(SkyTextureNode); | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("preetham", NODE_SKY_OLD); | 
					
						
							|  |  |  | 	type_enum.insert("hosek_wilkie", NODE_SKY_NEW); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_SKY_NEW); | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_VECTOR(sun_direction, "Sun Direction", make_float3(0.0f, 0.0f, 1.0f)); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(turbidity, "Turbidity", 2.2f); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(ground_albedo, "Ground Albedo", 0.3f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | SkyTextureNode::SkyTextureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : TextureNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SkyTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 	SunSky sunsky; | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(type == NODE_SKY_OLD) | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 		sky_texture_precompute_old(&sunsky, sun_direction, turbidity); | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	else if(type == NODE_SKY_NEW) | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 		sky_texture_precompute_new(&sunsky, sun_direction, turbidity, ground_albedo); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		assert(false); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.stack_assign(color_out); | 
					
						
							| 
									
										
										
										
											2016-06-12 00:01:57 +02:00
										 |  |  | 	compiler.add_node(NODE_TEX_SKY, vector_offset, compiler.stack_assign(color_out), type); | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 	compiler.add_node(__float_as_uint(sunsky.phi), __float_as_uint(sunsky.theta), __float_as_uint(sunsky.radiance_x), __float_as_uint(sunsky.radiance_y)); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.radiance_z), __float_as_uint(sunsky.config_x[0]), __float_as_uint(sunsky.config_x[1]), __float_as_uint(sunsky.config_x[2])); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.config_x[3]), __float_as_uint(sunsky.config_x[4]), __float_as_uint(sunsky.config_x[5]), __float_as_uint(sunsky.config_x[6])); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.config_x[7]), __float_as_uint(sunsky.config_x[8]), __float_as_uint(sunsky.config_y[0]), __float_as_uint(sunsky.config_y[1])); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.config_y[2]), __float_as_uint(sunsky.config_y[3]), __float_as_uint(sunsky.config_y[4]), __float_as_uint(sunsky.config_y[5])); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.config_y[6]), __float_as_uint(sunsky.config_y[7]), __float_as_uint(sunsky.config_y[8]), __float_as_uint(sunsky.config_z[0])); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.config_z[1]), __float_as_uint(sunsky.config_z[2]), __float_as_uint(sunsky.config_z[3]), __float_as_uint(sunsky.config_z[4])); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_uint(sunsky.config_z[5]), __float_as_uint(sunsky.config_z[6]), __float_as_uint(sunsky.config_z[7]), __float_as_uint(sunsky.config_z[8])); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SkyTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 	SunSky sunsky; | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(type == NODE_SKY_OLD) | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 		sky_texture_precompute_old(&sunsky, sun_direction, turbidity); | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	else if(type == NODE_SKY_NEW) | 
					
						
							| 
									
										
										
										
											2016-04-05 12:25:54 +02:00
										 |  |  | 		sky_texture_precompute_new(&sunsky, sun_direction, turbidity, ground_albedo); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		assert(false); | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							| 
									
										
										
										
											2013-08-28 14:11:28 +00:00
										 |  |  | 	compiler.parameter("theta", sunsky.theta); | 
					
						
							|  |  |  | 	compiler.parameter("phi", sunsky.phi); | 
					
						
							|  |  |  | 	compiler.parameter_color("radiance", make_float3(sunsky.radiance_x, sunsky.radiance_y, sunsky.radiance_z)); | 
					
						
							|  |  |  | 	compiler.parameter_array("config_x", sunsky.config_x, 9); | 
					
						
							|  |  |  | 	compiler.parameter_array("config_y", sunsky.config_y, 9); | 
					
						
							|  |  |  | 	compiler.parameter_array("config_z", sunsky.config_z, 9); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_sky_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | /* Gradient Texture */ | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(GradientTextureNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("gradient_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(GradientTextureNode); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("linear", NODE_BLEND_LINEAR); | 
					
						
							|  |  |  | 	type_enum.insert("quadratic", NODE_BLEND_QUADRATIC); | 
					
						
							|  |  |  | 	type_enum.insert("easing", NODE_BLEND_EASING); | 
					
						
							|  |  |  | 	type_enum.insert("diagonal", NODE_BLEND_DIAGONAL); | 
					
						
							|  |  |  | 	type_enum.insert("radial", NODE_BLEND_RADIAL); | 
					
						
							|  |  |  | 	type_enum.insert("quadratic_sphere", NODE_BLEND_QUADRATIC_SPHERE); | 
					
						
							|  |  |  | 	type_enum.insert("spherical", NODE_BLEND_SPHERICAL); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_BLEND_LINEAR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | GradientTextureNode::GradientTextureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : TextureNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void GradientTextureNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add_node(NODE_TEX_GRADIENT, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			type, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(fac_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out))); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void GradientTextureNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add(this, "node_gradient_texture"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | /* Noise Texture */ | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(NoiseTextureNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("noise_texture", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TEXTURE_MAPPING_DEFINE(NoiseTextureNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(detail, "Detail", 2.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(distortion, "Distortion", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NoiseTextureNode::NoiseTextureNode() | 
					
						
							|  |  |  | : TextureNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void NoiseTextureNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderInput *distortion_in = input("Distortion"); | 
					
						
							|  |  |  | 	ShaderInput *detail_in = input("Detail"); | 
					
						
							|  |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add_node(NODE_TEX_NOISE, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(detail_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(distortion_in)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(fac_out))); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add_node( | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(scale), | 
					
						
							|  |  |  | 		__float_as_int(detail), | 
					
						
							|  |  |  | 		__float_as_int(distortion)); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void NoiseTextureNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add(this, "node_noise_texture"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Voronoi Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(VoronoiTextureNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("voronoi_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(VoronoiTextureNode); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum coloring_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	coloring_enum.insert("intensity", NODE_VORONOI_INTENSITY); | 
					
						
							|  |  |  | 	coloring_enum.insert("cells", NODE_VORONOI_CELLS); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(coloring, "Coloring", coloring_enum, NODE_VORONOI_INTENSITY); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | VoronoiTextureNode::VoronoiTextureNode() | 
					
						
							|  |  |  | : TextureNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VoronoiTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_TEX_VORONOI, | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		coloring, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in), | 
					
						
							|  |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign(fac_out), | 
					
						
							|  |  |  | 			compiler.stack_assign(color_out)), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(scale)); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VoronoiTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "coloring"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_voronoi_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Musgrave Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MusgraveTextureNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("musgrave_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(MusgraveTextureNode); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("multifractal", NODE_MUSGRAVE_MULTIFRACTAL); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	type_enum.insert("fBM", NODE_MUSGRAVE_FBM); | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("hybrid_multifractal", NODE_MUSGRAVE_HYBRID_MULTIFRACTAL); | 
					
						
							|  |  |  | 	type_enum.insert("ridged_multifractal", NODE_MUSGRAVE_RIDGED_MULTIFRACTAL); | 
					
						
							|  |  |  | 	type_enum.insert("hetero_terrain", NODE_MUSGRAVE_HETERO_TERRAIN); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_MUSGRAVE_FBM); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(detail, "Detail", 2.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(dimension, "Dimension", 2.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(lacunarity, "Lacunarity", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(offset, "Offset", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(gain, "Gain", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | MusgraveTextureNode::MusgraveTextureNode() | 
					
						
							|  |  |  | : TextureNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MusgraveTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderInput *dimension_in = input("Dimension"); | 
					
						
							|  |  |  | 	ShaderInput *lacunarity_in = input("Lacunarity"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderInput *detail_in = input("Detail"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderInput *offset_in = input("Offset"); | 
					
						
							|  |  |  | 	ShaderInput *gain_in = input("Gain"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add_node(NODE_TEX_MUSGRAVE, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			type, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(fac_out)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(dimension_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(lacunarity_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(detail_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(offset_in)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(gain_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in))); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.add_node(__float_as_int(dimension), | 
					
						
							|  |  |  | 		__float_as_int(lacunarity), | 
					
						
							|  |  |  | 		__float_as_int(detail), | 
					
						
							|  |  |  | 		__float_as_int(offset)); | 
					
						
							|  |  |  | 	compiler.add_node(__float_as_int(gain), | 
					
						
							|  |  |  | 		__float_as_int(scale)); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MusgraveTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_musgrave_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | /* Wave Texture */ | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(WaveTextureNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("wave_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(WaveTextureNode); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("bands", NODE_WAVE_BANDS); | 
					
						
							|  |  |  | 	type_enum.insert("rings", NODE_WAVE_RINGS); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_WAVE_BANDS); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum profile_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	profile_enum.insert("sine", NODE_WAVE_PROFILE_SIN); | 
					
						
							|  |  |  | 	profile_enum.insert("saw", NODE_WAVE_PROFILE_SAW); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(profile, "Profile", profile_enum, NODE_WAVE_PROFILE_SIN); | 
					
						
							| 
									
										
										
										
											2015-12-29 14:42:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(distortion, "Distortion", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(detail, "Detail", 2.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(detail_scale, "Detail Scale", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							| 
									
										
										
										
											2015-12-29 14:42:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							| 
									
										
										
										
											2015-12-29 14:42:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | WaveTextureNode::WaveTextureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : TextureNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void WaveTextureNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							|  |  |  | 	ShaderInput *distortion_in = input("Distortion"); | 
					
						
							|  |  |  | 	ShaderInput *dscale_in = input("Detail Scale"); | 
					
						
							|  |  |  | 	ShaderInput *detail_in = input("Detail"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_TEX_WAVE, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			type, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(fac_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(dscale_in)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(detail_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(distortion_in)), | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		profile); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node( | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(scale), | 
					
						
							|  |  |  | 		__float_as_int(detail), | 
					
						
							|  |  |  | 		__float_as_int(distortion), | 
					
						
							|  |  |  | 		__float_as_int(detail_scale)); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void WaveTextureNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "profile"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-02 21:34:25 +00:00
										 |  |  | 	compiler.add(this, "node_wave_texture"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Magic Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MagicTextureNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("magic_texture", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TEXTURE_MAPPING_DEFINE(MagicTextureNode); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_INT(depth, "Depth", 2); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 5.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(distortion, "Distortion", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MagicTextureNode::MagicTextureNode() | 
					
						
							|  |  |  | : TextureNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MagicTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							|  |  |  | 	ShaderInput *distortion_in = input("Distortion"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add_node(NODE_TEX_MAGIC, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			depth, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(fac_out)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(distortion_in))); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add_node( | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(scale), | 
					
						
							|  |  |  | 		__float_as_int(distortion)); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void MagicTextureNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "depth"); | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | 	compiler.add(this, "node_magic_texture"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | /* Checker Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(CheckerTextureNode) | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("checker_texture", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TEXTURE_MAPPING_DEFINE(CheckerTextureNode); | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color1, "Color1", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color2, "Color2", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | CheckerTextureNode::CheckerTextureNode() | 
					
						
							|  |  |  | : TextureNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CheckerTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderInput *color1_in = input("Color1"); | 
					
						
							|  |  |  | 	ShaderInput *color2_in = input("Color2"); | 
					
						
							|  |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_TEX_CHECKER, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign(color1_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(color2_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(fac_out)), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(scale)); | 
					
						
							| 
									
										
										
										
											2012-03-08 19:52:58 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CheckerTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-08 14:55:43 +00:00
										 |  |  | 	compiler.add(this, "node_checker_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | /* Brick Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(BrickTextureNode) | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("brick_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	TEXTURE_MAPPING_DEFINE(BrickTextureNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_FLOAT(offset, "Offset", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_INT(offset_frequency, "Offset Frequency", 2); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(squash, "Squash", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_INT(squash_frequency, "Squash Frequency", 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TEXTURE_GENERATED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color1, "Color1", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color2, "Color2", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(mortar, "Mortar", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 5.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(mortar_size, "Mortar Size", 0.02f); | 
					
						
							| 
									
										
										
										
											2016-10-30 01:33:10 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(mortar_smooth, "Mortar Smooth", 0.0f); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(bias, "Bias", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(brick_width, "Brick Width", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(row_height, "Row Height", 0.25f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | BrickTextureNode::BrickTextureNode() | 
					
						
							|  |  |  | : TextureNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BrickTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderInput *color1_in = input("Color1"); | 
					
						
							|  |  |  | 	ShaderInput *color2_in = input("Color2"); | 
					
						
							|  |  |  | 	ShaderInput *mortar_in = input("Mortar"); | 
					
						
							|  |  |  | 	ShaderInput *scale_in = input("Scale"); | 
					
						
							|  |  |  | 	ShaderInput *mortar_size_in = input("Mortar Size"); | 
					
						
							| 
									
										
										
										
											2016-10-30 01:33:10 +02:00
										 |  |  | 	ShaderInput *mortar_smooth_in = input("Mortar Smooth"); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 	ShaderInput *bias_in = input("Bias"); | 
					
						
							|  |  |  | 	ShaderInput *brick_width_in = input("Brick Width"); | 
					
						
							|  |  |  | 	ShaderInput *row_height_in = input("Row Height"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int vector_offset = tex_mapping.compile_begin(compiler, vector_in); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_TEX_BRICK, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			vector_offset, | 
					
						
							|  |  |  | 			compiler.stack_assign(color1_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(color2_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(mortar_in)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(scale_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(mortar_size_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(bias_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(brick_width_in)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(row_height_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							| 
									
										
										
										
											2016-10-30 01:33:10 +02:00
										 |  |  | 			compiler.stack_assign_if_linked(fac_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(mortar_smooth_in))); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 	compiler.add_node(compiler.encode_uchar4(offset_frequency, squash_frequency), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(scale), | 
					
						
							|  |  |  | 		__float_as_int(mortar_size), | 
					
						
							|  |  |  | 		__float_as_int(bias)); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.add_node(__float_as_int(brick_width), | 
					
						
							|  |  |  | 		__float_as_int(row_height), | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 		__float_as_int(offset), | 
					
						
							|  |  |  | 		__float_as_int(squash)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-30 01:33:10 +02:00
										 |  |  | 	compiler.add_node(__float_as_int(mortar_smooth), | 
					
						
							|  |  |  | 		SVM_STACK_INVALID, | 
					
						
							|  |  |  | 		SVM_STACK_INVALID, | 
					
						
							|  |  |  | 		SVM_STACK_INVALID); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile_end(compiler, vector_in, vector_offset); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BrickTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-20 17:40:10 +00:00
										 |  |  | 	tex_mapping.compile(compiler); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "offset"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "offset_frequency"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "squash"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "squash_frequency"); | 
					
						
							| 
									
										
										
										
											2012-09-04 13:29:07 +00:00
										 |  |  | 	compiler.add(this, "node_brick_texture"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | /* Point Density Texture */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(PointDensityTextureNode) | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("point_density_texture", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_STRING(filename, "Filename", ustring("")); | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum space_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	space_enum.insert("object", NODE_TEX_VOXEL_SPACE_OBJECT); | 
					
						
							|  |  |  | 	space_enum.insert("world", NODE_TEX_VOXEL_SPACE_WORLD); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(space, "Space", space_enum, NODE_TEX_VOXEL_SPACE_OBJECT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	static NodeEnum interpolation_enum; | 
					
						
							|  |  |  | 	interpolation_enum.insert("closest", INTERPOLATION_CLOSEST); | 
					
						
							|  |  |  | 	interpolation_enum.insert("linear", INTERPOLATION_LINEAR); | 
					
						
							|  |  |  | 	interpolation_enum.insert("cubic", INTERPOLATION_CUBIC); | 
					
						
							|  |  |  | 	interpolation_enum.insert("smart", INTERPOLATION_SMART); | 
					
						
							|  |  |  | 	SOCKET_ENUM(interpolation, "Interpolation", interpolation_enum, INTERPOLATION_LINEAR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_TRANSFORM(tfm, "Transform", transform_identity()); | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_POSITION); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(density, "Density"); | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | PointDensityTextureNode::PointDensityTextureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	image_manager = NULL; | 
					
						
							|  |  |  | 	slot = -1; | 
					
						
							|  |  |  | 	builtin_data = NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | PointDensityTextureNode::~PointDensityTextureNode() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 	if(image_manager) { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		image_manager->remove_image(filename.string(), | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 		                            builtin_data, | 
					
						
							|  |  |  | 		                            interpolation, | 
					
						
							| 
									
										
										
										
											2015-10-05 12:28:36 +05:00
										 |  |  | 		                            EXTENSION_CLIP); | 
					
						
							| 
									
										
										
										
											2015-07-21 21:58:19 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ShaderNode *PointDensityTextureNode::clone() const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	PointDensityTextureNode *node = new PointDensityTextureNode(*this); | 
					
						
							|  |  |  | 	node->image_manager = NULL; | 
					
						
							|  |  |  | 	node->slot = -1; | 
					
						
							|  |  |  | 	return node; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PointDensityTextureNode::attributes(Shader *shader, | 
					
						
							|  |  |  |                                          AttributeRequestSet *attributes) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(shader->has_volume) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_GENERATED_TRANSFORM); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PointDensityTextureNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *density_out = output("Density"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const bool use_density = !density_out->links.empty(); | 
					
						
							|  |  |  | 	const bool use_color = !color_out->links.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	image_manager = compiler.image_manager; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 19:08:28 +05:00
										 |  |  | 	if(use_density || use_color) { | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 		if(slot == -1) { | 
					
						
							|  |  |  | 			bool is_float, is_linear; | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 			slot = image_manager->add_image(filename.string(), builtin_data, | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 			                                false, 0, | 
					
						
							|  |  |  | 			                                is_float, is_linear, | 
					
						
							|  |  |  | 			                                interpolation, | 
					
						
							| 
									
										
										
										
											2015-10-05 12:28:36 +05:00
										 |  |  | 			                                EXTENSION_CLIP, | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 			                                true); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(slot != -1) { | 
					
						
							|  |  |  | 			compiler.stack_assign(vector_in); | 
					
						
							|  |  |  | 			compiler.add_node(NODE_TEX_VOXEL, | 
					
						
							|  |  |  | 			                  slot, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			                  compiler.encode_uchar4(compiler.stack_assign(vector_in), | 
					
						
							|  |  |  | 			                                         compiler.stack_assign_if_linked(density_out), | 
					
						
							|  |  |  | 			                                         compiler.stack_assign_if_linked(color_out), | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			                                         space)); | 
					
						
							|  |  |  | 			if(space == NODE_TEX_VOXEL_SPACE_WORLD) { | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 				compiler.add_node(tfm.x); | 
					
						
							|  |  |  | 				compiler.add_node(tfm.y); | 
					
						
							|  |  |  | 				compiler.add_node(tfm.z); | 
					
						
							|  |  |  | 				compiler.add_node(tfm.w); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			if(use_density) { | 
					
						
							|  |  |  | 				compiler.add_node(NODE_VALUE_F, | 
					
						
							| 
									
										
										
										
											2016-12-06 15:36:35 +01:00
										 |  |  | 				                  __float_as_int(0.0f), | 
					
						
							|  |  |  | 				                  compiler.stack_assign(density_out)); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-05-17 22:08:34 +02:00
										 |  |  | 			if(use_color) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 				compiler.add_node(NODE_VALUE_V, compiler.stack_assign(color_out)); | 
					
						
							|  |  |  | 				compiler.add_node(NODE_VALUE_V, make_float3(TEX_IMAGE_MISSING_R, | 
					
						
							| 
									
										
										
										
											2016-12-06 15:36:35 +01:00
										 |  |  | 				                                            TEX_IMAGE_MISSING_G, | 
					
						
							|  |  |  | 				                                            TEX_IMAGE_MISSING_B)); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void PointDensityTextureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *density_out = output("Density"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const bool use_density = !density_out->links.empty(); | 
					
						
							|  |  |  | 	const bool use_color = !color_out->links.empty(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	image_manager = compiler.image_manager; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 19:08:28 +05:00
										 |  |  | 	if(use_density || use_color) { | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 		if(slot == -1) { | 
					
						
							|  |  |  | 			bool is_float, is_linear; | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 			slot = image_manager->add_image(filename.string(), builtin_data, | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 			                                false, 0, | 
					
						
							|  |  |  | 			                                is_float, is_linear, | 
					
						
							|  |  |  | 			                                interpolation, | 
					
						
							| 
									
										
										
										
											2015-10-05 12:28:36 +05:00
										 |  |  | 			                                EXTENSION_CLIP, | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 			                                true); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(slot != -1) { | 
					
						
							|  |  |  | 			compiler.parameter("filename", string_printf("@%d", slot).c_str()); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		if(space == NODE_TEX_VOXEL_SPACE_WORLD) { | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 			compiler.parameter("mapping", transform_transpose(tfm)); | 
					
						
							|  |  |  | 			compiler.parameter("use_mapping", 1); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.parameter(this, "interpolation"); | 
					
						
							| 
									
										
										
										
											2015-07-18 22:09:20 +02:00
										 |  |  | 		compiler.add(this, "node_voxel_texture"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-16 18:15:07 +00:00
										 |  |  | /* Normal */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(NormalNode) | 
					
						
							| 
									
										
										
										
											2011-12-16 18:15:07 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("normal", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_VECTOR(direction, "direction", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(normal, "Normal"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(dot, "Dot"); | 
					
						
							| 
									
										
										
										
											2011-12-16 18:15:07 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NormalNode::NormalNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-12-16 18:15:07 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NormalNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							|  |  |  | 	ShaderOutput *normal_out = output("Normal"); | 
					
						
							|  |  |  | 	ShaderOutput *dot_out = output("Dot"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_NORMAL, | 
					
						
							|  |  |  | 		compiler.stack_assign(normal_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(normal_out), | 
					
						
							|  |  |  | 		compiler.stack_assign(dot_out)); | 
					
						
							| 
									
										
										
										
											2011-12-16 18:15:07 +00:00
										 |  |  | 	compiler.add_node( | 
					
						
							|  |  |  | 		__float_as_int(direction.x), | 
					
						
							|  |  |  | 		__float_as_int(direction.y), | 
					
						
							|  |  |  | 		__float_as_int(direction.z)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NormalNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "direction"); | 
					
						
							| 
									
										
										
										
											2011-12-16 18:15:07 +00:00
										 |  |  | 	compiler.add(this, "node_normal"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Mapping */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MappingNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("mapping", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	TEXTURE_MAPPING_DEFINE(MappingNode); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(vector, "Vector"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | MappingNode::MappingNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MappingNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *vector_out = output("Vector"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	tex_mapping.compile(compiler, compiler.stack_assign(vector_in), compiler.stack_assign(vector_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MappingNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-12 22:42:13 +00:00
										 |  |  | 	Transform tfm = transform_transpose(tex_mapping.compute_transform()); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.parameter("Matrix", tfm); | 
					
						
							| 
									
										
										
										
											2012-12-06 09:13:57 +00:00
										 |  |  | 	compiler.parameter_point("mapping_min", tex_mapping.min); | 
					
						
							|  |  |  | 	compiler.parameter_point("mapping_max", tex_mapping.max); | 
					
						
							|  |  |  | 	compiler.parameter("use_minmax", tex_mapping.use_minmax); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add(this, "node_mapping"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 12:24:47 +02:00
										 |  |  | /* RGBToBW */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(RGBToBWNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("rgb_to_bw", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-17 05:20:47 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(val, "Val"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 12:24:47 +02:00
										 |  |  | RGBToBWNode::RGBToBWNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2016-05-29 12:24:47 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void RGBToBWNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-05-29 12:24:47 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(linear_rgb_to_gray(color)); | 
					
						
							| 
									
										
										
										
											2016-05-29 12:24:47 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RGBToBWNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add_node(NODE_CONVERT, | 
					
						
							|  |  |  | 	                 NODE_CONVERT_CF, | 
					
						
							|  |  |  | 	                 compiler.stack_assign(inputs[0]), | 
					
						
							|  |  |  | 	                 compiler.stack_assign(outputs[0])); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RGBToBWNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-03 13:08:21 +02:00
										 |  |  | 	compiler.add(this, "node_rgb_to_bw"); | 
					
						
							| 
									
										
										
										
											2016-05-29 12:24:47 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Convert */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | const NodeType* ConvertNode::node_types[ConvertNode::MAX_TYPE][ConvertNode::MAX_TYPE]; | 
					
						
							|  |  |  | bool ConvertNode::initialized = ConvertNode::register_types(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Node* ConvertNode::create(const NodeType *type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return new ConvertNode(type->inputs[0].type,  type->outputs[0].type); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | bool ConvertNode::register_types() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const int num_types = 8; | 
					
						
							|  |  |  | 	SocketType::Type types[num_types] = {SocketType::FLOAT, | 
					
						
							|  |  |  | 	                                     SocketType::INT, | 
					
						
							|  |  |  | 	                                     SocketType::COLOR, | 
					
						
							|  |  |  | 	                                     SocketType::VECTOR, | 
					
						
							|  |  |  | 	                                     SocketType::POINT, | 
					
						
							|  |  |  | 	                                     SocketType::NORMAL, | 
					
						
							|  |  |  | 	                                     SocketType::STRING, | 
					
						
							|  |  |  | 										 SocketType::CLOSURE}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(size_t i = 0; i < num_types; i++) { | 
					
						
							|  |  |  | 		SocketType::Type from = types[i]; | 
					
						
							|  |  |  | 		ustring from_name(SocketType::type_name(from)); | 
					
						
							|  |  |  | 		ustring from_value_name("value_" + from_name.string()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for(size_t j = 0; j < num_types; j++) { | 
					
						
							|  |  |  | 			SocketType::Type to = types[j]; | 
					
						
							|  |  |  | 			ustring to_name(SocketType::type_name(to)); | 
					
						
							|  |  |  | 			ustring to_value_name("value_" + to_name.string()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			string node_name = "convert_" + from_name.string() + "_to_" + to_name.string(); | 
					
						
							|  |  |  | 			NodeType* type = NodeType::add(node_name.c_str(), create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			type->register_input(from_value_name, from_value_name, from, | 
					
						
							|  |  |  | 				SOCKET_OFFSETOF(ConvertNode, value_float), SocketType::zero_default_value(), | 
					
						
							|  |  |  | 				NULL, NULL, SocketType::LINKABLE); | 
					
						
							|  |  |  | 			type->register_output(to_value_name, to_value_name, to); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			assert(from < MAX_TYPE); | 
					
						
							|  |  |  | 			assert(to < MAX_TYPE); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			node_types[from][to] = type; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | ConvertNode::ConvertNode(SocketType::Type from_, SocketType::Type to_, bool autoconvert) | 
					
						
							|  |  |  | : ShaderNode(node_types[from_][to_]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	from = from_; | 
					
						
							|  |  |  | 	to = to_; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(from == to) | 
					
						
							|  |  |  | 		special_type = SHADER_SPECIAL_TYPE_PROXY; | 
					
						
							|  |  |  | 	else if(autoconvert) | 
					
						
							|  |  |  | 		special_type = SHADER_SPECIAL_TYPE_AUTOCONVERT; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void ConvertNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2015-12-23 21:41:59 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	/* proxy nodes should have been removed at this point */ | 
					
						
							|  |  |  | 	assert(special_type != SHADER_SPECIAL_TYPE_PROXY); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-23 21:41:59 +01:00
										 |  |  | 	/* TODO(DingTo): conversion from/to int is not supported yet, don't fold in that case */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 		if(from == SocketType::FLOAT) { | 
					
						
							| 
									
										
										
										
											2016-05-29 13:26:41 +02:00
										 |  |  | 			if(SocketType::is_float3(to)) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 				folder.make_constant(make_float3(value_float, value_float, value_float)); | 
					
						
							| 
									
										
										
										
											2016-05-29 13:26:41 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-12-23 21:41:59 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-05-29 13:26:41 +02:00
										 |  |  | 		else if(SocketType::is_float3(from)) { | 
					
						
							|  |  |  | 			if(to == SocketType::FLOAT) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 				if(from == SocketType::COLOR) { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 					/* color to float */ | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 					folder.make_constant(linear_rgb_to_gray(value_color)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				else { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 					/* vector/point/normal to float */ | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 					folder.make_constant(average(value_vector)); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-05-29 13:26:41 +02:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			else if(SocketType::is_float3(to)) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 				folder.make_constant(value_color); | 
					
						
							| 
									
										
										
										
											2016-05-29 13:26:41 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-12-23 21:41:59 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-02 12:22:43 +03:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		ShaderInput *in = inputs[0]; | 
					
						
							|  |  |  | 		ShaderNode *prev = in->link->parent; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* no-op conversion of A to B to A */ | 
					
						
							|  |  |  | 		if(prev->type == node_types[to][from]) { | 
					
						
							|  |  |  | 			ShaderInput *prev_in = prev->inputs[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(SocketType::is_float3(from) && (to == SocketType::FLOAT || SocketType::is_float3(to)) && prev_in->link) { | 
					
						
							|  |  |  | 				folder.bypass(prev_in->link); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-12-23 21:41:59 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void ConvertNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	/* proxy nodes should have been removed at this point */ | 
					
						
							|  |  |  | 	assert(special_type != SHADER_SPECIAL_TYPE_PROXY); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderInput *in = inputs[0]; | 
					
						
							|  |  |  | 	ShaderOutput *out = outputs[0]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	if(from == SocketType::FLOAT) { | 
					
						
							|  |  |  | 		if(to == SocketType::INT) | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 			/* float to int */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_FI, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			/* float to float3 */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_FV, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(from == SocketType::INT) { | 
					
						
							|  |  |  | 		if(to == SocketType::FLOAT) | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 			/* int to float */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_IF, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			/* int to vector/point/normal */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_IV, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(to == SocketType::FLOAT) { | 
					
						
							|  |  |  | 		if(from == SocketType::COLOR) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 			/* color to float */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_CF, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			/* vector/point/normal to float */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_VF, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(to == SocketType::INT) { | 
					
						
							|  |  |  | 		if(from == SocketType::COLOR) | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 			/* color to int */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_CI, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 		else | 
					
						
							|  |  |  | 			/* vector/point/normal to int */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_CONVERT, NODE_CONVERT_VI, compiler.stack_assign(in), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* float3 to float3 */ | 
					
						
							|  |  |  | 		if(in->link) { | 
					
						
							|  |  |  | 			/* no op in SVM */ | 
					
						
							|  |  |  | 			compiler.stack_link(in, out); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			/* set 0,0,0 value */ | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_V, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_V, value_color); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConvertNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	/* proxy nodes should have been removed at this point */ | 
					
						
							|  |  |  | 	assert(special_type != SHADER_SPECIAL_TYPE_PROXY); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	if(from == SocketType::FLOAT) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		compiler.add(this, "node_convert_from_float"); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(from == SocketType::INT) | 
					
						
							| 
									
										
										
										
											2012-10-20 13:11:45 +00:00
										 |  |  | 		compiler.add(this, "node_convert_from_int"); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(from == SocketType::COLOR) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		compiler.add(this, "node_convert_from_color"); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(from == SocketType::VECTOR) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		compiler.add(this, "node_convert_from_vector"); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(from == SocketType::POINT) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		compiler.add(this, "node_convert_from_point"); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:32:09 +02:00
										 |  |  | 	else if(from == SocketType::NORMAL) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		compiler.add(this, "node_convert_from_normal"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		assert(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | BsdfNode::BsdfNode(const NodeType *node_type) | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 19:11:37 +05:00
										 |  |  | 	special_type = SHADER_SPECIAL_TYPE_CLOSURE; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-03 22:39:17 +00:00
										 |  |  | void BsdfNode::compile(SVMCompiler& compiler, ShaderInput *param1, ShaderInput *param2, ShaderInput *param3, ShaderInput *param4) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							| 
									
										
										
										
											2012-10-17 12:17:17 +00:00
										 |  |  | 	ShaderInput *tangent_in = input("Tangent"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	if(color_in->link) | 
					
						
							|  |  |  | 		compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(color_in)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color); | 
					
						
							| 
									
										
										
										
											2012-11-04 22:31:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	int normal_offset = (normal_in) ? compiler.stack_assign_if_linked(normal_in) : SVM_STACK_INVALID; | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	int tangent_offset = (tangent_in) ? compiler.stack_assign_if_linked(tangent_in) : SVM_STACK_INVALID; | 
					
						
							|  |  |  | 	int param3_offset = (param3) ? compiler.stack_assign(param3) : SVM_STACK_INVALID; | 
					
						
							|  |  |  | 	int param4_offset = (param4) ? compiler.stack_assign(param4) : SVM_STACK_INVALID; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_CLOSURE_BSDF, | 
					
						
							| 
									
										
										
										
											2011-05-13 12:11:08 +00:00
										 |  |  | 		compiler.encode_uchar4(closure, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			(param1)? compiler.stack_assign(param1): SVM_STACK_INVALID, | 
					
						
							|  |  |  | 			(param2)? compiler.stack_assign(param2): SVM_STACK_INVALID, | 
					
						
							| 
									
										
										
										
											2011-09-12 13:13:56 +00:00
										 |  |  | 			compiler.closure_mix_weight_offset()), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int((param1)? get_float(param1->socket_type): 0.0f), | 
					
						
							|  |  |  | 		__float_as_int((param2)? get_float(param2->socket_type): 0.0f)); | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(normal_offset, tangent_offset, param3_offset, param4_offset); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compile(compiler, NULL, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-27 15:47:55 +05:00
										 |  |  | void BsdfNode::compile(OSLCompiler& /*compiler*/) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | /* Anisotropic BSDF Closure */ | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(AnisotropicBsdfNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("anisotropic_bsdf", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum distribution_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_ANISO_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	distribution_enum.insert("GGX", CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID); | 
					
						
							| 
									
										
											  
											
												Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
											
										 
											2016-06-23 22:56:43 +02:00
										 |  |  | 	distribution_enum.insert("Multiscatter GGX", CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID); | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	distribution_enum.insert("ashikhmin_shirley", CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ANISO_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_VECTOR(tangent, "Tangent", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_TANGENT); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(roughness, "Roughness", 0.2f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(rotation, "Rotation", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | AnisotropicBsdfNode::AnisotropicBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 18:53:57 +05:00
										 |  |  | 	closure = CLOSURE_BSDF_MICROFACET_GGX_ANISO_ID; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | void AnisotropicBsdfNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	if(shader->has_surface) { | 
					
						
							|  |  |  | 		ShaderInput *tangent_in = input("Tangent"); | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 		if(!tangent_in->link) | 
					
						
							|  |  |  | 			attributes->add(ATTR_STD_GENERATED); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | void AnisotropicBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
											
										 
											2016-06-23 22:56:43 +02:00
										 |  |  | 	if(closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ANISO_ID) | 
					
						
							|  |  |  | 		BsdfNode::compile(compiler, input("Roughness"), input("Anisotropy"), input("Rotation"), input("Color")); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		BsdfNode::compile(compiler, input("Roughness"), input("Anisotropy"), input("Rotation")); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | void AnisotropicBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "distribution"); | 
					
						
							| 
									
										
										
										
											2014-06-08 12:16:28 +02:00
										 |  |  | 	compiler.add(this, "node_anisotropic_bsdf"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Glossy BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(GlossyBsdfNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("glossy_bsdf", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum distribution_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	distribution_enum.insert("sharp", CLOSURE_BSDF_REFLECTION_ID); | 
					
						
							|  |  |  | 	distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	distribution_enum.insert("GGX", CLOSURE_BSDF_MICROFACET_GGX_ID); | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	distribution_enum.insert("ashikhmin_shirley", CLOSURE_BSDF_ASHIKHMIN_SHIRLEY_ID); | 
					
						
							| 
									
										
											  
											
												Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
											
										 
											2016-06-23 22:56:43 +02:00
										 |  |  | 	distribution_enum.insert("Multiscatter GGX", CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_ID); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(roughness, "Roughness", 0.2f); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | GlossyBsdfNode::GlossyBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 18:53:57 +05:00
										 |  |  | 	closure = CLOSURE_BSDF_MICROFACET_GGX_ID; | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	distribution_orig = NBUILTIN_CLOSURES; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | void GlossyBsdfNode::simplify_settings(Scene *scene) | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(distribution_orig == NBUILTIN_CLOSURES) { | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 		distribution_orig = distribution; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Integrator *integrator = scene->integrator; | 
					
						
							|  |  |  | 	if(integrator->filter_glossy == 0.0f) { | 
					
						
							|  |  |  | 		/* Fallback to Sharp closure for Roughness close to 0.
 | 
					
						
							|  |  |  | 		 * Note: Keep the epsilon in sync with kernel! | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2015-12-15 20:04:00 +05:00
										 |  |  | 		ShaderInput *roughness_input = input("Roughness"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		if(!roughness_input->link && roughness <= 1e-4f) { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			distribution = CLOSURE_BSDF_REFLECTION_ID; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		/* Rollback to original distribution when filter glossy is used. */ | 
					
						
							|  |  |  | 		distribution = distribution_orig; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GlossyBsdfNode::has_integrator_dependency() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-12-15 20:04:00 +05:00
										 |  |  | 	ShaderInput *roughness_input = input("Roughness"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return !roughness_input->link && roughness <= 1e-4f; | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void GlossyBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(closure == CLOSURE_BSDF_REFLECTION_ID) | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		BsdfNode::compile(compiler, NULL, NULL); | 
					
						
							| 
									
										
											  
											
												Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
											
										 
											2016-06-23 22:56:43 +02:00
										 |  |  | 	else if(closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_ID) | 
					
						
							|  |  |  | 		BsdfNode::compile(compiler, input("Roughness"), NULL, input("Color")); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		BsdfNode::compile(compiler, input("Roughness"), NULL); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GlossyBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "distribution"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_glossy_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Glass BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(GlassBsdfNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("glass_bsdf", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum distribution_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	distribution_enum.insert("sharp", CLOSURE_BSDF_SHARP_GLASS_ID); | 
					
						
							|  |  |  | 	distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_GLASS_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	distribution_enum.insert("GGX", CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID); | 
					
						
							| 
									
										
											  
											
												Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
											
										 
											2016-06-23 22:56:43 +02:00
										 |  |  | 	distribution_enum.insert("Multiscatter GGX", CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(IOR, "IOR", 0.3f); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | GlassBsdfNode::GlassBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 18:53:57 +05:00
										 |  |  | 	closure = CLOSURE_BSDF_SHARP_GLASS_ID; | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	distribution_orig = NBUILTIN_CLOSURES; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | void GlassBsdfNode::simplify_settings(Scene *scene) | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(distribution_orig == NBUILTIN_CLOSURES) { | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 		distribution_orig = distribution; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Integrator *integrator = scene->integrator; | 
					
						
							|  |  |  | 	if(integrator->filter_glossy == 0.0f) { | 
					
						
							|  |  |  | 		/* Fallback to Sharp closure for Roughness close to 0.
 | 
					
						
							|  |  |  | 		 * Note: Keep the epsilon in sync with kernel! | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2015-12-15 20:04:00 +05:00
										 |  |  | 		ShaderInput *roughness_input = input("Roughness"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		if(!roughness_input->link && roughness <= 1e-4f) { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			distribution = CLOSURE_BSDF_SHARP_GLASS_ID; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* Rollback to original distribution when filter glossy is used. */ | 
					
						
							|  |  |  | 		distribution = distribution_orig; | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool GlassBsdfNode::has_integrator_dependency() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-12-15 20:04:00 +05:00
										 |  |  | 	ShaderInput *roughness_input = input("Roughness"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return !roughness_input->link && roughness <= 1e-4f; | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void GlassBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	if(closure == CLOSURE_BSDF_SHARP_GLASS_ID) | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		BsdfNode::compile(compiler, NULL, input("IOR")); | 
					
						
							| 
									
										
											  
											
												Cycles: Add multi-scattering, energy-conserving GGX as an option to the Glossy, Anisotropic and Glass BSDFs
This commit adds a new distribution to the Glossy, Anisotropic and Glass BSDFs that implements the
multiple-scattering microfacet model described in the paper "Multiple-Scattering Microfacet BSDFs with the Smith Model".
Essentially, the improvement is that unlike classical GGX, which only models single scattering and assumes
the contribution of multiple bounces to be zero, this new model performs a random walk on the microsurface until
the ray leaves it again, which ensures perfect energy conservation.
In practise, this means that the "darkening problem" - GGX materials becoming darker with increasing
roughness - is solved in a physically correct and efficient way.
The downside of this model is that it has no (known) analytic expression for evalation. However, it can be
evaluated stochastically, and although the correct PDF isn't known either, the properties of MIS and the
balance heuristic guarantee an unbiased result at the cost of slightly higher noise.
Reviewers: dingto, #cycles, brecht
Reviewed By: dingto, #cycles, brecht
Subscribers: bliblubli, ace_dragon, gregzaal, brecht, harvester, dingto, marcog, swerner, jtheninja, Blendify, nutel
Differential Revision: https://developer.blender.org/D2002
											
										 
											2016-06-23 22:56:43 +02:00
										 |  |  | 	else if(closure == CLOSURE_BSDF_MICROFACET_MULTI_GGX_GLASS_ID) | 
					
						
							|  |  |  | 		BsdfNode::compile(compiler, input("Roughness"), input("IOR"), input("Color")); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 		BsdfNode::compile(compiler, input("Roughness"), input("IOR")); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GlassBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "distribution"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_glass_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | /* Refraction BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(RefractionBsdfNode) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("refraction_bsdf", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum distribution_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	distribution_enum.insert("sharp", CLOSURE_BSDF_REFRACTION_ID); | 
					
						
							|  |  |  | 	distribution_enum.insert("beckmann", CLOSURE_BSDF_MICROFACET_BECKMANN_REFRACTION_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	distribution_enum.insert("GGX", CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID); | 
					
						
							|  |  |  | 	SOCKET_ENUM(distribution, "Distribution", distribution_enum, CLOSURE_BSDF_MICROFACET_GGX_REFRACTION_ID); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(IOR, "IOR", 0.3f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | RefractionBsdfNode::RefractionBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 18:53:57 +05:00
										 |  |  | 	closure = CLOSURE_BSDF_REFRACTION_ID; | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	distribution_orig = NBUILTIN_CLOSURES; | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | void RefractionBsdfNode::simplify_settings(Scene *scene) | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(distribution_orig == NBUILTIN_CLOSURES) { | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 		distribution_orig = distribution; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	Integrator *integrator = scene->integrator; | 
					
						
							|  |  |  | 	if(integrator->filter_glossy == 0.0f) { | 
					
						
							|  |  |  | 		/* Fallback to Sharp closure for Roughness close to 0.
 | 
					
						
							|  |  |  | 		 * Note: Keep the epsilon in sync with kernel! | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2015-12-15 20:04:00 +05:00
										 |  |  | 		ShaderInput *roughness_input = input("Roughness"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		if(!roughness_input->link && roughness <= 1e-4f) { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			distribution = CLOSURE_BSDF_REFRACTION_ID; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		/* Rollback to original distribution when filter glossy is used. */ | 
					
						
							|  |  |  | 		distribution = distribution_orig; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2015-11-20 18:18:27 +05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool RefractionBsdfNode::has_integrator_dependency() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-12-15 20:04:00 +05:00
										 |  |  | 	ShaderInput *roughness_input = input("Roughness"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return !roughness_input->link && roughness <= 1e-4f; | 
					
						
							| 
									
										
										
										
											2015-11-18 18:47:56 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | void RefractionBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = distribution; | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(closure == CLOSURE_BSDF_REFRACTION_ID) | 
					
						
							|  |  |  | 		BsdfNode::compile(compiler, NULL, input("IOR")); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		BsdfNode::compile(compiler, input("Roughness"), input("IOR")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RefractionBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "distribution"); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	compiler.add(this, "node_refraction_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | /* Toon BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ToonBsdfNode) | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("toon_bsdf", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum component_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	component_enum.insert("diffuse", CLOSURE_BSDF_DIFFUSE_TOON_ID); | 
					
						
							|  |  |  | 	component_enum.insert("glossy", CLOSURE_BSDF_GLOSSY_TOON_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(component, "Component", component_enum, CLOSURE_BSDF_DIFFUSE_TOON_ID); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(size, "Size", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(smooth, "Smooth", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ToonBsdfNode::ToonBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 18:53:57 +05:00
										 |  |  | 	closure = CLOSURE_BSDF_DIFFUSE_TOON_ID; | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToonBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = component; | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	BsdfNode::compile(compiler, input("Size"), input("Smooth")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ToonBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "component"); | 
					
						
							| 
									
										
										
										
											2013-05-23 17:45:20 +00:00
										 |  |  | 	compiler.add(this, "node_toon_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Velvet BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(VelvetBsdfNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("velvet_bsdf", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(sigma, "Sigma", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | VelvetBsdfNode::VelvetBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	closure = CLOSURE_BSDF_ASHIKHMIN_VELVET_ID; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VelvetBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	BsdfNode::compile(compiler, input("Sigma"), NULL); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VelvetBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_velvet_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Diffuse BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(DiffuseBsdfNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("diffuse_bsdf", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(roughness, "Roughness", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | DiffuseBsdfNode::DiffuseBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	closure = CLOSURE_BSDF_DIFFUSE_ID; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiffuseBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-11-14 17:31:47 +00:00
										 |  |  | 	BsdfNode::compile(compiler, input("Roughness"), NULL); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void DiffuseBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_diffuse_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Translucent BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(TranslucentBsdfNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("translucent_bsdf", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | TranslucentBsdfNode::TranslucentBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	closure = CLOSURE_BSDF_TRANSLUCENT_ID; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TranslucentBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BsdfNode::compile(compiler, NULL, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TranslucentBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_translucent_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Transparent BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(TransparentBsdfNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("transparent_bsdf", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | TransparentBsdfNode::TransparentBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	closure = CLOSURE_BSDF_TRANSPARENT_ID; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TransparentBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	BsdfNode::compile(compiler, NULL, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TransparentBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_transparent_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 20:26:52 +00:00
										 |  |  | /* Subsurface Scattering Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(SubsurfaceScatteringNode) | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("subsurface_scattering", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum falloff_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	falloff_enum.insert("cubic", CLOSURE_BSSRDF_CUBIC_ID); | 
					
						
							|  |  |  | 	falloff_enum.insert("gaussian", CLOSURE_BSSRDF_GAUSSIAN_ID); | 
					
						
							|  |  |  | 	falloff_enum.insert("burley", CLOSURE_BSSRDF_BURLEY_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(falloff, "Falloff", falloff_enum, CLOSURE_BSSRDF_BURLEY_ID); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(scale, "Scale", 0.01f); | 
					
						
							|  |  |  | 	SOCKET_IN_VECTOR(radius, "Radius", make_float3(0.1f, 0.1f, 0.1f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(sharpness, "Sharpness", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(texture_blur, "Texture Blur", 1.0f); | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_CLOSURE(BSSRDF, "BSSRDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-01 20:26:52 +00:00
										 |  |  | SubsurfaceScatteringNode::SubsurfaceScatteringNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-04-01 20:26:52 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-29 01:04:01 +02:00
										 |  |  | 	closure = falloff; | 
					
						
							| 
									
										
										
										
											2013-04-01 20:26:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SubsurfaceScatteringNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = falloff; | 
					
						
							| 
									
										
										
										
											2013-09-03 22:39:17 +00:00
										 |  |  | 	BsdfNode::compile(compiler, input("Scale"), input("Texture Blur"), input("Radius"), input("Sharpness")); | 
					
						
							| 
									
										
										
										
											2013-04-01 20:26:52 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SubsurfaceScatteringNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-29 01:04:01 +02:00
										 |  |  | 	closure = falloff; | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "falloff"); | 
					
						
							| 
									
										
										
										
											2013-04-01 20:26:52 +00:00
										 |  |  | 	compiler.add(this, "node_subsurface_scattering"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | bool SubsurfaceScatteringNode::has_bssrdf_bump() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* detect if anything is plugged into the normal input besides the default */ | 
					
						
							|  |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							|  |  |  | 	return (normal_in->link && normal_in->link->parent->special_type != SHADER_SPECIAL_TYPE_GEOMETRY); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Emissive Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(EmissionNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("emission", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							| 
									
										
										
										
											2016-07-27 14:04:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(strength, "Strength", 10.0f); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(emission, "Emission"); | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | EmissionNode::EmissionNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EmissionNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderInput *strength_in = input("Strength"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(color_in->link || strength_in->link) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_EMISSION_WEIGHT, | 
					
						
							|  |  |  | 		                  compiler.stack_assign(color_in), | 
					
						
							| 
									
										
										
										
											2016-07-27 14:04:28 +02:00
										 |  |  | 		                  compiler.stack_assign(strength_in)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color * strength); | 
					
						
							| 
									
										
										
										
											2011-09-12 13:13:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_CLOSURE_EMISSION, compiler.closure_mix_weight_offset()); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void EmissionNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_emission"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void EmissionNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderInput *strength_in = input("Strength"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 12:26:12 +02:00
										 |  |  | 	if((!color_in->link && color == make_float3(0.0f, 0.0f, 0.0f)) || | 
					
						
							|  |  |  | 	   (!strength_in->link && strength == 0.0f)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		folder.discard(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Background Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(BackgroundNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("background_shader", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(strength, "Strength", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(background, "Background"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | BackgroundNode::BackgroundNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BackgroundNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderInput *strength_in = input("Strength"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(color_in->link || strength_in->link) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_EMISSION_WEIGHT, | 
					
						
							|  |  |  | 		                  compiler.stack_assign(color_in), | 
					
						
							| 
									
										
										
										
											2016-12-06 15:36:35 +01:00
										 |  |  | 		                  compiler.stack_assign(strength_in)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color*strength); | 
					
						
							| 
									
										
										
										
											2011-09-12 13:13:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-10-19 00:13:41 +00:00
										 |  |  | 	compiler.add_node(NODE_CLOSURE_BACKGROUND, compiler.closure_mix_weight_offset()); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BackgroundNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_background"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void BackgroundNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderInput *strength_in = input("Strength"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 12:26:12 +02:00
										 |  |  | 	if((!color_in->link && color == make_float3(0.0f, 0.0f, 0.0f)) || | 
					
						
							|  |  |  | 	   (!strength_in->link && strength == 0.0f)) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		folder.discard(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-28 13:55:59 +00:00
										 |  |  | /* Holdout Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(HoldoutNode) | 
					
						
							| 
									
										
										
										
											2011-08-28 13:55:59 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("holdout", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(holdout, "Holdout"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HoldoutNode::HoldoutNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-08-28 13:55:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HoldoutNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-30 18:55:04 +00:00
										 |  |  | 	float3 value = make_float3(1.0f, 1.0f, 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_CLOSURE_SET_WEIGHT, value); | 
					
						
							| 
									
										
										
										
											2011-09-12 13:13:56 +00:00
										 |  |  | 	compiler.add_node(NODE_CLOSURE_HOLDOUT, compiler.closure_mix_weight_offset()); | 
					
						
							| 
									
										
										
										
											2011-08-28 13:55:59 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HoldoutNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_holdout"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | /* Ambient Occlusion */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(AmbientOcclusionNode) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("ambient_occlusion", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(AO, "AO"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | AmbientOcclusionNode::AmbientOcclusionNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void AmbientOcclusionNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	if(color_in->link) | 
					
						
							|  |  |  | 		compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(color_in)); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_CLOSURE_AMBIENT_OCCLUSION, compiler.closure_mix_weight_offset()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AmbientOcclusionNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_ambient_occlusion"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | /* Volume Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | VolumeNode::VolumeNode(const NodeType *node_type) | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	closure = CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID; | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VolumeNode::compile(SVMCompiler& compiler, ShaderInput *param1, ShaderInput *param2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	if(color_in->link) | 
					
						
							|  |  |  | 		compiler.add_node(NODE_CLOSURE_WEIGHT, compiler.stack_assign(color_in)); | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		compiler.add_node(NODE_CLOSURE_SET_WEIGHT, color); | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_CLOSURE_VOLUME, | 
					
						
							|  |  |  | 		compiler.encode_uchar4(closure, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			(param1)? compiler.stack_assign(param1): SVM_STACK_INVALID, | 
					
						
							|  |  |  | 			(param2)? compiler.stack_assign(param2): SVM_STACK_INVALID, | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | 			compiler.closure_mix_weight_offset()), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int((param1)? get_float(param1->socket_type): 0.0f), | 
					
						
							|  |  |  | 		__float_as_int((param2)? get_float(param2->socket_type): 0.0f)); | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VolumeNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compile(compiler, NULL, NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-27 15:47:55 +05:00
										 |  |  | void VolumeNode::compile(OSLCompiler& /*compiler*/) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | /* Absorption Volume Closure */ | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(AbsorptionVolumeNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("absorption_volume", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(density, "Density", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(volume, "Volume"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | AbsorptionVolumeNode::AbsorptionVolumeNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : VolumeNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	closure = CLOSURE_VOLUME_ABSORPTION_ID; | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | void AbsorptionVolumeNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	VolumeNode::compile(compiler, input("Density"), NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | void AbsorptionVolumeNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	compiler.add(this, "node_absorption_volume"); | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | /* Scatter Volume Closure */ | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ScatterVolumeNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("scatter_volume", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(density, "Density", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(anisotropy, "Anisotropy", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(volume_mix_weight, "VolumeMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(volume, "Volume"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | ScatterVolumeNode::ScatterVolumeNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : VolumeNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	closure = CLOSURE_VOLUME_HENYEY_GREENSTEIN_ID; | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | void ScatterVolumeNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	VolumeNode::compile(compiler, input("Density"), input("Anisotropy")); | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | void ScatterVolumeNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	compiler.add(this, "node_scatter_volume"); | 
					
						
							| 
									
										
										
										
											2011-09-27 20:03:16 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | /* Hair BSDF Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(HairBsdfNode) | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("hair_bsdf", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.8f, 0.8f, 0.8f)); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(surface_mix_weight, "SurfaceMixWeight", 0.0f, SocketType::SVM_INTERNAL); | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum component_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	component_enum.insert("reflection", CLOSURE_BSDF_HAIR_REFLECTION_ID); | 
					
						
							|  |  |  | 	component_enum.insert("transmission", CLOSURE_BSDF_HAIR_TRANSMISSION_ID); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(component, "Component", component_enum, CLOSURE_BSDF_HAIR_REFLECTION_ID); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(offset, "Offset", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(roughness_u, "RoughnessU", 0.2f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(roughness_v, "RoughnessV", 0.2f); | 
					
						
							|  |  |  | 	SOCKET_IN_VECTOR(tangent, "Tangent", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_CLOSURE(BSDF, "BSDF"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | HairBsdfNode::HairBsdfNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : BsdfNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-05-09 18:53:57 +05:00
										 |  |  | 	closure = CLOSURE_BSDF_HAIR_REFLECTION_ID; | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HairBsdfNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	closure = component; | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	BsdfNode::compile(compiler, input("RoughnessU"), input("RoughnessV"), input("Offset")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HairBsdfNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "component"); | 
					
						
							| 
									
										
										
										
											2013-09-15 23:58:00 +00:00
										 |  |  | 	compiler.add(this, "node_hair_bsdf"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Geometry */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(GeometryNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("geometry", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(position, "Position"); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(normal, "Normal"); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(tangent, "Tangent"); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(true_normal, "True Normal"); | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(incoming, "Incoming"); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(parametric, "Parametric"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(backfacing, "Backfacing"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(pointiness, "Pointiness"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | GeometryNode::GeometryNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-08-18 14:15:57 +00:00
										 |  |  | 	special_type = SHADER_SPECIAL_TYPE_GEOMETRY; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void GeometryNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	if(shader->has_surface) { | 
					
						
							| 
									
										
										
										
											2015-02-06 12:35:46 +05:00
										 |  |  | 		if(!output("Tangent")->links.empty()) { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 			attributes->add(ATTR_STD_GENERATED); | 
					
						
							| 
									
										
										
										
											2015-02-06 12:35:46 +05:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(!output("Pointiness")->links.empty()) { | 
					
						
							|  |  |  | 			attributes->add(ATTR_STD_POINTINESS); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2012-10-10 13:02:20 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void GeometryNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out; | 
					
						
							| 
									
										
										
										
											2016-05-07 19:47:37 +02:00
										 |  |  | 	ShaderNodeType geom_node = NODE_GEOMETRY; | 
					
						
							|  |  |  | 	ShaderNodeType attr_node = NODE_ATTR; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-21 12:55:19 +01:00
										 |  |  | 	if(bump == SHADER_BUMP_DX) { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		geom_node = NODE_GEOMETRY_BUMP_DX; | 
					
						
							| 
									
										
										
										
											2015-02-21 12:55:19 +01:00
										 |  |  | 		attr_node = NODE_ATTR_BUMP_DX; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		geom_node = NODE_GEOMETRY_BUMP_DY; | 
					
						
							| 
									
										
										
										
											2015-02-21 12:55:19 +01:00
										 |  |  | 		attr_node = NODE_ATTR_BUMP_DY; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Position"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(geom_node, NODE_GEOM_P, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Normal"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(geom_node, NODE_GEOM_N, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Tangent"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(geom_node, NODE_GEOM_T, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("True Normal"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(geom_node, NODE_GEOM_Ng, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Incoming"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(geom_node, NODE_GEOM_I, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 15:22:15 +00:00
										 |  |  | 	out = output("Parametric"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(geom_node, NODE_GEOM_uv, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Backfacing"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_backfacing, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-02-06 12:35:46 +05:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Pointiness"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2015-04-06 14:11:28 +05:00
										 |  |  | 		if(compiler.output_type() != SHADER_TYPE_VOLUME) { | 
					
						
							|  |  |  | 			compiler.add_node(attr_node, | 
					
						
							|  |  |  | 			                  ATTR_STD_POINTINESS, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			                  compiler.stack_assign(out), | 
					
						
							| 
									
										
										
										
											2015-04-06 14:11:28 +05:00
										 |  |  | 			                  NODE_ATTR_FLOAT); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_VALUE_F, __float_as_int(0.0f), compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2015-04-06 14:11:28 +05:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-02-06 12:35:46 +05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GeometryNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(bump == SHADER_BUMP_DX) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dx"); | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dy"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "center"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add(this, "node_geometry"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* TextureCoordinate */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(TextureCoordinateNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("texture_coordinate", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_BOOLEAN(from_dupli, "From Dupli", false); | 
					
						
							|  |  |  | 	SOCKET_BOOLEAN(use_transform, "Use Transform", false); | 
					
						
							|  |  |  | 	SOCKET_TRANSFORM(ob_tfm, "Object Transform", transform_identity()); | 
					
						
							| 
									
										
										
										
											2012-10-05 14:54:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(generated, "Generated"); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(normal, "Normal"); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(UV, "UV"); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(object, "Object"); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(camera, "Camera"); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(window, "Window"); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(reflection, "Reflection"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TextureCoordinateNode::TextureCoordinateNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void TextureCoordinateNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	if(shader->has_surface) { | 
					
						
							|  |  |  | 		if(!from_dupli) { | 
					
						
							|  |  |  | 			if(!output("Generated")->links.empty()) | 
					
						
							|  |  |  | 				attributes->add(ATTR_STD_GENERATED); | 
					
						
							|  |  |  | 			if(!output("UV")->links.empty()) | 
					
						
							|  |  |  | 				attributes->add(ATTR_STD_UV); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-10-06 11:52:54 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:33:55 +01:00
										 |  |  | 	if(shader->has_volume) { | 
					
						
							|  |  |  | 		if(!from_dupli) { | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 			if(!output("Generated")->links.empty()) { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:33:55 +01:00
										 |  |  | 				attributes->add(ATTR_STD_GENERATED_TRANSFORM); | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-31 17:33:55 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextureCoordinateNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out; | 
					
						
							| 
									
										
										
										
											2016-05-07 19:47:37 +02:00
										 |  |  | 	ShaderNodeType texco_node = NODE_TEX_COORD; | 
					
						
							|  |  |  | 	ShaderNodeType attr_node = NODE_ATTR; | 
					
						
							|  |  |  | 	ShaderNodeType geom_node = NODE_GEOMETRY; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(bump == SHADER_BUMP_DX) { | 
					
						
							|  |  |  | 		texco_node = NODE_TEX_COORD_BUMP_DX; | 
					
						
							|  |  |  | 		attr_node = NODE_ATTR_BUMP_DX; | 
					
						
							|  |  |  | 		geom_node = NODE_GEOMETRY_BUMP_DX; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) { | 
					
						
							|  |  |  | 		texco_node = NODE_TEX_COORD_BUMP_DY; | 
					
						
							|  |  |  | 		attr_node = NODE_ATTR_BUMP_DY; | 
					
						
							|  |  |  | 		geom_node = NODE_GEOMETRY_BUMP_DY; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Generated"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							|  |  |  | 		if(compiler.background) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(geom_node, NODE_GEOM_P, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 			if(from_dupli) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 				compiler.add_node(texco_node, NODE_TEXCO_DUPLI_GENERATED, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-31 17:33:55 +01:00
										 |  |  | 			else if(compiler.output_type() == SHADER_TYPE_VOLUME) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 				compiler.add_node(texco_node, NODE_TEXCO_VOLUME_GENERATED, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2013-12-31 17:33:55 +01:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 			else { | 
					
						
							|  |  |  | 				int attr = compiler.attribute(ATTR_STD_GENERATED); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 				compiler.add_node(attr_node, attr, compiler.stack_assign(out), NODE_ATTR_FLOAT3); | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
											  
											
												Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
  and the initial bounding/splitting is still single threaded, but recursive
  splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
  code from the Embree raytracer from Intel.
  http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
  some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
											
										 
											2012-04-28 08:53:59 +00:00
										 |  |  | 	out = output("Normal"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(texco_node, NODE_TEXCO_NORMAL, compiler.stack_assign(out)); | 
					
						
							| 
									
										
											  
											
												Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
  and the initial bounding/splitting is still single threaded, but recursive
  splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
  code from the Embree raytracer from Intel.
  http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
  some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
											
										 
											2012-04-28 08:53:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	out = output("UV"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 		if(from_dupli) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(texco_node, NODE_TEXCO_DUPLI_UV, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2012-10-06 11:52:54 +00:00
										 |  |  | 			int attr = compiler.attribute(ATTR_STD_UV); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(attr_node, attr, compiler.stack_assign(out), NODE_ATTR_FLOAT3); | 
					
						
							| 
									
										
										
										
											2012-10-04 21:40:39 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Object"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(texco_node, NODE_TEXCO_OBJECT, compiler.stack_assign(out), use_transform); | 
					
						
							| 
									
										
										
										
											2015-01-21 22:19:31 +05:00
										 |  |  | 		if(use_transform) { | 
					
						
							|  |  |  | 			Transform ob_itfm = transform_inverse(ob_tfm); | 
					
						
							|  |  |  | 			compiler.add_node(ob_itfm.x); | 
					
						
							|  |  |  | 			compiler.add_node(ob_itfm.y); | 
					
						
							|  |  |  | 			compiler.add_node(ob_itfm.z); | 
					
						
							|  |  |  | 			compiler.add_node(ob_itfm.w); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Camera"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(texco_node, NODE_TEXCO_CAMERA, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Window"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(texco_node, NODE_TEXCO_WINDOW, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Reflection"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							|  |  |  | 		if(compiler.background) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(geom_node, NODE_GEOM_I, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(texco_node, NODE_TEXCO_REFLECTION, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TextureCoordinateNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(bump == SHADER_BUMP_DX) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dx"); | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dy"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "center"); | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if(compiler.background) | 
					
						
							|  |  |  | 		compiler.parameter("is_background", true); | 
					
						
							| 
									
										
										
										
											2013-12-31 17:33:55 +01:00
										 |  |  | 	if(compiler.output_type() == SHADER_TYPE_VOLUME) | 
					
						
							|  |  |  | 		compiler.parameter("is_volume", true); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "use_transform"); | 
					
						
							| 
									
										
										
										
											2015-01-21 22:19:31 +05:00
										 |  |  | 	Transform ob_itfm = transform_transpose(transform_inverse(ob_tfm)); | 
					
						
							|  |  |  | 	compiler.parameter("object_itfm", ob_itfm); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "from_dupli"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add(this, "node_texture_coordinate"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | /* UV Map */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(UVMapNode) | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("uvmap", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_STRING(attribute, "attribute", ustring("")); | 
					
						
							|  |  |  | 	SOCKET_IN_BOOLEAN(from_dupli, "from dupli", false); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(UV, "UV"); | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | UVMapNode::UVMapNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UVMapNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(shader->has_surface) { | 
					
						
							|  |  |  | 		if(!from_dupli) { | 
					
						
							|  |  |  | 			if(!output("UV")->links.empty()) { | 
					
						
							| 
									
										
										
										
											2015-03-28 00:15:15 +05:00
										 |  |  | 				if(attribute != "") | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 					attributes->add(attribute); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					attributes->add(ATTR_STD_UV); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UVMapNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out = output("UV"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:47:37 +02:00
										 |  |  | 	ShaderNodeType texco_node = NODE_TEX_COORD; | 
					
						
							|  |  |  | 	ShaderNodeType attr_node = NODE_ATTR; | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 	int attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 13:15:45 +02:00
										 |  |  | 	if(bump == SHADER_BUMP_DX) { | 
					
						
							|  |  |  | 		texco_node = NODE_TEX_COORD_BUMP_DX; | 
					
						
							|  |  |  | 		attr_node = NODE_ATTR_BUMP_DX; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) { | 
					
						
							|  |  |  | 		texco_node = NODE_TEX_COORD_BUMP_DY; | 
					
						
							|  |  |  | 		attr_node = NODE_ATTR_BUMP_DY; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 	if(!out->links.empty()) { | 
					
						
							|  |  |  | 		if(from_dupli) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(texco_node, NODE_TEXCO_DUPLI_UV, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2015-03-28 00:15:15 +05:00
										 |  |  | 			if(attribute != "") | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 				attr = compiler.attribute(attribute); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				attr = compiler.attribute(ATTR_STD_UV); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(attr_node, attr, compiler.stack_assign(out), NODE_ATTR_FLOAT3); | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void UVMapNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2014-04-21 13:15:45 +02:00
										 |  |  | 	if(bump == SHADER_BUMP_DX) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dx"); | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dy"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "center"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "from_dupli"); | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	compiler.parameter(this, "attribute"); | 
					
						
							| 
									
										
										
										
											2014-04-02 11:40:29 +02:00
										 |  |  | 	compiler.add(this, "node_uv_map"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Light Path */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(LightPathNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("light_path", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_camera_ray, "Is Camera Ray"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_shadow_ray, "Is Shadow Ray"); | 
					
						
							| 
									
										
										
										
											2016-06-13 14:08:06 +02:00
										 |  |  | 	SOCKET_OUT_FLOAT(is_diffuse_ray, "Is Diffuse Ray"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_FLOAT(is_glossy_ray, "Is Glossy Ray"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_singular_ray, "Is Singular Ray"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_reflection_ray, "Is Reflection Ray"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_transmission_ray, "Is Transmission Ray"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_volume_scatter_ray, "Is Volume Scatter Ray"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(ray_length, "Ray Length"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(ray_depth, "Ray Depth"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(transparent_depth, "Transparent Depth"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(transmission_depth, "Transmission Depth"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | LightPathNode::LightPathNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LightPathNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Is Camera Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_camera, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Is Shadow Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_shadow, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Is Diffuse Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_diffuse, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Is Glossy Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_glossy, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-01 15:53:36 +00:00
										 |  |  | 	out = output("Is Singular Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_singular, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-09-01 15:53:36 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	out = output("Is Reflection Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_reflection, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-01 15:53:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	out = output("Is Transmission Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_transmission, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-02 17:03:46 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	out = output("Is Volume Scatter Ray"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_volume_scatter, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2013-12-28 01:54:44 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-02 17:03:46 +00:00
										 |  |  | 	out = output("Ray Length"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_length, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-05-02 17:03:46 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-31 20:30:37 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Ray Depth"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_depth, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2013-07-31 20:30:37 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-05-02 17:03:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-21 14:20:29 +02:00
										 |  |  | 	out = output("Transparent Depth"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_transparent, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2014-04-21 14:20:29 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-06 23:38:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Transmission Depth"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LIGHT_PATH, NODE_LP_ray_transmission, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2016-01-06 23:38:13 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LightPathNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_light_path"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | /* Light Falloff */ | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(LightFalloffNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("light_fallof", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(strength, "Strength", 100.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(smooth, "Smooth", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(quadratic, "Quadratic"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(linear, "Linear"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(constant, "Constant"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | LightFalloffNode::LightFalloffNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LightFalloffNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *strength_in = input("Strength"); | 
					
						
							|  |  |  | 	ShaderInput *smooth_in = input("Smooth"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ShaderOutput *out = output("Quadratic"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							|  |  |  | 		compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_QUADRATIC, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.encode_uchar4( | 
					
						
							|  |  |  | 				compiler.stack_assign(strength_in), | 
					
						
							|  |  |  | 				compiler.stack_assign(smooth_in), | 
					
						
							|  |  |  | 				compiler.stack_assign(out))); | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Linear"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							|  |  |  | 		compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_LINEAR, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.encode_uchar4( | 
					
						
							|  |  |  | 				compiler.stack_assign(strength_in), | 
					
						
							|  |  |  | 				compiler.stack_assign(smooth_in), | 
					
						
							|  |  |  | 				compiler.stack_assign(out))); | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Constant"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							|  |  |  | 		compiler.add_node(NODE_LIGHT_FALLOFF, NODE_LIGHT_FALLOFF_CONSTANT, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.encode_uchar4( | 
					
						
							|  |  |  | 				compiler.stack_assign(strength_in), | 
					
						
							|  |  |  | 				compiler.stack_assign(smooth_in), | 
					
						
							|  |  |  | 				compiler.stack_assign(out))); | 
					
						
							| 
									
										
										
										
											2012-05-07 20:24:38 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void LightFalloffNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_light_falloff"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | /* Object Info */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ObjectInfoNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("object_info", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(location, "Location"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(object_index, "Object Index"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(material_index, "Material Index"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(random, "Random"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | ObjectInfoNode::ObjectInfoNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectInfoNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out = output("Location"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_OBJECT_INFO, NODE_INFO_OB_LOCATION, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Object Index"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_OBJECT_INFO, NODE_INFO_OB_INDEX, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Material Index"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_OBJECT_INFO, NODE_INFO_MAT_INDEX, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Random"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_OBJECT_INFO, NODE_INFO_OB_RANDOM, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-05-21 12:52:28 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ObjectInfoNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_object_info"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | /* Particle Info */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ParticleInfoNode) | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("particle_info", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(index, "Index"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(age, "Age"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(lifetime, "Lifetime"); | 
					
						
							|  |  |  | 	SOCKET_OUT_POINT(location, "Location"); | 
					
						
							| 
									
										
										
										
											2013-12-22 14:11:10 +11:00
										 |  |  | #if 0	/* not yet supported */
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_QUATERNION(rotation, "Rotation"); | 
					
						
							| 
									
										
										
										
											2013-12-22 14:11:10 +11:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_FLOAT(size, "Size"); | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(velocity, "Velocity"); | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(angular_velocity, "Angular Velocity"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ParticleInfoNode::ParticleInfoNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void ParticleInfoNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-07-26 11:40:58 +00:00
										 |  |  | 	if(!output("Index")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | 	if(!output("Age")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							|  |  |  | 	if(!output("Lifetime")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	if(!output("Location")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							| 
									
										
										
										
											2013-12-22 14:11:10 +11:00
										 |  |  | #if 0	/* not yet supported */
 | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	if(!output("Rotation")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							| 
									
										
										
										
											2013-12-22 14:11:10 +11:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	if(!output("Size")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							|  |  |  | 	if(!output("Velocity")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							|  |  |  | 	if(!output("Angular Velocity")->links.empty()) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_PARTICLE); | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ParticleInfoNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-07-26 11:40:58 +00:00
										 |  |  | 	out = output("Index"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_INDEX, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-07-26 11:40:58 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | 	out = output("Age"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_AGE, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Lifetime"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LIFETIME, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Location"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_LOCATION, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	/* quaternion data is not yet supported by Cycles */ | 
					
						
							|  |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	out = output("Rotation"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ROTATION, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Size"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_SIZE, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Velocity"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_VELOCITY, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Angular Velocity"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_PARTICLE_INFO, NODE_INFO_PAR_ANGULAR_VELOCITY, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-08-31 19:38:59 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-06-08 16:17:57 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ParticleInfoNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_particle_info"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | /* Hair Info */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(HairInfoNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("hair_info", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(is_strand, "Is Strand"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(intercept, "Intercept"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(thickness, "Thickness"); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(tangent Normal, "Tangent Normal"); | 
					
						
							|  |  |  | #if 0 /*output for minimum hair width transparency - deactivated */
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fade, "Fade"); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | HairInfoNode::HairInfoNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void HairInfoNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2013-01-03 12:08:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	if(shader->has_surface) { | 
					
						
							|  |  |  | 		ShaderOutput *intercept_out = output("Intercept"); | 
					
						
							| 
									
										
										
										
											2013-01-03 12:08:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 		if(!intercept_out->links.empty()) | 
					
						
							|  |  |  | 			attributes->add(ATTR_STD_CURVE_INTERCEPT); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2013-01-03 12:08:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | void HairInfoNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *out; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	out = output("Is Strand"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_HAIR_INFO, NODE_INFO_CURVE_IS_STRAND, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Intercept"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2013-01-03 12:08:54 +00:00
										 |  |  | 		int attr = compiler.attribute(ATTR_STD_CURVE_INTERCEPT); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_ATTR, attr, compiler.stack_assign(out), NODE_ATTR_FLOAT); | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Thickness"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_HAIR_INFO, NODE_INFO_CURVE_THICKNESS, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	out = output("Tangent Normal"); | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_HAIR_INFO, NODE_INFO_CURVE_TANGENT_NORMAL, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-15 21:38:31 +00:00
										 |  |  | 	/*out = output("Fade");
 | 
					
						
							|  |  |  | 	if(!out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_HAIR_INFO, NODE_INFO_CURVE_FADE, compiler.stack_assign(out)); | 
					
						
							| 
									
										
										
										
											2013-04-15 21:38:31 +00:00
										 |  |  | 	}*/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HairInfoNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-29 01:57:32 +00:00
										 |  |  | 	compiler.add(this, "node_hair_info"); | 
					
						
							| 
									
										
										
										
											2012-12-28 14:21:30 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Value */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ValueNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("value", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_FLOAT(value, "Value", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(value, "Value"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ValueNode::ValueNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void ValueNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2015-12-06 23:47:38 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	folder.make_constant(value); | 
					
						
							| 
									
										
										
										
											2015-12-06 23:47:38 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void ValueNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *val_out = output("Value"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_VALUE_F, __float_as_int(value), compiler.stack_assign(val_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ValueNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.parameter("value_value", value); | 
					
						
							|  |  |  | 	compiler.add(this, "node_value"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Color */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(ColorNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("color", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_COLOR(value, "Value", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ColorNode::ColorNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void ColorNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2015-12-06 23:47:38 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	folder.make_constant(value); | 
					
						
							| 
									
										
										
										
											2015-12-06 23:47:38 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void ColorNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	if(!color_out->links.empty()) { | 
					
						
							|  |  |  | 		compiler.add_node(NODE_VALUE_V, compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		compiler.add_node(NODE_VALUE_V, value); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ColorNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.parameter_color("color_value", value); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add(this, "node_value"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Add Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(AddClosureNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("add_closure", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_CLOSURE(closure1, "Closure1"); | 
					
						
							|  |  |  | 	SOCKET_IN_CLOSURE(closure2, "Closure2"); | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(closure, "Closure"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | AddClosureNode::AddClosureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-08 00:41:01 +02:00
										 |  |  | 	special_type = SHADER_SPECIAL_TYPE_COMBINE_CLOSURE; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-27 15:47:55 +05:00
										 |  |  | void AddClosureNode::compile(SVMCompiler& /*compiler*/) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* handled in the SVM compiler */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AddClosureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_add_closure"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void AddClosureNode::constant_fold(const ConstantFolder& folder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *closure1_in = input("Closure1"); | 
					
						
							|  |  |  | 	ShaderInput *closure2_in = input("Closure2"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* remove useless add closures nodes */ | 
					
						
							|  |  |  | 	if(!closure1_in->link) { | 
					
						
							|  |  |  | 		folder.bypass_or_discard(closure2_in); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(!closure2_in->link) { | 
					
						
							|  |  |  | 		folder.bypass_or_discard(closure1_in); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Mix Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MixClosureNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("mix_closure", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_IN_CLOSURE(closure1, "Closure1"); | 
					
						
							|  |  |  | 	SOCKET_IN_CLOSURE(closure2, "Closure2"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_CLOSURE(closure, "Closure"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | MixClosureNode::MixClosureNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-08 00:41:01 +02:00
										 |  |  | 	special_type = SHADER_SPECIAL_TYPE_COMBINE_CLOSURE; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-27 15:47:55 +05:00
										 |  |  | void MixClosureNode::compile(SVMCompiler& /*compiler*/) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* handled in the SVM compiler */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MixClosureNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_mix_closure"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void MixClosureNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderInput *closure1_in = input("Closure1"); | 
					
						
							|  |  |  | 	ShaderInput *closure2_in = input("Closure2"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* remove useless mix closures nodes */ | 
					
						
							|  |  |  | 	if(closure1_in->link == closure2_in->link) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		folder.bypass_or_discard(closure1_in); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	/* remove unused mix closure input when factor is 0.0 or 1.0
 | 
					
						
							|  |  |  | 	 * check for closure links and make sure factor link is disconnected */ | 
					
						
							|  |  |  | 	else if(!fac_in->link) { | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 		/* factor 0.0 */ | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		if(fac <= 0.0f) { | 
					
						
							|  |  |  | 			folder.bypass_or_discard(closure1_in); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		/* factor 1.0 */ | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		else if(fac >= 1.0f) { | 
					
						
							|  |  |  | 			folder.bypass_or_discard(closure2_in); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | /* Mix Closure */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MixClosureWeightNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("mix_closure_weight", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(weight, "Weight", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(weight1, "Weight1"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(weight2, "Weight2"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | MixClosureWeightNode::MixClosureWeightNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MixClosureWeightNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *weight_in = input("Weight"); | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderOutput *weight1_out = output("Weight1"); | 
					
						
							|  |  |  | 	ShaderOutput *weight2_out = output("Weight2"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_MIX_CLOSURE, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign(fac_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(weight_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(weight1_out), | 
					
						
							|  |  |  | 			compiler.stack_assign(weight2_out))); | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-27 15:47:55 +05:00
										 |  |  | void MixClosureWeightNode::compile(OSLCompiler& /*compiler*/) | 
					
						
							| 
									
										
										
										
											2012-11-26 21:59:41 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 23:05:35 +00:00
										 |  |  | /* Invert */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(InvertNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("invert", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 23:05:35 +00:00
										 |  |  | InvertNode::InvertNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-12-03 23:05:35 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void InvertNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!fac_in->link) { | 
					
						
							|  |  |  | 		/* evaluate fully constant node */ | 
					
						
							|  |  |  | 		if(!color_in->link) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			folder.make_constant(interp(color, make_float3(1.0f, 1.0f, 1.0f) - color, fac)); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		/* remove no-op node */ | 
					
						
							|  |  |  | 		else if(fac == 0.0f) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			folder.bypass(color_in->link); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-03 23:05:35 +00:00
										 |  |  | void InvertNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_INVERT, | 
					
						
							|  |  |  | 		compiler.stack_assign(fac_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2011-12-03 23:05:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void InvertNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_invert"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Mix */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MixNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("mix", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("mix", NODE_MIX_BLEND); | 
					
						
							|  |  |  | 	type_enum.insert("add", NODE_MIX_ADD); | 
					
						
							|  |  |  | 	type_enum.insert("multiply", NODE_MIX_MUL); | 
					
						
							|  |  |  | 	type_enum.insert("screen", NODE_MIX_SCREEN); | 
					
						
							|  |  |  | 	type_enum.insert("overlay", NODE_MIX_OVERLAY); | 
					
						
							|  |  |  | 	type_enum.insert("subtract", NODE_MIX_SUB); | 
					
						
							|  |  |  | 	type_enum.insert("divide", NODE_MIX_DIV); | 
					
						
							|  |  |  | 	type_enum.insert("difference", NODE_MIX_DIFF); | 
					
						
							|  |  |  | 	type_enum.insert("darken", NODE_MIX_DARK); | 
					
						
							|  |  |  | 	type_enum.insert("lighten", NODE_MIX_LIGHT); | 
					
						
							|  |  |  | 	type_enum.insert("dodge", NODE_MIX_DODGE); | 
					
						
							|  |  |  | 	type_enum.insert("burn", NODE_MIX_BURN); | 
					
						
							|  |  |  | 	type_enum.insert("hue", NODE_MIX_HUE); | 
					
						
							|  |  |  | 	type_enum.insert("saturation", NODE_MIX_SAT); | 
					
						
							|  |  |  | 	type_enum.insert("value", NODE_MIX_VAL); | 
					
						
							|  |  |  | 	type_enum.insert("color", NODE_MIX_COLOR); | 
					
						
							|  |  |  | 	type_enum.insert("soft_light", NODE_MIX_SOFT); | 
					
						
							|  |  |  | 	type_enum.insert("linear_light", NODE_MIX_LINEAR); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_MIX_BLEND); | 
					
						
							| 
									
										
										
										
											2012-08-30 06:31:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_BOOLEAN(use_clamp, "Use Clamp", false); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color1, "Color1", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color2, "Color2", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | MixNode::MixNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | void MixNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderInput *color1_in = input("Color1"); | 
					
						
							|  |  |  | 	ShaderInput *color2_in = input("Color2"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_MIX, | 
					
						
							|  |  |  | 		compiler.stack_assign(fac_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color1_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color2_in)); | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	compiler.add_node(NODE_MIX, type, compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2012-08-30 06:31:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(use_clamp) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_MIX, 0, compiler.stack_assign(color_out)); | 
					
						
							|  |  |  | 		compiler.add_node(NODE_MIX, NODE_MIX_CLAMP, compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2012-08-30 06:31:02 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MixNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "use_clamp"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_mix"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void MixNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant_clamp(svm_mix(type, fac, color1, color2), use_clamp); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-30 20:03:49 +02:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		folder.fold_mix(type, use_clamp); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | /* Combine RGB */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(CombineRGBNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("combine_rgb", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(r, "R", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(g, "G", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(b, "B", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(image, "Image"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | CombineRGBNode::CombineRGBNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void CombineRGBNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(make_float3(r, g, b)); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | void CombineRGBNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *red_in = input("R"); | 
					
						
							|  |  |  | 	ShaderInput *green_in = input("G"); | 
					
						
							|  |  |  | 	ShaderInput *blue_in = input("B"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Image"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(red_in), 0, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(green_in), 1, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(blue_in), 2, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CombineRGBNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_combine_rgb"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | /* Combine XYZ */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(CombineXYZNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("combine_xyz", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(x, "X", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(y, "Y", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(z, "Z", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-18 22:36:42 +02:00
										 |  |  | 	SOCKET_OUT_VECTOR(vector, "Vector"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | CombineXYZNode::CombineXYZNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void CombineXYZNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(make_float3(x, y, z)); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | void CombineXYZNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *x_in = input("X"); | 
					
						
							|  |  |  | 	ShaderInput *y_in = input("Y"); | 
					
						
							|  |  |  | 	ShaderInput *z_in = input("Z"); | 
					
						
							|  |  |  | 	ShaderOutput *vector_out = output("Vector"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(x_in), 0, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_out)); | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(y_in), 1, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_out)); | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(z_in), 2, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_out)); | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CombineXYZNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_combine_xyz"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | /* Combine HSV */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(CombineHSVNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("combine_hsv", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(h, "H", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(s, "S", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(v, "V", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | CombineHSVNode::CombineHSVNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void CombineHSVNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(hsv_to_rgb(make_float3(h, s, v))); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | void CombineHSVNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *hue_in = input("H"); | 
					
						
							|  |  |  | 	ShaderInput *saturation_in = input("S"); | 
					
						
							|  |  |  | 	ShaderInput *value_in = input("V"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_COMBINE_HSV, | 
					
						
							|  |  |  | 		compiler.stack_assign(hue_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(saturation_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(value_in)); | 
					
						
							|  |  |  | 	compiler.add_node(NODE_COMBINE_HSV, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CombineHSVNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_combine_hsv"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-16 20:35:06 +00:00
										 |  |  | /* Gamma */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(GammaNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("gamma", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(gamma, "Gamma", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-16 20:35:06 +00:00
										 |  |  | GammaNode::GammaNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-12-16 20:35:06 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void GammaNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2015-12-22 13:53:13 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(svm_math_gamma_color(color, gamma)); | 
					
						
							| 
									
										
										
										
											2015-12-22 13:53:13 +01:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-29 00:35:53 +03:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 		ShaderInput *gamma_in = input("Gamma"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* 1 ^ X == X ^ 0 == 1 */ | 
					
						
							|  |  |  | 		if(folder.is_one(color_in) || folder.is_zero(gamma_in)) { | 
					
						
							|  |  |  | 			folder.make_one(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* X ^ 1 == X */ | 
					
						
							|  |  |  | 		else if(folder.is_one(gamma_in)) { | 
					
						
							|  |  |  | 			folder.try_bypass_or_make_constant(color_in, false); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-12-22 13:53:13 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-16 20:35:06 +00:00
										 |  |  | void GammaNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderInput *gamma_in = input("Gamma"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_GAMMA, | 
					
						
							|  |  |  | 		compiler.stack_assign(gamma_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2011-12-16 20:35:06 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GammaNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_gamma"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-24 16:32:31 +00:00
										 |  |  | /* Bright Contrast */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(BrightContrastNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("brightness_contrast", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(bright, "Bright", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(contrast, "Contrast", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-24 16:32:31 +00:00
										 |  |  | BrightContrastNode::BrightContrastNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-01-24 16:32:31 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void BrightContrastNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(svm_brightness_contrast(color, bright, contrast)); | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-24 16:32:31 +00:00
										 |  |  | void BrightContrastNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderInput *bright_in = input("Bright"); | 
					
						
							|  |  |  | 	ShaderInput *contrast_in = input("Contrast"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_BRIGHTCONTRAST, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.stack_assign(color_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign(bright_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(contrast_in))); | 
					
						
							| 
									
										
										
										
											2012-01-24 16:32:31 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BrightContrastNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_brightness"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | /* Separate RGB */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(SeparateRGBNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("separate_rgb", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Image", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 11:33:09 +01:00
										 |  |  | 	SOCKET_OUT_FLOAT(r, "R"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_FLOAT(g, "G"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(b, "B"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | SeparateRGBNode::SeparateRGBNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void SeparateRGBNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 		for(int channel = 0; channel < 3; channel++) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			if(outputs[channel] == folder.output) { | 
					
						
							|  |  |  | 				folder.make_constant(color[channel]); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | void SeparateRGBNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Image"); | 
					
						
							|  |  |  | 	ShaderOutput *red_out = output("R"); | 
					
						
							|  |  |  | 	ShaderOutput *green_out = output("G"); | 
					
						
							|  |  |  | 	ShaderOutput *blue_out = output("B"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_in), 0, | 
					
						
							|  |  |  | 		compiler.stack_assign(red_out)); | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_in), 1, | 
					
						
							|  |  |  | 		compiler.stack_assign(green_out)); | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_in), 2, | 
					
						
							|  |  |  | 		compiler.stack_assign(blue_out)); | 
					
						
							| 
									
										
										
										
											2011-12-01 21:46:10 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SeparateRGBNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_separate_rgb"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | /* Separate XYZ */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(SeparateXYZNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("separate_xyz", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(x, "X"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(y, "Y"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(z, "Z"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | SeparateXYZNode::SeparateXYZNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void SeparateXYZNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 		for(int channel = 0; channel < 3; channel++) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			if(outputs[channel] == folder.output) { | 
					
						
							|  |  |  | 				folder.make_constant(vector[channel]); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | void SeparateXYZNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *x_out = output("X"); | 
					
						
							|  |  |  | 	ShaderOutput *y_out = output("Y"); | 
					
						
							|  |  |  | 	ShaderOutput *z_out = output("Z"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_in), 0, | 
					
						
							|  |  |  | 		compiler.stack_assign(x_out)); | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_in), 1, | 
					
						
							|  |  |  | 		compiler.stack_assign(y_out)); | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_VECTOR, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_in), 2, | 
					
						
							|  |  |  | 		compiler.stack_assign(z_out)); | 
					
						
							| 
									
										
										
										
											2014-06-13 21:44:48 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SeparateXYZNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_separate_xyz"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | /* Separate HSV */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(SeparateHSVNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("separate_hsv", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(h, "H"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(s, "S"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(v, "V"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | SeparateHSVNode::SeparateHSVNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void SeparateHSVNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 		float3 hsv = rgb_to_hsv(color); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for(int channel = 0; channel < 3; channel++) { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			if(outputs[channel] == folder.output) { | 
					
						
							|  |  |  | 				folder.make_constant(hsv[channel]); | 
					
						
							|  |  |  | 				return; | 
					
						
							| 
									
										
										
										
											2016-06-19 13:28:50 +03:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | void SeparateHSVNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *hue_out = output("H"); | 
					
						
							|  |  |  | 	ShaderOutput *saturation_out = output("S"); | 
					
						
							|  |  |  | 	ShaderOutput *value_out = output("V"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_SEPARATE_HSV, | 
					
						
							|  |  |  | 		compiler.stack_assign(color_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(hue_out), | 
					
						
							|  |  |  | 		compiler.stack_assign(saturation_out)); | 
					
						
							|  |  |  | 	compiler.add_node(NODE_SEPARATE_HSV, | 
					
						
							|  |  |  | 		compiler.stack_assign(value_out)); | 
					
						
							| 
									
										
										
										
											2013-07-03 23:46:56 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SeparateHSVNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_separate_hsv"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Hue Saturation Value */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(HSVNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("hsv", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(hue, "Hue", 0.5f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(saturation, "Saturation", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(value, "Value", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 16:57:37 +00:00
										 |  |  | HSVNode::HSVNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-12-02 16:57:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HSVNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *hue_in = input("Hue"); | 
					
						
							|  |  |  | 	ShaderInput *saturation_in = input("Saturation"); | 
					
						
							|  |  |  | 	ShaderInput *value_in = input("Value"); | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderInput *color_in = input("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_HSV, | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign(color_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(fac_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(color_out)), | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign(hue_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(saturation_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(value_in))); | 
					
						
							| 
									
										
										
										
											2011-12-02 16:57:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void HSVNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_hsv"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Attribute */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(AttributeNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("attribute", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_STRING(attribute, "Attribute", ustring("")); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(vector, "Vector"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | AttributeNode::AttributeNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void AttributeNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *vector_out = output("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 	if(!color_out->links.empty() || !vector_out->links.empty() || !fac_out->links.empty()) { | 
					
						
							|  |  |  | 		AttributeStandard std = Attribute::name_standard(attribute.c_str()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(std != ATTR_STD_NONE) | 
					
						
							|  |  |  | 			attributes->add(std); | 
					
						
							|  |  |  | 		else | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 			attributes->add(attribute); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(shader->has_volume) | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_GENERATED_TRANSFORM); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AttributeNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 	ShaderOutput *vector_out = output("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:47:37 +02:00
										 |  |  | 	ShaderNodeType attr_node = NODE_ATTR; | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 	AttributeStandard std = Attribute::name_standard(attribute.c_str()); | 
					
						
							|  |  |  | 	int attr; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(std != ATTR_STD_NONE) | 
					
						
							|  |  |  | 		attr = compiler.attribute(std); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		attr = compiler.attribute(attribute); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(bump == SHADER_BUMP_DX) | 
					
						
							|  |  |  | 		attr_node = NODE_ATTR_BUMP_DX; | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) | 
					
						
							|  |  |  | 		attr_node = NODE_ATTR_BUMP_DY; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!color_out->links.empty() || !vector_out->links.empty()) { | 
					
						
							|  |  |  | 		if(!color_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(attr_node, attr, compiler.stack_assign(color_out), NODE_ATTR_FLOAT3); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(!vector_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(attr_node, attr, compiler.stack_assign(vector_out), NODE_ATTR_FLOAT3); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!fac_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(attr_node, attr, compiler.stack_assign(fac_out), NODE_ATTR_FLOAT); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void AttributeNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(bump == SHADER_BUMP_DX) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dx"); | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dy"); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "center"); | 
					
						
							| 
									
										
										
										
											2014-03-29 13:03:48 +01:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	if(Attribute::name_standard(attribute.c_str()) != ATTR_STD_NONE) | 
					
						
							|  |  |  | 		compiler.parameter("name", (string("geom:") + attribute.c_str()).c_str()); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		compiler.parameter("name", attribute.c_str()); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add(this, "node_attribute"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 20:36:13 +00:00
										 |  |  | /* Camera */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(CameraNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("camera_info", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(view_vector, "View Vector"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(view_z_depth, "View Z Depth"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(view_distance, "View Distance"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-12-02 20:36:13 +00:00
										 |  |  | CameraNode::CameraNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-12-02 20:36:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CameraNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *vector_out = output("View Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *z_depth_out = output("View Z Depth"); | 
					
						
							|  |  |  | 	ShaderOutput *distance_out = output("View Distance"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_CAMERA, | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_out), | 
					
						
							|  |  |  | 		compiler.stack_assign(z_depth_out), | 
					
						
							|  |  |  | 		compiler.stack_assign(distance_out)); | 
					
						
							| 
									
										
										
										
											2011-12-02 20:36:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CameraNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_camera"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Fresnel */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(FresnelNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("fresnel", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(IOR, "IOR", 1.45f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | FresnelNode::FresnelNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FresnelNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-09 13:14:00 +00:00
										 |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	ShaderInput *IOR_in = input("IOR"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_FRESNEL, | 
					
						
							|  |  |  | 		compiler.stack_assign(IOR_in), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		__float_as_int(IOR), | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(normal_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(fac_out))); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void FresnelNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_fresnel"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-05 01:24:41 +00:00
										 |  |  | /* Layer Weight */ | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(LayerWeightNode) | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("layer_weight", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(blend, "Blend", 0.5f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fresnel, "Fresnel"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(facing, "Facing"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LayerWeightNode::LayerWeightNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void LayerWeightNode::compile(SVMCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-11-22 00:33:28 +01:00
										 |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	ShaderInput *blend_in = input("Blend"); | 
					
						
							|  |  |  | 	ShaderOutput *fresnel_out = output("Fresnel"); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	ShaderOutput *facing_out = output("Facing"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	if(!fresnel_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LAYER_WEIGHT, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(blend_in), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 			__float_as_int(blend), | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.encode_uchar4(NODE_LAYER_WEIGHT_FRESNEL, | 
					
						
							|  |  |  | 			                       compiler.stack_assign_if_linked(normal_in), | 
					
						
							|  |  |  | 			                       compiler.stack_assign(fresnel_out))); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(!facing_out->links.empty()) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_LAYER_WEIGHT, | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(blend_in), | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 			__float_as_int(blend), | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.encode_uchar4(NODE_LAYER_WEIGHT_FACING, | 
					
						
							|  |  |  | 			                       compiler.stack_assign_if_linked(normal_in), | 
					
						
							|  |  |  | 			                       compiler.stack_assign(facing_out))); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-11-06 21:05:58 +00:00
										 |  |  | void LayerWeightNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-17 16:16:35 +00:00
										 |  |  | 	compiler.add(this, "node_layer_weight"); | 
					
						
							| 
									
										
										
										
											2011-09-16 13:14:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-20 15:58:37 +00:00
										 |  |  | /* Wireframe */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(WireframeNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("wireframe", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_BOOLEAN(use_pixel_size, "Use Pixel Size", false); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(size, "Size", 0.01f); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(fac, "Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-20 15:58:37 +00:00
										 |  |  | WireframeNode::WireframeNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-05-20 15:58:37 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WireframeNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *size_in = input("Size"); | 
					
						
							|  |  |  | 	ShaderOutput *fac_out = output("Fac"); | 
					
						
							| 
									
										
										
										
											2015-02-21 14:49:55 +05:00
										 |  |  | 	NodeBumpOffset bump_offset = NODE_BUMP_OFFSET_CENTER; | 
					
						
							|  |  |  | 	if(bump == SHADER_BUMP_DX) { | 
					
						
							|  |  |  | 		bump_offset = NODE_BUMP_OFFSET_DX; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) { | 
					
						
							|  |  |  | 		bump_offset = NODE_BUMP_OFFSET_DY; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	compiler.add_node(NODE_WIREFRAME, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	                  compiler.stack_assign(size_in), | 
					
						
							|  |  |  | 	                  compiler.stack_assign(fac_out), | 
					
						
							| 
									
										
										
										
											2015-02-21 14:49:55 +05:00
										 |  |  | 	                  compiler.encode_uchar4(use_pixel_size, | 
					
						
							|  |  |  | 	                                         bump_offset, | 
					
						
							|  |  |  | 	                                         0, 0)); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:58:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WireframeNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-02-21 14:49:55 +05:00
										 |  |  | 	if(bump == SHADER_BUMP_DX) { | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dx"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if(bump == SHADER_BUMP_DY) { | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "dy"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		compiler.parameter("bump_offset", "center"); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "use_pixel_size"); | 
					
						
							| 
									
										
										
										
											2013-05-20 15:58:37 +00:00
										 |  |  | 	compiler.add(this, "node_wireframe"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-09 20:46:22 +00:00
										 |  |  | /* Wavelength */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(WavelengthNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("wavelength", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(wavelength, "Wavelength", 500.0f); | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-09 20:46:22 +00:00
										 |  |  | WavelengthNode::WavelengthNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-06-09 20:46:22 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WavelengthNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *wavelength_in = input("Wavelength"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_WAVELENGTH, | 
					
						
							|  |  |  | 		compiler.stack_assign(wavelength_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2013-06-09 20:46:22 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void WavelengthNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_wavelength"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-31 20:56:32 +00:00
										 |  |  | /* Blackbody */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(BlackbodyNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("blackbody", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(temperature, "Temperature", 1200.0f); | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-31 20:56:32 +00:00
										 |  |  | BlackbodyNode::BlackbodyNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-07-31 20:56:32 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void BlackbodyNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant(svm_math_blackbody_color(temperature)); | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-31 20:56:32 +00:00
										 |  |  | void BlackbodyNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *temperature_in = input("Temperature"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_BLACKBODY, | 
					
						
							|  |  |  | 		compiler.stack_assign(temperature_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(color_out)); | 
					
						
							| 
									
										
										
										
											2013-07-31 20:56:32 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BlackbodyNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	compiler.add(this, "node_blackbody"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* Output */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(OutputNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("output", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_CLOSURE(surface, "Surface"); | 
					
						
							|  |  |  | 	SOCKET_IN_CLOSURE(volume, "Volume"); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(displacement, "Displacement", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | OutputNode::OutputNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-08 00:41:01 +02:00
										 |  |  | 	special_type = SHADER_SPECIAL_TYPE_OUTPUT; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OutputNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(compiler.output_type() == SHADER_TYPE_DISPLACEMENT) { | 
					
						
							|  |  |  | 		ShaderInput *displacement_in = input("Displacement"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(displacement_in->link) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.add_node(NODE_SET_DISPLACEMENT, compiler.stack_assign(displacement_in)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OutputNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2011-10-12 23:03:12 +00:00
										 |  |  | 	if(compiler.output_type() == SHADER_TYPE_SURFACE) | 
					
						
							|  |  |  | 		compiler.add(this, "node_output_surface"); | 
					
						
							|  |  |  | 	else if(compiler.output_type() == SHADER_TYPE_VOLUME) | 
					
						
							|  |  |  | 		compiler.add(this, "node_output_volume"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	else if(compiler.output_type() == SHADER_TYPE_DISPLACEMENT) | 
					
						
							|  |  |  | 		compiler.add(this, "node_output_displacement"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Math */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(MathNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("math", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("add", NODE_MATH_ADD); | 
					
						
							|  |  |  | 	type_enum.insert("subtract", NODE_MATH_SUBTRACT); | 
					
						
							|  |  |  | 	type_enum.insert("multiply", NODE_MATH_MULTIPLY); | 
					
						
							|  |  |  | 	type_enum.insert("divide", NODE_MATH_DIVIDE); | 
					
						
							|  |  |  | 	type_enum.insert("sine", NODE_MATH_SINE); | 
					
						
							|  |  |  | 	type_enum.insert("cosine", NODE_MATH_COSINE); | 
					
						
							|  |  |  | 	type_enum.insert("tangent", NODE_MATH_TANGENT); | 
					
						
							|  |  |  | 	type_enum.insert("arcsine", NODE_MATH_ARCSINE); | 
					
						
							|  |  |  | 	type_enum.insert("arccosine", NODE_MATH_ARCCOSINE); | 
					
						
							|  |  |  | 	type_enum.insert("arctangent", NODE_MATH_ARCTANGENT); | 
					
						
							|  |  |  | 	type_enum.insert("power", NODE_MATH_POWER); | 
					
						
							|  |  |  | 	type_enum.insert("logarithm", NODE_MATH_LOGARITHM); | 
					
						
							|  |  |  | 	type_enum.insert("minimum", NODE_MATH_MINIMUM); | 
					
						
							|  |  |  | 	type_enum.insert("maximum", NODE_MATH_MAXIMUM); | 
					
						
							|  |  |  | 	type_enum.insert("round", NODE_MATH_ROUND); | 
					
						
							|  |  |  | 	type_enum.insert("less_than", NODE_MATH_LESS_THAN); | 
					
						
							|  |  |  | 	type_enum.insert("greater_than", NODE_MATH_GREATER_THAN); | 
					
						
							|  |  |  | 	type_enum.insert("modulo", NODE_MATH_MODULO); | 
					
						
							|  |  |  | 	type_enum.insert("absolute", NODE_MATH_ABSOLUTE); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_MATH_ADD); | 
					
						
							| 
									
										
										
										
											2012-08-29 17:30:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_BOOLEAN(use_clamp, "Use Clamp", false); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(value1, "Value1", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(value2, "Value2", 0.0f); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_FLOAT(value, "Value"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | MathNode::MathNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void MathNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		folder.make_constant_clamp(svm_math(type, value1, value2), use_clamp); | 
					
						
							| 
									
										
										
										
											2014-10-26 19:40:04 +05:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-30 20:03:49 +02:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		folder.fold_math(type, use_clamp); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MathNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *value1_in = input("Value1"); | 
					
						
							|  |  |  | 	ShaderInput *value2_in = input("Value2"); | 
					
						
							|  |  |  | 	ShaderOutput *value_out = output("Value"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	compiler.add_node(NODE_MATH, type, compiler.stack_assign(value1_in), compiler.stack_assign(value2_in)); | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_MATH, compiler.stack_assign(value_out)); | 
					
						
							| 
									
										
										
										
											2012-08-29 17:30:14 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if(use_clamp) { | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.add_node(NODE_MATH, NODE_MATH_CLAMP, compiler.stack_assign(value_out)); | 
					
						
							|  |  |  | 		compiler.add_node(NODE_MATH, compiler.stack_assign(value_out)); | 
					
						
							| 
									
										
										
										
											2012-08-29 17:30:14 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void MathNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "use_clamp"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_math"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* VectorMath */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(VectorMathNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("vector_math", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("add", NODE_VECTOR_MATH_ADD); | 
					
						
							|  |  |  | 	type_enum.insert("subtract", NODE_VECTOR_MATH_SUBTRACT); | 
					
						
							|  |  |  | 	type_enum.insert("average", NODE_VECTOR_MATH_AVERAGE); | 
					
						
							|  |  |  | 	type_enum.insert("dot_product", NODE_VECTOR_MATH_DOT_PRODUCT); | 
					
						
							|  |  |  | 	type_enum.insert("cross_product", NODE_VECTOR_MATH_CROSS_PRODUCT); | 
					
						
							|  |  |  | 	type_enum.insert("normalize", NODE_VECTOR_MATH_NORMALIZE); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_VECTOR_MATH_ADD); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_VECTOR(vector1, "Vector1", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_IN_VECTOR(vector2, "Vector2", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_FLOAT(value, "Value"); | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(vector, "Vector"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | VectorMathNode::VectorMathNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void VectorMathNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | { | 
					
						
							|  |  |  | 	float value; | 
					
						
							|  |  |  | 	float3 vector; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | 		svm_vector_math(&value, | 
					
						
							| 
									
										
										
										
											2016-02-03 15:00:55 +01:00
										 |  |  | 		                &vector, | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		                type, | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 		                vector1, | 
					
						
							|  |  |  | 		                vector2); | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		if(folder.output == output("Value")) { | 
					
						
							|  |  |  | 			folder.make_constant(value); | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 		else if(folder.output == output("Vector")) { | 
					
						
							|  |  |  | 			folder.make_constant(vector); | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-30 20:03:49 +02:00
										 |  |  | 	else { | 
					
						
							|  |  |  | 		folder.fold_vector_math(type); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-25 13:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | void VectorMathNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector1_in = input("Vector1"); | 
					
						
							|  |  |  | 	ShaderInput *vector2_in = input("Vector2"); | 
					
						
							| 
									
										
										
										
											2011-04-28 11:45:06 +00:00
										 |  |  | 	ShaderOutput *value_out = output("Value"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	ShaderOutput *vector_out = output("Vector"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_VECTOR_MATH, | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		type, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.stack_assign(vector1_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(vector2_in)); | 
					
						
							|  |  |  | 	compiler.add_node(NODE_VECTOR_MATH, | 
					
						
							|  |  |  | 		compiler.stack_assign(value_out), | 
					
						
							|  |  |  | 		compiler.stack_assign(vector_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VectorMathNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_vector_math"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | /* VectorTransform */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(VectorTransformNode) | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("vector_transform", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	type_enum.insert("vector", NODE_VECTOR_TRANSFORM_TYPE_VECTOR); | 
					
						
							|  |  |  | 	type_enum.insert("point", NODE_VECTOR_TRANSFORM_TYPE_POINT); | 
					
						
							|  |  |  | 	type_enum.insert("normal", NODE_VECTOR_TRANSFORM_TYPE_NORMAL); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(type, "Type", type_enum, NODE_VECTOR_TRANSFORM_TYPE_VECTOR); | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum space_enum; | 
					
						
							|  |  |  | 	space_enum.insert("world", NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD); | 
					
						
							|  |  |  | 	space_enum.insert("object", NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT); | 
					
						
							|  |  |  | 	space_enum.insert("camera", NODE_VECTOR_TRANSFORM_CONVERT_SPACE_CAMERA); | 
					
						
							|  |  |  | 	SOCKET_ENUM(convert_from, "Convert From", space_enum, NODE_VECTOR_TRANSFORM_CONVERT_SPACE_WORLD); | 
					
						
							|  |  |  | 	SOCKET_ENUM(convert_to, "Convert To", space_enum, NODE_VECTOR_TRANSFORM_CONVERT_SPACE_OBJECT); | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_VECTOR(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_OUT_VECTOR(vector, "Vector"); | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | VectorTransformNode::VectorTransformNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VectorTransformNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *vector_in = input("Vector"); | 
					
						
							|  |  |  | 	ShaderOutput *vector_out = output("Vector"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_VECTOR_TRANSFORM, | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		compiler.encode_uchar4(type, convert_from, convert_to), | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4(compiler.stack_assign(vector_in), | 
					
						
							|  |  |  | 		                       compiler.stack_assign(vector_out))); | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VectorTransformNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "type"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "convert_from"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "convert_to"); | 
					
						
							| 
									
										
										
										
											2013-07-31 21:18:23 +00:00
										 |  |  | 	compiler.add(this, "node_vector_transform"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | /* BumpNode */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(BumpNode) | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("bump", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2013-05-10 16:57:17 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_BOOLEAN(invert, "Invert", false); | 
					
						
							| 
									
										
										
										
											2016-09-02 00:41:04 -04:00
										 |  |  | 	SOCKET_BOOLEAN(use_object_space, "UseObjectSpace", false); | 
					
						
							| 
									
										
										
										
											2015-06-11 23:09:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 	/* this input is used by the user, but after graph transform it is no longer
 | 
					
						
							|  |  |  | 	 * used and moved to sampler center/x/y instead */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_FLOAT(height, "Height", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(sample_center, "SampleCenter", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(sample_x, "SampleX", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(sample_y, "SampleY", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(strength, "Strength", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(distance, "Distance", 0.1f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(normal, "Normal"); | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | BumpNode::BumpNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	special_type = SHADER_SPECIAL_TYPE_BUMP; | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BumpNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *center_in = input("SampleCenter"); | 
					
						
							|  |  |  | 	ShaderInput *dx_in = input("SampleX"); | 
					
						
							|  |  |  | 	ShaderInput *dy_in = input("SampleY"); | 
					
						
							| 
									
										
										
										
											2013-05-08 13:23:13 +00:00
										 |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							| 
									
										
										
										
											2013-05-10 16:57:17 +00:00
										 |  |  | 	ShaderInput *strength_in = input("Strength"); | 
					
						
							|  |  |  | 	ShaderInput *distance_in = input("Distance"); | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 	ShaderOutput *normal_out = output("Normal"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 	/* pack all parameters in the node */ | 
					
						
							|  |  |  | 	compiler.add_node(NODE_SET_BUMP, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(normal_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(distance_in), | 
					
						
							| 
									
										
										
										
											2016-09-02 00:41:04 -04:00
										 |  |  | 			invert, | 
					
						
							|  |  |  | 			use_object_space), | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 		compiler.encode_uchar4( | 
					
						
							|  |  |  | 			compiler.stack_assign(center_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(dx_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(dy_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(strength_in)), | 
					
						
							|  |  |  | 		compiler.stack_assign(normal_out)); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void BumpNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "invert"); | 
					
						
							| 
									
										
										
										
											2016-09-02 00:41:04 -04:00
										 |  |  | 	compiler.parameter(this, "use_object_space"); | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | 	compiler.add(this, "node_bump"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | void BumpNode::constant_fold(const ConstantFolder& folder) | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *height_in = input("Height"); | 
					
						
							|  |  |  | 	ShaderInput *normal_in = input("Normal"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(height_in->link == NULL) { | 
					
						
							|  |  |  | 		if(normal_in->link == NULL) { | 
					
						
							|  |  |  | 			GeometryNode *geom = new GeometryNode(); | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			folder.graph->add(geom); | 
					
						
							|  |  |  | 			folder.bypass(geom->output("Normal")); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							| 
									
										
										
										
											2016-07-16 13:16:54 +02:00
										 |  |  | 			folder.bypass(normal_in->link); | 
					
						
							| 
									
										
										
										
											2016-05-02 00:05:16 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* TODO(sergey): Ignore bump with zero strength. */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | /* Curve node */ | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | CurvesNode::CurvesNode(const NodeType *node_type) | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | void CurvesNode::constant_fold(const ConstantFolder& folder, ShaderInput *value_in) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* evaluate fully constant node */ | 
					
						
							| 
									
										
										
										
											2016-08-22 11:11:45 +03:00
										 |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							| 
									
										
										
										
											2016-10-24 12:26:12 +02:00
										 |  |  | 		if(curves.size() == 0) { | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | 			return; | 
					
						
							| 
									
										
										
										
											2016-10-24 12:26:12 +02:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		float3 pos = (value - make_float3(min_x, min_x, min_x)) / (max_x - min_x); | 
					
						
							|  |  |  | 		float3 result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		result[0] = rgb_ramp_lookup(curves.data(), pos[0], true, true, curves.size()).x; | 
					
						
							|  |  |  | 		result[1] = rgb_ramp_lookup(curves.data(), pos[1], true, true, curves.size()).y; | 
					
						
							|  |  |  | 		result[2] = rgb_ramp_lookup(curves.data(), pos[2], true, true, curves.size()).z; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		folder.make_constant(interp(value, result, fac)); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-08-22 11:11:45 +03:00
										 |  |  | 	/* remove no-op node */ | 
					
						
							|  |  |  | 	else if(!fac_in->link && fac == 0.0f) { | 
					
						
							|  |  |  | 		/* link is not null because otherwise all inputs are constant */ | 
					
						
							|  |  |  | 		folder.bypass(value_in->link); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | void CurvesNode::compile(SVMCompiler& compiler, int type, ShaderInput *value_in, ShaderOutput *value_out) | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 22:08:34 +02:00
										 |  |  | 	if(curves.size() == 0) | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	compiler.add_node(type, | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	                  compiler.encode_uchar4(compiler.stack_assign(fac_in), | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	                                         compiler.stack_assign(value_in), | 
					
						
							|  |  |  | 	                                         compiler.stack_assign(value_out)), | 
					
						
							| 
									
										
										
										
											2015-12-04 20:17:25 +05:00
										 |  |  | 	                  __float_as_int(min_x), | 
					
						
							|  |  |  | 	                  __float_as_int(max_x)); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(curves.size()); | 
					
						
							|  |  |  | 	for(int i = 0; i < curves.size(); i++) | 
					
						
							|  |  |  | 		compiler.add_node(float3_to_float4(curves[i])); | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | void CurvesNode::compile(OSLCompiler& compiler, const char* name) | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 22:08:34 +02:00
										 |  |  | 	if(curves.size() == 0) | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 	compiler.parameter_color_array("ramp", curves); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "min_x"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "max_x"); | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	compiler.add(this, name); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CurvesNode::compile(SVMCompiler& /*compiler*/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void CurvesNode::compile(OSLCompiler& /*compiler*/) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	assert(0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* RGBCurvesNode */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | NODE_DEFINE(RGBCurvesNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("rgb_curves", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_COLOR_ARRAY(curves, "Curves", array<float3>()); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(min_x, "Min X", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(max_x, "Max X", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(value, "Color", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(value, "Color"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RGBCurvesNode::RGBCurvesNode() | 
					
						
							|  |  |  | : CurvesNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | void RGBCurvesNode::constant_fold(const ConstantFolder& folder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CurvesNode::constant_fold(folder, input("Color")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | void RGBCurvesNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CurvesNode::compile(compiler, NODE_RGB_CURVES, input("Color"), output("Color")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RGBCurvesNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CurvesNode::compile(compiler, "node_rgb_curves"); | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | /* VectorCurvesNode */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(VectorCurvesNode) | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("vector_curves", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_VECTOR_ARRAY(curves, "Curves", array<float3>()); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(min_x, "Min X", 0.0f); | 
					
						
							|  |  |  | 	SOCKET_FLOAT(max_x, "Max X", 1.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	SOCKET_IN_VECTOR(value, "Vector", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							| 
									
										
										
										
											2015-12-15 16:23:33 +05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	SOCKET_OUT_VECTOR(value, "Vector"); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | VectorCurvesNode::VectorCurvesNode() | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | : CurvesNode(node_type) | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | void VectorCurvesNode::constant_fold(const ConstantFolder& folder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	CurvesNode::constant_fold(folder, input("Vector")); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | void VectorCurvesNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	CurvesNode::compile(compiler, NODE_VECTOR_CURVES, input("Vector"), output("Vector")); | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void VectorCurvesNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-21 00:19:51 +02:00
										 |  |  | 	CurvesNode::compile(compiler, "node_vector_curves"); | 
					
						
							| 
									
										
										
										
											2012-12-11 14:39:37 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | /* RGBRampNode */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(RGBRampNode) | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("rgb_ramp", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_COLOR_ARRAY(ramp, "Ramp", array<float3>()); | 
					
						
							|  |  |  | 	SOCKET_FLOAT_ARRAY(ramp_alpha, "Ramp Alpha", array<float>()); | 
					
						
							|  |  |  | 	SOCKET_BOOLEAN(interpolate, "Interpolate", true); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(fac, "Fac", 0.0f); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_OUT_COLOR(color, "Color"); | 
					
						
							|  |  |  | 	SOCKET_OUT_FLOAT(alpha, "Alpha"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2013-05-10 11:44:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | RGBRampNode::RGBRampNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-30 23:30:36 +02:00
										 |  |  | void RGBRampNode::constant_fold(const ConstantFolder& folder) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if(ramp.size() == 0 || ramp.size() != ramp_alpha.size()) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if(folder.all_inputs_constant()) { | 
					
						
							|  |  |  | 		float f = clamp(fac, 0.0f, 1.0f) * (ramp.size() - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		/* clamp int as well in case of NaN */ | 
					
						
							|  |  |  | 		int i = clamp((int)f, 0, ramp.size()-1); | 
					
						
							|  |  |  | 		float t = f - (float)i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		bool use_lerp = interpolate && t > 0.0f; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(folder.output == output("Color")) { | 
					
						
							|  |  |  | 			float3 color = rgb_ramp_lookup(ramp.data(), fac, use_lerp, false, ramp.size()); | 
					
						
							|  |  |  | 			folder.make_constant(color); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if(folder.output == output("Alpha")) { | 
					
						
							|  |  |  | 			float alpha = float_ramp_lookup(ramp_alpha.data(), fac, use_lerp, false, ramp_alpha.size()); | 
					
						
							|  |  |  | 			folder.make_constant(alpha); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | void RGBRampNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 22:08:34 +02:00
										 |  |  | 	if(ramp.size() == 0 || ramp.size() != ramp_alpha.size()) | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | 	ShaderInput *fac_in = input("Fac"); | 
					
						
							|  |  |  | 	ShaderOutput *color_out = output("Color"); | 
					
						
							| 
									
										
										
										
											2012-03-26 13:21:43 +00:00
										 |  |  | 	ShaderOutput *alpha_out = output("Alpha"); | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-10 11:44:24 +00:00
										 |  |  | 	compiler.add_node(NODE_RGB_RAMP, | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.stack_assign(fac_in), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(color_out), | 
					
						
							|  |  |  | 			compiler.stack_assign_if_linked(alpha_out)), | 
					
						
							| 
									
										
										
										
											2013-05-10 11:44:24 +00:00
										 |  |  | 		interpolate); | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(ramp.size()); | 
					
						
							|  |  |  | 	for(int i = 0; i < ramp.size(); i++) | 
					
						
							|  |  |  | 		compiler.add_node(make_float4(ramp[i].x, ramp[i].y, ramp[i].z, ramp_alpha[i])); | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void RGBRampNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-17 22:08:34 +02:00
										 |  |  | 	if(ramp.size() == 0 || ramp.size() != ramp_alpha.size()) | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-08 01:54:35 +02:00
										 |  |  | 	compiler.parameter_color_array("ramp_color", ramp); | 
					
						
							|  |  |  | 	compiler.parameter_array("ramp_alpha", ramp_alpha.data(), ramp_alpha.size()); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "interpolate"); | 
					
						
							| 
									
										
										
										
											2012-09-15 15:41:37 +00:00
										 |  |  | 	 | 
					
						
							| 
									
										
										
										
											2012-03-26 12:45:14 +00:00
										 |  |  | 	compiler.add(this, "node_rgb_ramp"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | /* Set Normal Node */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(SetNormalNode) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	NodeType* type = NodeType::add("set_normal", create, NodeType::SHADER); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	SOCKET_IN_VECTOR(direction, "Direction", make_float3(0.0f, 0.0f, 0.0f)); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(normal, "Normal"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | SetNormalNode::SetNormalNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SetNormalNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput  *direction_in = input("Direction"); | 
					
						
							|  |  |  | 	ShaderOutput *normal_out = output("Normal"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 	compiler.add_node(NODE_CLOSURE_SET_NORMAL, | 
					
						
							|  |  |  | 		compiler.stack_assign(direction_in), | 
					
						
							|  |  |  | 		compiler.stack_assign(normal_out)); | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SetNormalNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-10-20 15:09:36 +00:00
										 |  |  | 	compiler.add(this, "node_set_normal");  | 
					
						
							| 
									
										
										
										
											2012-10-10 15:56:43 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | /* OSLNode */ | 
					
						
							| 
									
										
										
										
											2012-11-03 14:32:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | OSLNode::OSLNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(new NodeType(NodeType::SHADER)) | 
					
						
							| 
									
										
										
										
											2012-11-03 14:32:35 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-10-30 11:21:31 +00:00
										 |  |  | 	special_type = SHADER_SPECIAL_TYPE_SCRIPT; | 
					
						
							| 
									
										
										
										
											2012-11-03 14:32:35 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | OSLNode::~OSLNode() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	delete type; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-18 12:30:59 +02:00
										 |  |  | ShaderNode *OSLNode::clone() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-07-21 02:50:30 +02:00
										 |  |  | 	return OSLNode::create(this->inputs.size(), this); | 
					
						
							| 
									
										
										
										
											2016-06-18 12:30:59 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-21 02:50:30 +02:00
										 |  |  | OSLNode* OSLNode::create(size_t num_inputs, const OSLNode *from) | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* allocate space for the node itself and parameters, aligned to 16 bytes
 | 
					
						
							|  |  |  | 	 * assuming that's the most parameter types need */ | 
					
						
							|  |  |  | 	size_t node_size = align_up(sizeof(OSLNode), 16); | 
					
						
							|  |  |  | 	size_t inputs_size = align_up(SocketType::max_size(), 16) * num_inputs; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	char *node_memory = (char*) operator new(node_size + inputs_size); | 
					
						
							|  |  |  | 	memset(node_memory, 0, node_size + inputs_size); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-24 12:26:12 +02:00
										 |  |  | 	if(!from) { | 
					
						
							| 
									
										
										
										
											2016-07-21 02:50:30 +02:00
										 |  |  | 		return new(node_memory) OSLNode(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		/* copy input default values and node type for cloning */ | 
					
						
							|  |  |  | 		memcpy(node_memory + node_size, (char*)from + node_size, inputs_size); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		OSLNode *node = new(node_memory) OSLNode(*from); | 
					
						
							|  |  |  | 		node->type = new NodeType(*(from->type)); | 
					
						
							|  |  |  | 		return node; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | char* OSLNode::input_default_value() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/* pointer to default value storage, which is the same as our actual value */ | 
					
						
							|  |  |  | 	size_t num_inputs = type->inputs.size(); | 
					
						
							|  |  |  | 	size_t inputs_size = align_up(SocketType::max_size(), 16) * num_inputs; | 
					
						
							|  |  |  | 	return (char*)this + align_up(sizeof(OSLNode), 16) + inputs_size; | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | void OSLNode::add_input(ustring name, SocketType::Type socket_type) | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  |     char *memory = input_default_value(); | 
					
						
							|  |  |  | 	size_t offset = memory - (char*)this; | 
					
						
							|  |  |  | 	const_cast<NodeType*>(type)->register_input(name, name, socket_type, offset, memory, NULL, NULL, SocketType::LINKABLE); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSLNode::add_output(ustring name, SocketType::Type socket_type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	const_cast<NodeType*>(type)->register_output(name, name, socket_type); | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSLNode::compile(SVMCompiler&) | 
					
						
							| 
									
										
										
										
											2012-11-03 14:32:35 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* doesn't work for SVM, obviously ... */ | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 15:10:34 +02:00
										 |  |  | void OSLNode::compile(OSLCompiler& compiler) | 
					
						
							| 
									
										
										
										
											2012-11-03 14:32:35 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	if(!filepath.empty()) | 
					
						
							|  |  |  | 		compiler.add(this, filepath.c_str(), true); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		compiler.add(this, bytecode_hash.c_str(), false); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | /* Normal Map */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(NormalMapNode) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("normal_map", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum space_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	space_enum.insert("tangent", NODE_NORMAL_MAP_TANGENT); | 
					
						
							|  |  |  | 	space_enum.insert("object", NODE_NORMAL_MAP_OBJECT); | 
					
						
							|  |  |  | 	space_enum.insert("world", NODE_NORMAL_MAP_WORLD); | 
					
						
							|  |  |  | 	space_enum.insert("blender_object", NODE_NORMAL_MAP_BLENDER_OBJECT); | 
					
						
							|  |  |  | 	space_enum.insert("blender_world", NODE_NORMAL_MAP_BLENDER_WORLD); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(space, "Space", space_enum, NODE_TANGENT_RADIAL); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_STRING(attribute, "Attribute", ustring("")); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_IN_FLOAT(strength, "Strength", 1.0f); | 
					
						
							|  |  |  | 	SOCKET_IN_COLOR(color, "Color", make_float3(0.5f, 0.5f, 1.0f)); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_OUT_NORMAL(normal, "Normal"); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-11-08 16:35:20 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NormalMapNode::NormalMapNode() | 
					
						
							|  |  |  | : ShaderNode(node_type) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void NormalMapNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) { | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		if(attribute == ustring("")) { | 
					
						
							|  |  |  | 			attributes->add(ATTR_STD_UV_TANGENT); | 
					
						
							|  |  |  | 			attributes->add(ATTR_STD_UV_TANGENT_SIGN); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			attributes->add(ustring((string(attribute.c_str()) + ".tangent").c_str())); | 
					
						
							|  |  |  | 			attributes->add(ustring((string(attribute.c_str()) + ".tangent_sign").c_str())); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-15 16:35:05 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		attributes->add(ATTR_STD_VERTEX_NORMAL); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NormalMapNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderInput  *color_in = input("Color"); | 
					
						
							| 
									
										
										
										
											2012-11-08 16:35:20 +00:00
										 |  |  | 	ShaderInput  *strength_in = input("Strength"); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	ShaderOutput *normal_out = output("Normal"); | 
					
						
							|  |  |  | 	int attr = 0, attr_sign = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(space == NODE_NORMAL_MAP_TANGENT) { | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		if(attribute == ustring("")) { | 
					
						
							|  |  |  | 			attr = compiler.attribute(ATTR_STD_UV_TANGENT); | 
					
						
							|  |  |  | 			attr_sign = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			attr = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent").c_str())); | 
					
						
							|  |  |  | 			attr_sign = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent_sign").c_str())); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_NORMAL_MAP, | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.stack_assign(color_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(strength_in), | 
					
						
							|  |  |  | 			compiler.stack_assign(normal_out), | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			space), | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		attr, attr_sign); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void NormalMapNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(space == NODE_NORMAL_MAP_TANGENT) { | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		if(attribute == ustring("")) { | 
					
						
							|  |  |  | 			compiler.parameter("attr_name", ustring("geom:tangent")); | 
					
						
							|  |  |  | 			compiler.parameter("attr_sign_name", ustring("geom:tangent_sign")); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else { | 
					
						
							|  |  |  | 			compiler.parameter("attr_name", ustring((string(attribute.c_str()) + ".tangent").c_str())); | 
					
						
							|  |  |  | 			compiler.parameter("attr_sign_name", ustring((string(attribute.c_str()) + ".tangent_sign").c_str())); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "space"); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	compiler.add(this, "node_normal_map");  | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* Tangent */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | NODE_DEFINE(TangentNode) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	NodeType* type = NodeType::add("tangent", create, NodeType::SHADER); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum direction_type_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	direction_type_enum.insert("radial", NODE_TANGENT_RADIAL); | 
					
						
							|  |  |  | 	direction_type_enum.insert("uv_map", NODE_TANGENT_UVMAP); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(direction_type, "Direction Type", direction_type_enum, NODE_TANGENT_RADIAL); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	static NodeEnum axis_enum; | 
					
						
							| 
									
										
										
										
											2016-06-11 21:56:47 +02:00
										 |  |  | 	axis_enum.insert("x", NODE_TANGENT_AXIS_X); | 
					
						
							|  |  |  | 	axis_enum.insert("y", NODE_TANGENT_AXIS_Y); | 
					
						
							|  |  |  | 	axis_enum.insert("z", NODE_TANGENT_AXIS_Z); | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_ENUM(axis, "Axis", axis_enum, NODE_TANGENT_AXIS_X); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_STRING(attribute, "Attribute", ustring("")); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	SOCKET_IN_NORMAL(normal_osl, "NormalIn", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL | SocketType::OSL_INTERNAL); | 
					
						
							|  |  |  | 	SOCKET_OUT_NORMAL(tangent, "Tangent"); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	return type; | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TangentNode::TangentNode() | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | : ShaderNode(node_type) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | void TangentNode::attributes(Shader *shader, AttributeRequestSet *attributes) | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	if(shader->has_surface) { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 		if(direction_type == NODE_TANGENT_UVMAP) { | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 			if(attribute == ustring("")) | 
					
						
							|  |  |  | 				attributes->add(ATTR_STD_UV_TANGENT); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				attributes->add(ustring((string(attribute.c_str()) + ".tangent").c_str())); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 			attributes->add(ATTR_STD_GENERATED); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2013-12-31 17:30:34 +01:00
										 |  |  | 	ShaderNode::attributes(shader, attributes); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TangentNode::compile(SVMCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	ShaderOutput *tangent_out = output("Tangent"); | 
					
						
							|  |  |  | 	int attr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(direction_type == NODE_TANGENT_UVMAP) { | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		if(attribute == ustring("")) | 
					
						
							|  |  |  | 			attr = compiler.attribute(ATTR_STD_UV_TANGENT); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			attr = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent").c_str())); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		attr = compiler.attribute(ATTR_STD_GENERATED); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	compiler.add_node(NODE_TANGENT, | 
					
						
							|  |  |  | 		compiler.encode_uchar4( | 
					
						
							| 
									
										
										
										
											2016-05-02 20:12:42 +02:00
										 |  |  | 			compiler.stack_assign(tangent_out), | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 			direction_type, | 
					
						
							|  |  |  | 			axis), attr); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void TangentNode::compile(OSLCompiler& compiler) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-05-29 16:13:14 +02:00
										 |  |  | 	if(direction_type == NODE_TANGENT_UVMAP) { | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 		if(attribute == ustring("")) | 
					
						
							|  |  |  | 			compiler.parameter("attr_name", ustring("geom:tangent")); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			compiler.parameter("attr_name", ustring((string(attribute.c_str()) + ".tangent").c_str())); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-07 19:48:28 +02:00
										 |  |  | 	compiler.parameter(this, "direction_type"); | 
					
						
							|  |  |  | 	compiler.parameter(this, "axis"); | 
					
						
							| 
									
										
										
										
											2012-11-06 19:59:02 +00:00
										 |  |  | 	compiler.add(this, "node_tangent");  | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-27 11:58:34 +00:00
										 |  |  | CCL_NAMESPACE_END |