diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-04-15 14:28:32 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-04-15 14:28:32 +0400 |
commit | 9a85013692322f8a821b8228ad552f84d2a215e9 (patch) | |
tree | 666bb54fa093429d65b6b0322e8058c03f5fe223 /source/blender/blenlib/intern/math_geom_inline.c | |
parent | 2b018673509fe7a38a6332fae00bd605335bd286 (diff) |
Merge various small changes from render branch:
* Division by zero fix for TNT SVD code.
* Sound fix, in case ffmpeg decode fails, don't use the samples.
* Fix for incorrect bounds of transformed objects in new raytracing code.
* Gave memory arena's a name used for allocations for easier memory
usage debugging.
* Dupligroup no_draw option was using layers but not restrict view/render
setting. (not a bugfix exactly but would do display list context switching
while drawing for no reason).
* Fix objects instanced on hair particles not giving consistent results
when the object is transformed.
* New math functions: madd_v4_v4fl, len_squared_v3v3, interp_v4_v4v4v4,
mul_v4_m4v4, SH and form factor functions, box_minmax_bounds_m4.
* mul_m4_m4m4 and mul_m3_m3m3 now accept the same pointers for multiple
arguments.
* endjob callback for WM jobs system.
* Geometry node uv/color layer now has search list/autocomplete.
* Various small buildsystem tweaks, not strictly needed yet in trunk.
Diffstat (limited to 'source/blender/blenlib/intern/math_geom_inline.c')
-rw-r--r-- | source/blender/blenlib/intern/math_geom_inline.c | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c new file mode 100644 index 00000000000..8b04b2a4005 --- /dev/null +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -0,0 +1,138 @@ +/** + * $Id: math_base_inline.c 26367 2010-01-28 16:02:26Z 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) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * The Original Code is: some of this file. + * + * ***** END GPL LICENSE BLOCK ***** + * */ + +#include "BLI_math.h" + +#ifndef BLI_MATH_GEOM_INLINE +#define BLI_MATH_GEOM_INLINE + +/****************************** Spherical Harmonics **************************/ + +MINLINE void zero_sh(float r[9]) +{ + memset(r, 0, sizeof(float)*9); +} + +MINLINE void copy_sh_sh(float r[9], float a[9]) +{ + memcpy(r, a, sizeof(float)*9); +} + +MINLINE void mul_sh_fl(float r[9], float f) +{ + int i; + + for(i=0; i<9; i++) + r[i] *= f; +} + +MINLINE void add_sh_shsh(float r[9], float a[9], float b[9]) +{ + int i; + + for(i=0; i<9; i++) + r[i]= a[i] + b[i]; +} + +MINLINE float dot_shsh(float a[9], float b[9]) +{ + float r= 0.0f; + int i; + + for(i=0; i<9; i++) + r += a[i]*b[i]; + + return r; +} + +MINLINE float diffuse_shv3(float sh[9], float v[3]) +{ + /* See formula (13) in: + "An Efficient Representation for Irradiance Environment Maps" */ + static const float c1 = 0.429043f, c2 = 0.511664f, c3 = 0.743125f; + static const float c4 = 0.886227f, c5 = 0.247708f; + float x, y, z, sum; + + x= v[0]; + y= v[1]; + z= v[2]; + + sum= c1*sh[8]*(x*x - y*y); + sum += c3*sh[6]*z*z; + sum += c4*sh[0]; + sum += -c5*sh[6]; + sum += 2.0f*c1*(sh[4]*x*y + sh[7]*x*z + sh[5]*y*z); + sum += 2.0f*c2*(sh[3]*x + sh[1]*y + sh[2]*z); + + return sum; +} + +MINLINE void vec_fac_to_sh(float r[9], float v[3], float f) +{ + /* See formula (3) in: + "An Efficient Representation for Irradiance Environment Maps" */ + float sh[9], x, y, z; + + x= v[0]; + y= v[1]; + z= v[2]; + + sh[0]= 0.282095f; + + sh[1]= 0.488603f*y; + sh[2]= 0.488603f*z; + sh[3]= 0.488603f*x; + + sh[4]= 1.092548f*x*y; + sh[5]= 1.092548f*y*z; + sh[6]= 0.315392f*(3.0f*z*z - 1.0f); + sh[7]= 1.092548f*x*z; + sh[8]= 0.546274f*(x*x - y*y); + + mul_sh_fl(sh, f); + copy_sh_sh(r, sh); +} + +MINLINE float eval_shv3(float sh[9], float v[3]) +{ + float tmp[9]; + + vec_fac_to_sh(tmp, v, 1.0f); + return dot_shsh(tmp, sh); +} + +MINLINE void madd_sh_shfl(float r[9], float sh[3], float f) +{ + float tmp[9]; + + copy_sh_sh(tmp, sh); + mul_sh_fl(tmp, f); + add_sh_shsh(r, r, tmp); +} + +#endif /* BLI_MATH_GEOM_INLINE */ + |