[Bf-blender-cvs] [baa0f0e] master: Cycles: Support builtin images for OSL shading backend

Sergey Sharybin noreply at git.blender.org
Fri Jun 13 16:44:14 CEST 2014


Commit: baa0f0ee1ace8b14afdacd88c121f080906edbc0
Author: Sergey Sharybin
Date:   Thu Jun 12 13:26:48 2014 +0600
https://developer.blender.org/rBbaa0f0ee1ace8b14afdacd88c121f080906edbc0

Cycles: Support builtin images for OSL shading backend

This means packed images and movies are now supported when using OSL
backend for material shading.

Uses special file name to distinguish whether image is builtin or not.
This part might become a bit smarted or optimized a bit, but it's good
enough with this implementation already.

===================================================================

M	intern/cycles/kernel/osl/osl_services.cpp
M	intern/cycles/render/nodes.cpp

===================================================================

diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp
index 8fe48b9..6a59a38 100644
--- a/intern/cycles/kernel/osl/osl_services.cpp
+++ b/intern/cycles/kernel/osl/osl_services.cpp
@@ -871,14 +871,30 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
 		return true;
 	}
 #endif
+	bool status;
 
-	OSLThreadData *tdata = kg->osl_tdata;
-	OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
+	if(filename[0] == '@' && filename.find('.') == -1) {
+        int slot = atoi(filename.c_str() + 1);
+		float4 rgba = kernel_tex_image_interp(slot, s, 1.0f - t);
 
-	OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
+		result[0] = rgba[0];
+		if(options.nchannels > 1)
+			result[1] = rgba[1];
+		if(options.nchannels > 2)
+			result[2] = rgba[2];
+		if(options.nchannels > 3)
+			result[3] = rgba[3];
+		status = true;
+	}
+	else {
+		OSLThreadData *tdata = kg->osl_tdata;
+		OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
+
+		OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
 
-	bool status = ts->texture(th, thread_info,
-	                          options, s, t, dsdx, dtdx, dsdy, dtdy, result);
+		status = ts->texture(th, thread_info,
+		                     options, s, t, dsdx, dtdx, dsdy, dtdy, result);
+	}
 
 	if(!status) {
 		if(options.nchannels == 3 || options.nchannels == 4) {
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 1a1667f..2d7f9ea 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -305,10 +305,32 @@ void ImageTextureNode::compile(OSLCompiler& compiler)
 
 	tex_mapping.compile(compiler);
 
-	if(is_float == -1)
-		is_float = (int)image_manager->is_float_image(filename, NULL, is_linear);
+	image_manager = compiler.image_manager;
+	if(is_float == -1) {
+		if(builtin_data == NULL) {
+			is_float = (int)image_manager->is_float_image(filename, NULL, is_linear);
+		}
+		else {
+			bool is_float_bool;
+			slot = image_manager->add_image(filename, builtin_data,
+			                                animated, is_float_bool, is_linear,
+			                                interpolation, use_alpha);
+			is_float = (int)is_float_bool;
+		}
+	}
 
-	compiler.parameter("filename", filename.c_str());
+	if(slot == -1) {
+		compiler.parameter("filename", filename.c_str());
+	}
+	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());
+	}
 	if(is_linear || color_space != "Color")
 		compiler.parameter("color_space", "Linear");
 	else
@@ -459,10 +481,28 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler)
 
 	tex_mapping.compile(compiler);
 
-	if(is_float == -1)
-		is_float = (int)image_manager->is_float_image(filename, NULL, is_linear);
+	/* See comments in ImageTextureNode::compile about support
+	 * of builtin images.
+	 */
+	if(is_float == -1) {
+		if(builtin_data == NULL) {
+			is_float = (int)image_manager->is_float_image(filename, NULL, is_linear);
+		}
+		else {
+			bool is_float_bool;
+			slot = image_manager->add_image(filename, builtin_data,
+			                                animated, is_float_bool, is_linear,
+			                                INTERPOLATION_LINEAR, use_alpha);
+			is_float = (int)is_float_bool;
+		}
+	}
 
-	compiler.parameter("filename", filename.c_str());
+	if(slot == -1) {
+		compiler.parameter("filename", filename.c_str());
+	}
+	else {
+		compiler.parameter("filename", string_printf("@%d", slot).c_str());
+	}
 	compiler.parameter("projection", projection);
 	if(is_linear || color_space != "Color")
 		compiler.parameter("color_space", "Linear");
@@ -4121,4 +4161,3 @@ void TangentNode::compile(OSLCompiler& compiler)
 }
 
 CCL_NAMESPACE_END
-




More information about the Bf-blender-cvs mailing list