[Bf-blender-cvs] [6c0f79b] temp-cycles-microdisplacement: Add support for storing subdivision attributes in Mesh

Mai Lavelle noreply at git.blender.org
Thu Jun 9 12:11:34 CEST 2016


Commit: 6c0f79b6ca4a724aa25576f097c52a4803728a61
Author: Mai Lavelle
Date:   Wed Jun 8 06:06:21 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rB6c0f79b6ca4a724aa25576f097c52a4803728a61

Add support for storing subdivision attributes in Mesh

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

M	intern/cycles/kernel/kernel_types.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

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

diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 1ffcfb9..beb649c 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -572,8 +572,13 @@ typedef enum PrimitiveType {
 
 /* Attributes */
 
-#define ATTR_PRIM_TYPES		2
-#define ATTR_PRIM_CURVE		1
+typedef enum AttributePrimitive {
+	ATTR_PRIM_TRIANGLE = 0,
+	ATTR_PRIM_CURVE,
+	ATTR_PRIM_SUBD,
+
+	ATTR_PRIM_TYPES
+} AttributePrimitive;
 
 typedef enum AttributeElement {
 	ATTR_ELEMENT_NONE,
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp
index 71a3cba..99298d6 100644
--- a/intern/cycles/render/attribute.cpp
+++ b/intern/cycles/render/attribute.cpp
@@ -51,13 +51,14 @@ void Attribute::set(ustring name_, TypeDesc type_, AttributeElement element_)
 		type == TypeDesc::TypeNormal || type == TypeDesc::TypeMatrix);
 }
 
-void Attribute::resize(int numverts, int numtris, int numsteps, int numcurves, int numkeys, bool reserve_only)
+void Attribute::resize(int numverts, int numtris, int numsteps, int numcurves, int numkeys,
+                       int numpatches, AttributePrimitive prim, bool reserve_only)
 {
 	if(reserve_only) {
-		buffer.reserve(buffer_size(numverts, numtris, numsteps, numcurves, numkeys));
+		buffer.reserve(buffer_size(numverts, numtris, numsteps, numcurves, numkeys, numpatches, prim));
 	}
 	else {
-		buffer.resize(buffer_size(numverts, numtris, numsteps, numcurves, numkeys), 0);
+		buffer.resize(buffer_size(numverts, numtris, numsteps, numcurves, numkeys, numpatches, prim), 0);
 	}
 }
 
@@ -126,7 +127,8 @@ size_t Attribute::data_sizeof() const
 		return sizeof(float3);
 }
 
-size_t Attribute::element_size(int numverts, int numtris, int numsteps, int numcurves, int numkeys) const
+size_t Attribute::element_size(int numverts, int numtris, int numsteps, int numcurves, int numkeys,
+                               int numpatches, AttributePrimitive prim) const
 {
 	size_t size;
 	
@@ -143,11 +145,17 @@ size_t Attribute::element_size(int numverts, int numtris, int numsteps, int numc
 			size = numverts * (numsteps - 1);
 			break;
 		case ATTR_ELEMENT_FACE:
-			size = numtris;
+			if(prim == ATTR_PRIM_TRIANGLE)
+				size = numtris;
+			else
+				size = numpatches;
 			break;
 		case ATTR_ELEMENT_CORNER:
 		case ATTR_ELEMENT_CORNER_BYTE:
-			size = numtris*3;
+			if(prim == ATTR_PRIM_TRIANGLE)
+				size = numtris*3;
+			else
+				size = numpatches*4;
 			break;
 		case ATTR_ELEMENT_CURVE:
 			size = numcurves;
@@ -166,9 +174,10 @@ size_t Attribute::element_size(int numverts, int numtris, int numsteps, int numc
 	return size;
 }
 
-size_t Attribute::buffer_size(int numverts, int numtris, int numsteps, int numcurves, int numkeys) const
+size_t Attribute::buffer_size(int numverts, int numtris, int numsteps, int numcurves, int numkeys,
+                              int numpatches, AttributePrimitive prim) const
 {
-	return element_size(numverts, numtris, numsteps, numcurves, numkeys)*data_sizeof();
+	return element_size(numverts, numtris, numsteps, numcurves, numkeys, numpatches, prim)*data_sizeof();
 }
 
 bool Attribute::same_storage(TypeDesc a, TypeDesc b)
@@ -257,6 +266,7 @@ AttributeSet::AttributeSet()
 {
 	triangle_mesh = NULL;
 	curve_mesh = NULL;
+	subd_mesh = NULL;
 }
 
 AttributeSet::~AttributeSet()
@@ -291,9 +301,13 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement eleme
 
 	/* this is weak .. */
 	if(triangle_mesh)
-		attr->resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0, false);
+		attr->resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0,
+		             0, ATTR_PRIM_TRIANGLE, false);
 	if(curve_mesh)
-		attr->resize(0, 0, curve_mesh->motion_steps, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), false);
+		attr->resize(0, 0, curve_mesh->motion_steps, curve_mesh->num_curves(), curve_mesh->curve_keys.size(),
+		             0, ATTR_PRIM_CURVE, false);
+	if(subd_mesh)
+		attr->resize(subd_mesh->verts.size(), 0, 0, 0, 0, subd_mesh->patches.size(), ATTR_PRIM_SUBD, false);
 	
 	return attr;
 }
@@ -330,7 +344,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name)
 	if(name == ustring())
 		name = Attribute::standard_name(std);
 
-	if(triangle_mesh) {
+	if(triangle_mesh || subd_mesh) {
 		switch(std) {
 			case ATTR_STD_VERTEX_NORMAL:
 				attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX);
@@ -452,9 +466,12 @@ void AttributeSet::resize(bool reserve_only)
 {
 	foreach(Attribute& attr, attributes) {
 		if(triangle_mesh)
-			attr.resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0, reserve_only);
+			attr.resize(triangle_mesh->verts.size(), triangle_mesh->num_triangles(), triangle_mesh->motion_steps, 0, 0,
+			            0, ATTR_PRIM_TRIANGLE, reserve_only);
 		if(curve_mesh)
-			attr.resize(0, 0, 0, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), reserve_only);
+			attr.resize(0, 0, 0, curve_mesh->num_curves(), curve_mesh->curve_keys.size(), 0, ATTR_PRIM_CURVE, reserve_only);
+		if(subd_mesh)
+			attr.resize(subd_mesh->verts.size(), 0, 0, 0, 0, subd_mesh->patches.size(), ATTR_PRIM_SUBD, reserve_only);
 	}
 }
 
@@ -477,6 +494,10 @@ AttributeRequest::AttributeRequest(ustring name_)
 	curve_type = TypeDesc::TypeFloat;
 	curve_element = ATTR_ELEMENT_NONE;
 	curve_offset = 0;
+
+	subd_type = TypeDesc::TypeFloat;
+	subd_element = ATTR_ELEMENT_NONE;
+	subd_offset = 0;
 }
 
 AttributeRequest::AttributeRequest(AttributeStandard std_)
@@ -491,6 +512,10 @@ AttributeRequest::AttributeRequest(AttributeStandard std_)
 	curve_type = TypeDesc::TypeFloat;
 	curve_element = ATTR_ELEMENT_NONE;
 	curve_offset = 0;
+
+	subd_type = TypeDesc::TypeFloat;
+	subd_element = ATTR_ELEMENT_NONE;
+	subd_offset = 0;
 }
 
 /* AttributeRequestSet */
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index 41b3626..cb0426b 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute.h
@@ -58,11 +58,14 @@ public:
 	Attribute() {}
 	~Attribute();
 	void set(ustring name, TypeDesc type, AttributeElement element);
-	void resize(int numverts, int numfaces, int numsteps, int numcurves, int numkeys, bool reserve_only);
+	void resize(int numverts, int numfaces, int numsteps, int numcurves, int numkeys,
+	            int numpatches, AttributePrimitive prim, bool reserve_only);
 
 	size_t data_sizeof() const;
-	size_t element_size(int numverts, int numfaces, int numsteps, int numcurves, int numkeys) const;
-	size_t buffer_size(int numverts, int numfaces, int numsteps, int numcurves, int numkeys) const;
+	size_t element_size(int numverts, int numfaces, int numsteps, int numcurves, int numkeys,
+	                    int numpatches, AttributePrimitive prim) const;
+	size_t buffer_size(int numverts, int numfaces, int numsteps, int numcurves, int numkeys,
+	                   int numpatches, AttributePrimitive prim) const;
 
 	char *data() { return (buffer.size())? &buffer[0]: NULL; };
 	float3 *data_float3() { return (float3*)data(); }
@@ -99,6 +102,7 @@ class AttributeSet {
 public:
 	Mesh *triangle_mesh;
 	Mesh *curve_mesh;
+	Mesh *subd_mesh;
 	list<Attribute> attributes;
 
 	AttributeSet();
@@ -130,9 +134,9 @@ public:
 	AttributeStandard std;
 
 	/* temporary variables used by MeshManager */
-	TypeDesc triangle_type, curve_type;
-	AttributeElement triangle_element, curve_element;
-	int triangle_offset, curve_offset;
+	TypeDesc triangle_type, curve_type, subd_type;
+	AttributeElement triangle_element, curve_element, subd_element;
+	int triangle_offset, curve_offset, subd_offset;
 
 	explicit AttributeRequest(ustring name_);
 	explicit AttributeRequest(AttributeStandard std);
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 79f172a..5db7ea5 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -134,6 +134,7 @@ Mesh::Mesh()
 
 	attributes.triangle_mesh = this;
 	curve_attributes.curve_mesh = this;
+	subd_attributes.subd_mesh = this;
 
 	geometry_flags = GEOMETRY_NONE;
 
@@ -200,11 +201,15 @@ void Mesh::reserve_curves(int numcurves, int numkeys)
 void Mesh::resize_patches(int numpatches)
 {
 	patches.resize(numpatches);
+
+	subd_attributes.resize();
 }
 
 void Mesh::reserve_patches(int numpatches)
 {
 	patches.reserve(numpatches);
+
+	subd_attributes.resize(true);
 }
 
 void Mesh::clear()
@@ -227,6 +232,7 @@ void Mesh::clear()
 
 	attributes.clear();
 	curve_attributes.clear();
+	subd_attributes.clear();
 	used_shaders.clear();
 
 	transform_applied = false;
@@ -722,8 +728,9 @@ void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<Att
 			osl_attr.value = attr;
 			osl_attr.offset = 0;
 
-			og->attribute_map[i*ATTR_PRIM_TYPES][attr.name()] = osl_attr;
+			og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][attr.name()] = osl_attr;
 			og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_CURVE][attr.name()] = osl_attr;
+			og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_SUBD][attr.name()] = osl_attr;
 		}
 
 		/* find mesh attributes */
@@ -753,11 +760,11 @@ void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<Att
 				if(req.std != ATTR_STD_NONE) {
 					/* if standard attribute, add lookup by geom: name convention */
 					ustring stdname(string("geom:") + string(Attribute::standard_name(req.std)));
-					og->attribute_map[i*ATTR_PRIM_TYPES][stdname] = osl_attr;
+					og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][stdname] = osl_attr;
 				}
 				else if(req.name != ustring()) {
 					/* add lookup by mesh attribute name */
-					og->attribute_map[i*ATTR_PRIM_TYPES][req.name] = osl_attr;
+					og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][req.name] = osl_attr;
 				}
 			}
 
@@ -782,6 +789,28 @@ void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<Att
 					og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_CURVE][req.name] = osl_attr;
 				}
 			}
+
+			if(req.subd_element != ATTR_ELEMENT_NONE) {
+				osl_attr.elem = req.subd_element;
+				osl_attr.offset = req.subd_offset;
+
+				if(req.subd_type

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list