[Bf-blender-cvs] [5429060] cycles-ptex-12: WIP Subsurf ptex coords
Nicholas Bishop
noreply at git.blender.org
Mon Jan 26 02:04:59 CET 2015
Commit: 54290608d220c733c2d69ca85eb6a368453db0c6
Author: Nicholas Bishop
Date: Tue Jan 20 13:55:01 2015 +0100
Branches: cycles-ptex-12
https://developer.blender.org/rB54290608d220c733c2d69ca85eb6a368453db0c6
WIP Subsurf ptex coords
===================================================================
M source/blender/blenkernel/intern/subsurf_ccg.c
===================================================================
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 45ec337..f36de83 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -2869,6 +2869,19 @@ static void ccg_loops_to_corners(CustomData *fdata, CustomData *ldata,
copy_v2_v2(of->uv[j], lof->uv);
}
}
+
+#if 1
+ {
+ MTessFacePtex *dst = CustomData_get(fdata, findex, CD_TESSFACE_PTEX);
+
+ //ME_MTEXFACE_CPY(texface, texpoly);
+
+ MLoopPtexUV *mloopuv = CustomData_get(ldata, loopstart, CD_LOOP_PTEX_UV);
+ for (j = 0; j < 4; j++, mloopuv++) {
+ dst->corners[j] = *mloopuv;
+ }
+ }
+#endif
}
static void *ccgDM_get_vert_data_layer(DerivedMesh *dm, int type)
@@ -3009,15 +3022,146 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type)
return DM_get_tessface_data_layer(dm, type);
}
+static void ccgDM_ptex_update_grid(MLoopPtexUV (*output)[4],
+ const int gridFaces,
+ const float origin[2],
+ const float step[2],
+ const bool swp) {
+ int output_index = 0;
+ int y;
+ float v = origin[1];
+ for (y = 0; y < gridFaces; y++) {
+ int x;
+ float u = origin[0];
+ for (x = 0; x < gridFaces; x++) {
+ float uv[4][2] = {
+ {u, v },
+ {u, v + step[1]},
+ {u + step[0], v + step[1]},
+ {u + step[0], v },
+ };
+ int s;
+ for (s = 0; s < 4; s++) {
+ copy_v2_v2(output[output_index][s].uv, uv[s]);
+ if (swp) {
+ SWAP(float,
+ output[output_index][s].uv[0],
+ output[output_index][s].uv[1]);
+ }
+ // TODO
+ output[output_index][s].uv[1] = 1 - output[output_index][s].uv[1];
+ }
+
+ output_index++;
+ u += step[0];
+ }
+ v += step[1];
+ }
+}
+
+static void ccgDM_ptex_update_quad_loops(MLoopPtexUV (*output)[4],
+ const int gridFaces) {
+ const float f = 0.5f / ((float)(gridFaces));
+ const float origin[2] = {0.5, 0.5};
+ const float step[4][2] = {
+ {f, -f},
+ {f, f},
+ {-f, f},
+ {-f, -f},
+ };
+ const bool swp[4] = {true, false, true, false};
+ int output_index = 0;
+ int s;
+ for (s = 0; s < 4; s++) {
+ ccgDM_ptex_update_grid(output + output_index, gridFaces, origin,
+ step[s], swp[s]);
+ output_index += gridFaces * gridFaces;
+ }
+}
+
+static void ccgDM_ptex_update_subface_loops(MLoopPtexUV (*output)[4],
+ const int gridFaces,
+ const int numVerts) {
+ const float f = 1.0f / ((float)(gridFaces));
+ int output_index = 0;
+ int s;
+ for (s = 0; s < numVerts; s++) {
+ float origin[2] = {0, 1};
+ float step[2] = {f, -f};
+ bool swp = true;
+ ccgDM_ptex_update_grid(output + output_index, gridFaces, origin,
+ step, swp);
+ output_index += gridFaces * gridFaces;
+ }
+}
+
+static void *ccgDM_get_loop_data_layer(DerivedMesh *dm, int type)
+{
+ CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
+ CCGSubSurf *ss = ccgdm->ss;
+ const int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
+
+ if (type == CD_LOOP_PTEX_UV) {
+ MLoopPtexUV (*output)[4] = DM_get_loop_data_layer(dm, CD_LOOP_PTEX_UV);
+
+ if (!output) {
+ const int totface = ccgSubSurf_getNumFaces(ss);
+ int ptex_id = 0;
+ int i, output_index = 0;
+
+ DM_add_loop_layer(dm, CD_LOOP_PTEX_UV, CD_CALLOC, NULL);
+ output = DM_get_loop_data_layer(dm, CD_LOOP_PTEX_UV);
+
+ for (i = 0; i < totface; i++) {
+ CCGFace *f = ccgdm->faceMap[i].face;
+ const int numVerts = ccgSubSurf_getFaceNumVerts(f);
+ int j;
+
+ if (numVerts == 4) {
+ ccgDM_ptex_update_quad_loops(output + output_index,
+ gridFaces);
+ } else {
+ ccgDM_ptex_update_subface_loops(output + output_index,
+ gridFaces,
+ numVerts);
+ }
+
+ for (j = 0; j < numVerts; j++) {
+ int k;
+ for (k = 0; k < gridFaces * gridFaces; k++) {
+ int l;
+ for (l = 0; l < 4; l++) {
+ output[output_index][l].id = ptex_id;
+ }
+ output_index++;
+ }
+ if (numVerts != 4) {
+ ptex_id++;
+ }
+ }
+ if (numVerts == 4) {
+ ptex_id++;
+ }
+
+ //output_index += numVerts * gridFaces * gridFaces;
+ }
+ }
+ return output;
+ }
+
+ return DM_get_loop_data_layer(dm, type);
+}
+
static void *ccgDM_get_poly_data_layer(DerivedMesh *dm, int type)
{
+ CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
+ CCGSubSurf *ss = ccgdm->ss;
+ const int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
+
if (type == CD_ORIGINDEX) {
/* create origindex on demand to save memory */
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *)dm;
- CCGSubSurf *ss = ccgdm->ss;
int *origindex;
int a, i, index, totface;
- int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
/* Avoid re-creation if the layer exists already */
origindex = DM_get_poly_data_layer(dm, CD_ORIGINDEX);
@@ -3067,7 +3211,7 @@ static void *ccgDM_get_edge_data(DerivedMesh *dm, int index, int type)
static void *ccgDM_get_tessface_data(DerivedMesh *dm, int index, int type)
{
- if (ELEM(type, CD_ORIGINDEX, CD_TESSLOOPNORMAL)) {
+ if (ELEM(type, CD_ORIGINDEX, CD_TESSLOOPNORMAL, CD_TESSFACE_PTEX)) {
/* ensure creation of CD_ORIGINDEX/CD_TESSLOOPNORMAL layers */
ccgDM_get_tessface_data_layer(dm, type);
}
@@ -3077,10 +3221,12 @@ static void *ccgDM_get_tessface_data(DerivedMesh *dm, int index, int type)
static void *ccgDM_get_poly_data(DerivedMesh *dm, int index, int type)
{
- if (type == CD_ORIGINDEX) {
+#if 1
+ if (type == CD_ORIGINDEX || type == CD_TESSFACE_PTEX) {
/* ensure creation of CD_ORIGINDEX layer */
ccgDM_get_tessface_data_layer(dm, type);
}
+#endif
return DM_get_poly_data(dm, index, type);
}
@@ -3451,6 +3597,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
ccgdm->dm.getVertDataArray = ccgDM_get_vert_data_layer;
ccgdm->dm.getEdgeDataArray = ccgDM_get_edge_data_layer;
ccgdm->dm.getTessFaceDataArray = ccgDM_get_tessface_data_layer;
+ ccgdm->dm.getLoopDataArray = ccgDM_get_loop_data_layer;
ccgdm->dm.getPolyDataArray = ccgDM_get_poly_data_layer;
ccgdm->dm.getNumGrids = ccgDM_getNumGrids;
ccgdm->dm.getGridSize = ccgDM_getGridSize;
@@ -3559,6 +3706,15 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
mcol = DM_get_tessface_data_layer(&ccgdm->dm, CD_MCOL);
#endif
+
+ // TODO, quick hacks
+#if 1
+ ccgDM_get_loop_data_layer(&ccgdm->dm, CD_LOOP_PTEX_UV);
+ ccgDM_get_poly_data_layer(&ccgdm->dm, CD_TESSFACE_PTEX);
+ CustomData_add_layer(&ccgdm->dm.faceData, CD_TESSFACE_PTEX,
+ CD_CALLOC, NULL, ccgdm->dm.numTessFaceData);
+#endif
+
loopindex = loopindex2 = 0; /* current loop index */
for (index = 0; index < totface; index++) {
CCGFace *f = ccgdm->faceMap[index].face;
@@ -3658,25 +3814,26 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
/*interpolate per-face data*/
for (y = 0; y < gridFaces; y++) {
for (x = 0; x < gridFaces; x++) {
- w2 = w + s * numVerts * g2_wid * g2_wid + (y * g2_wid + x) * numVerts;
- CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
- loopidx, w2, NULL, numVerts, loopindex2);
- loopindex2++;
-
- w2 = w + s * numVerts * g2_wid * g2_wid + ((y + 1) * g2_wid + (x)) * numVerts;
- CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
- loopidx, w2, NULL, numVerts, loopindex2);
- loopindex2++;
-
- w2 = w + s * numVerts * g2_wid * g2_wid + ((y + 1) * g2_wid + (x + 1)) * numVerts;
- CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
- loopidx, w2, NULL, numVerts, loopindex2);
- loopindex2++;
-
- w2 = w + s * numVerts * g2_wid * g2_wid + ((y) * g2_wid + (x + 1)) * numVerts;
- CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
- loopidx, w2, NULL, numVerts, loopindex2);
- loopindex2++;
+ int x2, y2;
+ for (x2 = 0; x2 <= 1; x2++) {
+ for (y2 = 0; y2 <= 1; y2++) {
+ /* This gives the (x,y) pattern:
+ * (0,0) (0,1) (1,1) (1,0) */
+ int y3 = (x2 == 0) ? y2 : 1 - y2;
+
+ /* Pointer arithmetic */
+ w2 = w + (s * numVerts * g2_wid * g2_wid +
+ ((y + y3) * g2_wid +
+ (x + x2)) * numVerts);
+
+ CustomData_interp(&dm->loopData, &ccgdm->dm.loopData,
+ loopidx, w2, NULL, numVerts, loopindex2);
+ /* ptex_uvs[loopindex2].uv[0] = w2[1]; */
+ /* ptex_uvs[loopindex2].uv[1] = w2[3]; */
+
+ loopindex2++;
+ }
+ }
/*copy over poly data, e.g. mtexpoly*/
CustomData_copy_data(&dm->polyData, &ccgdm->dm.polyData, origIndex, faceNum, 1);
@@ -3799,7 +3956,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
ccgdm->dm.numPolyData = faceNum;
/* All tessellated CD layers were updated! */
- ccgdm->dm.dirty &= ~DM_DIRTY_TESS_CDLAYERS;
+ //ccgdm->dm.dirty &= ~DM_DIRTY_TESS_CDLAYERS;
#ifndef USE_DYNSIZE
BLI_array_free(vertidx);
More information about the Bf-blender-cvs
mailing list