Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMai Lavelle <mai.lavelle@gmail.com>2016-04-13 02:17:34 +0300
committerBrecht Van Lommel <brechtvanlommel@gmail.com>2016-04-13 02:37:33 +0300
commitc1a27a76cf9f40ab9dabb5888ee535e585444fcd (patch)
treeda5610d92bae46bc9f5682ea934f23d689a20a3b /intern/cycles/render/mesh.cpp
parent068ee2cd98fc987453cd50285c387c6480c6d99c (diff)
Cycles microdisplacement: preserve smooth normals for linear subdivison
This way we prevent cracks in the model due to discontinuous normals, by using smooth normals for displacement instead of always getting flat normals after linear subdivision. Reviewed By: brecht Differential Revision: https://developer.blender.org/D1916
Diffstat (limited to 'intern/cycles/render/mesh.cpp')
-rw-r--r--intern/cycles/render/mesh.cpp48
1 files changed, 40 insertions, 8 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp
index aa9f773917a..241a1c44ebf 100644
--- a/intern/cycles/render/mesh.cpp
+++ b/intern/cycles/render/mesh.cpp
@@ -1451,31 +1451,63 @@ void Mesh::tessellate(DiagSplit *split)
{
int num_faces = triangles.size();
+ add_face_normals();
+ add_vertex_normals();
+
+ Attribute *attr_fN = attributes.find(ATTR_STD_FACE_NORMAL);
+ float3 *fN = attr_fN->data_float3();
+
+ Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL);
+ float3 *vN = attr_vN->data_float3();
+
for(int f = 0; f < num_faces; f++) {
if(!forms_quad[f]) {
/* triangle */
- LinearTrianglePatch* patch = new LinearTrianglePatch();
- float3 *hull = patch->hull;
+ LinearTrianglePatch patch;
+ float3 *hull = patch.hull;
+ float3 *normals = patch.normals;
for(int i = 0; i < 3; i++) {
hull[i] = verts[triangles[f].v[i]];
}
- split->split_triangle(patch);
- delete patch;
+ if(smooth[f]) {
+ for(int i = 0; i < 3; i++) {
+ normals[i] = vN[triangles[f].v[i]];
+ }
+ }
+ else {
+ for(int i = 0; i < 3; i++) {
+ normals[i] = fN[f];
+ }
+ }
+
+ split->split_triangle(&patch);
}
else {
/* quad */
- LinearQuadPatch* patch = new LinearQuadPatch();
- float3 *hull = patch->hull;
+ LinearQuadPatch patch;
+ float3 *hull = patch.hull;
+ float3 *normals = patch.normals;
hull[0] = verts[triangles[f ].v[0]];
hull[1] = verts[triangles[f ].v[1]];
hull[3] = verts[triangles[f ].v[2]];
hull[2] = verts[triangles[f+1].v[2]];
- split->split_quad(patch);
- delete patch;
+ if(smooth[f]) {
+ normals[0] = vN[triangles[f ].v[0]];
+ normals[1] = vN[triangles[f ].v[1]];
+ normals[3] = vN[triangles[f ].v[2]];
+ normals[2] = vN[triangles[f+1].v[2]];
+ }
+ else {
+ for(int i = 0; i < 4; i++) {
+ normals[i] = fN[f];
+ }
+ }
+
+ split->split_quad(&patch);
// consume second triangle in quad
f++;