[Bf-blender-cvs] [a6aac09b] cycles-ptex-19: WIP ptex node in cycles

Nicholas Bishop noreply at git.blender.org
Wed Jan 28 19:40:41 CET 2015


Commit: a6aac09b5b6afd6f8bc391fafcc1419df48d79a0
Author: Nicholas Bishop
Date:   Sun Jan 25 22:48:59 2015 +0100
Branches: cycles-ptex-19
https://developer.blender.org/rBa6aac09b5b6afd6f8bc391fafcc1419df48d79a0

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

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index 295dade..c3a9b48 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -388,6 +388,31 @@ static void create_mesh(Scene *scene, Mesh *mesh, BL::Mesh b_mesh, const vector<
 		}
 	}
 
+	// TODO
+#if 1
+	if (mesh->need_attribute(scene, ATTR_STD_PTEX_LAYER, ustring("TODO"))) {
+		Attribute *attr = mesh->attributes.add(ATTR_STD_PTEX_LAYER);
+		mesh->attributes.reserve();
+
+		BL::Mesh::loop_ptex_iterator l;
+		
+		float *slot = attr->data_float();
+		bool is_float;
+		bool is_linear;
+		// Get layer, get RNA image pointer
+		// TODO
+		for (b_mesh.loop_ptex.begin(l); l != b_mesh.loop_ptex.end(); ++l) {
+
+			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..e0db0e1 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, bool &is_ptex)
 {
 	/* empty image */
 	is_float = false;
@@ -953,6 +953,9 @@ void BlenderSession::builtin_image_info(const string &builtin_name, void *builti
 		height = b_image.size()[1];
 		depth = 1;
 		channels = b_image.channels();
+
+		// TODO
+		is_float = false;
 	}
 	else if(b_id.is_a(&RNA_Object)) {
 		/* smoke volume data */
@@ -981,7 +984,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,
+										  void **ptex_table, int *ptex_table_len)
 {
 	if(!builtin_data)
 		return false;
@@ -1019,6 +1023,20 @@ bool BlenderSession::builtin_image_pixels(const string &builtin_name, void *buil
 		}
 	}
 
+	{
+		//b_image.ptex_table();
+		
+
+		BL::DynamicArray<float> table = b_image.ptex_table();
+		(*ptex_table_len) = table.length / 4;
+		// TODO
+		(*ptex_table) = table.data;
+		table.data = NULL;
+
+		//memcpy((*ptex_table) = b_image.ptex_table();
+		//(*ptex_table_len) = b_image.ptex_table_len();
+	}
+
 	/* 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..65a4c57 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, bool &is_ptex);
+	bool builtin_image_pixels(const string &builtin_name, void *builtin_data, unsigned char *pixels,
+							  void **ptex_table, int *ptex_table_len);
 	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..4e9accf 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 = "TODO";
+		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..71ed030 100644
--- a/intern/cycles/kernel/svm/svm_image.h
+++ b/intern/cycles/kernel/svm/svm_image.h
@@ -380,6 +380,11 @@ ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *sta
 
 	float4 f;
 
+	// TODO
+	if (srgb & 4) {
+		id = stack_load_int(stack, id);
+	}
+
 	if (srgb & 2) {
 		assert(co.x >= 0 && co.x <= 1);
 		assert(co.y >= 0 && co.y <= 1);
@@ -403,6 +408,9 @@ ccl_device void svm_node_tex_image(KernelGlobals *kg, ShaderData *sd, float *sta
 		float2 ptex_uv = ptex_origin + make_float2(co.x, co.y) * ptex_res;
 		ptex_uv /= tex_size;
 
+		// TODO :(
+		id = 1024;
+
 		f = svm_image_texture(kg, id, ptex_uv.x, ptex_uv.y, srgb,
 									 use_alpha);
 	}
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(AttributeStandard std, ustring name)
+{
+	foreach(AttributeRequest& req, requests)
+		if(req.std == std && req.name == name)
+			return true;
+
+	return false;
+}
+
 size_t AttributeRequestSet::size()
 {
 	return requests.size();
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index bbc6cf7..a73b2d4 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list