[Bf-blender-cvs] [1210d21] cycles-ptex-06: Checkpoint, works with triangles now

Nicholas Bishop noreply at git.blender.org
Thu Jan 15 20:12:59 CET 2015


Commit: 1210d211a47b042a7fc0c6f26ba26473597add78
Author: Nicholas Bishop
Date:   Wed Jan 7 21:04:32 2015 +0100
Branches: cycles-ptex-06
https://developer.blender.org/rB1210d211a47b042a7fc0c6f26ba26473597add78

Checkpoint, works with triangles now

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

M	intern/cycles/kernel/osl/osl_services.cpp
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/mesh.c
M	source/blender/blenkernel/intern/mesh_evaluate.c
M	source/blender/blenkernel/intern/subsurf_ccg.c
M	source/blender/makesdna/DNA_customdata_types.h

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

diff --git a/intern/cycles/kernel/osl/osl_services.cpp b/intern/cycles/kernel/osl/osl_services.cpp
index 5049138..c5a2424 100644
--- a/intern/cycles/kernel/osl/osl_services.cpp
+++ b/intern/cycles/kernel/osl/osl_services.cpp
@@ -850,7 +850,7 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
 			return false;
 
 		float u = s;
-		float v = 1 - t;
+		float v = t;
 		float dudx = 0.0f;
 		float dvdx = 0.0f;
 		float dudy = 0.0f;
@@ -885,6 +885,10 @@ bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
 		for(int c = r->numChannels(); c < nchannels; c++)
 			result[c] = result[0];
 
+		// result[0] = u;
+		// result[1] = v;
+		// result[2] = 0;
+
 		return true;
 	}
 #endif
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index b074bda..841417d 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1257,6 +1257,12 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
 	{sizeof(short[4][3]), "", 0, NULL, NULL, NULL, NULL, layerSwap_flnor, NULL},
 	/* 41: CD_PTEX_QUAD_FACE_ID */
 	{sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, layerDefault_origindex},
+	/* 43: CD_PTEX_UV */
+	/* TODO(bishop): technically this is extra data, MLoopUV.flag
+	 * probably not needed */
+	{sizeof(MLoopUV), "MLoopUV", 1, N_("UVMap"), NULL, NULL, layerInterp_mloopuv, NULL, NULL,
+	 layerEqual_mloopuv, layerMultiply_mloopuv, layerInitMinMax_mloopuv, 
+	 layerAdd_mloopuv, layerDoMinMax_mloopuv, layerCopyValue_mloopuv, NULL, NULL, NULL, layerMaxNum_tface},
 };
 
 /* note, numbers are from trunk and need updating for bmesh */
@@ -1273,7 +1279,7 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
 	/* 30-34 */ "CDSubSurfCrease", "CDOrigSpaceLoop", "CDPreviewLoopCol", "CDBMElemPyPtr", "CDPaintMask",
 	/* 35-36 */ "CDGridPaintMask", "CDMVertSkin",
 	/* 37-40 */ "CDFreestyleEdge", "CDFreestyleFace", "CDMLoopTangent", "CDTessLoopNormal",
-	/*    41 */ "CDPtexQuadFaceID",
+	/* 41-42 */ "CDPtexQuadFaceID", "CDPtexUV",
 };
 
 
@@ -1299,7 +1305,7 @@ const CustomDataMask CD_MASK_DERIVEDMESH =
     CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT |
     CD_MASK_PREVIEW_MCOL | CD_MASK_SHAPEKEY | CD_MASK_RECAST |
     CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
-	CD_MASK_PTEX_QUAD_FACE_ID;
+	CD_MASK_PTEX_QUAD_FACE_ID | CD_MASK_PTEX_UV;
 const CustomDataMask CD_MASK_BMESH =
     CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
     CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT |
@@ -1320,7 +1326,7 @@ const CustomDataMask CD_MASK_EVERYTHING =
     /* BMESH ONLY END */
     CD_MASK_PAINT_MASK | CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN |
     CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
-    CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_PTEX_QUAD_FACE_ID;
+    CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_PTEX_QUAD_FACE_ID | CD_MASK_PTEX_UV;
 
 static const LayerTypeInfo *layerType_getInfo(int type)
 {
@@ -2397,7 +2403,7 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
 		if (pdata->layers[i].type == CD_MTEXPOLY) {
 			CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, pdata->layers[i].name);
 		}
-		if (pdata->layers[i].type == CD_PTEX_QUAD_FACE_ID) {
+		else if (pdata->layers[i].type == CD_PTEX_QUAD_FACE_ID) {
 			CustomData_add_layer_named(fdata, CD_PTEX_QUAD_FACE_ID, CD_CALLOC, NULL, total, pdata->layers[i].name);
 		}
 	}
@@ -2414,6 +2420,12 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
 		else if (ldata->layers[i].type == CD_NORMAL) {
 			CustomData_add_layer_named(fdata, CD_TESSLOOPNORMAL, CD_CALLOC, NULL, total, ldata->layers[i].name);
 		}
+		else if (ldata->layers[i].type == CD_PTEX_UV) {
+			//CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, ldata->layers[i].name);
+			// TODO
+			CustomData_set_layer_active(fdata, CD_MTFACE, 0);
+			CustomData_set_layer_render(fdata, CD_MTFACE, 0);
+		}
 	}
 
 	CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 85fbb81..fa44806 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -2239,7 +2239,7 @@ Mesh *BKE_mesh_new_from_object(
 				if (calc_undeformed)
 					mask |= CD_MASK_ORCO;
 				if (true) // TODO(bishop): if (ptex)
-					mask |= CD_MASK_PTEX_QUAD_FACE_ID;
+					mask |= CD_MASK_PTEX_QUAD_FACE_ID | CD_MASK_PTEX_UV;
 
 				/* Write the display mesh into the dummy mesh */
 				if (render)
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index 6c73ad5..a38598c 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -1339,6 +1339,24 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData
 			*dst = src[*pidx];
 		}
 	}
+	for (i = 0; i < numPtex; i++) {
+		MTFace *texface = CustomData_get_layer_n(fdata, CD_MTFACE, i); 
+		MLoopUV *ptex_uv = CustomData_get_layer_n(ldata, CD_PTEX_UV, i); 
+
+		for (findex = 0, pidx = polyindices, lidx = loopindices; 
+		     findex < num_faces; 
+		     pidx++, lidx++, findex++, texface++) 
+		{ 
+			// TODO, stole from customdata.c 
+			MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, NULL, 
+								 0, 0, TF_DYNAMIC | TF_CONVERTED, 0, 0}; 
+			//(*texface) = default_tf; 
+			for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {  
+				copy_v2_v2(texface->uv[j], ptex_uv[(*lidx)[j]].uv);  
+			}  
+		} 
+	} 
+	
 
 	for (i = 0; i < numCol; i++) {
 		MCol (*mcol)[4] = CustomData_get_layer_n(fdata, CD_MCOL, i);
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 6c33cb1..d845575 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -3067,6 +3067,118 @@ static void *ccgDM_get_tessface_data_layer(DerivedMesh *dm, int type)
 	return DM_get_tessface_data_layer(dm, type);
 }
 
+/* TODO: Probably too many degrees of freedom here, but eases testing for now */
+static void ccgDM_ptex_update_grid(MLoopUV (*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]);
+				}
+			}
+
+			output_index++;
+			u += step[0];
+		}
+		v += step[1];
+	}
+}
+
+static void ccgDM_ptex_update_quad_loops(MLoopUV (*output)[4],
+                                         const int gridFaces) {
+	const float f = 0.5f / ((float)(gridFaces));
+	float origin[4][2] = {
+		{0.5, 0.5},
+		{0.5, 0.5},
+		{0.5, 0.5},
+		{0.5, 0.5},
+	};
+	float step[4][2] = {
+		{f, -f},
+		{f, f},
+		{-f, f},
+		{-f, -f},
+	};
+	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[s], step[s], swp[s]);
+		output_index += gridFaces * gridFaces;
+	}
+}
+
+static void ccgDM_ptex_update_subface_loops(MLoopUV (*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_PTEX_UV) {
+		MLoopUV (*output)[4] = DM_get_loop_data_layer(dm, CD_PTEX_UV);
+
+		if (!output) {
+			const int totface = ccgSubSurf_getNumFaces(ss);
+			int i, output_index = 0;
+
+			DM_add_loop_layer(dm, CD_PTEX_UV, CD_CALLOC, NULL);
+			output = DM_get_loop_data_layer(dm, CD_PTEX_UV);
+
+			for (i = 0; i < totface; i++) {
+				CCGFace *f = ccgdm->faceMap[i].face;
+				const int numVerts = ccgSubSurf_getFaceNumVerts(f);
+
+				if (numVerts == 4) {
+					ccgDM_ptex_update_quad_loops(output + output_index,
+					                             gridFaces);
+				} else {
+					ccgDM_ptex_update_subface_loops(output + output_index,
+					                                gridFaces,
+					                                numVerts);
+				}
+				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;
@@ -3548,6 +3660,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;
@@ -3656,6 +3769,11 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
 	mcol = DM_get_tessface_data_layer(&ccgdm->dm, CD_MCOL);
 #endif
 
+	
+	// TO

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list