[Bf-blender-cvs] [bb5c0e6] temp-cycles-microdisplacement: Attributes for subdivision

Mai Lavelle noreply at git.blender.org
Tue Apr 12 18:46:02 CEST 2016


Commit: bb5c0e6393814a4400c46477863abeca09a863f1
Author: Mai Lavelle
Date:   Thu Mar 17 16:24:13 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rBbb5c0e6393814a4400c46477863abeca09a863f1

Attributes for subdivision

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

M	intern/cycles/blender/blender_mesh.cpp
M	intern/cycles/kernel/geom/geom_attribute.h
M	intern/cycles/kernel/geom/geom_cache_triangle.h
M	intern/cycles/kernel/geom/geom_primitive.h
M	intern/cycles/kernel/kernel_types.h
M	intern/cycles/kernel/svm/svm_attribute.h
M	intern/cycles/render/attribute.cpp
M	intern/cycles/render/attribute.h
M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/mesh.h
M	intern/cycles/util/util_math.h

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

diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp
index b80d474..4130ccc 100644
--- a/intern/cycles/blender/blender_mesh.cpp
+++ b/intern/cycles/blender/blender_mesh.cpp
@@ -191,7 +191,8 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
                                   const vector<int>& nverts,
                                   const vector<int>& face_flags,
                                   bool need_sign,
-                                  bool active_render)
+                                  bool active_render,
+                                  bool subdivision)
 {
 	/* setup userdata */
 	MikkUserData userdata(b_mesh, b_layer, nverts.size());
@@ -216,6 +217,7 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
 	genTangSpaceDefault(&context);
 
 	/* create tangent attributes */
+	AttributeSet& mesh_attributes = subdivision? mesh->subd_attributes: mesh->attributes;
 	Attribute *attr;
 	ustring name;
 	if(b_layer != NULL)
@@ -224,9 +226,9 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
 		name = ustring("orco.tangent");
 
 	if(active_render)
-		attr = mesh->attributes.add(ATTR_STD_UV_TANGENT, name);
+		attr = mesh_attributes.add(ATTR_STD_UV_TANGENT, name);
 	else
-		attr = mesh->attributes.add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CORNER);
+		attr = mesh_attributes.add(name, TypeDesc::TypeVector, ATTR_ELEMENT_CORNER);
 
 	float3 *tangent = attr->data_float3();
 
@@ -242,41 +244,60 @@ static void mikk_compute_tangents(BL::Mesh& b_mesh,
 			name_sign = ustring("orco.tangent_sign");
 
 		if(active_render)
-			attr_sign = mesh->attributes.add(ATTR_STD_UV_TANGENT_SIGN, name_sign);
+			attr_sign = mesh_attributes.add(ATTR_STD_UV_TANGENT_SIGN, name_sign);
 		else
-			attr_sign = mesh->attributes.add(name_sign, TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER);
+			attr_sign = mesh_attributes.add(name_sign, TypeDesc::TypeFloat, ATTR_ELEMENT_CORNER);
 
 		tangent_sign = attr_sign->data_float();
 	}
 
-	for(int i = 0; i < nverts.size(); i++) {
-		int tri_a[3], tri_b[3];
-		face_split_tri_indices(nverts[i], face_flags[i], tri_a, tri_b);
-
-		tangent[0] = float4_to_float3(userdata.tangent[i*4 + tri_a[0]]);
-		tangent[1] = float4_to_float3(userdata.tangent[i*4 + tri_a[1]]);
-		tangent[2] = float4_to_float3(userdata.tangent[i*4 + tri_a[2]]);
-		tangent += 3;
-
-		if(tangent_sign) {
-			tangent_sign[0] = userdata.tangent[i*4 + tri_a[0]].w;
-			tangent_sign[1] = userdata.tangent[i*4 + tri_a[1]].w;
-			tangent_sign[2] = userdata.tangent[i*4 + tri_a[2]].w;
-			tangent_sign += 3;
-		}
+	if(!subdivision) {
+		for(int i = 0; i < nverts.size(); i++) {
+			int tri_a[3], tri_b[3];
+			face_split_tri_indices(nverts[i], face_flags[i], tri_a, tri_b);
 
-		if(nverts[i] == 4) {
-			tangent[0] = float4_to_float3(userdata.tangent[i*4 + tri_b[0]]);
-			tangent[1] = float4_to_float3(userdata.tangent[i*4 + tri_b[1]]);
-			tangent[2] = float4_to_float3(userdata.tangent[i*4 + tri_b[2]]);
+			tangent[0] = float4_to_float3(userdata.tangent[i*4 + tri_a[0]]);
+			tangent[1] = float4_to_float3(userdata.tangent[i*4 + tri_a[1]]);
+			tangent[2] = float4_to_float3(userdata.tangent[i*4 + tri_a[2]]);
 			tangent += 3;
 
 			if(tangent_sign) {
-				tangent_sign[0] = userdata.tangent[i*4 + tri_b[0]].w;
-				tangent_sign[1] = userdata.tangent[i*4 + tri_b[1]].w;
-				tangent_sign[2] = userdata.tangent[i*4 + tri_b[2]].w;
+				tangent_sign[0] = userdata.tangent[i*4 + tri_a[0]].w;
+				tangent_sign[1] = userdata.tangent[i*4 + tri_a[1]].w;
+				tangent_sign[2] = userdata.tangent[i*4 + tri_a[2]].w;
 				tangent_sign += 3;
 			}
+
+			if(nverts[i] == 4) {
+				tangent[0] = float4_to_float3(userdata.tangent[i*4 + tri_b[0]]);
+				tangent[1] = float4_to_float3(userdata.tangent[i*4 + tri_b[1]]);
+				tangent[2] = float4_to_float3(userdata.tangent[i*4 + tri_b[2]]);
+				tangent += 3;
+
+				if(tangent_sign) {
+					tangent_sign[0] = userdata.tangent[i*4 + tri_b[0]].w;
+					tangent_sign[1] = userdata.tangent[i*4 + tri_b[1]].w;
+					tangent_sign[2] = userdata.tangent[i*4 + tri_b[2]].w;
+					tangent_sign += 3;
+				}
+			}
+		}
+	}
+	else {
+		for(int i = 0; i < nverts.size(); i++) {
+			tangent[0] = float4_to_float3(userdata.tangent[i*4 + 0]);
+			tangent[1] = float4_to_float3(userdata.tangent[i*4 + 1]);
+			tangent[2] = float4_to_float3(userdata.tangent[i*4 + 2]);
+			tangent[3] = float4_to_float3(userdata.tangent[i*4 + 3]);
+			tangent += 4;
+
+			if(tangent_sign) {
+				tangent_sign[0] = userdata.tangent[i*4 + 0].w;
+				tangent_sign[1] = userdata.tangent[i*4 + 1].w;
+				tangent_sign[2] = userdata.tangent[i*4 + 2].w;
+				tangent_sign[3] = userdata.tangent[i*4 + 3].w;
+				tangent_sign += 4;
+			}
 		}
 	}
 }
@@ -335,14 +356,15 @@ static void attr_create_vertex_color(Scene *scene,
                                      Mesh *mesh,
                                      BL::Mesh& b_mesh,
                                      const vector<int>& nverts,
-                                     const vector<int>& face_flags)
+                                     const vector<int>& face_flags,
+                                     bool subdivision)
 {
 	BL::Mesh::tessface_vertex_colors_iterator l;
 	for(b_mesh.tessface_vertex_colors.begin(l); l != b_mesh.tessface_vertex_colors.end(); ++l) {
 		if(!mesh->need_attribute(scene, ustring(l->name().c_str())))
 			continue;
 
-		Attribute *attr = mesh->attributes.add(
+		Attribute *attr = (subdivision? mesh->subd_attributes: mesh->attributes).add(
 			ustring(l->name().c_str()), TypeDesc::TypeColor, ATTR_ELEMENT_CORNER_BYTE);
 
 		BL::MeshColorLayer::data_iterator c;
@@ -361,18 +383,27 @@ static void attr_create_vertex_color(Scene *scene,
 				colors[3] = color_float_to_byte(color_srgb_to_scene_linear(get_float3(c->color4())));
 			}
 
-			cdata[0] = colors[tri_a[0]];
-			cdata[1] = colors[tri_a[1]];
-			cdata[2] = colors[tri_a[2]];
+			if(!subdivision) {
+				cdata[0] = colors[tri_a[0]];
+				cdata[1] = colors[tri_a[1]];
+				cdata[2] = colors[tri_a[2]];
 
-			if(nverts[i] == 4) {
-				cdata[3] = colors[tri_b[0]];
-				cdata[4] = colors[tri_b[1]];
-				cdata[5] = colors[tri_b[2]];
-				cdata += 6;
+				if(nverts[i] == 4) {
+					cdata[3] = colors[tri_b[0]];
+					cdata[4] = colors[tri_b[1]];
+					cdata[5] = colors[tri_b[2]];
+					cdata += 6;
+				}
+				else
+					cdata += 3;
+			}
+			else {
+				cdata[0] = colors[0];
+				cdata[1] = colors[1];
+				cdata[2] = colors[2];
+				cdata[3] = colors[3];
+				cdata += 4;
 			}
-			else
-				cdata += 3;
 		}
 	}
 }
@@ -382,7 +413,8 @@ static void attr_create_uv_map(Scene *scene,
                                Mesh *mesh,
                                BL::Mesh& b_mesh,
                                const vector<int>& nverts,
-                               const vector<int>& face_flags)
+                               const vector<int>& face_flags,
+                               bool subdivision)
 {
 	if(b_mesh.tessface_uv_textures.length() != 0) {
 		BL::Mesh::tessface_uv_textures_iterator l;
@@ -397,9 +429,9 @@ static void attr_create_uv_map(Scene *scene,
 				Attribute *attr;
 
 				if(active_render)
-					attr = mesh->attributes.add(std, name);
+					attr = (subdivision? mesh->subd_attributes: mesh->attributes).add(std, name);
 				else
-					attr = mesh->attributes.add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CORNER);
+					attr = (subdivision? mesh->subd_attributes: mesh->attributes).add(name, TypeDesc::TypePoint, ATTR_ELEMENT_CORNER);
 
 				BL::MeshTextureFaceLayer::data_iterator t;
 				float3 *fdata = attr->data_float3();
@@ -417,16 +449,25 @@ static void attr_create_uv_map(Scene *scene,
 						uvs[3] = get_float3(t->uv4());
 					}
 
-					fdata[0] = uvs[tri_a[0]];
-					fdata[1] = uvs[tri_a[1]];
-					fdata[2] = uvs[tri_a[2]];
-					fdata += 3;
-
-					if(nverts[i] == 4) {
-						fdata[0] = uvs[tri_b[0]];
-						fdata[1] = uvs[tri_b[1]];
-						fdata[2] = uvs[tri_b[2]];
+					if(!subdivision) {
+						fdata[0] = uvs[tri_a[0]];
+						fdata[1] = uvs[tri_a[1]];
+						fdata[2] = uvs[tri_a[2]];
 						fdata += 3;
+
+						if(nverts[i] == 4) {
+							fdata[0] = uvs[tri_b[0]];
+							fdata[1] = uvs[tri_b[1]];
+							fdata[2] = uvs[tri_b[2]];
+							fdata += 3;
+						}
+					}
+					else {
+						fdata[0] = uvs[0];
+						fdata[1] = uvs[1];
+						fdata[2] = uvs[2];
+						fdata[3] = uvs[3];
+						fdata += 4;
 					}
 				}
 			}
@@ -446,7 +487,8 @@ static void attr_create_uv_map(Scene *scene,
 				                      nverts,
 				                      face_flags,
 				                      need_sign,
-				                      active_render);
+				                      active_render,
+				                      subdivision);
 			}
 		}
 	}
@@ -458,7 +500,8 @@ static void attr_create_uv_map(Scene *scene,
 		                      nverts,
 		                      face_flags,
 		                      need_sign,
-		                      true);
+		                      true,
+		                      subdivision);
 	}
 }
 
@@ -569,7 +612,7 @@ static void create_mesh(Scene *scene,
 
 	/* create generated coordinates from undeformed coordinates */
 	if(mesh->need_attribute(scene, ATTR_STD_GENERATED)) {
-		Attribute *attr = mesh->attributes.add(ATTR_STD_GENERATED);
+		Attribute *attr = (subdivision? mesh->subd_attributes: mesh->attributes).add(ATTR_STD_GENERATED);
 
 		float3 loc, size;
 		mesh_texture_space(b_mesh, loc, size);
@@ -650,8 +693,8 @@ static void create_mesh(Scene *scene,
 	/* Create all needed attributes.
 	 * The calculate functions will check whether they're needed or not.
 	 */
-	attr_create_vertex_color(scene, mesh, b_mesh, nverts, face_flags);
-	attr_create_uv_map(scene, mesh, b_mesh, nverts, face_flags);
+	attr_create_vertex_color(scene, mesh, b_mesh, nverts, face_flags, subdivision);
+	attr_create_uv_map(scene, mesh, b_mesh, nverts, face_flags, subdivision);
 
 	/* for volume objects, create a matrix to transform from object space to
 	 * mesh texture space. this does not work with deformations but that can
diff --git a/intern/cycles/kernel/geom/geom_attribute.h b/intern/cycles/kernel/geom/geom_attribute.h
index c7364e9..d42b91b 100644
--- a/intern/cycles/kernel/geom/geom_attribute.h
+++ b/intern/cycles/kernel/geom/geom_attribute

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list