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

Log Message:
-----------
fix colour overflow bug

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
    branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Modified: 
branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c     
2009-05-23 20:33:04 UTC (rev 20367)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c     
2009-05-23 22:19:25 UTC (rev 20368)
@@ -51,11 +51,11 @@
 // TODO: simple function to return value for 3 channels. needs improvement
 void def_synthetic(float theta, float phi, float *val)
 {
-        if (theta < M_PI / 3) {
-                val[0] = val[1] = val[2] = 255;
+        if (theta < M_PI / 6) {
+                val[0] = val[1] = val[2] = 1.0;
         }
         else {
-                val[0] = val[1] = val[2] = 0;
+                val[0] = val[1] = val[2] = 0.0;
         }
 }
 

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-23 20:33:04 UTC (rev 20367)
+++ 
branches/soc-2009-yukishiro/source/blender/editors/space_view3d/drawobject.c    
    2009-05-23 22:19:25 UTC (rev 20368)
@@ -124,6 +124,7 @@
        (((vd->drawtype==OB_SOLID) && (dt>=OB_SOLID) && (vd->flag2 & 
V3D_SOLID_TEX) && (vd->flag & V3D_ZBUF_SELECT)) == 0) \
        )
 
+#define FTOCHAR(val) ((val)<=0.0f)? 0 : (((val)>(1.0f-0.5f/255.0f))? 255 : 
(char)((255.0f*(val))+0.5f))
 
 /* pretty stupid */
 /* editmball.c */
@@ -2291,23 +2292,26 @@
         // TODO: get vertex material colour
         mat = me->mat[0]; //me->mat[(int)v.mat_nr];
         if (mat != NULL) {
-                color[0] = 255 * mat->r;
-                color[1] = 255 * mat->g;
-                color[2] = 255 * mat->b;
+                color[0] = mat->r;
+                color[1] = mat->g;
+                color[2] = mat->b;
         } else {
-              color[0] = color[1] = color[2] = 128;
+              color[0] = color[1] = color[2] = 0.8;
         }
 
         brightness[0] = brightness[1] = brightness[2] = 0;
-        for (k = 0; k < 25; k++) {
+        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] = brightness[0] * color[0];
-       col[1] = brightness[1] * color[1];
-       col[2] = brightness[2] * color[2];
+       col[0] = FTOCHAR(color[0]);
+       col[1] = FTOCHAR(color[1]);
+       col[2] = FTOCHAR(color[2]);
        col[3] = 255;
 }
 
@@ -2444,7 +2448,7 @@
                                 LightEnv *env;
                                 MShCoeffs *mco;
                                 MFace *mf = me->mface;
-                                int i, k;
+                                int i;
 
                                shcol = DM_get_face_data_layer(dm, CD_SH_MCOL);
                                 mco = CustomData_get_layer(&me->vdata, 
CD_MSHCOEFFS);

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c      
2009-05-23 20:33:04 UTC (rev 20367)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c      
2009-05-23 22:19:25 UTC (rev 20368)
@@ -292,9 +292,9 @@
         int k, m;
         float phi, theta, *y_val;
         float l_val[3];
-        float weight = 4.0f/(float)NUM_SAMPLES;
         int num_sh = (L+1)*(L+1);
 
+        // scaling is not done for light coeffs. an extra factor would be used
         for (k = 0; k < NUM_SAMPLES; k++) {
                 phi = sample_angles[k][0];
                 theta = sample_angles[k][1];
@@ -309,8 +309,10 @@
         }
 
         for (m = 0; m < num_sh; m++) {
-                env->shcoeffs[m][0] *= weight;
-                env->shcoeffs[m][1] *= weight;
-                env->shcoeffs[m][2] *= weight;
+                printf("%f %f %f\n", 
+                        env->shcoeffs[m][0],
+                        env->shcoeffs[m][1],
+                        env->shcoeffs[m][2]
+                      );
         }
 }


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

Reply via email to