diff options
author | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-11-13 16:17:27 +0400 |
---|---|---|
committer | Lukas Toenne <lukas.toenne@googlemail.com> | 2011-11-13 16:17:27 +0400 |
commit | 11c83d843206648a33bcc8b4d754577ec0a51d2a (patch) | |
tree | 58af33c372ba5d77f68d6ed7b37e5aecd6e6c678 /source/blender/render | |
parent | b1019a56b54294fc91293c5c43ef46d54950ae84 (diff) |
Ocean Sim modifier patch
by Matt Ebb, Hamed Zaghaghi
This adds a new Modifier "Ocean" to simulate large-scale wave motion.
Details can be found in the wiki documentation [1], the project homepage [2] and the patch tracker [3]
The modifier is disabled by default for now. To enable it, the WITH_OCEANSIM (cmake) / WITH_BF_OCEANSIM (scons) flags have to be set. The code depends on fftw3, so this also has to be enabled.
[1]
http://wiki.blender.org/index.php/Doc:2.6/Manual/Modifiers/Simulation/Ocean
[2]
http://www.savetheoceansim.com
[3]
http://projects.blender.org/tracker/?group_id=9&atid=127&func=detail&aid=28338
Diffstat (limited to 'source/blender/render')
-rw-r--r-- | source/blender/render/CMakeLists.txt | 2 | ||||
-rw-r--r-- | source/blender/render/intern/include/texture_ocean.h | 28 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_texture.c | 11 | ||||
-rw-r--r-- | source/blender/render/intern/source/texture_ocean.c | 162 |
4 files changed, 202 insertions, 1 deletions
diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt index 763cd3780fb..c7b27c3cd7e 100644 --- a/source/blender/render/CMakeLists.txt +++ b/source/blender/render/CMakeLists.txt @@ -74,6 +74,7 @@ set(SRC intern/source/sss.c intern/source/strand.c intern/source/sunsky.c + intern/source/texture_ocean.c intern/source/volume_precache.c intern/source/volumetric.c intern/source/voxeldata.c @@ -104,6 +105,7 @@ set(SRC intern/include/strand.h intern/include/sunsky.h intern/include/texture.h + intern/include/texture_ocean.h intern/include/volume_precache.h intern/include/volumetric.h intern/include/voxeldata.h diff --git a/source/blender/render/intern/include/texture_ocean.h b/source/blender/render/intern/include/texture_ocean.h new file mode 100644 index 00000000000..b0a0647d115 --- /dev/null +++ b/source/blender/render/intern/include/texture_ocean.h @@ -0,0 +1,28 @@ +/* + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * Contributors: Matt Ebb + * + * ***** END GPL LICENSE BLOCK ***** + */ + +void prepare_ocean_tex_modifier(struct OceanTex *ot); + +int ocean_texture(struct Tex *tex, float *texvec, struct TexResult *texres); diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index afc52f7c92a..bd323a5b2d3 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -79,6 +79,7 @@ #include "rendercore.h" #include "shading.h" #include "texture.h" +#include "texture_ocean.h" #include "renderdatabase.h" /* needed for UV */ @@ -1264,7 +1265,9 @@ static int multitex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, case TEX_VOXELDATA: retval= voxeldatatex(tex, texvec, texres); break; - + case TEX_OCEAN: + retval= ocean_texture(tex, texvec, texres); + break; } if (tex->flag & TEX_COLORBAND) { @@ -2193,6 +2196,12 @@ void do_material_tex(ShadeInput *shi, Render *re) use_ntap_bump = 0; use_compat_bump = 1; } + + /* case ocean */ + if(tex->type == TEX_OCEAN) { + use_ntap_bump = 0; + use_compat_bump = 0; + } /* which coords */ if(mtex->texco==TEXCO_ORCO) { diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c new file mode 100644 index 00000000000..c9d84b23e33 --- /dev/null +++ b/source/blender/render/intern/source/texture_ocean.c @@ -0,0 +1,162 @@ +/* + * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * Contributors: Matt Ebb + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include <stddef.h> + +#include "BLI_math.h" +#include "BLI_utildefines.h" + +#include "DNA_modifier_types.h" +#include "DNA_object_types.h" +#include "DNA_texture_types.h" + +#include "BKE_global.h" /* XXX */ + +#include "BKE_modifier.h" +#include "BKE_ocean.h" +#include "BKE_utildefines.h" + +#include "render_types.h" +#include "RE_shader_ext.h" + +#include "texture.h" + + +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ +/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */ +/* only to be used here in this file, it's for speed */ +extern struct Render R; +/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + + + + +/* ***** actual texture sampling ***** */ +int ocean_texture(Tex *tex, float *texvec, TexResult *texres) +{ + int retval = TEX_INT; + OceanTex *ot= tex->ot; + OceanResult or; + const float u = 0.5+0.5*texvec[0]; + const float v = 0.5+0.5*texvec[1]; + float foam; + int cfra = R.r.cfra; + int normals=0; + ModifierData *md; + + texres->tin = 0.0f; + + if (!ot || !ot->object || !ot->object->modifiers.first) + return 0; + + if ((md = (ModifierData *)modifiers_findByType(ot->object, eModifierType_Ocean))) { + OceanModifierData *omd = (OceanModifierData *)md; + + if (!omd->ocean) + return 0; + + normals = (omd->flag & MOD_OCEAN_GENERATE_NORMALS); + + if (omd->oceancache && omd->cached==TRUE) { + + CLAMP(cfra, omd->bakestart, omd->bakeend); + cfra -= omd->bakestart; // shift to 0 based + + BKE_ocean_cache_eval_uv(omd->oceancache, &or, cfra, u, v); + + } else { // non-cached + + if (G.rendering) + BKE_ocean_eval_uv_catrom(omd->ocean, &or, u, v); + else + BKE_ocean_eval_uv(omd->ocean, &or, u, v); + + or.foam = BKE_ocean_jminus_to_foam(or.Jminus, omd->foam_coverage); + } + } + + + switch (ot->output) { + case TEX_OCN_DISPLACEMENT: + /* XYZ displacement */ + texres->tr = 0.5 + 0.5 * or.disp[0]; + texres->tg = 0.5 + 0.5 * or.disp[2]; + texres->tb = 0.5 + 0.5 * or.disp[1]; + + texres->tr = MAX2(0.0, texres->tr); + texres->tg = MAX2(0.0, texres->tg); + texres->tb = MAX2(0.0, texres->tb); + + BRICONTRGB; + + retval = TEX_RGB; + break; + + case TEX_OCN_EMINUS: + /* -ve eigenvectors ? */ + texres->tr = or.Eminus[0]; + texres->tg = or.Eminus[2]; + texres->tb = or.Eminus[1]; + retval = TEX_RGB; + break; + + case TEX_OCN_EPLUS: + /* -ve eigenvectors ? */ + texres->tr = or.Eplus[0]; + texres->tg = or.Eplus[2]; + texres->tb = or.Eplus[1]; + retval = TEX_RGB; + break; + + case TEX_OCN_JPLUS: + texres->tin = or.Jplus; + retval = TEX_INT; + case TEX_OCN_FOAM: + + texres->tin = or.foam; + + BRICONT; + + retval = TEX_INT; + break; + } + + /* if normals needed */ + + if (texres->nor && normals) { + + texres->nor[0] = or.normal[0]; + texres->nor[1] = or.normal[2]; + texres->nor[2] = or.normal[1]; + + normalize_v3(texres->nor); + retval |= TEX_NOR; + } + + texres->ta = 1.0; + + return retval; +} + |