[Bf-blender-cvs] [f84e760] temp-cycles-microdisplacement: Cycles microdisplacement: Store undisplaced coordinates for meshes when requested

Mai Lavelle noreply at git.blender.org
Thu Aug 18 18:22:33 CEST 2016


Commit: f84e760aed4b79d121ec9e84f0803abc4819da4b
Author: Mai Lavelle
Date:   Sat Aug 13 12:27:17 2016 -0400
Branches: temp-cycles-microdisplacement
https://developer.blender.org/rBf84e760aed4b79d121ec9e84f0803abc4819da4b

Cycles microdisplacement: Store undisplaced coordinates for meshes when requested

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

M	intern/cycles/render/mesh.cpp
M	intern/cycles/render/mesh.h
M	intern/cycles/render/shader.cpp

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

diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index 25a3d1d..5299768 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -558,6 +558,28 @@ void Mesh::add_vertex_normals()
 	}
 }
 
+void Mesh::add_undisplaced()
+{
+	AttributeSet& attrs = (subdivision_type == SUBDIVISION_NONE) ? attributes : subd_attributes;
+
+	/* don't compute if already there */
+	if(attrs.find(ATTR_STD_POSITION_UNDISPLACED)) {
+		return;
+	}
+
+	/* get attribute */
+	Attribute *attr = attrs.add(ATTR_STD_POSITION_UNDISPLACED);
+	attr->flags |= ATTR_SUBDIVIDED;
+
+	float3 *data = attr->data_float3();
+
+	/* copy verts */
+	size_t size = attr->buffer_size(this, (subdivision_type == SUBDIVISION_NONE) ? ATTR_PRIM_TRIANGLE : ATTR_PRIM_SUBD);
+	if(size) {
+		memcpy(data, verts.data(), size);
+	}
+}
+
 void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal)
 {
 	Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL);
@@ -1658,6 +1680,10 @@ void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scen
 			mesh->add_face_normals();
 			mesh->add_vertex_normals();
 
+			if(mesh->need_attribute(scene, ATTR_STD_POSITION_UNDISPLACED)) {
+				mesh->add_undisplaced();
+			}
+
 			if(progress.get_cancel()) return;
 		}
 	}
diff --git a/intern/cycles/render/mesh.h b/intern/cycles/render/mesh.h
index a77e296..c0310f4 100644
--- a/intern/cycles/render/mesh.h
+++ b/intern/cycles/render/mesh.h
@@ -215,6 +215,7 @@ public:
 	void compute_bounds();
 	void add_face_normals();
 	void add_vertex_normals();
+	void add_undisplaced();
 
 	void pack_normals(Scene *scene, uint *shader, float4 *vnormal);
 	void pack_verts(const vector<uint>& tri_prim_index,
diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp
index 4a3233a..1876791 100644
--- a/intern/cycles/render/shader.cpp
+++ b/intern/cycles/render/shader.cpp
@@ -240,6 +240,10 @@ void Shader::tag_update(Scene *scene)
 	attributes.clear();
 	foreach(ShaderNode *node, graph->nodes)
 		node->attributes(this, &attributes);
+
+	if(has_displacement && displacement_method == DISPLACE_BOTH) {
+		attributes.add(ATTR_STD_POSITION_UNDISPLACED);
+	}
 	
 	/* compare if the attributes changed, mesh manager will check
 	 * need_update_attributes, update the relevant meshes and clear it. */




More information about the Bf-blender-cvs mailing list