[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21256] branches/soc-2009-yukishiro/source /blender: fix math in sh compute

Jingyuan Huang jingyuan.huang at gmail.com
Tue Jun 30 04:36:47 CEST 2009


Revision: 21256
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21256
Author:   yukishiro
Date:     2009-06-30 04:36:46 +0200 (Tue, 30 Jun 2009)

Log Message:
-----------
fix math in sh compute

Modified Paths:
--------------
    branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.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-06-30 01:17:50 UTC (rev 21255)
+++ branches/soc-2009-yukishiro/source/blender/blenkernel/intern/lightenv.c	2009-06-30 02:36:46 UTC (rev 21256)
@@ -52,7 +52,7 @@
 
 
 // TODO: simple function to return value for 3 channels. needs improvement
-void def_synthetic(float theta, float phi, float val[3], void *data)
+void def_synthetic(float phi, float theta, float val[3], void *data)
 {
 	if (theta < M_PI / 12) {
 		val[0] = val[1] = val[2] = 1.0;

Modified: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-06-30 01:17:50 UTC (rev 21255)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-06-30 02:36:46 UTC (rev 21256)
@@ -693,7 +693,7 @@
 {
         int k, m, i, j;
         float phi, theta, *y_val, l_val[3];
-        float u, v, r, delta, dA, d_omega;
+        float u, v, r, deltau, deltav, dA, d_omega;
         int num_sh = (env->degree + 1) * (env->degree + 1);
         ImBuf *ibuf;
         Vec3 pnt;
@@ -718,21 +718,22 @@
                 ibuf = BKE_image_get_ibuf(env->probe_image, NULL);
 
                 Y = allocate_ShCoeffs();
-                delta = 2.0f / (float)ibuf->x;
-                dA = M_PI * M_PI * delta * delta;
+                deltau = 2.0f / (float)ibuf->x;
+                deltav = 2.0f / (float)ibuf->y;
+                dA = M_PI * M_PI * deltau * deltav;
 
                 for (i = 0; i < ibuf->x; i++) {
                         for (j = 0; j < ibuf->y; j++) {
-                                v = 1 - delta * i;
-                                u = delta * j - 1;
+                                u = deltau * i - 1;
+                                v = deltav * j - 1; // [-1, 1]
                                 r = sqrt(u * u + v * v);
                                 if (r > 1.0) continue;
 
                                 theta = M_PI * r;
                                 phi = atan2(v, u);
                                 pnt[0] = sin(theta) * cos(phi);
-                                pnt[1] = sin(theta) * sin(phi);
-                                pnt[2] = cos(theta);
+                                pnt[1] = cos(theta);
+                                pnt[2] = sin(theta) * sin(phi);
 
                                 compute_Y(pnt, Y);
                                 d_omega = dA * sinc(theta);
@@ -787,29 +788,33 @@
 {
         int m, i, j;
         float phi, theta, *y_val, *lval;
-        float u, v, r, xdelta, ydelta;
+        float u, v, r, deltau, deltav;
         int num_sh = (env->degree+1) * (env->degree+1);
         Vec3 pnt;
         ShCoeffs Y;
 
         Y = allocate_ShCoeffs();
-        xdelta = 2.0f / (float)width;
-        ydelta = 2.0f / (float)height;
+        deltau = 2.0f / (float)width;
+        deltav = 2.0f / (float)height;
 
         for (i = xmin; i < xmax; i++) {
                 for (j = ymin; j < ymax; j++) {
                         lval = col + (xmax - xmin) * (j - ymin) * 4 + (i - xmin) * 4;
 
-                        v = 1 - xdelta * i;
-                        u = ydelta * j - 1;
+                        u = deltau * i - 1;
+                        v = deltav * j - 1;
                         r = sqrt(u * u + v * v);
-                        if (r > 1.0) continue;
+                        if (r > 1.0) {
+				lval[0] = lval[1] = lval[2] = 0.0;
+				lval[3] = 1.0;
+				continue;
+			}
         
                         theta = M_PI * r;
                         phi = atan2(v, u);
                         pnt[0] = sin(theta) * cos(phi);
-                        pnt[1] = sin(theta) * sin(phi);
-                        pnt[2] = cos(theta);
+                        pnt[1] = cos(theta);
+                        pnt[2] = sin(theta) * sin(phi);
         
                         compute_Y(pnt, Y);
                         y_val = *Y;
@@ -832,29 +837,30 @@
 {       
         int m, i, j;
         float phi, theta, *y_val, *lval;
-        float u, v, r, delta;
+        float u, v, r, deltau, deltav;
         int offset, num_sh = (env->degree+1) * (env->degree+1);
         Vec3 pnt;
         ShCoeffs Y;
 
         Y = allocate_ShCoeffs();
-        delta = 2.0f / (float)ibuf->x;
+        deltau = 2.0f / (float)ibuf->x;
+        deltav = 2.0f / (float)ibuf->y;
 
         for (i = 0; i < ibuf->x; i++) {
                 for (j = 0; j < ibuf->y; j++) {
                         offset = ibuf->x * j * 4 + i * 4;
                         lval = (float*)ibuf->rect_float + offset;
 
-                        v = 1 - delta * i;
-                        u = delta * j - 1;
+                        u = deltau * i - 1;
+                        v = deltav * j - 1;
                         r = sqrt(u * u + v * v);
                         if (r > 1.0) continue;
         
                         theta = M_PI * r;
                         phi = atan2(v, u);
                         pnt[0] = sin(theta) * cos(phi);
-                        pnt[1] = sin(theta) * sin(phi);
-                        pnt[2] = cos(theta);
+                        pnt[1] = cos(theta);
+                        pnt[2] = sin(theta) * sin(phi);
         
                         compute_Y(pnt, Y);
                         y_val = *Y;
@@ -925,20 +931,21 @@
 void SH_eval_color(float *col, LightEnv *env, float *n)
 {
 	int channel, i;
-	float coeffs[9];
+	float coeffs[9], no[3];
 
 	if (env == NULL) {
 		col[0] = col[1] = col[2] = 0;
 		return;
 	}
 
-	// XXX: need to remove this hack
-	n[0] = -n[0]; n[1] = -n[1];
+	no[0] = -n[0]; // TODO
+	no[1] = n[1];
+	no[2] = n[2];
 
 	for (channel = 0; channel < 3; channel++) {
 		for (i = 0; i < 9; i++) { 
 			coeffs[i] = env->shcoeffs[i][channel];
 		}
-		col[channel] = SH_eval(coeffs, n);
+		col[channel] = SH_eval(coeffs, no);
 	}
 }





More information about the Bf-blender-cvs mailing list