Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-11-22 22:03:33 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-11-22 22:03:33 +0400
commitb78701f6fe1daa33c38a7b72563565c09677f325 (patch)
treecbc66cc2cac620e73754ec08eef2adb2ff8be96f
parentb450d3c3b6585cefe52d007c0088c4dc7b2e78ec (diff)
ocean sim
- UV's were not being calculated if there were too many VColor layers. - precalc (omd->size * omd->spatial_size) was being called in a loop. - use vector functions to avoid pointer indrections on each access which the compiler wont optimize - eg: och->ibufs_disp[f]->rect_float[4*(res_x*j + i) + 1] - dont call abs() on ints (converts to double and back to int in this case). also unrelated render buttons change. move saving options directly under the file path since these were easy to confuse with image format options like zbuf, ycc, preview.. etc.
-rw-r--r--release/scripts/startup/bl_ui/properties_render.py3
-rw-r--r--source/blender/blenkernel/intern/ocean.c66
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c118
3 files changed, 94 insertions, 93 deletions
diff --git a/release/scripts/startup/bl_ui/properties_render.py b/release/scripts/startup/bl_ui/properties_render.py
index 2d731164713..57df602f19a 100644
--- a/release/scripts/startup/bl_ui/properties_render.py
+++ b/release/scripts/startup/bl_ui/properties_render.py
@@ -456,13 +456,14 @@ class RENDER_PT_output(RenderButtonsPanel, Panel):
file_format = rd.image_settings.file_format
layout.prop(rd, "filepath", text="")
- layout.template_image_settings(rd.image_settings)
flow = layout.column_flow()
flow.prop(rd, "use_overwrite")
flow.prop(rd, "use_placeholder")
flow.prop(rd, "use_file_extension")
+ layout.template_image_settings(rd.image_settings)
+
if file_format == 'QUICKTIME_CARBON':
layout.operator("scene.render_data_set_quicktime_codec")
diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c
index 52e4406017b..ae622358fd2 100644
--- a/source/blender/blenkernel/intern/ocean.c
+++ b/source/blender/blenkernel/intern/ocean.c
@@ -313,8 +313,8 @@ void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u,float
float uu,vv;
// first wrap the texture so 0 <= (u,v) < 1
- u = fmod(u,1.0f);
- v = fmod(v,1.0f);
+ u = fmodf(u,1.0f);
+ v = fmodf(v,1.0f);
if (u < 0) u += 1.0f;
if (v < 0) v += 1.0f;
@@ -1021,6 +1021,22 @@ static void cache_filename(char *string, const char *path, const char *relbase,
BKE_makepicstring(string, cachepath, relbase, frame, R_IMF_IMTYPE_OPENEXR, 1, TRUE);
}
+/* silly functions but useful to inline when the args do a lot of indirections */
+MINLINE void rgb_to_rgba_unit_alpha(float r_rgba[4], const float rgb[3])
+{
+ r_rgba[0]= rgb[0];
+ r_rgba[1]= rgb[1];
+ r_rgba[2]= rgb[2];
+ r_rgba[3]= 1.0f;
+}
+MINLINE void value_to_rgba_unit_alpha(float r_rgba[4], const float value)
+{
+ r_rgba[0]= value;
+ r_rgba[1]= value;
+ r_rgba[2]= value;
+ r_rgba[3]= 1.0f;
+}
+
void BKE_free_ocean_cache(struct OceanCache *och)
{
int i, f=0;
@@ -1076,9 +1092,7 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, in
if (och->ibufs_disp[f]) {
ibuf_sample(och->ibufs_disp[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
- ocr->disp[0] = result[0];
- ocr->disp[1] = result[1];
- ocr->disp[2] = result[2];
+ copy_v3_v3(ocr->disp, result);
}
if (och->ibufs_foam[f]) {
@@ -1088,34 +1102,31 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, in
if (och->ibufs_norm[f]) {
ibuf_sample(och->ibufs_norm[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
- ocr->normal[0] = result[0];
- ocr->normal[1] = result[1];
- ocr->normal[2] = result[2];
+ copy_v3_v3(ocr->normal, result);
}
}
void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, int f, int i, int j)
{
- int res_x = och->resolution_x;
- int res_y = och->resolution_y;
+ const int res_x = och->resolution_x;
+ const int res_y = och->resolution_y;
+
+ if (i < 0) i= -i;
+ if (j < 0) j= -j;
- i = abs(i) % res_x;
- j = abs(j) % res_y;
+ i = i % res_x;
+ j = j % res_y;
if (och->ibufs_disp[f]) {
- ocr->disp[0] = och->ibufs_disp[f]->rect_float[4*(res_x*j + i) + 0];
- ocr->disp[1] = och->ibufs_disp[f]->rect_float[4*(res_x*j + i) + 1];
- ocr->disp[2] = och->ibufs_disp[f]->rect_float[4*(res_x*j + i) + 2];
+ copy_v3_v3(ocr->disp, &och->ibufs_disp[f]->rect_float[4*(res_x*j + i)]);
}
if (och->ibufs_foam[f]) {
- ocr->foam = och->ibufs_foam[f]->rect_float[4*(res_x*j + i) + 0];
+ ocr->foam = och->ibufs_foam[f]->rect_float[4*(res_x*j + i)];
}
if (och->ibufs_norm[f]) {
- ocr->normal[0] = och->ibufs_norm[f]->rect_float[4*(res_x*j + i) + 0];
- ocr->normal[1] = och->ibufs_norm[f]->rect_float[4*(res_x*j + i) + 1];
- ocr->normal[2] = och->ibufs_norm[f]->rect_float[4*(res_x*j + i) + 2];
+ copy_v3_v3(ocr->normal, &och->ibufs_norm[f]->rect_float[4*(res_x*j + i)]);
}
}
@@ -1206,7 +1217,7 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
/* setup image format */
imf.imtype= R_IMF_IMTYPE_OPENEXR;
imf.depth= R_IMF_CHAN_DEPTH_16;
- imf.exr_codec= R_IMF_EXR_CODEC_ZIP; /* ZIP */
+ imf.exr_codec= R_IMF_EXR_CODEC_ZIP;
for (f=och->start, i=0; f<=och->end; f++, i++) {
@@ -1226,10 +1237,7 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
BKE_ocean_eval_ij(o, &ocr, x, y);
/* add to the image */
- ibuf_disp->rect_float[4*(res_x*y + x) + 0] = ocr.disp[0];
- ibuf_disp->rect_float[4*(res_x*y + x) + 1] = ocr.disp[1];
- ibuf_disp->rect_float[4*(res_x*y + x) + 2] = ocr.disp[2];
- ibuf_disp->rect_float[4*(res_x*y + x) + 3] = 1.0f;
+ rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4*(res_x*y + x)], ocr.disp);
if (o->_do_jacobian) {
/* TODO, cleanup unused code - campbell */
@@ -1282,17 +1290,11 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
prev_foam[res_x*y + x] = foam_result;
- ibuf_foam->rect_float[4*(res_x*y + x) + 0] = foam_result;
- ibuf_foam->rect_float[4*(res_x*y + x) + 1] = foam_result;
- ibuf_foam->rect_float[4*(res_x*y + x) + 2] = foam_result;
- ibuf_foam->rect_float[4*(res_x*y + x) + 3] = 1.0;
+ value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4*(res_x*y + x)], foam_result);
}
if (o->_do_normals) {
- ibuf_normal->rect_float[4*(res_x*y + x) + 0] = ocr.normal[0];
- ibuf_normal->rect_float[4*(res_x*y + x) + 1] = ocr.normal[1];
- ibuf_normal->rect_float[4*(res_x*y + x) + 2] = ocr.normal[2];
- ibuf_normal->rect_float[4*(res_x*y + x) + 3] = 1.0;
+ rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4*(res_x*y + x)], ocr.normal);
}
}
}
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index 434b9e00f0e..81366fba501 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -78,10 +78,10 @@ static void init_ocean_modifier(struct OceanModifierData *omd)
BKE_free_ocean_data(omd->ocean);
BKE_init_ocean(omd->ocean, omd->resolution*omd->resolution, omd->resolution*omd->resolution, omd->spatial_size, omd->spatial_size,
- omd->wind_velocity, omd->smallest_wave, 1.0, omd->wave_direction, omd->damp, omd->wave_alignment,
- omd->depth, omd->time,
- do_heightfield, do_chop, do_normals, do_jacobian,
- omd->seed);
+ omd->wind_velocity, omd->smallest_wave, 1.0, omd->wave_direction, omd->damp, omd->wave_alignment,
+ omd->depth, omd->time,
+ do_heightfield, do_chop, do_normals, do_jacobian,
+ omd->seed);
}
static void simulate_ocean_modifier(struct OceanModifierData *omd)
@@ -90,7 +90,7 @@ static void simulate_ocean_modifier(struct OceanModifierData *omd)
BKE_simulate_ocean(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount);
}
-#endif // WITH_OCEANSIM
+#endif /* WITH_OCEANSIM */
@@ -261,13 +261,7 @@ static void dm_get_bounds(DerivedMesh *dm, float *sx, float *sy, float *ox, floa
#endif
#ifdef WITH_OCEANSIM
-MINLINE float ocean_co(OceanModifierData *omd, float v)
-{
- //float scale = 1.0 / (omd->size * omd->spatial_size);
- //*v = (*v * scale) + 0.5;
- return (v / (omd->size * omd->spatial_size)) + 0.5f;
-}
#define OMP_MIN_RES 18
static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
@@ -378,10 +372,7 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
DerivedMesh *dm=NULL;
OceanResult ocr;
- MVert *mv;
- MFace *mf;
-
- int cdlayer;
+ MVert *mverts, *mv;
int i, j;
@@ -390,6 +381,14 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
int cfra;
+ /* use cached & inverted value for speed
+ * expanded this would read...
+ *
+ * (axis / (omd->size * omd->spatial_size)) + 0.5f) */
+#define OCEAN_CO(_size_co_inv, _v) ((_v * _size_co_inv) + 0.5f)
+
+ const float size_co_inv= 1.0f / (omd->size * omd->spatial_size);
+
/* update modifier */
if (omd->refresh & MOD_OCEAN_REFRESH_ADD)
omd->ocean = BKE_add_ocean();
@@ -422,72 +421,71 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
num_verts = dm->getNumVerts(dm);
num_faces = dm->getNumFaces(dm);
+ mverts = dm->getVertArray(dm);
+
/* add vcols before displacement - allows lookup based on position */
if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
- MCol *mc;
- float foam;
- char cf;
-
- float u=0.0, v=0.0;
-
- cdlayer= CustomData_number_of_layers(&dm->faceData, CD_MCOL);
- if(cdlayer >= MAX_MCOL)
- return dm;
-
- CustomData_add_layer_named(&dm->faceData, CD_MCOL, CD_CALLOC, NULL, num_faces, omd->foamlayername);
-
- mc = dm->getFaceDataArray(dm, CD_MCOL);
- mv = dm->getVertArray(dm);
- mf = dm->getFaceArray(dm);
-
- for (i = 0; i < num_faces; i++, mf++) {
- j= mf->v4 ? 3 : 2;
- do {
- const float *co= mv[*(&mf->v1 + j)].co;
- u = ocean_co(omd, co[0]);
- v = ocean_co(omd, co[1]);
-
- if (omd->oceancache && omd->cached==TRUE) {
- BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
- foam = ocr.foam;
- CLAMP(foam, 0.0f, 1.0f);
- }
- else {
- BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
- foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
- }
-
- cf = (char)(foam * 255);
- mc[i*4 + j].r = mc[i*4 + j].g = mc[i*4 + j].b = cf;
- mc[i*4 + j].a = 255;
- } while (j--);
+ int cdlayer= CustomData_number_of_layers(&dm->faceData, CD_MCOL);
+
+ if(cdlayer < MAX_MCOL) {
+ MFace *mfaces= dm->getFaceArray(dm);
+ MFace *mf;
+
+ MCol *mcols, *mc;
+ float foam;
+
+ CustomData_add_layer_named(&dm->faceData, CD_MCOL, CD_CALLOC, NULL, num_faces, omd->foamlayername);
+
+ mcols = dm->getFaceDataArray(dm, CD_MCOL);
+
+ for (i = 0, mf= mfaces; i < num_faces; i++, mf++) {
+ j= mf->v4 ? 3 : 2;
+ do {
+ const float *co= mverts[*(&mf->v1 + j)].co;
+ const float u = OCEAN_CO(size_co_inv, co[0]);
+ const float v = OCEAN_CO(size_co_inv, co[1]);
+
+ if (omd->oceancache && omd->cached==TRUE) {
+ BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
+ foam = ocr.foam;
+ CLAMP(foam, 0.0f, 1.0f);
+ }
+ else {
+ BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
+ foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
+ }
+
+ mc= &mcols[i*4 + j];
+ mc->r = mc->g = mc->b = (char)(foam * 255);
+ /* mc->a = 255; */ /* no need to set */
+ } while (j--);
+ }
}
}
/* displace the geometry */
- mv = dm->getVertArray(dm);
-
//#pragma omp parallel for private(i, ocr) if (omd->resolution > OMP_MIN_RES)
- for (i=0; i< num_verts; i++) {
- const float u = ocean_co(omd, mv[i].co[0]);
- const float v = ocean_co(omd, mv[i].co[1]);
+ for (i=0, mv= mverts; i< num_verts; i++, mv++) {
+ const float u = OCEAN_CO(size_co_inv, mv->co[0]);
+ const float v = OCEAN_CO(size_co_inv, mv->co[1]);
if (omd->oceancache && omd->cached==TRUE)
BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
else
BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
- mv[i].co[2] += ocr.disp[1];
+ mv->co[2] += ocr.disp[1];
if (omd->chop_amount > 0.0f) {
- mv[i].co[0] += ocr.disp[0];
- mv[i].co[1] += ocr.disp[2];
+ mv->co[0] += ocr.disp[0];
+ mv->co[1] += ocr.disp[2];
}
}
+ #undef OCEAN_CO
return dm;
}