[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20231] branches/soc-2009-yukishiro/source /blender: add sh files

Jingyuan Huang jingyuan.huang at gmail.com
Sat May 16 23:12:09 CEST 2009


Revision: 20231
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20231
Author:   yukishiro
Date:     2009-05-16 23:12:09 +0200 (Sat, 16 May 2009)

Log Message:
-----------
add sh files

Added Paths:
-----------
    branches/soc-2009-yukishiro/source/blender/sh/
    branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt
    branches/soc-2009-yukishiro/source/blender/sh/Makefile
    branches/soc-2009-yukishiro/source/blender/sh/SConscript
    branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
    branches/soc-2009-yukishiro/source/blender/sh/intern/
    branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c

Added: branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt	                        (rev 0)
+++ branches/soc-2009-yukishiro/source/blender/sh/CMakeLists.txt	2009-05-16 21:12:09 UTC (rev 20231)
@@ -0,0 +1,34 @@
+# $Id: CMakeLists.txt 19820 2009-04-20 15:06:46Z blendix $
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+# The Original Code is Copyright (C) 2006, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Jacques Beaurain.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+FILE(GLOB SRC intern/*.c)
+
+SET(INC 
+  intern/include ../../../intern/guardedalloc ../blenlib ../makesdna
+  extern/include ../blenkernel ../blenloader
+)
+
+BLENDERLIB_NOLIST(bf_sh "${SRC}" "${INC}")

Added: branches/soc-2009-yukishiro/source/blender/sh/Makefile
===================================================================

Added: branches/soc-2009-yukishiro/source/blender/sh/SConscript
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SConscript	                        (rev 0)
+++ branches/soc-2009-yukishiro/source/blender/sh/SConscript	2009-05-16 21:12:09 UTC (rev 20231)
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+Import ('env')
+
+cflags=''
+sources = env.Glob('intern/*.c')
+
+incs = '#/intern/guardedalloc ../blenlib ../makesdna'
+incs += ' extern/include ../blenkernel ../blenloader'
+
+env.BlenderLib ( libname = 'bf_sh', sources = sources, includes = Split(incs), libtype='core', priority=145, compileflags=cflags )
+

Added: branches/soc-2009-yukishiro/source/blender/sh/SH_api.h
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	                        (rev 0)
+++ branches/soc-2009-yukishiro/source/blender/sh/SH_api.h	2009-05-16 21:12:09 UTC (rev 20231)
@@ -0,0 +1,36 @@
+/**  
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef _SH_API_H
+#define _SH_API_H
+
+void SH_init();
+void SH_ComputeCoefficients(Scene *scene);
+void SH_exit();
+
+#endif //_SH_API_H

Added: branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c
===================================================================
--- branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	                        (rev 0)
+++ branches/soc-2009-yukishiro/source/blender/sh/intern/compute.c	2009-05-16 21:12:09 UTC (rev 20231)
@@ -0,0 +1,308 @@
+/**  
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <math.h>
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_arithb.h"
+#include "BLI_blenlib.h"
+#include "BLI_dynstr.h"
+#include "BLI_linklist.h"
+#include "BLI_memarena.h"
+#include "PIL_time.h"
+#include "BLI_threads.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_mesh.h"
+#include "BKE_customdata.h"
+
+#define v3_new_vec(a, b, c, u) { u[0] = a; u[1] = b; u[2] = c; }
+#define NUM_SAMPLES 100
+#define SQRT_SAMPLES 10
+
+typedef float Vec3[3];
+typedef float** ShCoeffs;
+
+// TODO: clean up static variables when exiting
+static int inited = 0;
+static ShCoeffs aan;
+static ShCoeffs bbn;
+static Vec3 *samples;
+static ShCoeffs *samples_Y;
+
+static void free_ShCoeffs(ShCoeffs sh_coeffs)
+{
+        if (sh_coeffs == NULL) return;
+        MEM_freeN(*sh_coeffs);
+        MEM_freeN(sh_coeffs);
+}
+
+static ShCoeffs allocate_ShCoeffs()
+{
+        float **a;
+        float  *x;
+        int l;
+
+        a = MEM_mallocN(5 * sizeof(float*), "SH coeffs");
+        if (a==NULL) return NULL;
+        
+        x = MEM_mallocN(5 * 5 * sizeof(float), "SH coeffs data");
+        if (x==NULL) {
+                free(a);
+                return NULL;
+        }
+        
+        /* OK, got all the memory we need, now initialise pointers... */
+        for (l=0; l<=4; l++) a[l] = &(x[l*l+l]);
+        return a;
+}
+
+static void free_ShCoeffs_array(ShCoeffs * a)
+{
+        if (a == NULL) return;
+        MEM_freeN(**a);
+        MEM_freeN(*a);
+        MEM_freeN(a);
+}
+
+static ShCoeffs* allocate_ShCoeffs_array(int n)
+{
+        ShCoeffs *a;
+        float **b;
+        float *x;
+        int j, l;
+
+        a = MEM_mallocN(n * sizeof(ShCoeffs), "SH coeffs array");
+        b = MEM_mallocN(n * 5 * sizeof(float*), "SH coeffs");
+        x = MEM_mallocN(n * 5 * 5 * sizeof(float), "SH coeffs data");
+
+        if (a == NULL || b == NULL || x == NULL) {
+                MEM_freeN(a);
+                MEM_freeN(b);
+                MEM_freeN(x);
+                return NULL;
+        }
+
+        for (j=0; j<n; j++) {
+                a[j] = &(b[j*5]);
+                for (l=0; l<=4; l++) a[j][l] = &(x[j*5*5 + l*l+l]);
+        }
+        return a;
+}
+
+static void compute_Y(Vec3 u, ShCoeffs *Y)
+{
+        int l, m;
+        
+        (*Y)[0][0] = aan[0][0];
+        
+        // work out the degree 1 case immediately...
+        (*Y)[1][0]  = aan[1][0] * u[2];
+        (*Y)[1][-1] = aan[1][1] * u[1];
+        (*Y)[1][1]  = aan[1][1] * u[0];
+        
+        // And then do DEGREES 2..L via the recurrences...
+        for (l = 2; l <= 4; l++) {
+                (*Y)[l][l]    = aan[l][l] * (u[0] * (*Y)[l-1][l-1] - u[1] * (*Y)[l-1][-l+1]);
+                (*Y)[l][-l]   = aan[l][l] * (u[1] * (*Y)[l-1][l-1] + u[0] * (*Y)[l-1][-l+1]);
+                (*Y)[l][l-1]  = aan[l][l-1] * u[2] * (*Y)[l-1][l-1];
+                (*Y)[l][-l+1] = aan[l][l-1] * u[2] * (*Y)[l-1][-l+1];
+                (*Y)[l][0]    = aan[l][0]   * u[2] * (*Y)[l-1][0] + bbn[l][0] * (*Y)[l-2][0]; 
+
+                for (m = 1; m <= l-2; m++) {
+                        (*Y)[l][m]  = aan[l][m] * u[2] * (*Y)[l-1][m]  + bbn[l][m] * (*Y)[l-2][m] ;
+                        (*Y)[l][-m] = aan[l][m] * u[2] * (*Y)[l-1][-m] + bbn[l][m] * (*Y)[l-2][-m];
+                }
+        }
+}
+
+static void aan_bbn_update()
+{
+        int l, m;
+
+        aan = allocate_ShCoeffs();
+        bbn = allocate_ShCoeffs();
+
+        aan[0][0] = 1.0/sqrt(4.0*M_PI);
+        aan[1][0] = aan[0][0] *sqrt(3.0);
+        aan[1][1] = -aan[1][0];
+
+        for (l=2; l<=4; l++) {
+                aan[l][l] =  -sqrt((2.0*l+1)/(2.0*l));
+                aan[l][l-1] = sqrt(2.0*l+1.0);
+                aan[l][0]   = sqrt(4*l*l-1.0) / l;
+                bbn[l][0]   = (1.0/l - 1.0) * sqrt( (float)(2*l+1)/(float)(2*l-3));
+
+                for (m=1; m<l; m++) {
+                        aan[l][m] =  sqrt((float)(4*l*l-1) / (float)(l*l-m*m));
+                        bbn[l][m] = -sqrt((float)( (2*l+1) * ((l-1)*(l-1)-m*m) ) / 
+                                          (float)( (2*l-3) * (l*l-m*m)         ));
+                }
+        }
+}
+
+static void generate_ray_samples(int num_sqrt_samples)
+{
+    double a, b, x, y;
+    double inv_MAX = 1.0 / (double)RAND_MAX;
+
+    int i, j;
+    for (i = 0; i < num_sqrt_samples; i++) {
+        for (j = 0; j < num_sqrt_samples; j++) {
+            a = rand() * inv_MAX;
+            b = rand() * inv_MAX;
+            x = (i + a) / (double)num_sqrt_samples;
+            y = (j + b) / (double)num_sqrt_samples;
+
+            v3_new_vec(
+                cos(2.0 * M_PI * x) * 2.0 * sqrt(y * (1.0 - y)),
+                sin(2.0 * M_PI * x) * 2.0 * sqrt(y * (1.0 - y)),
+                (1.0 - 2.0 * y),
+                samples[i * num_sqrt_samples + j]);
+        }
+    }
+
+    for (i = 0; i < NUM_SAMPLES; i++) {
+        compute_Y(samples[i], &(samples_Y[i]));        
+    }
+}
+
+void SH_init()
+{

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list