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.
This commit is contained in:
@@ -456,13 +456,14 @@ class RENDER_PT_output(RenderButtonsPanel, Panel):
|
|||||||
file_format = rd.image_settings.file_format
|
file_format = rd.image_settings.file_format
|
||||||
|
|
||||||
layout.prop(rd, "filepath", text="")
|
layout.prop(rd, "filepath", text="")
|
||||||
layout.template_image_settings(rd.image_settings)
|
|
||||||
|
|
||||||
flow = layout.column_flow()
|
flow = layout.column_flow()
|
||||||
flow.prop(rd, "use_overwrite")
|
flow.prop(rd, "use_overwrite")
|
||||||
flow.prop(rd, "use_placeholder")
|
flow.prop(rd, "use_placeholder")
|
||||||
flow.prop(rd, "use_file_extension")
|
flow.prop(rd, "use_file_extension")
|
||||||
|
|
||||||
|
layout.template_image_settings(rd.image_settings)
|
||||||
|
|
||||||
if file_format == 'QUICKTIME_CARBON':
|
if file_format == 'QUICKTIME_CARBON':
|
||||||
layout.operator("scene.render_data_set_quicktime_codec")
|
layout.operator("scene.render_data_set_quicktime_codec")
|
||||||
|
|
||||||
|
@@ -313,8 +313,8 @@ void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u,float
|
|||||||
float uu,vv;
|
float uu,vv;
|
||||||
|
|
||||||
// first wrap the texture so 0 <= (u,v) < 1
|
// first wrap the texture so 0 <= (u,v) < 1
|
||||||
u = fmod(u,1.0f);
|
u = fmodf(u,1.0f);
|
||||||
v = fmod(v,1.0f);
|
v = fmodf(v,1.0f);
|
||||||
|
|
||||||
if (u < 0) u += 1.0f;
|
if (u < 0) u += 1.0f;
|
||||||
if (v < 0) v += 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);
|
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)
|
void BKE_free_ocean_cache(struct OceanCache *och)
|
||||||
{
|
{
|
||||||
int i, f=0;
|
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]) {
|
if (och->ibufs_disp[f]) {
|
||||||
ibuf_sample(och->ibufs_disp[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
|
ibuf_sample(och->ibufs_disp[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
|
||||||
ocr->disp[0] = result[0];
|
copy_v3_v3(ocr->disp, result);
|
||||||
ocr->disp[1] = result[1];
|
|
||||||
ocr->disp[2] = result[2];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (och->ibufs_foam[f]) {
|
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]) {
|
if (och->ibufs_norm[f]) {
|
||||||
ibuf_sample(och->ibufs_norm[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
|
ibuf_sample(och->ibufs_norm[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
|
||||||
ocr->normal[0] = result[0];
|
copy_v3_v3(ocr->normal, result);
|
||||||
ocr->normal[1] = result[1];
|
|
||||||
ocr->normal[2] = result[2];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, int f, int i, int j)
|
void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, int f, int i, int j)
|
||||||
{
|
{
|
||||||
int res_x = och->resolution_x;
|
const int res_x = och->resolution_x;
|
||||||
int res_y = och->resolution_y;
|
const int res_y = och->resolution_y;
|
||||||
|
|
||||||
i = abs(i) % res_x;
|
if (i < 0) i= -i;
|
||||||
j = abs(j) % res_y;
|
if (j < 0) j= -j;
|
||||||
|
|
||||||
|
i = i % res_x;
|
||||||
|
j = j % res_y;
|
||||||
|
|
||||||
if (och->ibufs_disp[f]) {
|
if (och->ibufs_disp[f]) {
|
||||||
ocr->disp[0] = och->ibufs_disp[f]->rect_float[4*(res_x*j + i) + 0];
|
copy_v3_v3(ocr->disp, &och->ibufs_disp[f]->rect_float[4*(res_x*j + i)]);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (och->ibufs_foam[f]) {
|
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]) {
|
if (och->ibufs_norm[f]) {
|
||||||
ocr->normal[0] = och->ibufs_norm[f]->rect_float[4*(res_x*j + i) + 0];
|
copy_v3_v3(ocr->normal, &och->ibufs_norm[f]->rect_float[4*(res_x*j + i)]);
|
||||||
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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1206,7 +1217,7 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
|
|||||||
/* setup image format */
|
/* setup image format */
|
||||||
imf.imtype= R_IMF_IMTYPE_OPENEXR;
|
imf.imtype= R_IMF_IMTYPE_OPENEXR;
|
||||||
imf.depth= R_IMF_CHAN_DEPTH_16;
|
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++) {
|
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);
|
BKE_ocean_eval_ij(o, &ocr, x, y);
|
||||||
|
|
||||||
/* add to the image */
|
/* add to the image */
|
||||||
ibuf_disp->rect_float[4*(res_x*y + x) + 0] = ocr.disp[0];
|
rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4*(res_x*y + x)], ocr.disp);
|
||||||
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;
|
|
||||||
|
|
||||||
if (o->_do_jacobian) {
|
if (o->_do_jacobian) {
|
||||||
/* TODO, cleanup unused code - campbell */
|
/* 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;
|
prev_foam[res_x*y + x] = foam_result;
|
||||||
|
|
||||||
ibuf_foam->rect_float[4*(res_x*y + x) + 0] = foam_result;
|
value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4*(res_x*y + x)], 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o->_do_normals) {
|
if (o->_do_normals) {
|
||||||
ibuf_normal->rect_float[4*(res_x*y + x) + 0] = ocr.normal[0];
|
rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4*(res_x*y + x)], ocr.normal);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -78,10 +78,10 @@ static void init_ocean_modifier(struct OceanModifierData *omd)
|
|||||||
|
|
||||||
BKE_free_ocean_data(omd->ocean);
|
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,
|
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->wind_velocity, omd->smallest_wave, 1.0, omd->wave_direction, omd->damp, omd->wave_alignment,
|
||||||
omd->depth, omd->time,
|
omd->depth, omd->time,
|
||||||
do_heightfield, do_chop, do_normals, do_jacobian,
|
do_heightfield, do_chop, do_normals, do_jacobian,
|
||||||
omd->seed);
|
omd->seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void simulate_ocean_modifier(struct OceanModifierData *omd)
|
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);
|
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
|
#endif
|
||||||
|
|
||||||
#ifdef WITH_OCEANSIM
|
#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
|
#define OMP_MIN_RES 18
|
||||||
static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
|
static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
|
||||||
@@ -378,10 +372,7 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
|
|||||||
DerivedMesh *dm=NULL;
|
DerivedMesh *dm=NULL;
|
||||||
OceanResult ocr;
|
OceanResult ocr;
|
||||||
|
|
||||||
MVert *mv;
|
MVert *mverts, *mv;
|
||||||
MFace *mf;
|
|
||||||
|
|
||||||
int cdlayer;
|
|
||||||
|
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@@ -390,6 +381,14 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
|
|||||||
|
|
||||||
int cfra;
|
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 */
|
/* update modifier */
|
||||||
if (omd->refresh & MOD_OCEAN_REFRESH_ADD)
|
if (omd->refresh & MOD_OCEAN_REFRESH_ADD)
|
||||||
omd->ocean = BKE_add_ocean();
|
omd->ocean = BKE_add_ocean();
|
||||||
@@ -422,72 +421,71 @@ static DerivedMesh *doOcean(ModifierData *md, Object *ob,
|
|||||||
num_verts = dm->getNumVerts(dm);
|
num_verts = dm->getNumVerts(dm);
|
||||||
num_faces = dm->getNumFaces(dm);
|
num_faces = dm->getNumFaces(dm);
|
||||||
|
|
||||||
|
mverts = dm->getVertArray(dm);
|
||||||
|
|
||||||
/* add vcols before displacement - allows lookup based on position */
|
/* add vcols before displacement - allows lookup based on position */
|
||||||
|
|
||||||
if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
|
if (omd->flag & MOD_OCEAN_GENERATE_FOAM) {
|
||||||
MCol *mc;
|
int cdlayer= CustomData_number_of_layers(&dm->faceData, CD_MCOL);
|
||||||
float foam;
|
|
||||||
char cf;
|
|
||||||
|
|
||||||
float u=0.0, v=0.0;
|
if(cdlayer < MAX_MCOL) {
|
||||||
|
MFace *mfaces= dm->getFaceArray(dm);
|
||||||
|
MFace *mf;
|
||||||
|
|
||||||
cdlayer= CustomData_number_of_layers(&dm->faceData, CD_MCOL);
|
MCol *mcols, *mc;
|
||||||
if(cdlayer >= MAX_MCOL)
|
float foam;
|
||||||
return dm;
|
|
||||||
|
|
||||||
CustomData_add_layer_named(&dm->faceData, CD_MCOL, CD_CALLOC, NULL, num_faces, omd->foamlayername);
|
CustomData_add_layer_named(&dm->faceData, CD_MCOL, CD_CALLOC, NULL, num_faces, omd->foamlayername);
|
||||||
|
|
||||||
mc = dm->getFaceDataArray(dm, CD_MCOL);
|
mcols = dm->getFaceDataArray(dm, CD_MCOL);
|
||||||
mv = dm->getVertArray(dm);
|
|
||||||
mf = dm->getFaceArray(dm);
|
|
||||||
|
|
||||||
for (i = 0; i < num_faces; i++, mf++) {
|
for (i = 0, mf= mfaces; i < num_faces; i++, mf++) {
|
||||||
j= mf->v4 ? 3 : 2;
|
j= mf->v4 ? 3 : 2;
|
||||||
do {
|
do {
|
||||||
const float *co= mv[*(&mf->v1 + j)].co;
|
const float *co= mverts[*(&mf->v1 + j)].co;
|
||||||
u = ocean_co(omd, co[0]);
|
const float u = OCEAN_CO(size_co_inv, co[0]);
|
||||||
v = ocean_co(omd, co[1]);
|
const float v = OCEAN_CO(size_co_inv, co[1]);
|
||||||
|
|
||||||
if (omd->oceancache && omd->cached==TRUE) {
|
if (omd->oceancache && omd->cached==TRUE) {
|
||||||
BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
|
BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
|
||||||
foam = ocr.foam;
|
foam = ocr.foam;
|
||||||
CLAMP(foam, 0.0f, 1.0f);
|
CLAMP(foam, 0.0f, 1.0f);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
|
BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
|
||||||
foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
|
foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
|
||||||
}
|
}
|
||||||
|
|
||||||
cf = (char)(foam * 255);
|
mc= &mcols[i*4 + j];
|
||||||
mc[i*4 + j].r = mc[i*4 + j].g = mc[i*4 + j].b = cf;
|
mc->r = mc->g = mc->b = (char)(foam * 255);
|
||||||
mc[i*4 + j].a = 255;
|
/* mc->a = 255; */ /* no need to set */
|
||||||
} while (j--);
|
} while (j--);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* displace the geometry */
|
/* displace the geometry */
|
||||||
|
|
||||||
mv = dm->getVertArray(dm);
|
|
||||||
|
|
||||||
//#pragma omp parallel for private(i, ocr) if (omd->resolution > OMP_MIN_RES)
|
//#pragma omp parallel for private(i, ocr) if (omd->resolution > OMP_MIN_RES)
|
||||||
for (i=0; i< num_verts; i++) {
|
for (i=0, mv= mverts; i< num_verts; i++, mv++) {
|
||||||
const float u = ocean_co(omd, mv[i].co[0]);
|
const float u = OCEAN_CO(size_co_inv, mv->co[0]);
|
||||||
const float v = ocean_co(omd, mv[i].co[1]);
|
const float v = OCEAN_CO(size_co_inv, mv->co[1]);
|
||||||
|
|
||||||
if (omd->oceancache && omd->cached==TRUE)
|
if (omd->oceancache && omd->cached==TRUE)
|
||||||
BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
|
BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
|
||||||
else
|
else
|
||||||
BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
|
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) {
|
if (omd->chop_amount > 0.0f) {
|
||||||
mv[i].co[0] += ocr.disp[0];
|
mv->co[0] += ocr.disp[0];
|
||||||
mv[i].co[1] += ocr.disp[2];
|
mv->co[1] += ocr.disp[2];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#undef OCEAN_CO
|
||||||
|
|
||||||
return dm;
|
return dm;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user