Revision: 20526
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20526
Author:   yukishiro
Date:     2009-05-31 04:56:25 +0200 (Sun, 31 May 2009)

Log Message:
-----------
reduce material colour computation. still not happy with how it's done

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_DerivedMesh.h
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
    
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c

Modified: 
branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_DerivedMesh.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_DerivedMesh.h     
2009-05-31 02:35:58 UTC (rev 20525)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/BKE_DerivedMesh.h     
2009-05-31 02:56:25 UTC (rev 20526)
@@ -461,6 +461,8 @@
 
 void weight_to_rgb(float input, float *fr, float *fg, float *fb);
 
+void calc_sh_color(struct Scene *scene, struct Object *ob, DerivedMesh *dm, 
unsigned char *shcol);
+
 /* convert layers requested by a GLSL material to actually available layers in
  * the DerivedMesh, with both a pointer for arrays and an offset for editmesh 
*/
 typedef struct DMVertexAttribs {

Modified: 
branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c  
2009-05-31 02:35:58 UTC (rev 20525)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/DerivedMesh.c  
2009-05-31 02:56:25 UTC (rev 20526)
@@ -39,6 +39,8 @@
 
 #include "DNA_effect_types.h"
 #include "DNA_key_types.h"
+#include "DNA_lightenv_types.h"
+#include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
 #include "DNA_modifier_types.h"
@@ -68,6 +70,7 @@
 #include "BKE_fluidsim.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
+#include "BKE_lightenv.h"
 #include "BKE_material.h"
 #include "BKE_modifier.h"
 #include "BKE_mesh.h"
@@ -1582,13 +1585,66 @@
        CustomData_add_layer(&dm->faceData, CD_WEIGHT_MCOL, CD_ASSIGN, wtcol, 
dm->numFaceData);
 }
 
+static void calc_sh_vert_color(Object *ob, int index, MShCoeffs *mco, float 
(*lco)[3], unsigned char *col)
+{
+        Mesh *me = ob->data;
+        Material * mat;
+        float color[3];
+        float brightness[3];
+        int k;
 
+        // TODO: get face material colour
+        if (me->mat) mat = me->mat[0];
+
+        if (mat != NULL) {
+                color[0] = mat->r;
+                color[1] = mat->g;
+                color[2] = mat->b;
+        } else {
+              color[0] = color[1] = color[2] = 0.8;
+        }
+
+        brightness[0] = brightness[1] = brightness[2] = 0;
+        for (k = 0; k < 9; k++) {
+                brightness[0] += mco[index].val[k] * lco[k][0];
+                brightness[1] += mco[index].val[k] * lco[k][1];
+                brightness[2] += mco[index].val[k] * lco[k][2];
+        }
+       color[0] *= brightness[0];
+       color[1] *= brightness[1];
+       color[2] *= brightness[2];
+
+       col[0] = FTOCHAR(color[0]);
+       col[1] = FTOCHAR(color[1]);
+       col[2] = FTOCHAR(color[2]);
+       col[3] = 255;
+}
+
+void calc_sh_color(Scene *scene, Object *ob, DerivedMesh *dm, unsigned char 
*shcol)
+{
+        int i, totface= dm->getNumFaces(dm);
+        MFace *mf= dm->getFaceArray(dm);
+        Mesh *me= get_mesh(ob);
+        MShCoeffs *mco= CustomData_get_layer(&me->vdata, CD_MSHCOEFFS);
+        LightEnv *env= get_scene_lightenv(scene);
+
+        for (i=0; i<totface; i++, mf++) {
+                calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 
+ 0) * 4]);
+                calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 
+ 1) * 4]);
+                calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, &shcol[(i*4 
+ 2) * 4]);
+                if (mf->v4)
+                        calc_sh_vert_color(ob, mf->v1, mco, env->shcoeffs, 
&shcol[(i*4 + 3) * 4]);
+        }
+}
+
+
 static void add_sh_mcol_dm(Scene *scene, Object *ob, DerivedMesh *dm)
 {
         unsigned char *shcol;
-        int totface = dm->getNumFaces(dm);
+        int totface= dm->getNumFaces(dm);
 
         shcol = MEM_callocN (sizeof (unsigned char) * totface * 4 * 4, "sh 
color");
+        calc_sh_color(scene, ob, dm, shcol);
         CustomData_add_layer(&dm->faceData, CD_SH_MCOL, CD_ASSIGN, shcol, 
dm->numFaceData);
 }
 

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c    
    2009-05-31 02:35:58 UTC (rev 20525)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c    
    2009-05-31 02:56:25 UTC (rev 20526)
@@ -46,7 +46,6 @@
 #include "DNA_effect_types.h"
 #include "DNA_lamp_types.h"
 #include "DNA_lattice_types.h"
-#include "DNA_lightenv_types.h"
 #include "DNA_material_types.h"
 #include "DNA_mesh_types.h"
 #include "DNA_meshdata_types.h"
@@ -80,7 +79,6 @@
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_key.h"
-#include "BKE_lightenv.h"
 #include "BKE_lattice.h"
 #include "BKE_mesh.h"
 #include "BKE_material.h"
@@ -2279,43 +2277,7 @@
        return 1;
 }
 
-// TODO: consider move the routine somewhere else
-static void calc_sh_vert_color(Object *ob, int vert, MShCoeffs *mco, float 
(*lco)[3], unsigned char *col)
-{
-        Mesh *me = ob->data;
-        MVert v = me->mvert[vert];
-        Material * mat;
-        float color[3];
-        float brightness[3];
-        int k;
 
-        // TODO: get vertex material colour
-        if (me->mat) mat = me->mat[0];
-
-        if (mat != NULL) {
-                color[0] = mat->r;
-                color[1] = mat->g;
-                color[2] = mat->b;
-        } else {
-              color[0] = color[1] = color[2] = 0.8;
-        }
-
-        brightness[0] = brightness[1] = brightness[2] = 0;
-        for (k = 0; k < 9; k++) {
-                brightness[0] += mco[vert].val[k] * lco[k][0];
-                brightness[1] += mco[vert].val[k] * lco[k][1];
-                brightness[2] += mco[vert].val[k] * lco[k][2];
-        }
-       color[0] *= brightness[0];
-       color[1] *= brightness[1];
-       color[2] *= brightness[2];
-
-       col[0] = FTOCHAR(color[0]);
-       col[1] = FTOCHAR(color[1]);
-       col[2] = FTOCHAR(color[2]);
-       col[3] = 255;
-}
-
 static void draw_mesh_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, 
Base *base, int dt, int flag)
 {
        Object *ob= base->object;
@@ -2443,28 +2405,16 @@
                                dm->drawMappedFaces(dm, 
wpaint__setSolidDrawOptions, NULL, 0);
                        }
                         else if(G.f & G_LIGHTPAINT) {
-                               unsigned char *shcol;
-                                LightEnv *env;
-                                MShCoeffs *mco;
-                                MFace *mf = dm->getFaceArray(dm);//= me->mface;
-                                int num_faces, i;
 
                                 glDisable(GL_LIGHTING);
                                 
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
                                 glEnable(GL_COLOR_MATERIAL); 
                                 glShadeModel(GL_SMOOTH);
 
-                               shcol = DM_get_face_data_layer(dm, CD_SH_MCOL);
-                                mco = CustomData_get_layer(&me->vdata, 
CD_MSHCOEFFS);
-                                env = get_scene_lightenv(scene);
-
-                                // TODO: calculation shouldn't be done every 
update
-                                for (i=0; i<totface; i++, mf++) {
-                                        calc_sh_vert_color(ob, mf->v1, mco, 
env->shcoeffs, &shcol[(i*4 + 0) * 4]);
-                                        calc_sh_vert_color(ob, mf->v1, mco, 
env->shcoeffs, &shcol[(i*4 + 1) * 4]);
-                                        calc_sh_vert_color(ob, mf->v1, mco, 
env->shcoeffs, &shcol[(i*4 + 2) * 4]);
-                                        if (mf->v4)
-                                                calc_sh_vert_color(ob, mf->v1, 
mco, env->shcoeffs, &shcol[(i*4 + 3) * 4]);
+                                unsigned char *shcol= 
DM_get_face_data_layer(dm, CD_SH_MCOL);
+                                if (rv3d->pad3 == 1) {
+                                        calc_sh_color(scene, ob, dm, shcol);
+                                        rv3d->pad3 = 0;
                                 }
 
                                 dm->drawFacesColored(dm, me->flag, shcol, 
NULL);

Modified: 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c
===================================================================
--- 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c  
    2009-05-31 02:35:58 UTC (rev 20525)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/space_view3d.c  
    2009-05-31 02:56:25 UTC (rev 20526)
@@ -368,6 +368,7 @@
 
 static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
 {
+       RegionView3D *rv3d; 
        /* context changes */
        switch(wmn->category) {
                case NC_SCENE:
@@ -405,6 +406,8 @@
                case NC_MATERIAL:
                        switch(wmn->data) {
                                case ND_SHADING_DRAW:
+                                        rv3d = ar->regiondata;
+                                        rv3d->pad3 = 1;
                                        ED_region_tag_redraw(ar);
                                        break;
                        }


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to