[Bf-blender-cvs] [1013aae] cycles-ptex-06: Edge iterator

Nicholas Bishop noreply at git.blender.org
Thu Jan 15 20:13:29 CET 2015


Commit: 1013aaef2d83ecf1af442e3e05f23272ba8db98c
Author: Nicholas Bishop
Date:   Thu Jan 15 16:51:38 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rB1013aaef2d83ecf1af442e3e05f23272ba8db98c

Edge iterator

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

M	intern/cycles/render/image.cpp

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

diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index cd28e00..ec98654 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -87,6 +87,99 @@ static int ptex_data_type_size_in_bytes(const Ptex::DataType dt)
 	return 0;
 }
 
+struct PtexEdgeIter {
+	/* Set up a texel iterator for one edge of a face
+	 *
+	 * face and edge_id: specify the edge being iterated over
+	 *
+	 * from_res: the resolution of a neighboring face, controls the
+	 *           distance to step each time next() is called; next()
+	 *           can be called up to `from_res` times.
+	 *
+	 * reverse: iterate over the edge backwards. In general this is
+	 *          `true` because adjacent face edges have (implicit)
+	 *          opposite directions.
+	 */
+	PtexEdgeIter(PtexFaceData &face,
+				 const Ptex::EdgeId edge_id,
+				 const int from_res,
+				 const bool reverse)
+		: face(face)
+	{
+		const Ptex::Res &res = face.res();
+
+		float u_res = res.u() - 1.0f;
+		float v_res = res.v() - 1.0f;
+		const float u_step = (u_res + 1.0f) / (float)from_res;
+		const float v_step = (v_res + 1.0f) / (float)from_res;
+
+		switch (edge_id) {
+			case Ptex::e_bottom:
+				if (reverse) {
+					pos = make_float2(u_res, 0);
+					step = make_float2(-u_step, 0);
+				}
+				else {
+					pos = make_float2(0, 0);
+					step = make_float2(u_step, 0);
+				}
+				break;
+
+			case Ptex::e_right:
+				if (reverse) {
+					pos = make_float2(u_res, v_res);
+					step = make_float2(0, -v_step);
+				}
+				else {
+					pos = make_float2(u_res, 0);
+					step = make_float2(0, v_step);
+				}
+				break;
+
+			case Ptex::e_top:
+				if (reverse) {
+					pos = make_float2(0, v_res);
+					step = make_float2(u_step, 0);
+				}
+				else {
+					pos = make_float2(u_res, v_res);
+					step = make_float2(-u_step, 0);
+				}
+				break;
+
+			case Ptex::e_left:
+				if (reverse) {
+					pos = make_float2(0, 0);
+					step = make_float2(0, v_step);
+				}
+				else {
+					pos = make_float2(0, v_res);
+					step = make_float2(0, -v_step);
+				}
+		}
+	}
+
+	void next() {
+		pos += step;
+	}
+
+	/* TODO(nicholasbishop): not doing any special filtering for
+	 * adjacent faces of differing resolutions, not sure how much that
+	 * will matter in practice */
+	void read_texel(void *texel)
+	{
+		const int x = (int)(pos.x);
+		const int y = (int)(pos.y);
+		assert(x < face.res().u());
+		assert(y < face.res().v());
+		face.getPixel(x, y, texel);
+	}
+
+	PtexFaceData &face;
+	float2 pos;
+	float2 step;
+};
+
 // TODO: probably excessive calculation here, might look at making
 // into an iterator design
 //
@@ -179,8 +272,8 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 	const int bpt = output.bytes_per_texel;
 	int dst_offset = ((elem.co[1] * output.width + elem.co[0]) * bpt);
 
-	if (face_id != 14)
-		;//return;
+	if (face_id != 0)
+		return;
 
 	r->getData(face_id, output.texels.data() + dst_offset, dst_stride);
 
@@ -235,15 +328,18 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 		// TODO, all kinds of uglyness here
 
 		if (no_adj) {
+			PtexEdgeIter iter(*face_data[0], adj_edge[0], side_res, false);
 			for (int j = 0; j < side_res; j++) {
 				float t = (float)j / (float)(side_res - 1);
 
 				assert(output.valid_pixel_index(dst_offset));
-				ptex_read_border_pixel(*face_data[0], adj_edge[0], t,
-									   output.texels.data() +
-									   dst_offset);
+				// ptex_read_border_pixel(*face_data[0], adj_edge[0], t,
+				// 					   output.texels.data() +
+				// 					   dst_offset);
+				iter.read_texel(output.texels.data() + dst_offset);
 
 				dst_offset += x_inc[i] + y_inc[i];
+				iter.next();
 			}
 		}
 		else if (is_subface && !adj_info.isSubface()) {
@@ -303,6 +399,8 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 			}
 		}
 		else {
+			PtexEdgeIter iter(*face_data[0], adj_edge[0], side_res, true);
+
 			for (int j = 0; j < side_res; j++) {
 				assert(output.valid_pixel_index(dst_offset));
 
@@ -312,12 +410,14 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
 
 				// Adjacent edge will have opposite direction
 				t = 1 - t;
-			
-				ptex_read_border_pixel(*face_data[0], adj_edge[0], t,
-									   output.texels.data() +
-									   dst_offset);
+
+				iter.read_texel(output.texels.data() + dst_offset);
+				// ptex_read_border_pixel(*face_data[0], adj_edge[0], t,
+				// 					   output.texels.data() +
+				// 					   dst_offset);
 
 				dst_offset += x_inc[i] + y_inc[i];
+				iter.next();
 			}
 		}
 	}




More information about the Bf-blender-cvs mailing list