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:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-03-20 16:35:35 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-03-20 16:35:35 +0300
commit549b5e1222fcda5ca9b7d1892ca4d05e2c62c066 (patch)
treef69a4a833a3eb092530bb0d7959e43cf05ca0362 /source/blender/blenkernel/intern/cdderivedmesh.c
parenta50cdf713a800c07629495f0d5e7124cddbbc2c9 (diff)
Fix/change in normal computation, now the viewport uses the same angle
weighted normals as the render engine, and the render engine will copy normals from the mesh rather than always recalculating them. Subsurf/multires still use regular vertex normals, but they are expected to be sufficiently high resolution to not need this. This means that normal maps displayed in the viewport actually match the render engine exactly and don't have artifacts due to this discrepancy. It of course also avoids unexpected surprises where your render normals look different than your viewport normals. Subversion bumped to 4 for version patch to recalculate normals. Patch by Morten Mikkelsen, with some small changes.
Diffstat (limited to 'source/blender/blenkernel/intern/cdderivedmesh.c')
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c38
1 files changed, 27 insertions, 11 deletions
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 407d2ded085..b7034a7db8a 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -1798,7 +1798,7 @@ void CDDM_calc_normals(DerivedMesh *dm)
int i;
int numVerts = dm->numVertData;
int numFaces = dm->numFaceData;
- MFace *mf;
+ MFace *mfaces;
MVert *mv;
if(numVerts == 0) return;
@@ -1817,27 +1817,43 @@ void CDDM_calc_normals(DerivedMesh *dm)
NULL, dm->numFaceData);
/* calculate face normals and add to vertex normals */
- mf = CDDM_get_faces(dm);
- for(i = 0; i < numFaces; i++, mf++) {
+ mfaces = CDDM_get_faces(dm);
+ for(i = 0; i < numFaces; i++) {
+ MFace * mf = &mfaces[i];
float *f_no = face_nors[i];
if(mf->v4)
- normal_quad_v3( f_no,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, mv[mf->v4].co);
+ normal_quad_v3(f_no, mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, mv[mf->v4].co);
else
- normal_tri_v3( f_no,mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co);
+ normal_tri_v3(f_no, mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co);
- add_v3_v3(temp_nors[mf->v1], f_no);
- add_v3_v3(temp_nors[mf->v2], f_no);
- add_v3_v3(temp_nors[mf->v3], f_no);
- if(mf->v4)
- add_v3_v3(temp_nors[mf->v4], f_no);
+ if((mf->flag&ME_SMOOTH)!=0) {
+ float *n4 = (mf->v4)? temp_nors[mf->v4]: NULL;
+ float *c4 = (mf->v4)? mv[mf->v4].co: NULL;
+
+ accumulate_vertex_normals(temp_nors[mf->v1], temp_nors[mf->v2], temp_nors[mf->v3], n4,
+ f_no, mv[mf->v1].co, mv[mf->v2].co, mv[mf->v3].co, c4);
+ }
+ }
+
+ for(i = 0; i < numFaces; i++) {
+ MFace * mf = &mfaces[i];
+
+ if((mf->flag&ME_SMOOTH)==0) {
+ float *f_no = face_nors[i];
+
+ if(is_zero_v3(temp_nors[mf->v1])) copy_v3_v3(temp_nors[mf->v1], f_no);
+ if(is_zero_v3(temp_nors[mf->v2])) copy_v3_v3(temp_nors[mf->v2], f_no);
+ if(is_zero_v3(temp_nors[mf->v3])) copy_v3_v3(temp_nors[mf->v3], f_no);
+ if(mf->v4 && is_zero_v3(temp_nors[mf->v4])) copy_v3_v3(temp_nors[mf->v4], f_no);
+ }
}
/* normalize vertex normals and assign */
for(i = 0; i < numVerts; i++, mv++) {
float *no = temp_nors[i];
- if (normalize_v3(no) == 0.0)
+ if(normalize_v3(no) == 0.0f)
normalize_v3_v3(no, mv->co);
normal_float_to_short_v3(mv->no, no);