[Bf-blender-cvs] [8c87fdb] cycles-ptex-06: Border fixes
Nicholas Bishop
noreply at git.blender.org
Thu Jan 15 20:13:27 CET 2015
Commit: 8c87fdb5064404e697b52ad2ca4cbb461212e273
Author: Nicholas Bishop
Date: Thu Jan 15 15:37:12 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rB8c87fdb5064404e697b52ad2ca4cbb461212e273
Border fixes
===================================================================
M intern/cycles/render/image.cpp
===================================================================
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index cce8536..cd28e00 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -89,6 +89,9 @@ static int ptex_data_type_size_in_bytes(const Ptex::DataType dt)
// TODO: probably excessive calculation here, might look at making
// into an iterator design
+//
+// Also TODO: not doing any special filtering for adjacent faces of
+// differing resolutions, not sure if that will matter in practice...
static void ptex_read_border_pixel(PtexFaceData &face,
const Ptex::EdgeId eid,
const float t, void *pixel)
@@ -171,23 +174,23 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
const int dst_stride,
const uint face_id)
{
-#if 0
PtexTableElement &elem = output.table[face_id];
const int bpt = output.bytes_per_texel;
int dst_offset = ((elem.co[1] * output.width + elem.co[0]) * bpt);
if (face_id != 14)
- return;
+ ;//return;
r->getData(face_id, output.texels.data() + dst_offset, dst_stride);
// Fill in borders
const Ptex::FaceInfo &info = r->getFaceInfo(face_id);
+ const bool is_subface = info.isSubface();
const int x_inc[4] = {bpt, 0, -bpt, 0};
const int y_inc[4] = {0, dst_stride, 0, -dst_stride};
dst_offset = ((elem.co[1] - 1) * output.width +
- (elem.co[0] - 1)) * bpt;
+ (elem.co[0] - 1)) * bpt;
//PtexBorderIter iter(output, r, face_id, dst_stride);
for (int i = 0; i < 4; i++) {
@@ -197,83 +200,127 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
Ptex::EdgeId adj_edge[2] = {info.adjedge(i)};
const int side_res = elem.res[(i == 0 || i == 2) ? 0 : 1];
- bool flip = true;
+ bool no_adj = false;
if (adj_face_id[0] == -1) {
- // If there's no adjacent face, pretend the face is
- // adjacent to itself (i.e. copy its own borders)
+ /* If there's no adjacent face, pretend the face is
+ * adjacent to itself (i.e. copy its own borders) */
adj_face_id[0] = face_id;
adj_edge[0] = (Ptex::EdgeId)i;
- flip = false;
+ no_adj = true;
}
const Ptex::FaceInfo &adj_info = r->getFaceInfo(adj_face_id[0]);
- if (!info.isSubface() && adj_info.isSubface()) {
- // Face is adjacent to two subfaces
- adj_face_id =
+ if (!is_subface && adj_info.isSubface()) {
+ /* Face is adjacent to two subfaces */
+ int next_edge_id = (adj_edge[0] + 3) % 4;
+ adj_face_id[1] = adj_info.adjface(next_edge_id);
+ adj_edge[1] = adj_info.adjedge(next_edge_id);
+ adj_edge[1] = (Ptex::EdgeId)((adj_edge[1] + 3) % 4);
}
-
-
// TODO: handle faces adjacent to subfaces correctly
// TODO: handle subfaces adjacent to faces correctly
// TODO: handle corners correctly
- dst_offset += x_inc[i];
- dst_offset += y_inc[i];
+ dst_offset += x_inc[i] + y_inc[i];
+
+ PtexFaceData *face_data[2] = {
+ r->getData(adj_face_id[0]),
+ adj_face_id[1] == -1 ? NULL : r->getData(adj_face_id[1])
+ };
- PtexFaceData &face_data = *r->getData(adj_face);
- for (int j = 0; j < side_res; j++) {
- assert(output.valid_pixel_index(dst_offset));
+ // TODO, all kinds of uglyness here
- // TODO, all kinds of uglyness here
+ if (no_adj) {
+ 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);
+
+ dst_offset += x_inc[i] + y_inc[i];
+ }
+ }
+ else if (is_subface && !adj_info.isSubface()) {
+ for (int j = 0; j < side_res; j++) {
+ assert(output.valid_pixel_index(dst_offset));
- float t = (float)j / (float)(side_res - 1);
+ float t = (float)j / (float)(side_res - 1);
- if (flip) {
// Adjacent edge will have opposite direction
t = 1 - t;
- }
-
- if (info.isSubface() && !adjinfo.isSubface()) {
- t *= 0.5f;
- bool is_primary = adjinfo.adjface(adjedge) == face_id;
- if (!is_primary) {
- t += 0.5f;
+
+ if (is_subface && !adj_info.isSubface()) {
+ t *= 0.5f;
+ bool is_primary = adj_info.adjface(adj_edge[0]) == face_id;
+ if (!is_primary) {
+ t += 0.5f;
+ }
}
+
+ ptex_read_border_pixel(*face_data[0], adj_edge[0], t,
+ output.texels.data() +
+ dst_offset);
+
+ dst_offset += x_inc[i] + y_inc[i];
}
+ }
+ else if (!is_subface && adj_info.isSubface()) {
+ const int half_side_res = side_res / 2;
+ for (int j = 0; j < half_side_res; j++) {
+ assert(output.valid_pixel_index(dst_offset));
- bool regular = true;
- if (!info.isSubface() && adjinfo.isSubface()) {
- t *= 2.0f;
- if (t < 1) {
- int neid = (adjedge + 3) % 4;
- int afid = adjinfo.adjface(neid);
- int aeid = adjinfo.adjedge(neid);
- PtexFaceData &ffd = *r->getData(afid);
-
- t -= 1;
- ptex_read_border_pixel(ffd, (Ptex::EdgeId)aeid, t,
- output.texels.data() +
- dst_offset);
- regular = false;
- }
+ float t = (float)j / (float)(half_side_res - 1);
+
+ // 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);
+
+ dst_offset += x_inc[i] + y_inc[i];
}
- if (regular) {
- ptex_read_border_pixel(face_data, adjedge, t,
+ for (int j = 0; j < half_side_res; j++) {
+ assert(output.valid_pixel_index(dst_offset));
+
+ float t = (float)j / (float)(half_side_res - 1);
+
+ // Adjacent edge will have opposite direction
+ t = 1 - t;
+
+ ptex_read_border_pixel(*face_data[1], adj_edge[1], t,
output.texels.data() +
dst_offset);
+
+ dst_offset += x_inc[i] + y_inc[i];
}
+ }
+ else {
+ for (int j = 0; j < side_res; j++) {
+ assert(output.valid_pixel_index(dst_offset));
+
+ // TODO, all kinds of uglyness here
+
+ float t = (float)j / (float)(side_res - 1);
- dst_offset += x_inc[i];
- dst_offset += y_inc[i];
+ // 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);
+
+ dst_offset += x_inc[i] + y_inc[i];
+ }
}
- // if (i == 0) break;
}
-#endif
}
// TODO
More information about the Bf-blender-cvs
mailing list