diff options
Diffstat (limited to 'source/blender/blenkernel/intern/ocean.c')
-rw-r--r-- | source/blender/blenkernel/intern/ocean.c | 66 |
1 files changed, 34 insertions, 32 deletions
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); } } } |