98
94
/* ********* sim data arrays ********* */
100
96
/* two dimensional arrays of complex */
101
fftw_complex *_fft_in; // init w sim w
102
fftw_complex *_fft_in_x; // init w sim w
103
fftw_complex *_fft_in_z; // init w sim w
104
fftw_complex *_fft_in_jxx; // init w sim w
105
fftw_complex *_fft_in_jzz; // init w sim w
106
fftw_complex *_fft_in_jxz; // init w sim w
107
fftw_complex *_fft_in_nx; // init w sim w
108
fftw_complex *_fft_in_nz; // init w sim w
109
fftw_complex *_htilda; // init w sim w (only once)
97
fftw_complex *_fft_in; /* init w sim w */
98
fftw_complex *_fft_in_x; /* init w sim w */
99
fftw_complex *_fft_in_z; /* init w sim w */
100
fftw_complex *_fft_in_jxx; /* init w sim w */
101
fftw_complex *_fft_in_jzz; /* init w sim w */
102
fftw_complex *_fft_in_jxz; /* init w sim w */
103
fftw_complex *_fft_in_nx; /* init w sim w */
104
fftw_complex *_fft_in_nz; /* init w sim w */
105
fftw_complex *_htilda; /* init w sim w (only once) */
111
107
/* fftw "plans" */
112
fftw_plan _disp_y_plan; // init w sim r
113
fftw_plan _disp_x_plan; // init w sim r
114
fftw_plan _disp_z_plan; // init w sim r
115
fftw_plan _N_x_plan; // init w sim r
116
fftw_plan _N_z_plan; // init w sim r
117
fftw_plan _Jxx_plan; // init w sim r
118
fftw_plan _Jxz_plan; // init w sim r
119
fftw_plan _Jzz_plan; // init w sim r
108
fftw_plan _disp_y_plan; /* init w sim r */
109
fftw_plan _disp_x_plan; /* init w sim r */
110
fftw_plan _disp_z_plan; /* init w sim r */
111
fftw_plan _N_x_plan; /* init w sim r */
112
fftw_plan _N_z_plan; /* init w sim r */
113
fftw_plan _Jxx_plan; /* init w sim r */
114
fftw_plan _Jxz_plan; /* init w sim r */
115
fftw_plan _Jzz_plan; /* init w sim r */
121
117
/* two dimensional arrays of float */
122
double * _disp_y; // init w sim w via plan?
123
double * _N_x; // init w sim w via plan?
124
/*float * _N_y; all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/
125
double _N_y; // sim w ********* can be rearranged?
126
double * _N_z; // init w sim w via plan?
127
double * _disp_x; // init w sim w via plan?
128
double * _disp_z; // init w sim w via plan?
118
double *_disp_y; /* init w sim w via plan? */
119
double *_N_x; /* init w sim w via plan? */
120
/* all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/
122
double _N_y; /* sim w ********* can be rearranged? */
123
double *_N_z; /* init w sim w via plan? */
124
double *_disp_x; /* init w sim w via plan? */
125
double *_disp_z; /* init w sim w via plan? */
130
127
/* two dimensional arrays of float */
131
128
/* Jacobian and minimum eigenvalue */
132
double * _Jxx; // init w sim w
133
double * _Jzz; // init w sim w
134
double * _Jxz; // init w sim w
129
double *_Jxx; /* init w sim w */
130
double *_Jzz; /* init w sim w */
131
double *_Jxz; /* init w sim w */
136
133
/* one dimensional float array */
137
float * _kx; // init w sim r
138
float * _kz; // init w sim r
134
float *_kx; /* init w sim r */
135
float *_kz; /* init w sim r */
140
137
/* two dimensional complex array */
141
fftw_complex * _h0; // init w sim r
142
fftw_complex * _h0_minus; // init w sim r
138
fftw_complex *_h0; /* init w sim r */
139
fftw_complex *_h0_minus; /* init w sim r */
144
141
/* two dimensional float array */
145
float * _k; // init w sim r
142
float *_k; /* init w sim r */
150
147
static float nextfr(float min, float max)
152
return BLI_frand()*(min-max)+max;
149
return BLI_frand() * (min - max) + max;
155
static float gaussRand (void)
152
static float gaussRand(void)
157
float x; // Note: to avoid numerical problems with very small
158
float y; // numbers, we make these variables singe-precision
159
float length2; // floats, but later we call the double-precision log()
160
// and sqrt() functions instead of logf() and sqrtf().
163
x = (float) (nextfr (-1, 1));
164
y = (float)(nextfr (-1, 1));
154
/* Note: to avoid numerical problems with very small numbers, we make these variables singe-precision floats,
155
* but later we call the double-precision log() and sqrt() functions instead of logf() and sqrtf().
162
x = (float) (nextfr(-1, 1));
163
y = (float)(nextfr(-1, 1));
165
164
length2 = x * x + y * y;
167
while (length2 >= 1 || length2 == 0);
165
} while (length2 >= 1 || length2 == 0);
169
167
return x * sqrtf(-2.0f * logf(length2) / length2);
173
171
* Some useful functions
175
MINLINE float lerp(float a,float b,float f)
180
MINLINE float catrom(float p0,float p1,float p2,float p3,float f)
182
return 0.5f *((2.0f * p1) +
184
(2.0f*p0 - 5.0f*p1 + 4.0f*p2 - p3) * f*f +
185
(-p0 + 3.0f*p1- 3.0f*p2 + p3) * f*f*f);
173
MINLINE float catrom(float p0, float p1, float p2, float p3, float f)
175
return 0.5f * ((2.0f * p1) +
177
(2.0f * p0 - 5.0f * p1 + 4.0f * p2 - p3) * f * f +
178
(-p0 + 3.0f * p1 - 3.0f * p2 + p3) * f * f * f);
188
181
MINLINE float omega(float k, float depth)
190
return sqrt(GRAVITY*k * tanh(k*depth));
183
return sqrtf(GRAVITY * k * tanhf(k * depth));
193
// modified Phillips spectrum
194
static float Ph(struct Ocean* o, float kx,float kz )
186
/* modified Phillips spectrum */
187
static float Ph(struct Ocean *o, float kx, float kz)
197
float k2 = kx*kx + kz*kz;
190
float k2 = kx * kx + kz * kz;
201
return 0.0f; // no DC component
193
return 0.0f; /* no DC component */
204
// damp out the waves going in the direction opposite the wind
205
tmp = (o->_wx * kx + o->_wz * kz)/sqrtf(k2);
196
/* damp out the waves going in the direction opposite the wind */
197
tmp = (o->_wx * kx + o->_wz * kz) / sqrtf(k2);
208
199
tmp *= o->_damp_reflections;
211
return o->_A * expf( -1.0f / (k2*(o->_L*o->_L))) * expf(-k2 * (o->_l*o->_l)) * powf(fabsf(tmp),o->_wind_alignment) / (k2*k2);
202
return o->_A * expf(-1.0f / (k2 * (o->_L * o->_L))) * expf(-k2 * (o->_l * o->_l)) *
203
powf(fabsf(tmp), o->_wind_alignment) / (k2 * k2);
214
static void compute_eigenstuff(struct OceanResult *ocr, float jxx,float jzz,float jxz)
206
static void compute_eigenstuff(struct OceanResult *ocr, float jxx, float jzz, float jxz)
216
float a,b,qplus,qminus;
208
float a, b, qplus, qminus;
218
b = sqrt((jxx - jzz)*(jxx - jzz) + 4 * jxz * jxz);
220
ocr->Jminus = 0.5f*(a-b);
221
ocr->Jplus = 0.5f*(a+b);
223
qplus = (ocr->Jplus - jxx)/jxz;
224
qminus = (ocr->Jminus - jxx)/jxz;
226
a = sqrt(1 + qplus*qplus);
227
b = sqrt(1 + qminus*qminus);
229
ocr->Eplus[0] = 1.0f/ a;
210
b = sqrt((jxx - jzz) * (jxx - jzz) + 4 * jxz * jxz);
212
ocr->Jminus = 0.5f * (a - b);
213
ocr->Jplus = 0.5f * (a + b);
215
qplus = (ocr->Jplus - jxx) / jxz;
216
qminus = (ocr->Jminus - jxx) / jxz;
218
a = sqrt(1 + qplus * qplus);
219
b = sqrt(1 + qminus * qminus);
221
ocr->Eplus[0] = 1.0f / a;
230
222
ocr->Eplus[1] = 0.0f;
231
ocr->Eplus[2] = qplus/a;
223
ocr->Eplus[2] = qplus / a;
233
ocr->Eminus[0] = 1.0f/b;
225
ocr->Eminus[0] = 1.0f / b;
234
226
ocr->Eminus[1] = 0.0f;
235
ocr->Eminus[2] = qminus/b;
227
ocr->Eminus[2] = qminus / b;
404
398
i2 = i2 % oc->_M;
405
399
j2 = j2 % oc->_N;
409
403
i0 = i0 < 0 ? i0 + oc->_M : i0;
410
404
i3 = i3 >= oc->_M ? i3 - oc->_M : i3;
414
408
j0 = j0 < 0 ? j0 + oc->_N : j0;
415
409
j3 = j3 >= oc->_N ? j3 - oc->_N : j3;
417
#define INTERP(m) catrom(catrom(m[i0*oc->_N+j0],m[i1*oc->_N+j0],m[i2*oc->_N+j0],m[i3*oc->_N+j0],frac_x),\
418
catrom(m[i0*oc->_N+j1],m[i1*oc->_N+j1],m[i2*oc->_N+j1],m[i3*oc->_N+j1],frac_x),\
419
catrom(m[i0*oc->_N+j2],m[i1*oc->_N+j2],m[i2*oc->_N+j2],m[i3*oc->_N+j2],frac_x),\
420
catrom(m[i0*oc->_N+j3],m[i1*oc->_N+j3],m[i2*oc->_N+j3],m[i3*oc->_N+j3],frac_x),\
411
#define INTERP(m) catrom(catrom(m[i0 * oc->_N + j0], m[i1 * oc->_N + j0], \
412
m[i2 * oc->_N + j0], m[i3 * oc->_N + j0], frac_x), \
413
catrom(m[i0 * oc->_N + j1], m[i1 * oc->_N + j1], \
414
m[i2 * oc->_N + j1], m[i3 * oc->_N + j1], frac_x), \
415
catrom(m[i0 * oc->_N + j2], m[i1 * oc->_N + j2], \
416
m[i2 * oc->_N + j2], m[i3 * oc->_N + j2], frac_x), \
417
catrom(m[i0 * oc->_N + j3], m[i1 * oc->_N + j3], \
418
m[i2 * oc->_N + j3], m[i3 * oc->_N + j3], frac_x), \
422
if (oc->_do_disp_y) {
426
423
ocr->disp[1] = INTERP(oc->_disp_y);
425
if (oc->_do_normals) {
430
426
ocr->normal[0] = INTERP(oc->_N_x);
431
ocr->normal[1] = oc->_N_y/*INTERP(oc->_N_y) (MEM01)*/;
427
ocr->normal[1] = oc->_N_y /*INTERP(oc->_N_y) (MEM01)*/;
432
428
ocr->normal[2] = INTERP(oc->_N_z);
436
431
ocr->disp[0] = INTERP(oc->_disp_x);
437
432
ocr->disp[2] = INTERP(oc->_disp_z);
455
void BKE_ocean_eval_xz(struct Ocean *oc, struct OceanResult *ocr, float x,float z)
457
BKE_ocean_eval_uv(oc, ocr, x/oc->_Lx,z/oc->_Lz);
460
void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x,float z)
462
BKE_ocean_eval_uv_catrom(oc, ocr, x/oc->_Lx,z/oc->_Lz);
465
// note that this doesn't wrap properly for i,j < 0, but its
466
// not really meant for that being just a way to get the raw data out
467
// to save in some image format.
468
void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i,int j)
449
void BKE_ocean_eval_xz(struct Ocean *oc, struct OceanResult *ocr, float x, float z)
451
BKE_ocean_eval_uv(oc, ocr, x / oc->_Lx, z / oc->_Lz);
454
void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x, float z)
456
BKE_ocean_eval_uv_catrom(oc, ocr, x / oc->_Lx, z / oc->_Lz);
459
/* note that this doesn't wrap properly for i, j < 0, but its not really meant for that being just a way to get
460
* the raw data out to save in some image format.
462
void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j)
470
464
BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ);
472
466
i = abs(i) % oc->_M;
473
467
j = abs(j) % oc->_N;
475
ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i*oc->_N+j] : 0.0f;
469
ocr->disp[1] = oc->_do_disp_y ? (float)oc->_disp_y[i * oc->_N + j] : 0.0f;
479
ocr->disp[0] = oc->_disp_x[i*oc->_N+j];
480
ocr->disp[2] = oc->_disp_z[i*oc->_N+j];
472
ocr->disp[0] = oc->_disp_x[i * oc->_N + j];
473
ocr->disp[2] = oc->_disp_z[i * oc->_N + j];
483
476
ocr->disp[0] = 0.0f;
484
477
ocr->disp[2] = 0.0f;
489
ocr->normal[0] = oc->_N_x[i*oc->_N+j];
490
ocr->normal[1] = oc->_N_y/*oc->_N_y[i*oc->_N+j] (MEM01)*/;
491
ocr->normal[2] = oc->_N_z[i*oc->_N+j];
480
if (oc->_do_normals) {
481
ocr->normal[0] = oc->_N_x[i * oc->_N + j];
482
ocr->normal[1] = oc->_N_y /* oc->_N_y[i * oc->_N + j] (MEM01) */;
483
ocr->normal[2] = oc->_N_z[i * oc->_N + j];
493
485
normalize_v3(ocr->normal);
496
if (oc->_do_jacobian)
498
compute_eigenstuff(ocr, oc->_Jxx[i*oc->_N+j],oc->_Jzz[i*oc->_N+j],oc->_Jxz[i*oc->_N+j]);
488
if (oc->_do_jacobian) {
489
compute_eigenstuff(ocr, oc->_Jxx[i * oc->_N + j], oc->_Jzz[i * oc->_N + j], oc->_Jxz[i * oc->_N + j]);
501
492
BLI_rw_mutex_unlock(&oc->oceanmutex);
510
501
BLI_rw_mutex_lock(&o->oceanmutex, THREAD_LOCK_WRITE);
512
// compute a new htilda
503
/* compute a new htilda */
513
504
#pragma omp parallel for private(i, j)
514
for (i = 0 ; i < o->_M ; ++i)
516
// note the <= _N/2 here, see the fftw doco about
517
// the mechanics of the complex->real fft storage
518
for ( j = 0 ; j <= o->_N / 2 ; ++j)
505
for (i = 0; i < o->_M; ++i) {
506
/* note the <= _N/2 here, see the fftw doco about the mechanics of the complex->real fft storage */
507
for (j = 0; j <= o->_N / 2; ++j) {
520
508
fftw_complex exp_param1;
521
509
fftw_complex exp_param2;
522
510
fftw_complex conj_param;
525
init_complex(exp_param1, 0.0, omega(o->_k[i*(1+o->_N/2)+j],o->_depth)*t);
526
init_complex(exp_param2, 0.0, -omega(o->_k[i*(1+o->_N/2)+j],o->_depth)*t);
513
init_complex(exp_param1, 0.0, omega(o->_k[i * (1 + o->_N / 2) + j], o->_depth) * t);
514
init_complex(exp_param2, 0.0, -omega(o->_k[i * (1 + o->_N / 2) + j], o->_depth) * t);
527
515
exp_complex(exp_param1, exp_param1);
528
516
exp_complex(exp_param2, exp_param2);
529
conj_complex(conj_param, o->_h0_minus[i*o->_N+j]);
517
conj_complex(conj_param, o->_h0_minus[i * o->_N + j]);
531
mul_complex_c(exp_param1, o->_h0[i*o->_N+j], exp_param1);
519
mul_complex_c(exp_param1, o->_h0[i * o->_N + j], exp_param1);
532
520
mul_complex_c(exp_param2, conj_param, exp_param2);
534
add_comlex_c(o->_htilda[i*(1+o->_N/2)+j], exp_param1, exp_param2);
535
mul_complex_f(o->_fft_in[i*(1+o->_N/2)+j], o->_htilda[i*(1+o->_N/2)+j], scale);
522
add_comlex_c(o->_htilda[i * (1 + o->_N / 2) + j], exp_param1, exp_param2);
523
mul_complex_f(o->_fft_in[i * (1 + o->_N / 2) + j], o->_htilda[i * (1 + o->_N / 2) + j], scale);
589
573
init_complex(mul_param, -scale, 0);
590
574
mul_complex_f(mul_param, mul_param, chop_amount);
591
575
mul_complex_c(mul_param, mul_param, minus_i);
592
mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
593
mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kz[j] / o->_k[i*(1+o->_N/2)+j]));
594
init_complex(o->_fft_in_z[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
576
mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]);
577
mul_complex_f(mul_param, mul_param,
578
((o->_k[i * (1 + o->_N / 2) + j] == 0.0f) ?
580
o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j]));
581
init_complex(o->_fft_in_z[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param));
597
584
fftw_execute(o->_disp_z_plan);
601
588
#pragma omp section
606
for ( i = 0 ; i < o->_M ; ++i)
608
for ( j = 0 ; j <= o->_N / 2 ; ++j)
590
if (o->_do_jacobian) {
592
for (i = 0; i < o->_M; ++i) {
593
for (j = 0; j <= o->_N / 2; ++j) {
610
594
fftw_complex mul_param;
612
//init_complex(mul_param, -scale, 0);
596
/* init_complex(mul_param, -scale, 0); */
613
597
init_complex(mul_param, -1, 0);
615
599
mul_complex_f(mul_param, mul_param, chop_amount);
616
mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
617
mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i]*o->_kx[i] / o->_k[i*(1+o->_N/2)+j]));
618
init_complex(o->_fft_in_jxx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
600
mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]);
601
mul_complex_f(mul_param, mul_param,
602
((o->_k[i * (1 + o->_N / 2) + j] == 0.0f) ?
604
o->_kx[i] * o->_kx[i] / o->_k[i * (1 + o->_N / 2) + j]));
605
init_complex(o->_fft_in_jxx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param));
621
608
fftw_execute(o->_Jxx_plan);
623
for ( i = 0 ; i < o->_M ; ++i)
625
for ( j = 0 ; j < o->_N ; ++j)
627
o->_Jxx[i*o->_N+j] += 1.0;
610
for (i = 0; i < o->_M; ++i) {
611
for (j = 0; j < o->_N; ++j) {
612
o->_Jxx[i * o->_N + j] += 1.0;
633
618
#pragma omp section
638
for ( i = 0 ; i < o->_M ; ++i)
640
for ( j = 0 ; j <= o->_N / 2 ; ++j)
620
if (o->_do_jacobian) {
622
for (i = 0; i < o->_M; ++i) {
623
for (j = 0; j <= o->_N / 2; ++j) {
642
624
fftw_complex mul_param;
644
//init_complex(mul_param, -scale, 0);
626
/* init_complex(mul_param, -scale, 0); */
645
627
init_complex(mul_param, -1, 0);
647
629
mul_complex_f(mul_param, mul_param, chop_amount);
648
mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
649
mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kz[j]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j]));
650
init_complex(o->_fft_in_jzz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
630
mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]);
631
mul_complex_f(mul_param, mul_param,
632
((o->_k[i * (1 + o->_N / 2) + j] == 0.0f) ?
634
o->_kz[j] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j]));
635
init_complex(o->_fft_in_jzz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param));
653
638
fftw_execute(o->_Jzz_plan);
654
for ( i = 0 ; i < o->_M ; ++i)
656
for ( j = 0 ; j < o->_N ; ++j)
658
o->_Jzz[i*o->_N+j] += 1.0;
639
for (i = 0; i < o->_M; ++i) {
640
for (j = 0; j < o->_N; ++j) {
641
o->_Jzz[i * o->_N + j] += 1.0;
664
647
#pragma omp section
669
for ( i = 0 ; i < o->_M ; ++i)
671
for ( j = 0 ; j <= o->_N / 2 ; ++j)
649
if (o->_do_jacobian) {
651
for (i = 0; i < o->_M; ++i) {
652
for (j = 0; j <= o->_N / 2; ++j) {
673
653
fftw_complex mul_param;
675
//init_complex(mul_param, -scale, 0);
655
/* init_complex(mul_param, -scale, 0); */
676
656
init_complex(mul_param, -1, 0);
678
658
mul_complex_f(mul_param, mul_param, chop_amount);
679
mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
680
mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0f ? 0.0f : o->_kx[i]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j]));
681
init_complex(o->_fft_in_jxz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
659
mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]);
660
mul_complex_f(mul_param, mul_param,
661
((o->_k[i * (1 + o->_N / 2) + j] == 0.0f) ?
663
o->_kx[i] * o->_kz[j] / o->_k[i * (1 + o->_N / 2) + j]));
664
init_complex(o->_fft_in_jxz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param));
684
667
fftw_execute(o->_Jxz_plan);
688
671
#pragma omp section
693
for ( i = 0 ; i < o->_M ; ++i)
695
for ( j = 0 ; j <= o->_N / 2 ; ++j)
674
if (o->_do_normals) {
675
for (i = 0; i < o->_M; ++i) {
676
for (j = 0; j <= o->_N / 2; ++j) {
697
677
fftw_complex mul_param;
699
679
init_complex(mul_param, 0.0, -1.0);
700
mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
680
mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]);
701
681
mul_complex_f(mul_param, mul_param, o->_kx[i]);
702
init_complex(o->_fft_in_nx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
682
init_complex(o->_fft_in_nx[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param));
705
685
fftw_execute(o->_N_x_plan);
710
690
#pragma omp section
714
for ( i = 0 ; i < o->_M ; ++i)
716
for ( j = 0 ; j <= o->_N / 2 ; ++j)
692
if (o->_do_normals) {
693
for (i = 0; i < o->_M; ++i) {
694
for (j = 0; j <= o->_N / 2; ++j) {
718
695
fftw_complex mul_param;
720
697
init_complex(mul_param, 0.0, -1.0);
721
mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
698
mul_complex_c(mul_param, mul_param, o->_htilda[i * (1 + o->_N / 2) + j]);
722
699
mul_complex_f(mul_param, mul_param, o->_kz[i]);
723
init_complex(o->_fft_in_nz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
700
init_complex(o->_fft_in_nz[i * (1 + o->_N / 2) + j], real_c(mul_param), image_c(mul_param));
726
703
fftw_execute(o->_N_z_plan);
729
for ( i = 0 ; i < o->_M ; ++i) {
730
for ( j = 0 ; j < o->_N ; ++j) {
731
o->_N_y[i*o->_N+j] = 1.0f/scale;
706
for (i = 0; i < o->_M; ++i) {
707
for (j = 0; j < o->_N; ++j) {
708
o->_N_y[i * o->_N + j] = 1.0f / scale;
736
o->_N_y = 1.0f/scale;
713
o->_N_y = 1.0f / scale;
742
719
BLI_rw_mutex_unlock(&o->oceanmutex);
814
790
o->_do_chop = do_chop;
815
791
o->_do_jacobian = do_jacobian;
817
o->_k = (float*) MEM_mallocN(M * (1+N/2) * sizeof(float), "ocean_k");
818
o->_h0 = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0");
819
o->_h0_minus = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus");
820
o->_kx = (float*) MEM_mallocN(o->_M * sizeof(float), "ocean_kx");
821
o->_kz = (float*) MEM_mallocN(o->_N * sizeof(float), "ocean_kz");
793
o->_k = (float *) MEM_mallocN(M * (1 + N / 2) * sizeof(float), "ocean_k");
794
o->_h0 = (fftw_complex *) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0");
795
o->_h0_minus = (fftw_complex *) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus");
796
o->_kx = (float *) MEM_mallocN(o->_M * sizeof(float), "ocean_kx");
797
o->_kz = (float *) MEM_mallocN(o->_N * sizeof(float), "ocean_kz");
823
// make this robust in the face of erroneous usage
799
/* make this robust in the face of erroneous usage */
824
800
if (o->_Lx == 0.0f)
827
803
if (o->_Lz == 0.0f)
830
// the +ve components and DC
831
for (i = 0 ; i <= o->_M/2 ; ++i)
806
/* the +ve components and DC */
807
for (i = 0; i <= o->_M / 2; ++i)
832
808
o->_kx[i] = 2.0f * (float)M_PI * i / o->_Lx;
834
// the -ve components
835
for (i = o->_M-1,ii=0 ; i > o->_M/2 ; --i,++ii)
810
/* the -ve components */
811
for (i = o->_M - 1, ii = 0; i > o->_M / 2; --i, ++ii)
836
812
o->_kx[i] = -2.0f * (float)M_PI * ii / o->_Lx;
838
// the +ve components and DC
839
for (i = 0 ; i <= o->_N/2 ; ++i)
814
/* the +ve components and DC */
815
for (i = 0; i <= o->_N / 2; ++i)
840
816
o->_kz[i] = 2.0f * (float)M_PI * i / o->_Lz;
842
// the -ve components
843
for (i = o->_N-1,ii=0 ; i > o->_N/2 ; --i,++ii)
818
/* the -ve components */
819
for (i = o->_N - 1, ii = 0; i > o->_N / 2; --i, ++ii)
844
820
o->_kz[i] = -2.0f * (float)M_PI * ii / o->_Lz;
846
// pre-calculate the k matrix
847
for (i = 0 ; i < o->_M ; ++i)
848
for (j = 0 ; j <= o->_N / 2 ; ++j)
849
o->_k[i*(1+o->_N/2)+j] = sqrt(o->_kx[i]*o->_kx[i] + o->_kz[j]*o->_kz[j] );
822
/* pre-calculate the k matrix */
823
for (i = 0; i < o->_M; ++i)
824
for (j = 0; j <= o->_N / 2; ++j)
825
o->_k[i * (1 + o->_N / 2) + j] = sqrt(o->_kx[i] * o->_kx[i] + o->_kz[j] * o->_kz[j]);
854
for (i = 0 ; i < o->_M ; ++i)
856
for (j = 0 ; j < o->_N ; ++j)
830
for (i = 0; i < o->_M; ++i) {
831
for (j = 0; j < o->_N; ++j) {
858
832
float r1 = gaussRand();
859
833
float r2 = gaussRand();
861
835
fftw_complex r1r2;
862
836
init_complex(r1r2, r1, r2);
863
mul_complex_f(o->_h0[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f)));
864
mul_complex_f(o->_h0_minus[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i],-o->_kz[j]) / 2.0f)));
837
mul_complex_f(o->_h0[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, o->_kx[i], o->_kz[j]) / 2.0f)));
838
mul_complex_f(o->_h0_minus[i * o->_N + j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i], -o->_kz[j]) / 2.0f)));
868
o->_fft_in = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in");
869
o->_htilda = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_htilda");
842
o->_fft_in = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in");
843
o->_htilda = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_htilda");
871
845
if (o->_do_disp_y) {
872
o->_disp_y = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y");
873
o->_disp_y_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in, o->_disp_y, FFTW_ESTIMATE);
846
o->_disp_y = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y");
847
o->_disp_y_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in, o->_disp_y, FFTW_ESTIMATE);
876
850
if (o->_do_normals) {
877
o->_fft_in_nx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nx");
878
o->_fft_in_nz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nz");
880
o->_N_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x");
881
/*o->_N_y = (float*) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01)*/
882
o->_N_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z");
884
o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE);
885
o->_N_z_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_nz, o->_N_z, FFTW_ESTIMATE);
851
o->_fft_in_nx = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nx");
852
o->_fft_in_nz = (fftw_complex *) MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_nz");
854
o->_N_x = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x");
855
/* o->_N_y = (float *) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01) */
856
o->_N_z = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z");
858
o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE);
859
o->_N_z_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_nz, o->_N_z, FFTW_ESTIMATE);
888
862
if (o->_do_chop) {
889
o->_fft_in_x = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_x");
890
o->_fft_in_z = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_z");
892
o->_disp_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x");
893
o->_disp_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z");
895
o->_disp_x_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_x, o->_disp_x, FFTW_ESTIMATE);
896
o->_disp_z_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_z, o->_disp_z, FFTW_ESTIMATE);
863
o->_fft_in_x = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_x");
864
o->_fft_in_z = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex), "ocean_fft_in_z");
866
o->_disp_x = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x");
867
o->_disp_z = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z");
869
o->_disp_x_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_x, o->_disp_x, FFTW_ESTIMATE);
870
o->_disp_z_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_z, o->_disp_z, FFTW_ESTIMATE);
898
872
if (o->_do_jacobian) {
899
o->_fft_in_jxx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxx");
900
o->_fft_in_jzz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jzz");
901
o->_fft_in_jxz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxz");
903
o->_Jxx = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx");
904
o->_Jzz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz");
905
o->_Jxz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz");
907
o->_Jxx_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jxx, o->_Jxx, FFTW_ESTIMATE);
908
o->_Jzz_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jzz, o->_Jzz, FFTW_ESTIMATE);
909
o->_Jxz_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jxz, o->_Jxz, FFTW_ESTIMATE);
873
o->_fft_in_jxx = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex),
875
o->_fft_in_jzz = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex),
877
o->_fft_in_jxz = (fftw_complex *)MEM_mallocN(o->_M * (1 + o->_N / 2) * sizeof(fftw_complex),
880
o->_Jxx = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx");
881
o->_Jzz = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz");
882
o->_Jxz = (double *)MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz");
884
o->_Jxx_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jxx, o->_Jxx, FFTW_ESTIMATE);
885
o->_Jzz_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jzz, o->_Jzz, FFTW_ESTIMATE);
886
o->_Jxz_plan = fftw_plan_dft_c2r_2d(o->_M, o->_N, o->_fft_in_jxz, o->_Jxz, FFTW_ESTIMATE);
912
889
BLI_rw_mutex_unlock(&o->oceanmutex);
993
966
/* ********* Baking/Caching ********* */
996
#define CACHE_TYPE_DISPLACE 1
997
#define CACHE_TYPE_FOAM 2
998
#define CACHE_TYPE_NORMAL 3
969
#define CACHE_TYPE_DISPLACE 1
970
#define CACHE_TYPE_FOAM 2
971
#define CACHE_TYPE_NORMAL 3
1000
973
static void cache_filename(char *string, const char *path, const char *relbase, int frame, int type)
1002
975
char cachepath[FILE_MAX];
1003
976
const char *fname;
1006
case CACHE_TYPE_FOAM:
1009
case CACHE_TYPE_NORMAL:
1012
case CACHE_TYPE_DISPLACE:
979
case CACHE_TYPE_FOAM:
982
case CACHE_TYPE_NORMAL:
985
case CACHE_TYPE_DISPLACE:
1018
991
BLI_join_dirfile(cachepath, sizeof(cachepath), path, fname);
1020
BKE_makepicstring(string, cachepath, relbase, frame, R_IMF_IMTYPE_OPENEXR, 1, TRUE);
993
BKE_makepicstring_from_type(string, cachepath, relbase, frame, R_IMF_IMTYPE_OPENEXR, 1, TRUE);
1023
996
/* silly functions but useful to inline when the args do a lot of indirections */
1024
997
MINLINE void rgb_to_rgba_unit_alpha(float r_rgba[4], const float rgb[3])
1031
1004
MINLINE void value_to_rgba_unit_alpha(float r_rgba[4], const float value)
1039
1012
void BKE_free_ocean_cache(struct OceanCache *och)
1043
1016
if (!och) return;
1045
1018
if (och->ibufs_disp) {
1046
for (i=och->start, f=0; i<=och->end; i++, f++)
1019
for (i = och->start, f = 0; i <= och->end; i++, f++) {
1048
1020
if (och->ibufs_disp[f]) {
1049
1021
IMB_freeImBuf(och->ibufs_disp[f]);
1165
1134
/* ibufs array is zero based, but filenames are based on frame numbers */
1166
1135
/* still need to clamp frame numbers to valid range of images on disk though */
1167
1136
CLAMP(frame, och->start, och->end);
1168
f = frame - och->start; // shift to 0 based
1137
f = frame - och->start; /* shift to 0 based */
1170
1139
/* if image is already loaded in mem, return */
1171
if (och->ibufs_disp[f] != NULL ) return;
1140
if (och->ibufs_disp[f] != NULL) return;
1142
/* use default color spaces since we know for sure cache files were saved with default settings too */
1174
1144
cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_DISPLACE);
1175
och->ibufs_disp[f] = IMB_loadiffname(string, 0);
1176
//if (och->ibufs_disp[f] == NULL) printf("error loading %s\n", string);
1177
//else printf("loaded cache %s\n", string);
1145
och->ibufs_disp[f] = IMB_loadiffname(string, 0, NULL);
1147
if (och->ibufs_disp[f] == NULL)
1148
printf("error loading %s\n", string);
1150
printf("loaded cache %s\n", string);
1179
1153
cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_FOAM);
1180
och->ibufs_foam[f] = IMB_loadiffname(string, 0);
1181
//if (och->ibufs_foam[f] == NULL) printf("error loading %s\n", string);
1182
//else printf("loaded cache %s\n", string);
1154
och->ibufs_foam[f] = IMB_loadiffname(string, 0, NULL);
1156
if (och->ibufs_foam[f] == NULL)
1157
printf("error loading %s\n", string);
1159
printf("loaded cache %s\n", string);
1184
1162
cache_filename(string, och->bakepath, och->relbase, frame, CACHE_TYPE_NORMAL);
1185
och->ibufs_norm[f] = IMB_loadiffname(string, 0);
1186
//if (och->ibufs_norm[f] == NULL) printf("error loading %s\n", string);
1187
//else printf("loaded cache %s\n", string);
1163
och->ibufs_norm[f] = IMB_loadiffname(string, 0, NULL);
1165
if (och->ibufs_norm[f] == NULL)
1166
printf("error loading %s\n", string);
1168
printf("loaded cache %s\n", string);
1191
void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(void *, float progress, int *cancel), void *update_cb_data)
1173
void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(void *, float progress, int *cancel),
1174
void *update_cb_data)
1193
1176
/* note: some of these values remain uninitialized unless certain options
1194
1177
* are enabled, take care that BKE_ocean_eval_ij() initializes a member
1195
1178
* before use - campbell */
1196
1179
OceanResult ocr;
1198
ImageFormatData imf= {0};
1181
ImageFormatData imf = {0};
1200
int f, i=0, x, y, cancel=0;
1183
int f, i = 0, x, y, cancel = 0;
1201
1184
float progress;
1203
1186
ImBuf *ibuf_foam, *ibuf_disp, *ibuf_normal;
1209
1192
if (!o) return;
1211
if (o->_do_jacobian) prev_foam = MEM_callocN(res_x*res_y*sizeof(float), "previous frame foam bake data");
1212
else prev_foam = NULL;
1194
if (o->_do_jacobian) prev_foam = MEM_callocN(res_x * res_y * sizeof(float), "previous frame foam bake data");
1195
else prev_foam = NULL;
1216
1199
/* setup image format */
1217
imf.imtype= R_IMF_IMTYPE_OPENEXR;
1218
imf.depth= R_IMF_CHAN_DEPTH_16;
1219
imf.exr_codec= R_IMF_EXR_CODEC_ZIP;
1200
imf.imtype = R_IMF_IMTYPE_OPENEXR;
1201
imf.depth = R_IMF_CHAN_DEPTH_16;
1202
imf.exr_codec = R_IMF_EXR_CODEC_ZIP;
1221
for (f=och->start, i=0; f<=och->end; f++, i++) {
1204
for (f = och->start, i = 0; f <= och->end; f++, i++) {
1223
1206
/* create a new imbuf to store image for this frame */
1224
1207
ibuf_foam = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
1225
1208
ibuf_disp = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
1226
1209
ibuf_normal = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
1228
ibuf_disp->profile = ibuf_foam->profile = ibuf_normal->profile = IB_PROFILE_LINEAR_RGB;
1230
1211
BKE_simulate_ocean(o, och->time[i], och->wave_scale, och->chop_amount);
1232
1213
/* add new foam */
1233
for (y=0; y < res_y; y++) {
1234
for (x=0; x < res_x; x++) {
1214
for (y = 0; y < res_y; y++) {
1215
for (x = 0; x < res_x; x++) {
1236
1217
BKE_ocean_eval_ij(o, &ocr, x, y);
1238
1219
/* add to the image */
1239
rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4*(res_x*y + x)], ocr.disp);
1220
rgb_to_rgba_unit_alpha(&ibuf_disp->rect_float[4 * (res_x * y + x)], ocr.disp);
1241
1222
if (o->_do_jacobian) {
1242
1223
/* TODO, cleanup unused code - campbell */
1244
float /*r,*/ /* UNUSED */ pr=0.0f, foam_result;
1225
float /*r, */ /* UNUSED */ pr = 0.0f, foam_result;
1245
1226
float neg_disp, neg_eplus;
1247
1228
ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, och->foam_coverage);
1249
1230
/* accumulate previous value for this cell */
1251
pr = prev_foam[res_x*y + x];
1232
pr = prev_foam[res_x * y + x];
1254
/* r = BLI_frand(); */ /* UNUSED */ // randomly reduce foam
1256
//pr = pr * och->foam_fade; // overall fade
1258
// remember ocean coord sys is Y up!
1259
// break up the foam where height (Y) is low (wave valley),
1260
// and X and Z displacement is greatest
1235
/* r = BLI_frand(); */ /* UNUSED */ /* randomly reduce foam */
1237
/* pr = pr * och->foam_fade; */ /* overall fade */
1239
/* remember ocean coord sys is Y up!
1240
* break up the foam where height (Y) is low (wave valley), and X and Z displacement is greatest
1263
1244
vec[0] = ocr.disp[0];
1266
1247
CLAMP(hor_stretch, 0.0, 1.0);
1269
neg_disp = ocr.disp[1] < 0.0f ? 1.0f+ocr.disp[1] : 1.0f;
1250
neg_disp = ocr.disp[1] < 0.0f ? 1.0f + ocr.disp[1] : 1.0f;
1270
1251
neg_disp = neg_disp < 0.0f ? 0.0f : neg_disp;
1272
1253
/* foam, 'ocr.Eplus' only initialized with do_jacobian */
1273
neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2]:1.0f;
1274
neg_eplus = neg_eplus<0.0f ? 0.0f : neg_eplus;
1276
//if (ocr.disp[1] < 0.0 || r > och->foam_fade)
1277
// pr *= och->foam_fade;
1280
//pr = pr * (1.0 - hor_stretch) * ocr.disp[1];
1281
//pr = pr * neg_disp * neg_eplus;
1283
if (pr < 1.0f) pr *=pr;
1254
neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2] : 1.0f;
1255
neg_eplus = neg_eplus < 0.0f ? 0.0f : neg_eplus;
1258
if (ocr.disp[1] < 0.0 || r > och->foam_fade)
1259
pr *= och->foam_fade;
1262
pr = pr * (1.0 - hor_stretch) * ocr.disp[1];
1263
pr = pr * neg_disp * neg_eplus;
1285
1269
pr *= och->foam_fade * (0.75f + neg_eplus * 0.25f);
1288
foam_result = pr + ocr.foam;
1290
prev_foam[res_x*y + x] = foam_result;
1292
value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4*(res_x*y + x)], foam_result);
1271
/* A full clamping should not be needed! */
1272
foam_result = min_ff(pr + ocr.foam, 1.0f);
1274
prev_foam[res_x * y + x] = foam_result;
1276
/*foam_result = min_ff(foam_result, 1.0f); */
1278
value_to_rgba_unit_alpha(&ibuf_foam->rect_float[4 * (res_x * y + x)], foam_result);
1295
1281
if (o->_do_normals) {
1296
rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4*(res_x*y + x)], ocr.normal);
1282
rgb_to_rgba_unit_alpha(&ibuf_normal->rect_float[4 * (res_x * y + x)], ocr.normal);
1301
1287
/* write the images */
1302
1288
cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_DISPLACE);
1303
if (0 == BKE_write_ibuf(ibuf_disp, string, &imf))
1289
if (0 == BKE_imbuf_write(ibuf_disp, string, &imf))
1304
1290
printf("Cannot save Displacement File Output to %s\n", string);
1306
1292
if (o->_do_jacobian) {
1307
cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_FOAM);
1308
if (0 == BKE_write_ibuf(ibuf_foam, string, &imf))
1293
cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_FOAM);
1294
if (0 == BKE_imbuf_write(ibuf_foam, string, &imf))
1309
1295
printf("Cannot save Foam File Output to %s\n", string);
1312
1298
if (o->_do_normals) {
1313
cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_NORMAL);
1314
if (0 == BKE_write_ibuf(ibuf_normal, string, &imf))
1299
cache_filename(string, och->bakepath, och->relbase, f, CACHE_TYPE_NORMAL);
1300
if (0 == BKE_imbuf_write(ibuf_normal, string, &imf))
1315
1301
printf("Cannot save Normal File Output to %s\n", string);