[Bf-blender-cvs] [434ebc0] cycles-ptex-24: WIP ptex node in cycles

Nicholas Bishop noreply at git.blender.org
Fri Jan 30 18:00:43 CET 2015


Commit: 434ebc054990c41e0bbafa7427b346d124924152
Author: Nicholas Bishop
Date:   Sun Jan 25 22:48:59 2015 +0100
Branches: cycles-ptex-24
https://developer.blender.org/rB434ebc054990c41e0bbafa7427b346d124924152

WIP ptex node in cycles

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/blender/blender_session.cpp
M	intern/cycles/blender/blender_session.h
M	intern/cycles/blender/blender_shader.cpp
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/svm/svm_image.h
M	intern/cycles/render/attribute.cpp
M	intern/cycles/render/attribute.h
M	intern/cycles/render/image.cpp
M	intern/cycles/render/image.h
M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/mesh.h
M	intern/cycles/render/nodes.cpp
M	intern/cycles/render/nodes.h
M	intern/cycles/util/util_types.h

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 295dade..e0a350c 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -388,6 +388,33 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
 		}
 	}
 
+	// TODO
+#if 1
+	{
+		BL::Mesh::loop_ptex_iterator l;
+		for (b_mesh.loop_ptex.begin(l); l != b_mesh.loop_ptex.end(); ++l) {
+			const ustring layer_name = ustring(l->name());
+			if (mesh->need_attribute(scene, layer_name)) {
+				Attribute *attr = mesh->attributes.add(layer_name,
+													   TypeDesc::TypeFloat,
+													   ATTR_ELEMENT_MESH);
+				//mesh->attributes.reserve();
+				float *slot = attr->data_float();
+				bool is_float;
+				bool is_linear;
+				// TODO
+
+				BL::Image image = l->image();
+
+				// Other alternative is: get data, pack new image here
+				(*slot) = scene->image_manager->add_image
+					("TODO", image.ptr.data, false, 1,
+					 is_float, is_linear, INTERPOLATION_LINEAR, true);
+			}
+		}
+	}
+#endif
+
 	/* create vertex color attributes */
 	{
 		BL::Mesh::tessface_vertex_colors_iterator l;
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index eb3f54a..db70bad 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -101,8 +101,8 @@ void BlenderSession::create_session()
 	scene = new Scene(scene_params, session_params.device);
 
 	/* setup callbacks for builtin image support */
-	scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6, _7);
-	scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3);
+	scene->image_manager->builtin_image_info_cb = function_bind(&BlenderSession::builtin_image_info, this, _1, _2, _3, _4, _5, _6, _7, _8);
+	scene->image_manager->builtin_image_pixels_cb = function_bind(&BlenderSession::builtin_image_pixels, this, _1, _2, _3, _4, _5);
 	scene->image_manager->builtin_image_float_pixels_cb = function_bind(&BlenderSession::builtin_image_float_pixels, this, _1, _2, _3);
 
 	/* create session */
@@ -927,7 +927,7 @@ int BlenderSession::builtin_image_frame(const string &builtin_name)
 	return atoi(builtin_name.substr(last + 1, builtin_name.size() - last - 1).c_str());
 }
 
-void BlenderSession::builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &depth, int &channels)
+void BlenderSession::builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &depth, int &channels, int &num_ptex_regions)
 {
 	/* empty image */
 	is_float = false;
@@ -953,6 +953,10 @@ void BlenderSession::builtin_image_info(const string &builtin_name, void *builti
 		height = b_image.size()[1];
 		depth = 1;
 		channels = b_image.channels();
+
+		// TODO: ptex
+		is_float = false;
+		num_ptex_regions = b_image.ptex_regions().length;
 	}
 	else if(b_id.is_a(&RNA_Object)) {
 		/* smoke volume data */
@@ -981,7 +985,8 @@ void BlenderSession::builtin_image_info(const string &builtin_name, void *builti
 	}
 }
 
-bool BlenderSession::builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels)
+bool BlenderSession::builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels,
+										  PtexRegions ptex_regions, const int num_ptex_regions)
 {
 	if(!builtin_data)
 		return false;
@@ -1019,6 +1024,14 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name, void *buil
 		}
 	}
 
+	{
+		// TODO
+		BL::DynamicArray<int> regions = b_image.ptex_regions();
+		assert(num_ptex_regions == regions.length);
+		memcpy(ptex_regions, regions.data,
+			   sizeof(**ptex_regions) * num_ptex_regions);
+	}
+
 	/* premultiply, byte images are always straight for blender */
 	unsigned char *cp = pixels;
 	for(int i = 0; i < width * height; i++, cp += channels) {
diff --git a/intern/cycles/blender/blender_session.h b/intern/cycles/blender/blender_session.h
index 33da307..0eeabda 100644
--- a/intern/cycles/blender/blender_session.h
+++ b/intern/cycles/blender/blender_session.h
@@ -104,8 +104,9 @@ protected:
 	void do_write_update_render_tile(RenderTile& rtile, bool do_update_only);
 
 	int builtin_image_frame(const string &builtin_name);
-	void builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &depth, int &channels);
-	bool builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels);
+	void builtin_image_info(const string &builtin_name, void *builtin_data, bool &is_float, int &width, int &height, int &depth, int &channels, int &num_ptex_regions);
+	bool builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels,
+							  PtexRegions ptex_regions, int num_ptex_regions);
 	bool builtin_image_float_pixels(const string &builtin_name, void *builtin_data, float *pixels);
 };
 
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index baf79a7..e485e39 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -591,6 +591,15 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
 		get_tex_mapping(&image->tex_mapping, b_image_node.texture_mapping());
 		node = image;
 	}
+	else if (b_node.is_a(&RNA_ShaderNodeTexPtex)) {
+		// TODO
+		BL::ShaderNodeTexPtex b_image_node(b_node);
+		PtexTextureNode *image = new PtexTextureNode();
+
+		image->ptex = true;
+		image->ptex_layer = b_image_node.layer_name();
+		node = image;
+	}
 	else if (b_node.is_a(&RNA_ShaderNodeTexEnvironment)) {
 		BL::ShaderNodeTexEnvironment b_env_node(b_node);
 		BL::Image b_image(b_env_node.image());
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 77d3ea8..19452b9 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -534,6 +534,7 @@ typedef enum AttributeStandard {
 	ATTR_STD_VOLUME_FLAME,
 	ATTR_STD_VOLUME_HEAT,
 	ATTR_STD_VOLUME_VELOCITY,
+	ATTR_STD_PTEX_LAYER,
 	ATTR_STD_NUM,
 
 	ATTR_STD_NOT_FOUND = ~0
diff --git a/intern/cycles/kernel/svm/svm_image.h b/intern/cycles/kernel/svm/svm_image.h
index 3f1f956..3be70f0 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -380,13 +380,26 @@ ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *sta
 
 	float4 f;
 
+	// TODO
+	if (srgb & 4) {
+		AttributeElement ae;
+		int image_attr_offset = find_attribute(kg, sd, id, &ae);
+		assert(image_attr_offset != ATTR_STD_NOT_FOUND);
+		float fid = kernel_tex_fetch(__attributes_float, image_attr_offset);
+		id = (int)(fid + 0.5f);
+		//assert(id == 1024 || id == 1025);
+	}
+	else {
+		assert(false);
+	}
+
 	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);
+		uint offset = kernel_tex_fetch(__ptex_table, id - /* TODO */ 1024);
 		float2 tex_size =
 			make_float2((float)kernel_tex_fetch(__ptex_table, offset + 0),
 						(float)kernel_tex_fetch(__ptex_table, offset + 1));
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp
index 15d7134..2ec38f1 100644
--- a/intern/cycles/render/attribute.cpp
+++ b/intern/cycles/render/attribute.cpp
@@ -230,6 +230,8 @@ const char *Attribute::standard_name(AttributeStandard std)
 			return "heat";
 		case ATTR_STD_VOLUME_VELOCITY:
 			return "velocity";
+		case ATTR_STD_PTEX_LAYER:
+			return "ptex_layer";
 		case ATTR_STD_NOT_FOUND:
 		case ATTR_STD_NONE:
 		case ATTR_STD_NUM:
@@ -375,6 +377,9 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name)
 			case ATTR_STD_VOLUME_VELOCITY:
 				attr = add(name, TypeDesc::TypeVector, ATTR_ELEMENT_VOXEL);
 				break;
+			case ATTR_STD_PTEX_LAYER:
+				attr = add(name, TypeDesc::TypeFloat, ATTR_ELEMENT_MESH);
+				break;
 			default:
 				assert(0);
 				break;
@@ -456,32 +461,35 @@ void AttributeSet::clear()
 
 /* AttributeRequest */
 
-AttributeRequest::AttributeRequest(ustring name_)
+static void attribute_request_init(AttributeRequest &req,
+								   AttributeStandard std,
+								   ustring name)
 {
-	name = name_;
-	std = ATTR_STD_NONE;
+	req.name = name;
+	req.std = std;
 
-	triangle_type = TypeDesc::TypeFloat;
-	triangle_element = ATTR_ELEMENT_NONE;
-	triangle_offset = 0;
+	req.triangle_type = TypeDesc::TypeFloat;
+	req.triangle_element = ATTR_ELEMENT_NONE;
+	req.triangle_offset = 0;
 
-	curve_type = TypeDesc::TypeFloat;
-	curve_element = ATTR_ELEMENT_NONE;
-	curve_offset = 0;
+	req.curve_type = TypeDesc::TypeFloat;
+	req.curve_element = ATTR_ELEMENT_NONE;
+	req.curve_offset = 0;
 }
 
-AttributeRequest::AttributeRequest(AttributeStandard std_)
+AttributeRequest::AttributeRequest(ustring name_)
 {
-	name = ustring();
-	std = std_;
+	attribute_request_init(*this, ATTR_STD_NONE, name_);
+}
 
-	triangle_type = TypeDesc::TypeFloat;
-	triangle_element = ATTR_ELEMENT_NONE;
-	triangle_offset = 0;
+AttributeRequest::AttributeRequest(AttributeStandard std_)
+{
+	attribute_request_init(*this, std_, ustring());
+}
 
-	curve_type = TypeDesc::TypeFloat;
-	curve_element = ATTR_ELEMENT_NONE;
-	curve_offset = 0;
+AttributeRequest::AttributeRequest(AttributeStandard std_, ustring name_)
+{
+	attribute_request_init(*this, std_, name_);
 }
 
 /* AttributeRequestSet */
@@ -535,6 +543,14 @@ void AttributeRequestSet::add(AttributeStandard std)
 	requests.push_back(AttributeRequest(std));
 }
 
+void AttributeRequestSet::add(AttributeStandard std, ustring name)
+{
+	if (find(std, name))
+		return;
+
+	requests.push_back(AttributeRequest(std, name));
+}
+
 void AttributeRequestSet::add(AttributeRequestSet& reqs)
 {
 	foreach(AttributeRequest& req, reqs.requests) {
@@ -563,6 +579,15 @@ bool AttributeRequestSet::find(AttributeStandard std)
 	return false;
 }
 
+bool AttributeRequestSet::find(AttributeStand

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list