2.5: remove vertex normal flip option, this is more harmful than helpful
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 30 Jul 2010 11:50:00 +0000 (11:50 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 30 Jul 2010 11:50:00 +0000 (11:50 +0000)
in many cases, and also gave incorrect rim lighting.

12 files changed:
release/scripts/ui/properties_data_mesh.py
source/blender/blenkernel/intern/mesh.c
source/blender/makesdna/DNA_curve_types.h
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesrna/intern/rna_curve.c
source/blender/makesrna/intern/rna_mesh.c
source/blender/render/intern/include/render_types.h
source/blender/render/intern/include/renderdatabase.h
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/rayshade.c
source/blender/render/intern/source/renderdatabase.c
source/blender/render/intern/source/shadeinput.c

index 44d3d19e79318a3284c91f87f654cec8ff58dfbd..c3170be886010d367c3c152840d3a5b088a1f2f4 100644 (file)
@@ -114,7 +114,6 @@ class DATA_PT_normals(DataButtonsPanel):
             col = split.column()
         else:
             col.separator()
-        col.prop(mesh, "vertex_normal_flip")
         col.prop(mesh, "double_sided")
 
 
index cd8b2eb0a8eaa1f15b5f5e0ddb591a2541486e6a..66e8c10206c5024c955dc16353d234ebfe2dc7f0 100644 (file)
@@ -697,7 +697,6 @@ void mball_to_mesh(ListBase *lb, Mesh *me)
        if(dl==0) return;
 
        if(dl->type==DL_INDEX4) {
-               me->flag= ME_NOPUNOFLIP;
                me->totvert= dl->nr;
                me->totface= dl->parts;
                
index c13cb08baddd221b0ea565d556b433b0dae36505..283c810a1f63eca40fee9d413de7c387031111e3 100644 (file)
@@ -245,7 +245,7 @@ typedef struct Curve {
 #define CU_PATH                        8
 #define CU_FOLLOW              16
 #define CU_UV_ORCO             32
-#define CU_NOPUNOFLIP  64
+#define CU_DEPRECATED  64
 #define CU_STRETCH             128
 #define CU_OFFS_PATHDIST       256
 #define CU_FAST                        512 /* Font: no filling inside editmode */
index 68b05dd659528a2710f42cddf646520fdcac48d6..4e41309cff4b3f3eac4de89918fc7263eba3cf4f 100644 (file)
@@ -129,7 +129,7 @@ typedef struct TFace {
 
 /* me->flag */
 /* #define ME_ISDONE           1 */
-#define ME_NOPUNOFLIP  2
+#define ME_DEPRECATED  2
 #define ME_TWOSIDED            4
 #define ME_UVEFFECT            8
 #define ME_VCOLEFFECT  16
index e006f3444b00fc7ae2a24dd76e198b9ddd5404f9..d10aed1595a00d9cc5357a909580b76e7c0f3fe5 100644 (file)
@@ -706,11 +706,6 @@ static void rna_def_nurbs(BlenderRNA *brna, StructRNA *srna)
        RNA_def_property_boolean_sdna(prop, NULL, "flag", CU_UV_ORCO);
        RNA_def_property_ui_text(prop, "Map Along Length", "Generate texture mapping coordinates following the curve direction, rather than the local bounding box");
        RNA_def_property_update(prop, 0, "rna_Curve_update_data");
-       
-       prop= RNA_def_property(srna, "vertex_normal_flip", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CU_NOPUNOFLIP);
-       RNA_def_property_ui_text(prop, "Vertex Normal Flip", "Flip vertex normals towards the camera during render");
-       RNA_def_property_update(prop, 0, "rna_Curve_update_data");
 }
 
 static void rna_def_font(BlenderRNA *brna, StructRNA *srna)
index 6e172e3bdd0999753f0623a3e9377805931add9f..37d6b2b93de511cfa85e78c8a4cdf7c13fcf229f 100644 (file)
@@ -1748,10 +1748,6 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_range(prop, 1, 80);
        RNA_def_property_ui_text(prop, "Auto Smooth Angle", "Defines maximum angle between face normals that 'Auto Smooth' will operate on");
 
-       prop= RNA_def_property(srna, "vertex_normal_flip", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ME_NOPUNOFLIP);
-       RNA_def_property_ui_text(prop, "Vertex Normal Flip", "Flip vertex normals towards the camera during render");
-
        prop= RNA_def_property(srna, "double_sided", PROP_BOOLEAN, PROP_NONE);
        RNA_def_property_boolean_sdna(prop, NULL, "flag", ME_TWOSIDED);
        RNA_def_property_ui_text(prop, "Double Sided", "Render/display the mesh with double or single sided lighting");
index 2b0de46f2e6ddc325de45aeaf5d87d57cb2d373d..c75ae594daf8a7e675809962c16da1fbbd040b27 100644 (file)
@@ -587,23 +587,21 @@ typedef struct LampRen {
 #define R_HALO                 2
 #define R_SEC_FIELD            4
 #define R_LAMPHALO             8
-#define R_GLOB_NOPUNOFLIP      16
-#define R_NEED_TANGENT 32
-#define R_BAKE_TRACE   128
-#define R_BAKING               256
+#define R_NEED_TANGENT 16
+#define R_BAKE_TRACE   32
+#define R_BAKING               64
 
 /* vlakren->flag (vlak = face in dutch) char!!! */
 #define R_SMOOTH               1
 #define R_HIDDEN               2
 /* strand flag, means special handling */
 #define R_STRAND               4
-#define R_NOPUNOFLIP   8
-#define R_FULL_OSA             16
-#define R_FACE_SPLIT   32
+#define R_FULL_OSA             8
+#define R_FACE_SPLIT   16
 /* Tells render to divide face other way. */
-#define R_DIVIDE_24            64      
+#define R_DIVIDE_24            32      
 /* vertex normals are tangent or view-corrected vector, for hair strands */
-#define R_TANGENT              128             
+#define R_TANGENT              64              
 
 /* strandbuffer->flag */
 #define R_STRAND_BSPLINE       1
index 2a0086b436c0dd7072e8e0e77e37581ffa77734c..76e7fe7b4f325dd025156452c00f76932b46113f 100644 (file)
@@ -115,7 +115,7 @@ struct MCol *RE_vlakren_get_mcol(struct ObjectRen *obr, VlakRen *ren, int n, cha
 float *RE_vlakren_get_surfnor(struct ObjectRen *obr, VlakRen *ren, int verify);
 float *RE_vlakren_get_nmap_tangent(struct ObjectRen *obr, VlakRen *ren, int verify);
 RadFace **RE_vlakren_get_radface(struct ObjectRen *obr, VlakRen *ren, int verify);
-int RE_vlakren_get_normal(struct Render *re, struct ObjectInstanceRen *obi, struct VlakRen *vlr, float *nor);
+void RE_vlakren_get_normal(struct Render *re, struct ObjectInstanceRen *obi, struct VlakRen *vlr, float *nor);
 
 float *RE_strandren_get_surfnor(struct ObjectRen *obr, struct StrandRen *strand, int verify);
 float *RE_strandren_get_uv(struct ObjectRen *obr, struct StrandRen *strand, int n, char **name, int verify);
index c5d69e69586946a8016417161cf40eea80e21a24..6564dd09864437c90b6ec00109975ede2846ed73 100644 (file)
@@ -355,17 +355,6 @@ static void split_v_renderfaces(ObjectRen *obr, int startvlak, int startvert, in
        }
 }
 
-/* ------------------------------------------------------------------------- */
-
-static int check_vnormal(float *n, float *veno)
-{
-       float inp;
-
-       inp=n[0]*veno[0]+n[1]*veno[1]+n[2]*veno[2];
-       if(inp < -FLT_EPSILON10) return 1;
-       return 0;
-}
-
 /* ------------------------------------------------------------------------- */
 /* Stress, tangents and normals                                              */
 /* ------------------------------------------------------------------------- */
@@ -536,9 +525,6 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d
                        float n1[3], n2[3], n3[3], n4[3];
                        float fac1, fac2, fac3, fac4=0.0f;
                        
-                       if(re->flag & R_GLOB_NOPUNOFLIP)
-                               vlr->flag |= R_NOPUNOFLIP;
-                       
                        sub_v3_v3v3(n1, v2->co, v1->co);
                        normalize_v3(n1);
                        sub_v3_v3v3(n2, v3->co, v2->co);
@@ -562,21 +548,11 @@ static void calc_vertexnormals(Render *re, ObjectRen *obr, int do_tangent, int d
                                fac3= saacos(-n2[0]*n3[0]-n2[1]*n3[1]-n2[2]*n3[2]);
                                fac4= saacos(-n3[0]*n4[0]-n3[1]*n4[1]-n3[2]*n4[2]);
 
-                               if(!(vlr->flag & R_NOPUNOFLIP)) {
-                                       if( check_vnormal(vlr->n, v4->n) ) fac4= -fac4;
-                               }
-
                                v4->n[0] +=fac4*vlr->n[0];
                                v4->n[1] +=fac4*vlr->n[1];
                                v4->n[2] +=fac4*vlr->n[2];
                        }
 
-                       if(!(vlr->flag & R_NOPUNOFLIP)) {
-                               if( check_vnormal(vlr->n, v1->n) ) fac1= -fac1;
-                               if( check_vnormal(vlr->n, v2->n) ) fac2= -fac2;
-                               if( check_vnormal(vlr->n, v3->n) ) fac3= -fac3;
-                       }
-
                        v1->n[0] +=fac1*vlr->n[0];
                        v1->n[1] +=fac1*vlr->n[1];
                        v1->n[2] +=fac1*vlr->n[2];
@@ -1021,7 +997,7 @@ static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, Par
        else width= 1.0f;
        
        if(ma->mode & MA_TANGENT_STR)
-               flag= R_SMOOTH|R_NOPUNOFLIP|R_TANGENT;
+               flag= R_SMOOTH|R_TANGENT;
        else
                flag= R_SMOOTH;
        
@@ -2431,7 +2407,7 @@ static void init_render_mball(Render *re, ObjectRen *obr)
                        normal_tri_v3( vlr->n,vlr->v3->co, vlr->v2->co, vlr->v1->co);
 
                vlr->mat= ma;
-               vlr->flag= ME_SMOOTH+R_NOPUNOFLIP;
+               vlr->flag= ME_SMOOTH;
                vlr->ec= 0;
 
                /* mball -too bad- always has triangles, because quads can be non-planar */
@@ -2460,10 +2436,8 @@ static void init_render_mball(Render *re, ObjectRen *obr)
 /* returns amount of vertices added for orco */
 static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, float *orco, float mat[4][4])
 {
-       Object *ob= obr->ob;
        VertRen *v1, *v2, *v3, *v4, *ver;
        VlakRen *vlr, *vlr1, *vlr2, *vlr3;
-       Curve *cu= ob->data;
        float *data, n1[3];
        int u, v, orcoret= 0;
        int p1, p2, p3, p4, a;
@@ -2543,9 +2517,6 @@ static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar,
                        vlr->mat= matar[ dl->col];
                        vlr->ec= ME_V1V2+ME_V2V3;
                        vlr->flag= dl->rt;
-                       if( (cu->flag & CU_NOPUNOFLIP) ) {
-                               vlr->flag |= R_NOPUNOFLIP;
-                       }
                        
                        add_v3_v3(v1->n, n1);
                        add_v3_v3(v2->n, n1);
@@ -2694,9 +2665,6 @@ static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr,
 
                                        vlr->mat= ma;
                                        vlr->flag= flag;
-                                       if(cu &&(cu->flag & ME_NOPUNOFLIP)) {
-                                               vlr->flag |= R_NOPUNOFLIP;
-                                       }
                                        vlr->ec= 0; /* mesh edges rendered separately */
 
                                        if(len==0) obr->totvlak--;
@@ -2904,9 +2872,6 @@ static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
 
                                                vlr->mat= matar[ dl->col ];
                                                vlr->flag= 0;
-                                               if( (cu->flag & CU_NOPUNOFLIP) ) {
-                                                       vlr->flag |= R_NOPUNOFLIP;
-                                               }
                                                vlr->ec= 0;
                                        }
                                }
@@ -3391,9 +3356,6 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
 
                                                        vlr->mat= ma;
                                                        vlr->flag= flag;
-                                                       if((me->flag & ME_NOPUNOFLIP) ) {
-                                                               vlr->flag |= R_NOPUNOFLIP;
-                                                       }
                                                        vlr->ec= 0; /* mesh edges rendered separately */
 
                                                        if(len==0) obr->totvlak--;
@@ -5612,7 +5574,6 @@ void RE_Database_Baking(Render *re, Scene *scene, unsigned int lay, int type, Ob
        
        RE_init_threadcount(re);
        
-       re->flag |= R_GLOB_NOPUNOFLIP;
        re->flag |= R_BAKING;
        re->excludeob= actob;
        if(actob)
index b4a43373ef490e9574709676a1973e274709b213..724fd9a311063b01d9b0943c6cf688c90db4a244 100644 (file)
@@ -531,10 +531,6 @@ void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr)
 
        shade_input_set_normals(shi);
 
-       /* point normals to viewing direction */
-       if(INPR(shi->facenor, shi->view) < 0.0f)
-               shade_input_flip_normals(shi);
-
        shade_input_set_shade_texco(shi);
        if (shi->mat->material_type == MA_TYPE_VOLUME) {
                if(ELEM(is->mode, RE_RAY_SHADOW, RE_RAY_SHADOW_TRA)) {
index 2bfc8f6c1efdb9644d88fec0a132f4a1bc755331..ce55935d39225b6dbf154f33382bd58d797a09d0 100644 (file)
@@ -440,10 +440,9 @@ VlakRen *RE_vlakren_copy(ObjectRen *obr, VlakRen *vlr)
        return vlr1;
 }
 
-int RE_vlakren_get_normal(Render *re, ObjectInstanceRen *obi, VlakRen *vlr, float *nor)
+void RE_vlakren_get_normal(Render *re, ObjectInstanceRen *obi, VlakRen *vlr, float *nor)
 {
-       float v1[3], (*nmat)[3]= obi->nmat;
-       int flipped= 0;
+       float (*nmat)[3]= obi->nmat;
 
        if(obi->flag & R_TRANSFORMED) {
                VECCOPY(nor, vlr->n);
@@ -453,29 +452,6 @@ int RE_vlakren_get_normal(Render *re, ObjectInstanceRen *obi, VlakRen *vlr, floa
        }
        else
                VECCOPY(nor, vlr->n);
-
-       if((vlr->flag & R_NOPUNOFLIP)==0) {
-               if(re->r.mode & R_ORTHO) {
-                       if(nor[2] > 0.0f)
-                               flipped= 1;
-               }
-               else {
-                       VECCOPY(v1, vlr->v1->co);
-                       if(obi->flag & R_TRANSFORMED)
-                               mul_m4_v3(obi->mat, v1);
-                       if(INPR(v1, nor) < 0.0f) {
-                               flipped= 1;
-                       }
-               }
-
-               if(flipped) {
-                       nor[0]= -nor[0];
-                       nor[1]= -nor[1];
-                       nor[2]= -nor[2];
-               }
-       }
-
-       return flipped;
 }
 
 void RE_set_customdata_names(ObjectRen *obr, CustomData *data)
index fc9aba208703b3c9c789b9d4bb03097f827957f9..56ab56d04111393449731267fad241beab58091a 100644 (file)
@@ -273,7 +273,8 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen
        shi->mode= shi->mat->mode_l;            /* or-ed result for all nodes */
 
        /* facenormal copy, can get flipped */
-       shi->flippednor= RE_vlakren_get_normal(&R, obi, vlr, shi->facenor);
+       shi->flippednor= 0;
+       RE_vlakren_get_normal(&R, obi, vlr, shi->facenor);
        
        /* calculate vertexnormals */
        if(vlr->flag & R_SMOOTH) {
@@ -286,24 +287,6 @@ void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen
                        mul_m3_v3(obi->nmat, shi->n2);
                        mul_m3_v3(obi->nmat, shi->n3);
                }
-
-               if(!(vlr->flag & (R_NOPUNOFLIP|R_TANGENT))) {
-                       if(INPR(shi->facenor, shi->n1) < 0.0f) {
-                               shi->n1[0]= -shi->n1[0];
-                               shi->n1[1]= -shi->n1[1];
-                               shi->n1[2]= -shi->n1[2];
-                       }
-                       if(INPR(shi->facenor, shi->n2) < 0.0f) {
-                               shi->n2[0]= -shi->n2[0];
-                               shi->n2[1]= -shi->n2[1];
-                               shi->n2[2]= -shi->n2[2];
-                       }
-                       if(INPR(shi->facenor, shi->n3) < 0.0f) {
-                               shi->n3[0]= -shi->n3[0];
-                               shi->n3[1]= -shi->n3[1];
-                               shi->n3[2]= -shi->n3[2];
-                       }
-               }
        }
 }
 
@@ -826,6 +809,10 @@ void shade_input_set_normals(ShadeInput *shi)
        /* used in nodes */
        VECCOPY(shi->vno, shi->vn);
 
+       /* flip normals to viewing direction */
+       if(!(shi->vlr->flag & R_TANGENT))
+               if(dot_v3v3(shi->facenor, shi->view) < 0.0f)
+                       shade_input_flip_normals(shi);
 }
 
 /* use by raytrace, sss, bake to flip into the right direction */