Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: some of this file. 00022 * 00023 * ***** END GPL LICENSE BLOCK ***** 00024 * */ 00025 00031 #include "BLI_math.h" 00032 00033 #ifndef BLI_MATH_GEOM_INLINE_H 00034 #define BLI_MATH_GEOM_INLINE_H 00035 00036 /****************************** Spherical Harmonics **************************/ 00037 00038 MINLINE void zero_sh(float r[9]) 00039 { 00040 memset(r, 0, sizeof(float)*9); 00041 } 00042 00043 MINLINE void copy_sh_sh(float r[9], const float a[9]) 00044 { 00045 memcpy(r, a, sizeof(float)*9); 00046 } 00047 00048 MINLINE void mul_sh_fl(float r[9], const float f) 00049 { 00050 int i; 00051 00052 for(i=0; i<9; i++) 00053 r[i] *= f; 00054 } 00055 00056 MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9]) 00057 { 00058 int i; 00059 00060 for(i=0; i<9; i++) 00061 r[i]= a[i] + b[i]; 00062 } 00063 00064 MINLINE float dot_shsh(float a[9], float b[9]) 00065 { 00066 float r= 0.0f; 00067 int i; 00068 00069 for(i=0; i<9; i++) 00070 r += a[i]*b[i]; 00071 00072 return r; 00073 } 00074 00075 MINLINE float diffuse_shv3(float sh[9], const float v[3]) 00076 { 00077 /* See formula (13) in: 00078 "An Efficient Representation for Irradiance Environment Maps" */ 00079 static const float c1 = 0.429043f, c2 = 0.511664f, c3 = 0.743125f; 00080 static const float c4 = 0.886227f, c5 = 0.247708f; 00081 float x, y, z, sum; 00082 00083 x= v[0]; 00084 y= v[1]; 00085 z= v[2]; 00086 00087 sum= c1*sh[8]*(x*x - y*y); 00088 sum += c3*sh[6]*z*z; 00089 sum += c4*sh[0]; 00090 sum += -c5*sh[6]; 00091 sum += 2.0f*c1*(sh[4]*x*y + sh[7]*x*z + sh[5]*y*z); 00092 sum += 2.0f*c2*(sh[3]*x + sh[1]*y + sh[2]*z); 00093 00094 return sum; 00095 } 00096 00097 MINLINE void vec_fac_to_sh(float r[9], const float v[3], const float f) 00098 { 00099 /* See formula (3) in: 00100 "An Efficient Representation for Irradiance Environment Maps" */ 00101 float sh[9], x, y, z; 00102 00103 x= v[0]; 00104 y= v[1]; 00105 z= v[2]; 00106 00107 sh[0]= 0.282095f; 00108 00109 sh[1]= 0.488603f*y; 00110 sh[2]= 0.488603f*z; 00111 sh[3]= 0.488603f*x; 00112 00113 sh[4]= 1.092548f*x*y; 00114 sh[5]= 1.092548f*y*z; 00115 sh[6]= 0.315392f*(3.0f*z*z - 1.0f); 00116 sh[7]= 1.092548f*x*z; 00117 sh[8]= 0.546274f*(x*x - y*y); 00118 00119 mul_sh_fl(sh, f); 00120 copy_sh_sh(r, sh); 00121 } 00122 00123 MINLINE float eval_shv3(float sh[9], const float v[3]) 00124 { 00125 float tmp[9]; 00126 00127 vec_fac_to_sh(tmp, v, 1.0f); 00128 return dot_shsh(tmp, sh); 00129 } 00130 00131 MINLINE void madd_sh_shfl(float r[9], const float sh[3], const float f) 00132 { 00133 float tmp[9]; 00134 00135 copy_sh_sh(tmp, sh); 00136 mul_sh_fl(tmp, f); 00137 add_sh_shsh(r, r, tmp); 00138 } 00139 00140 #endif /* BLI_MATH_GEOM_INLINE_H */ 00141