[Bf-blender-cvs] [11079f3] cycles-ptex-06: Basic borders working
Nicholas Bishop
noreply at git.blender.org
Thu Jan 15 20:13:23 CET 2015
Commit: 11079f38a2383e8bbabc3d50b68d882c658aa0bd
Author: Nicholas Bishop
Date: Wed Jan 14 13:02:08 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rB11079f38a2383e8bbabc3d50b68d882c658aa0bd
Basic borders working
===================================================================
M intern/cycles/render/image.cpp
===================================================================
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp
index 4396a63..2b773fe 100644
--- a/intern/cycles/render/image.cpp
+++ b/intern/cycles/render/image.cpp
@@ -50,6 +50,8 @@ struct PtexPackedTexture {
int num_channels;
+ int bytes_per_texel;
+
void test_write() {
// Quick test to visually examine the packed output
const char *filename = "/tmp/packed.png";
@@ -81,10 +83,91 @@ static int ptex_data_type_size_in_bytes(const Ptex::DataType dt)
return 0;
}
-static void ptex_read_border_pixel(PtexFaceData &face, const Ptex::EdgeId,
- const float t, void *output)
+// TODO: probably excessive calculation here, might look at making
+// into an iterator design
+static void ptex_read_border_pixel(PtexFaceData &face,
+ const Ptex::EdgeId eid,
+ const float t, void *pixel)
{
- //face.
+ const Ptex::Res &res = face.res();
+ const int u_res = res.u() - 1;
+ const int v_res = res.v() - 1;
+ int u = 0, v = 0;
+ switch (eid) {
+ case Ptex::e_bottom:
+ u = floor_to_int(t * u_res);
+ v = 0;
+ break;
+
+ case Ptex::e_right:
+ u = u_res;
+ v = floor_to_int(t * v_res);
+ break;
+
+ case Ptex::e_top:
+ u = floor_to_int((1 - t) * u_res);
+ v = v_res;
+ break;
+
+ case Ptex::e_left:
+ u = 0;
+ v = floor_to_int((1 - t) * v_res);
+ break;
+ }
+ face.getPixel(u, v, pixel);
+}
+
+static void ptex_copy_face_pixels(PtexPackedTexture &output,
+ PtexPtr<PtexTexture> &r,
+ const int dst_stride,
+ const uint face_id)
+{
+ PtexTableElement &elem = output.table[face_id];
+
+ 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;
+
+ r->getData(face_id, output.texels.data() + dst_offset, dst_stride);
+
+ // Fill in borders
+ const Ptex::FaceInfo &info = r->getFaceInfo(face_id);
+ const int x_inc[4] = {bpt, 0, -bpt, 0};
+ const int y_inc[4] = {0, dst_stride, 0, -dst_stride};
+ int x = elem.co[0], y = elem.co[1];
+ 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);
+
+ // TODO: handle subfaces correctly
+
+ // 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++) {
+ 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,
+ output.texels.data() + offset);
+ }
+ offset += x_inc[i];
+ offset += y_inc[i];
+ }
+ // if (i == 0) break;
+ }
}
// TODO
@@ -157,39 +240,21 @@ static bool ptex_pack(PtexPackedTexture *output, const char *path,
const int type_size_in_bytes = ptex_data_type_size_in_bytes(r->dataType());
- const int texel_size_in_bytes = r->numChannels() * type_size_in_bytes;
+
+ output->bytes_per_texel = r->numChannels() * type_size_in_bytes;
output->num_channels = r->numChannels();
output->texels.resize(output->width * output->height *
- texel_size_in_bytes);
+ output->bytes_per_texel);
// Copy face textures
- const int dst_stride = output->width * texel_size_in_bytes;
+ const int dst_stride = output->width * output->bytes_per_texel;
for (SortedFaceIds::const_iterator iter = sorted_face_ids.begin();
iter != sorted_face_ids.end(); ++iter) {
const uint face_id = iter->second;
- PtexTableElement &elem = output->table[face_id];
-
- const int dst_offset = ((elem.co[1] * output->width + elem.co[0]) *
- texel_size_in_bytes);
-
- r->getData(face_id, output->texels.data() + dst_offset, dst_stride);
-
- // Fill in borders
- const Ptex::FaceInfo &info = r->getFaceInfo(face_id);
- for (int i = 0; i < 4; i++) {
- const int adjface = info.adjface(i);
- const Ptex::EdgeId adjedge = info.adjedge(i);
-
- // TODO: handle subfaces correctly
-
- const PtexFaceData *face_data = r->getData(adjface);
- for (int j = 0; j < elem.res[i % 2 == 0 ? 0 : 1]; j++) {
-
- }
- break;
- }
+
+ ptex_copy_face_pixels(*output, r, dst_stride, face_id);
}
return true;
More information about the Bf-blender-cvs
mailing list