[Bf-blender-cvs] [d8d0160] cycles-ptex-06: Add flag to distinguish ptex files in texture node

Nicholas Bishop noreply at git.blender.org
Fri Jan 16 12:54:31 CET 2015


Commit: d8d016018dff8ce9590e02db72075058507660d5
Author: Nicholas Bishop
Date:   Fri Jan 16 11:59:53 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rBd8d016018dff8ce9590e02db72075058507660d5

Add flag to distinguish ptex files in texture node

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

M	intern/cycles/kernel/svm/svm_image.h
M	intern/cycles/render/nodes.cpp

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

diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index b4c624a..4c1f89c 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -395,34 +395,41 @@ ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *sta
 	float3 co = stack_load_float3(stack, co_offset);
 	uint use_alpha = stack_valid(alpha_offset);
 
-	assert(co.x >= 0 && co.x <= 1);
-	assert(co.y >= 0 && co.y <= 1);
-
-	// TODO: test hacks for Ptex
-	uint face_id = (uint)(co[2] + 0.5f);
-	uint offset = kernel_tex_fetch(__ptex_table, id);
-	float2 tex_size =
-		make_float2((float)kernel_tex_fetch(__ptex_table, offset + 0),
-					(float)kernel_tex_fetch(__ptex_table, offset + 1));
-	offset += 2;
-	offset += 4 * face_id;
-
-	float2 ptex_origin =
-		make_float2((float)kernel_tex_fetch(__ptex_table, offset + 0),
-					(float)kernel_tex_fetch(__ptex_table, offset + 1));
-	float2 ptex_res =
-		make_float2((float)kernel_tex_fetch(__ptex_table, offset + 2),
-					(float)kernel_tex_fetch(__ptex_table, offset + 3));
-
-	float2 ptex_uv = ptex_origin + make_float2(co.x, 1 - co.y) * ptex_res;
-	ptex_uv /= tex_size;
-
-	float4 f = svm_image_texture(kg, id, ptex_uv.x, ptex_uv.y, srgb,
-								 use_alpha);
-	/* f.x = face_id / 20.0f; */
-	/* f.y = 0; */
-	/* f.z = 0;  */
-	//float4 f = svm_image_texture(kg, id, co.x, co.y, srgb, use_alpha);
+	float4 f;
+
+	if (srgb & 2) {
+		assert(co.x >= 0 && co.x <= 1);
+		assert(co.y >= 0 && co.y <= 1);
+
+		// TODO: test hacks for Ptex
+		uint face_id = (uint)(co[2] + 0.5f);
+		uint offset = kernel_tex_fetch(__ptex_table, id);
+		float2 tex_size =
+			make_float2((float)kernel_tex_fetch(__ptex_table, offset + 0),
+						(float)kernel_tex_fetch(__ptex_table, offset + 1));
+		offset += 2;
+		offset += 4 * face_id;
+
+		float2 ptex_origin =
+			make_float2((float)kernel_tex_fetch(__ptex_table, offset + 0),
+						(float)kernel_tex_fetch(__ptex_table, offset + 1));
+		float2 ptex_res =
+			make_float2((float)kernel_tex_fetch(__ptex_table, offset + 2),
+						(float)kernel_tex_fetch(__ptex_table, offset + 3));
+
+		float2 ptex_uv = ptex_origin + make_float2(co.x, 1 - co.y) * ptex_res;
+		ptex_uv /= tex_size;
+
+		f = svm_image_texture(kg, id, ptex_uv.x, ptex_uv.y, srgb,
+									 use_alpha);
+		
+		/* f.x = face_id / 20.0f; */
+		/* f.y = 0; */
+		/* f.z = 0;  */
+	}
+	else {
+		f = svm_image_texture(kg, id, co.x, co.y, srgb, use_alpha);
+	}
 
 	if(stack_valid(out_offset))
 		stack_store_float3(stack, out_offset, make_float3(f.x, f.y, f.z));
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 7c3e4b2..853122d 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -258,6 +258,11 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
 		compiler.stack_assign(vector_in);
 
 		int srgb = (is_linear || color_space != "Color")? 0: 1;
+		// TODO(nicholasbishop): clean this up of course
+		int flags = srgb;
+		if (string_endswith(filename, ".ptx")) {
+			flags |= 2;
+		}
 		int vector_offset = vector_in->stack_offset;
 
 		if(!tex_mapping.skip()) {
@@ -272,7 +277,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
 					vector_offset,
 					color_out->stack_offset,
 					alpha_out->stack_offset,
-					srgb));
+					flags));
 		}
 		else {
 			compiler.add_node(NODE_TEX_IMAGE_BOX,
@@ -281,7 +286,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
 					vector_offset,
 					color_out->stack_offset,
 					alpha_out->stack_offset,
-					srgb),
+					flags & 1),
 				__float_as_int(projection_blend));
 		}




More information about the Bf-blender-cvs mailing list