[Bf-blender-cvs] [cb1624d] cycles-ptex-06: checkpoint
Nicholas Bishop
noreply at git.blender.org
Thu Jan 15 20:13:25 CET 2015
Commit: cb1624d720f9b5177bb5aef589489d24354345e3
Author: Nicholas Bishop
Date: Wed Jan 14 15:03:24 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rBcb1624d720f9b5177bb5aef589489d24354345e3
checkpoint
===================================================================
M intern/cycles/render/image.cpp
===================================================================
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 2b773fe..05e8d48 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -95,23 +95,23 @@ static void ptex_read_border_pixel(PtexFaceData &face,
int u = 0, v = 0;
switch (eid) {
case Ptex::e_bottom:
- u = floor_to_int(t * u_res);
+ u = (int)(t * u_res + 0.5f);
v = 0;
break;
case Ptex::e_right:
u = u_res;
- v = floor_to_int(t * v_res);
+ v = (int)(t * v_res + 0.5f);
break;
case Ptex::e_top:
- u = floor_to_int((1 - t) * u_res);
+ u = (int)((1.0f - t) * u_res + 0.5f);
v = v_res;
break;
case Ptex::e_left:
u = 0;
- v = floor_to_int((1 - t) * v_res);
+ v = (int)((1.0f - t) * v_res + 0.5f);
break;
}
face.getPixel(u, v, pixel);
@@ -127,8 +127,8 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
const int bpt = output.bytes_per_texel;
const int dst_offset = ((elem.co[1] * output.width + elem.co[0]) * bpt);
- // if (face_id != 15)
- // return;
+ if (face_id != 1)
+ return;
r->getData(face_id, output.texels.data() + dst_offset, dst_stride);
@@ -140,29 +140,82 @@ static void ptex_copy_face_pixels(PtexPackedTexture &output,
int offset = ((y - 1) * output.width + (x - 1)) * bpt;
for (int i = 0; i < 4; i++) {
- const int adjface = info.adjface(i);
- const Ptex::EdgeId adjedge = info.adjedge(i);
+ int adjface = info.adjface(i);
+ Ptex::EdgeId adjedge = info.adjedge(i);
+ const int side_res = elem.res[(i == 0 || i == 2) ? 0 : 1];
+ bool flip = true;
+
+ if (adjface == -1) {
+ // If there's no adjacent face, pretend the face is
+ // adjacent to itself (i.e. copy its own borders)
+ adjface = face_id;
+ adjedge = (Ptex::EdgeId)i;
+ flip = false;
+ }
+
+ const Ptex::FaceInfo &adjinfo = r->getFaceInfo(adjface);
- // TODO: handle subfaces correctly
+ // TODO: handle faces adjacent to subfaces correctly
+
+ // TODO: handle subfaces adjacent to faces correctly
+ if (info.isSubface() && !adjinfo.isSubface()) {
+
+ }
// TODO: handle corners correctly
offset += x_inc[i];
offset += y_inc[i];
- PtexFaceData *face_data = r->getData(adjface);
- const int len = elem.res[i % 2 == 0 ? 0 : 1];
- for (int j = 0; j < len; j++) {
+ PtexFaceData &face_data = *r->getData(adjface);
+ for (int j = 0; j < side_res; j++) {
assert(offset >= 0);
assert(offset < bpt * output.height * output.width);
- if (face_data) {
- const float t = (float)j / (float)(len - 1);
- ptex_read_border_pixel(*face_data, adjedge,
- // Adjacent edge will have
- // opposite direction
- 1 - t,
+
+ // TODO, all kinds of uglyness here
+
+ 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 = false;
+ for (int k = 0; k < 4; k++) {
+ if (adjinfo.adjface(k) == face_id) {
+ is_primary = true;
+ break;
+ }
+ }
+ if (!is_primary) {
+ t += 0.5f;
+ }
+ }
+
+ 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() + offset);
+ regular = false;
+ }
+ }
+
+ if (regular) {
+ ptex_read_border_pixel(face_data, adjedge, t,
output.texels.data() + offset);
}
+
offset += x_inc[i];
offset += y_inc[i];
}
More information about the Bf-blender-cvs
mailing list