remove double promotions and some formatting edits (tabs & spaces mixed)
authorCampbell Barton <ideasman42@gmail.com>
Sun, 13 Nov 2011 16:10:01 +0000 (16:10 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 13 Nov 2011 16:10:01 +0000 (16:10 +0000)
source/blender/blenkernel/intern/ocean.c
source/blender/modifiers/intern/MOD_ocean.c
source/blender/render/intern/source/texture_ocean.c

index e050ff89f8622917511906c876e04a98735c4ee3..76b5d37bad84c555fca6129431f51f3475ad1ba4 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
 
 typedef struct Ocean {
        /* ********* input parameters to the sim ********* */
-    float _V;
-    float _l;
-    float _w;
-    float _A;
-    float _damp_reflections;
-    float _wind_alignment;
-    float _depth;
-       
-    float _wx;
-    float _wz;
-       
-    float _L;
-       
-    /* dimensions of computational grid */
-    int _M;
-    int _N;
-       
-    /* spatial size of computational grid */
-    float _Lx;
-    float _Lz;
-       
-    float normalize_factor;                                    // init w
-    float time;
-
-    short _do_disp_y;
-    short _do_normals;
-    short _do_chop;
-    short _do_jacobian;
-       
+       float _V;
+       float _l;
+       float _w;
+       float _A;
+       float _damp_reflections;
+       float _wind_alignment;
+       float _depth;
+
+       float _wx;
+       float _wz;
+
+       float _L;
+
+       /* dimensions of computational grid */
+       int _M;
+       int _N;
+
+       /* spatial size of computational grid */
+       float _Lx;
+       float _Lz;
+
+       float normalize_factor;                                 // init w
+       float time;
+
+       short _do_disp_y;
+       short _do_normals;
+       short _do_chop;
+       short _do_jacobian;
+
        /* mutex for threaded texture access */
        ThreadRWMutex oceanmutex;
-       
+
        /* ********* sim data arrays ********* */
-       
-    /* two dimensional arrays of complex */
-    fftw_complex *_fft_in;                     // init w       sim w
+
+       /* two dimensional arrays of complex */
+       fftw_complex *_fft_in;                  // init w       sim w
        fftw_complex *_fft_in_x;                        // init w       sim w
        fftw_complex *_fft_in_z;                        // init w       sim w
        fftw_complex *_fft_in_jxx;                      // init w       sim w
@@ -106,137 +106,137 @@ typedef struct Ocean {
        fftw_complex *_fft_in_jxz;                      // init w       sim w
        fftw_complex *_fft_in_nx;                       // init w       sim w
        fftw_complex *_fft_in_nz;                       // init w       sim w
-    fftw_complex *_htilda;                     // init w       sim w (only once)
-       
-    /* fftw "plans" */
-    fftw_plan _disp_y_plan;                    // init w       sim r
-    fftw_plan _disp_x_plan;                    // init w       sim r
-    fftw_plan _disp_z_plan;                    // init w       sim r
-    fftw_plan _N_x_plan;                       // init w       sim r
-    fftw_plan _N_z_plan;                       // init w       sim r
-    fftw_plan _Jxx_plan;                       // init w       sim r
-    fftw_plan _Jxz_plan;                       // init w       sim r
-    fftw_plan _Jzz_plan;                       // init w       sim r
-       
-    /* two dimensional arrays of float */
-    double *  _disp_y;                         // init w       sim w via plan?
-    double * _N_x;                                     // init w       sim w via plan?
-    /*float * _N_y; all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/
-    double _N_y;                                       //                      sim w ********* can be rearranged?
-    double * _N_z;                                     // init w       sim w via plan?
-    double * _disp_x;                          // init w       sim w via plan?
-    double * _disp_z;                          // init w       sim w via plan?
-       
-    /* two dimensional arrays of float */
-    /* Jacobian and minimum eigenvalue */
-    double * _Jxx;                                     // init w       sim w
-    double * _Jzz;                                     // init w       sim w
-    double * _Jxz;                                     // init w       sim w
-       
-    /* one dimensional float array */
-    float * _kx;                                       // init w       sim r
-    float * _kz;                                       // init w       sim r
-       
-    /* two dimensional complex array */
-    fftw_complex * _h0;                                // init w       sim r
-    fftw_complex * _h0_minus;          // init w       sim r
-    
-    /* two dimensional float array */
-    float * _k;                                                // init w       sim r
+       fftw_complex *_htilda;                  // init w       sim w (only once)
+
+       /* fftw "plans" */
+       fftw_plan _disp_y_plan;                 // init w       sim r
+       fftw_plan _disp_x_plan;                 // init w       sim r
+       fftw_plan _disp_z_plan;                 // init w       sim r
+       fftw_plan _N_x_plan;                    // init w       sim r
+       fftw_plan _N_z_plan;                    // init w       sim r
+       fftw_plan _Jxx_plan;                    // init w       sim r
+       fftw_plan _Jxz_plan;                    // init w       sim r
+       fftw_plan _Jzz_plan;                    // init w       sim r
+
+       /* two dimensional arrays of float */
+       double *  _disp_y;                              // init w       sim w via plan?
+       double * _N_x;                                  // init w       sim w via plan?
+       /*float * _N_y; all member of this array has same values, so convert this array to a float to reduce memory usage (MEM01)*/
+       double _N_y;                                    //                      sim w ********* can be rearranged?
+       double * _N_z;                                  // init w       sim w via plan?
+       double * _disp_x;                               // init w       sim w via plan?
+       double * _disp_z;                               // init w       sim w via plan?
+
+       /* two dimensional arrays of float */
+       /* Jacobian and minimum eigenvalue */
+       double * _Jxx;                                  // init w       sim w
+       double * _Jzz;                                  // init w       sim w
+       double * _Jxz;                                  // init w       sim w
+
+       /* one dimensional float array */
+       float * _kx;                                    // init w       sim r
+       float * _kz;                                    // init w       sim r
+
+       /* two dimensional complex array */
+       fftw_complex * _h0;                             // init w       sim r
+       fftw_complex * _h0_minus;               // init w       sim r
+
+       /* two dimensional float array */
+       float * _k;                                             // init w       sim r
 } Ocean;
 
 
 
 static float nextfr(float min, float max)
 {
-       return BLI_frand()*(min-max)+max; 
+       return BLI_frand()*(min-max)+max;
 }
 
 static float gaussRand (void)
 {
-    float x;           // Note: to avoid numerical problems with very small
-    float y;           // numbers, we make these variables singe-precision
-    float length2;     // floats, but later we call the double-precision log()
+       float x;                // Note: to avoid numerical problems with very small
+       float y;                // numbers, we make these variables singe-precision
+       float length2;  // floats, but later we call the double-precision log()
        // and sqrt() functions instead of logf() and sqrtf().
-    do
-    {
+       do
+       {
                x = (float) (nextfr (-1, 1));
                y = (float)(nextfr (-1, 1));
                length2 = x * x + y * y;
-    }
-    while (length2 >= 1 || length2 == 0);
-       
-    return x * sqrt (-2 * log (length2) / length2);
+       }
+       while (length2 >= 1 || length2 == 0);
+
+       return x * sqrtf(-2.0f * logf(length2) / length2);
 }
 
 /**
  * Som usefull functions
  * */
-MINLINE float lerp(float a,float b,float f) 
+MINLINE float lerp(float a,float b,float f)
 {
-       return a + (b-a)*f; 
+       return a + (b-a)*f;
 }
 
-MINLINE float catrom(float p0,float p1,float p2,float p3,float f) 
-{ 
-    return 0.5 *((2 * p1) +
-                 (-p0 + p2) * f +
-                 (2*p0 - 5*p1 + 4*p2 - p3) * f*f +
-                 (-p0 + 3*p1- 3*p2 + p3) * f*f*f);
+MINLINE float catrom(float p0,float p1,float p2,float p3,float f)
+{
+       return 0.5f *((2.0f * p1) +
+                     (-p0 + p2) * f +
+                     (2.0f*p0 - 5.0f*p1 + 4.0f*p2 - p3) * f*f +
+                     (-p0 + 3.0f*p1- 3.0f*p2 + p3) * f*f*f);
 }
 
-MINLINE float omega(float k, float depth) 
-{ 
-    return sqrt(GRAVITY*k * tanh(k*depth));
+MINLINE float omega(float k, float depth)
+{
+       return sqrt(GRAVITY*k * tanh(k*depth));
 }
 
-// modified Phillips spectrum 
-static float Ph(struct Ocean* o, float kx,float kz ) 
+// modified Phillips spectrum
+static float Ph(struct Ocean* o, float kx,float kz )
 {
        float tmp;
-    float k2 = kx*kx + kz*kz;
-       
-    if (k2 == 0.0)
-    {
-        return 0.0; // no DC component
-    }
-       
-    // damp out the waves going in the direction opposite the wind
-    tmp = (o->_wx * kx  + o->_wz * kz)/sqrt(k2);
-    if (tmp < 0) 
-    {
-        tmp *= o->_damp_reflections;
-    }
-
-    return o->_A * exp( -1.0f / (k2*(o->_L*o->_L))) * exp(-k2 * (o->_l*o->_l)) * pow(fabs(tmp),o->_wind_alignment) / (k2*k2);
+       float k2 = kx*kx + kz*kz;
+
+       if (k2 == 0.0f)
+       {
+               return 0.0f; // no DC component
+       }
+
+       // damp out the waves going in the direction opposite the wind
+       tmp = (o->_wx * kx  + o->_wz * kz)/sqrtf(k2);
+       if (tmp < 0)
+       {
+               tmp *= o->_damp_reflections;
+       }
+
+       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);
 }
 
 static void compute_eigenstuff(struct OceanResult *ocr, float jxx,float jzz,float jxz)
 {
-    float a,b,qplus,qminus;
-    a = jxx + jzz; 
-    b = sqrt((jxx - jzz)*(jxx - jzz) + 4 * jxz * jxz);
-       
-    ocr->Jminus = 0.5*(a-b);
-    ocr->Jplus  = 0.5*(a+b);
-       
-    qplus  = (ocr->Jplus  - jxx)/jxz;
-    qminus = (ocr->Jminus - jxx)/jxz;
-       
-    a = sqrt(1 + qplus*qplus);
-    b = sqrt(1 + qminus*qminus);
-       
-    ocr->Eplus[0] = 1.0/ a;
-    ocr->Eplus[1] = 0.0;
-    ocr->Eplus[2] = qplus/a;
-       
-    ocr->Eminus[0] = 1.0/b;
-    ocr->Eminus[1] = 0.0;
-    ocr->Eminus[2] = qminus/b; 
+       float a,b,qplus,qminus;
+       a = jxx + jzz;
+       b = sqrt((jxx - jzz)*(jxx - jzz) + 4 * jxz * jxz);
+
+       ocr->Jminus = 0.5f*(a-b);
+       ocr->Jplus  = 0.5f*(a+b);
+
+       qplus  = (ocr->Jplus  - jxx)/jxz;
+       qminus = (ocr->Jminus - jxx)/jxz;
+
+       a = sqrt(1 + qplus*qplus);
+       b = sqrt(1 + qminus*qminus);
+
+       ocr->Eplus[0] = 1.0f/ a;
+       ocr->Eplus[1] = 0.0f;
+       ocr->Eplus[2] = qplus/a;
+
+       ocr->Eminus[0] = 1.0f/b;
+       ocr->Eminus[1] = 0.0f;
+       ocr->Eminus[2] = qminus/b;
 }
 
 /*
- * instead of Complex.h 
+ * instead of Complex.h
  * in fftw.h "fftw_complex" typedefed as double[2]
  * below you can see functions are needed to work with such complex numbers.
  * */
@@ -294,171 +294,172 @@ static void conj_complex(fftw_complex res, fftw_complex cmpl1)
 static void exp_complex(fftw_complex res, fftw_complex cmpl)
 {
        float r = expf(cmpl[0]);
-       
+
        res[0] = cos(cmpl[1])*r;
        res[1] = sin(cmpl[1])*r;
 }
 
-float BKE_ocean_jminus_to_foam(float jminus, float coverage) {
-       float foam = jminus * -0.005 + coverage;
-       CLAMP(foam, 0.0, 1.0);
+float BKE_ocean_jminus_to_foam(float jminus, float coverage)
+{
+       float foam = jminus * -0.005f + coverage;
+       CLAMP(foam, 0.0f, 1.0f);
        return foam*foam;
 }
 
 void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u,float v)
 {
-    int i0,i1,j0,j1;
-    float frac_x,frac_z;
-    float uu,vv;
-       
-    // first wrap the texture so 0 <= (u,v) < 1
-    u = fmod(u,1.0f);
-    v = fmod(v,1.0f);
-       
-    if (u < 0) u += 1.0f;
-    if (v < 0) v += 1.0f;
-       
-    BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ);
-       
+       int i0,i1,j0,j1;
+       float frac_x,frac_z;
+       float uu,vv;
+
+       // first wrap the texture so 0 <= (u,v) < 1
+       u = fmod(u,1.0f);
+       v = fmod(v,1.0f);
+
+       if (u < 0) u += 1.0f;
+       if (v < 0) v += 1.0f;
+
+       BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ);
+
        uu = u * oc->_M;
-    vv = v * oc->_N;
-       
-    i0 = (int)floor(uu);
-    j0 = (int)floor(vv);
-       
-    i1 = (i0 + 1);
-    j1 = (j0 + 1);
-       
-    frac_x = uu - i0;
-    frac_z = vv - j0;
-       
-    i0 = i0 % oc->_M;
-    j0 = j0 % oc->_N;
-       
-    i1 = i1 % oc->_M;
-    j1 = j1 % oc->_N;
-       
-       
+       vv = v * oc->_N;
+
+       i0 = (int)floor(uu);
+       j0 = (int)floor(vv);
+
+       i1 = (i0 + 1);
+       j1 = (j0 + 1);
+
+       frac_x = uu - i0;
+       frac_z = vv - j0;
+
+       i0 = i0 % oc->_M;
+       j0 = j0 % oc->_N;
+
+       i1 = i1 % oc->_M;
+       j1 = j1 % oc->_N;
+
+
 #define BILERP(m) (lerp(lerp(m[i0*oc->_N+j0],m[i1*oc->_N+j0],frac_x),lerp(m[i0*oc->_N+j1],m[i1*oc->_N+j1],frac_x),frac_z))
-    {
-        if (oc->_do_disp_y) {
-               ocr->disp[1] = BILERP(oc->_disp_y);
-        }
-               
-        if (oc->_do_normals) {
-               ocr->normal[0] = BILERP(oc->_N_x);
-               ocr->normal[1] = oc->_N_y/*BILERP(oc->_N_y) (MEM01)*/;
-               ocr->normal[2] = BILERP(oc->_N_z);
-        }
-               
-        if (oc->_do_chop) {
-               ocr->disp[0] = BILERP(oc->_disp_x);
-               ocr->disp[2] = BILERP(oc->_disp_z); 
-        } else {
-               ocr->disp[0] = 0.0;
-               ocr->disp[2] = 0.0;
-        }
-               
-        if (oc->_do_jacobian) {
-            compute_eigenstuff(ocr, BILERP(oc->_Jxx),BILERP(oc->_Jzz),BILERP(oc->_Jxz));
-        }                      
-    }
+       {
+               if (oc->_do_disp_y) {
+                       ocr->disp[1] = BILERP(oc->_disp_y);
+               }
+
+               if (oc->_do_normals) {
+                       ocr->normal[0] = BILERP(oc->_N_x);
+                       ocr->normal[1] = oc->_N_y/*BILERP(oc->_N_y) (MEM01)*/;
+                       ocr->normal[2] = BILERP(oc->_N_z);
+               }
+
+               if (oc->_do_chop) {
+                       ocr->disp[0] = BILERP(oc->_disp_x);
+                       ocr->disp[2] = BILERP(oc->_disp_z);
+               } else {
+                       ocr->disp[0] = 0.0;
+                       ocr->disp[2] = 0.0;
+               }
+
+               if (oc->_do_jacobian) {
+                       compute_eigenstuff(ocr, BILERP(oc->_Jxx),BILERP(oc->_Jzz),BILERP(oc->_Jxz));
+               }
+       }
 #undef BILERP
-       
+
        BLI_rw_mutex_unlock(&oc->oceanmutex);
 }
 
 // use catmullrom interpolation rather than linear
 void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u,float v)
 {
-    int i0,i1,i2,i3,j0,j1,j2,j3;
-    float frac_x,frac_z;
-    float uu,vv;
-       
-    // first wrap the texture so 0 <= (u,v) < 1
-    u = fmod(u,1.0f);
-    v = fmod(v,1.0f);
-       
-    if (u < 0) u += 1.0f;
-    if (v < 0) v += 1.0f;
-       
+       int i0,i1,i2,i3,j0,j1,j2,j3;
+       float frac_x,frac_z;
+       float uu,vv;
+
+       // first wrap the texture so 0 <= (u,v) < 1
+       u = fmod(u,1.0f);
+       v = fmod(v,1.0f);
+
+       if (u < 0) u += 1.0f;
+       if (v < 0) v += 1.0f;
+
        BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ);
-       
-    uu = u * oc->_M;
-    vv = v * oc->_N;
-       
-    i1 = (int)floor(uu);
-    j1 = (int)floor(vv);
-       
-    i2 = (i1 + 1);
-    j2 = (j1 + 1);
-       
-    frac_x = uu - i1;
-    frac_z = vv - j1;
-       
-    i1 = i1 % oc->_M;
-    j1 = j1 % oc->_N;
-       
-    i2 = i2 % oc->_M;
-    j2 = j2 % oc->_N;
-       
-    i0 = (i1-1);
-    i3 = (i2+1);
-    i0 = i0 <   0 ? i0 + oc->_M : i0;
-    i3 = i3 >= oc->_M ? i3 - oc->_M : i3;
-       
-    j0 = (j1-1);
-    j3 = (j2+1);
-    j0 = j0 <   0 ? j0 + oc->_N : j0;
-    j3 = j3 >= oc->_N ? j3 - oc->_N : j3;
-       
+
+       uu = u * oc->_M;
+       vv = v * oc->_N;
+
+       i1 = (int)floor(uu);
+       j1 = (int)floor(vv);
+
+       i2 = (i1 + 1);
+       j2 = (j1 + 1);
+
+       frac_x = uu - i1;
+       frac_z = vv - j1;
+
+       i1 = i1 % oc->_M;
+       j1 = j1 % oc->_N;
+
+       i2 = i2 % oc->_M;
+       j2 = j2 % oc->_N;
+
+       i0 = (i1-1);
+       i3 = (i2+1);
+       i0 = i0 <   0 ? i0 + oc->_M : i0;
+       i3 = i3 >= oc->_M ? i3 - oc->_M : i3;
+
+       j0 = (j1-1);
+       j3 = (j2+1);
+       j0 = j0 <   0 ? j0 + oc->_N : j0;
+       j3 = j3 >= oc->_N ? j3 - oc->_N : j3;
+
 #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),\
-catrom(m[i0*oc->_N+j1],m[i1*oc->_N+j1],m[i2*oc->_N+j1],m[i3*oc->_N+j1],frac_x),\
-catrom(m[i0*oc->_N+j2],m[i1*oc->_N+j2],m[i2*oc->_N+j2],m[i3*oc->_N+j2],frac_x),\
-catrom(m[i0*oc->_N+j3],m[i1*oc->_N+j3],m[i2*oc->_N+j3],m[i3*oc->_N+j3],frac_x),\
-frac_z)
-       
-    {
-        if (oc->_do_disp_y)
-        {
-               ocr->disp[1] = INTERP(oc->_disp_y) ;
-        }
-        if (oc->_do_normals)
-        {
-               ocr->normal[0] = INTERP(oc->_N_x);
-               ocr->normal[1] = oc->_N_y/*INTERP(oc->_N_y) (MEM01)*/;
-               ocr->normal[2] = INTERP(oc->_N_z);
-        }
-        if (oc->_do_chop) 
-        {
-               ocr->disp[0] = INTERP(oc->_disp_x);
-               ocr->disp[2] = INTERP(oc->_disp_z); 
-        }
-        else
-        {
-               ocr->disp[0] = 0.0;
-               ocr->disp[2] = 0.0;
-        }
-               
-        if (oc->_do_jacobian)
-        {
-            compute_eigenstuff(ocr, INTERP(oc->_Jxx),INTERP(oc->_Jzz),INTERP(oc->_Jxz));
-        }                      
-    }
+       catrom(m[i0*oc->_N+j1],m[i1*oc->_N+j1],m[i2*oc->_N+j1],m[i3*oc->_N+j1],frac_x),\
+       catrom(m[i0*oc->_N+j2],m[i1*oc->_N+j2],m[i2*oc->_N+j2],m[i3*oc->_N+j2],frac_x),\
+       catrom(m[i0*oc->_N+j3],m[i1*oc->_N+j3],m[i2*oc->_N+j3],m[i3*oc->_N+j3],frac_x),\
+       frac_z)
+
+       {
+               if (oc->_do_disp_y)
+               {
+                       ocr->disp[1] = INTERP(oc->_disp_y) ;
+               }
+               if (oc->_do_normals)
+               {
+                       ocr->normal[0] = INTERP(oc->_N_x);
+                       ocr->normal[1] = oc->_N_y/*INTERP(oc->_N_y) (MEM01)*/;
+                       ocr->normal[2] = INTERP(oc->_N_z);
+               }
+               if (oc->_do_chop)
+               {
+                       ocr->disp[0] = INTERP(oc->_disp_x);
+                       ocr->disp[2] = INTERP(oc->_disp_z);
+               }
+               else
+               {
+                       ocr->disp[0] = 0.0;
+                       ocr->disp[2] = 0.0;
+               }
+
+               if (oc->_do_jacobian)
+               {
+                       compute_eigenstuff(ocr, INTERP(oc->_Jxx),INTERP(oc->_Jzz),INTERP(oc->_Jxz));
+               }
+       }
 #undef INTERP
-       
+
        BLI_rw_mutex_unlock(&oc->oceanmutex);
-       
+
 }
 
 void BKE_ocean_eval_xz(struct Ocean *oc, struct OceanResult *ocr, float x,float z)
 {
-    BKE_ocean_eval_uv(oc, ocr, x/oc->_Lx,z/oc->_Lz);
+       BKE_ocean_eval_uv(oc, ocr, x/oc->_Lx,z/oc->_Lz);
 }
 
 void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x,float z)
 {
-    BKE_ocean_eval_uv_catrom(oc, ocr, x/oc->_Lx,z/oc->_Lz);
+       BKE_ocean_eval_uv_catrom(oc, ocr, x/oc->_Lx,z/oc->_Lz);
 }
 
 // note that this doesn't wrap properly for i,j < 0, but its
@@ -467,310 +468,310 @@ void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x
 void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i,int j)
 {
        BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ);
-       
-    i = abs(i) % oc->_M;
-    j = abs(j) % oc->_N;
-       
-    ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i*oc->_N+j] : 0.0f;
-       
-    if (oc->_do_chop)
-    {
-       ocr->disp[0] = oc->_disp_x[i*oc->_N+j];
-       ocr->disp[2] = oc->_disp_z[i*oc->_N+j];
-    }
-    else
-    {
-       ocr->disp[0] = 0.0f;
-       ocr->disp[2] = 0.0f;
-    }
-       
-    if (oc->_do_normals)
-    {
-       ocr->normal[0] = oc->_N_x[i*oc->_N+j];
-       ocr->normal[1] = oc->_N_y/*oc->_N_y[i*oc->_N+j] (MEM01)*/;
-       ocr->normal[2] = oc->_N_z[i*oc->_N+j];
-    }
-       
-    if (oc->_do_jacobian)
-    {
+
+       i = abs(i) % oc->_M;
+       j = abs(j) % oc->_N;
+
+       ocr->disp[1] = oc->_do_disp_y ? oc->_disp_y[i*oc->_N+j] : 0.0f;
+
+       if (oc->_do_chop)
+       {
+               ocr->disp[0] = oc->_disp_x[i*oc->_N+j];
+               ocr->disp[2] = oc->_disp_z[i*oc->_N+j];
+       }
+       else
+       {
+               ocr->disp[0] = 0.0f;
+               ocr->disp[2] = 0.0f;
+       }
+
+       if (oc->_do_normals)
+       {
+               ocr->normal[0] = oc->_N_x[i*oc->_N+j];
+               ocr->normal[1] = oc->_N_y/*oc->_N_y[i*oc->_N+j] (MEM01)*/;
+               ocr->normal[2] = oc->_N_z[i*oc->_N+j];
+       }
+
+       if (oc->_do_jacobian)
+       {
                compute_eigenstuff(ocr, oc->_Jxx[i*oc->_N+j],oc->_Jzz[i*oc->_N+j],oc->_Jxz[i*oc->_N+j]);
-    }
-       
+       }
+
        BLI_rw_mutex_unlock(&oc->oceanmutex);
 }
 
 void BKE_simulate_ocean(struct Ocean *o, float t, float scale, float chop_amount)
 {
        int i, j;
-       
+
        scale *= o->normalize_factor;
-               
+
        BLI_rw_mutex_lock(&o->oceanmutex, THREAD_LOCK_WRITE);
-       
+
        // compute a new htilda
-       #pragma omp parallel for private(i, j)
-    for (i = 0 ; i  < o->_M ; ++i)
-    {
-        // note the <= _N/2 here, see the fftw doco about
-        // the mechanics of the complex->real fft storage
-        for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
-        {
-               fftw_complex exp_param1;
-               fftw_complex exp_param2;
-               fftw_complex conj_param;
-               
-               
-               init_complex(exp_param1, 0.0, omega(o->_k[i*(1+o->_N/2)+j],o->_depth)*t);
-               init_complex(exp_param2, 0.0, -omega(o->_k[i*(1+o->_N/2)+j],o->_depth)*t);
-               exp_complex(exp_param1, exp_param1);
-               exp_complex(exp_param2, exp_param2);
-               conj_complex(conj_param, o->_h0_minus[i*o->_N+j]);
-               
-               mul_complex_c(exp_param1, o->_h0[i*o->_N+j], exp_param1);
-               mul_complex_c(exp_param2, conj_param, exp_param2);
-                       
-               add_comlex_c(o->_htilda[i*(1+o->_N/2)+j], exp_param1, exp_param2);
-               mul_complex_f(o->_fft_in[i*(1+o->_N/2)+j], o->_htilda[i*(1+o->_N/2)+j], scale);
-        }
-    }
-       
-       #pragma omp parallel sections private(i, j)
-       {
-               
-       #pragma omp section
+#pragma omp parallel for private(i, j)
+       for (i = 0 ; i  < o->_M ; ++i)
        {
-               if (o->_do_disp_y)
+               // note the <= _N/2 here, see the fftw doco about
+               // the mechanics of the complex->real fft storage
+               for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
                {
-                       // y displacement
-                       fftw_execute(o->_disp_y_plan);
+                       fftw_complex exp_param1;
+                       fftw_complex exp_param2;
+                       fftw_complex conj_param;
+
+
+                       init_complex(exp_param1, 0.0, omega(o->_k[i*(1+o->_N/2)+j],o->_depth)*t);
+                       init_complex(exp_param2, 0.0, -omega(o->_k[i*(1+o->_N/2)+j],o->_depth)*t);
+                       exp_complex(exp_param1, exp_param1);
+                       exp_complex(exp_param2, exp_param2);
+                       conj_complex(conj_param, o->_h0_minus[i*o->_N+j]);
+
+                       mul_complex_c(exp_param1, o->_h0[i*o->_N+j], exp_param1);
+                       mul_complex_c(exp_param2, conj_param, exp_param2);
+
+                       add_comlex_c(o->_htilda[i*(1+o->_N/2)+j], exp_param1, exp_param2);
+                       mul_complex_f(o->_fft_in[i*(1+o->_N/2)+j], o->_htilda[i*(1+o->_N/2)+j], scale);
                }
-       } // section 1
-               
-       #pragma omp section
+       }
+
+#pragma omp parallel sections private(i, j)
        {
-               if (o->_do_chop)
+
+#pragma omp section
                {
-                       // x displacement
-                       for ( i = 0 ; i  < o->_M ; ++i)
-                       {   
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
-                               {     
-                                       fftw_complex mul_param;
-                                       fftw_complex minus_i;
-                                       
-                                       init_complex(minus_i, 0.0, -1.0);
-                                       init_complex(mul_param, -scale, 0);
-                                       mul_complex_f(mul_param, mul_param, chop_amount);
-                                       mul_complex_c(mul_param, mul_param, minus_i);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i] / o->_k[i*(1+o->_N/2)+j]));
-                                       init_complex(o->_fft_in_x[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
-                               }
+                       if (o->_do_disp_y)
+                       {
+                               // y displacement
+                               fftw_execute(o->_disp_y_plan);
                        }
-                       fftw_execute(o->_disp_x_plan);
-               }
-       } //section 2
-               
-       #pragma omp section
-       {
-               if (o->_do_chop)
-               {       
-                       // z displacement
-                       for ( i = 0 ; i  < o->_M ; ++i)
-                       {   
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j) 
-                               {               
-                                       fftw_complex mul_param;
-                                       fftw_complex minus_i;
-                                       
-                                       init_complex(minus_i, 0.0, -1.0);
-                                       init_complex(mul_param, -scale, 0);
-                                       mul_complex_f(mul_param, mul_param, chop_amount);
-                                       mul_complex_c(mul_param, mul_param, minus_i);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       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]));
-                                       init_complex(o->_fft_in_z[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));                             
-                               }
-                       } 
-                       fftw_execute(o->_disp_z_plan);
-               }
-       } // section 3
+               } // section 1
 
-       #pragma omp section
-       {
-               if (o->_do_jacobian)
+#pragma omp section
                {
-                       // Jxx
-                       for ( i = 0 ; i  < o->_M ; ++i)
+                       if (o->_do_chop)
                        {
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
-                               {    
-                                       fftw_complex mul_param;
-                                       
-                                       //init_complex(mul_param, -scale, 0);
-                                       init_complex(mul_param, -1, 0);
-                                       
-                                       mul_complex_f(mul_param, mul_param, chop_amount);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       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]));
-                                       init_complex(o->_fft_in_jxx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                               // x displacement
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+                                               fftw_complex minus_i;
+
+                                               init_complex(minus_i, 0.0, -1.0);
+                                               init_complex(mul_param, -scale, 0);
+                                               mul_complex_f(mul_param, mul_param, chop_amount);
+                                               mul_complex_c(mul_param, mul_param, minus_i);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i] / o->_k[i*(1+o->_N/2)+j]));
+                                               init_complex(o->_fft_in_x[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
                                }
+                               fftw_execute(o->_disp_x_plan);
                        }
-                       fftw_execute(o->_Jxx_plan);
-                       
-                       for ( i = 0 ; i  < o->_M ; ++i)
-                       {   
-                               for ( j  = 0 ; j  < o->_N ; ++j) 
+               } //section 2
+
+#pragma omp section
+               {
+                       if (o->_do_chop)
+                       {
+                               // z displacement
+                               for ( i = 0 ; i  < o->_M ; ++i)
                                {
-                                       o->_Jxx[i*o->_N+j] += 1.0;
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+                                               fftw_complex minus_i;
+
+                                               init_complex(minus_i, 0.0, -1.0);
+                                               init_complex(mul_param, -scale, 0);
+                                               mul_complex_f(mul_param, mul_param, chop_amount);
+                                               mul_complex_c(mul_param, mul_param, minus_i);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               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]));
+                                               init_complex(o->_fft_in_z[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
                                }
+                               fftw_execute(o->_disp_z_plan);
                        }
-               }
-       } // section 4
-       
-       #pragma omp section
-       {
-               if (o->_do_jacobian)
+               } // section 3
+
+#pragma omp section
                {
-                       // Jzz
-                       for ( i = 0 ; i  < o->_M ; ++i)
+                       if (o->_do_jacobian)
                        {
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
-                               {   
-                                       fftw_complex mul_param;
-                                       
-                                       //init_complex(mul_param, -scale, 0);
-                                       init_complex(mul_param, -1, 0);
-                                       
-                                       mul_complex_f(mul_param, mul_param, chop_amount);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       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]));
-                                       init_complex(o->_fft_in_jzz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                               // Jxx
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+
+                                               //init_complex(mul_param, -scale, 0);
+                                               init_complex(mul_param, -1, 0);
+
+                                               mul_complex_f(mul_param, mul_param, chop_amount);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               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]));
+                                               init_complex(o->_fft_in_jxx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
+                               }
+                               fftw_execute(o->_Jxx_plan);
+
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  < o->_N ; ++j)
+                                       {
+                                               o->_Jxx[i*o->_N+j] += 1.0;
+                                       }
                                }
                        }
-                       fftw_execute(o->_Jzz_plan);
-                       for ( i = 0 ; i  < o->_M ; ++i)
-                       {   
-                               for ( j  = 0 ; j  < o->_N ; ++j) 
+               } // section 4
+
+#pragma omp section
+               {
+                       if (o->_do_jacobian)
+                       {
+                               // Jzz
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+
+                                               //init_complex(mul_param, -scale, 0);
+                                               init_complex(mul_param, -1, 0);
+
+                                               mul_complex_f(mul_param, mul_param, chop_amount);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               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]));
+                                               init_complex(o->_fft_in_jzz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
+                               }
+                               fftw_execute(o->_Jzz_plan);
+                               for ( i = 0 ; i  < o->_M ; ++i)
                                {
-                                       o->_Jzz[i*o->_N+j] += 1.0;
+                                       for ( j  = 0 ; j  < o->_N ; ++j)
+                                       {
+                                               o->_Jzz[i*o->_N+j] += 1.0;
+                                       }
                                }
                        }
-               }
-       } // section 5
-               
-       #pragma omp section
-       {       
-               if (o->_do_jacobian)
+               } // section 5
+
+#pragma omp section
                {
-                       // Jxz
-                       for ( i = 0 ; i  < o->_M ; ++i)
+                       if (o->_do_jacobian)
                        {
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
-                               {     
-                                       fftw_complex mul_param;
-                                       
-                                       //init_complex(mul_param, -scale, 0);
-                                       init_complex(mul_param, -1, 0);
-
-                                       mul_complex_f(mul_param, mul_param, chop_amount);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       mul_complex_f(mul_param, mul_param, (o->_k[i*(1+o->_N/2)+j] == 0.0 ? 0.0 : o->_kx[i]*o->_kz[j] / o->_k[i*(1+o->_N/2)+j]));
-                                       init_complex(o->_fft_in_jxz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                               // Jxz
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+
+                                               //init_complex(mul_param, -scale, 0);
+                                               init_complex(mul_param, -1, 0);
+
+                                               mul_complex_f(mul_param, mul_param, chop_amount);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               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]));
+                                               init_complex(o->_fft_in_jxz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
                                }
+                               fftw_execute(o->_Jxz_plan);
                        }
-                       fftw_execute(o->_Jxz_plan);
-               }
-       } // section 6
-               
-       #pragma omp section
-       {
-               // fft normals
-               if (o->_do_normals)
+               } // section 6
+
+#pragma omp section
                {
-                       for ( i = 0 ; i  < o->_M ; ++i)
+                       // fft normals
+                       if (o->_do_normals)
                        {
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
-                               {     
-                                       fftw_complex mul_param;
-                                       
-                                       init_complex(mul_param, 0.0, -1.0);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       mul_complex_f(mul_param, mul_param, o->_kx[i]);
-                                       init_complex(o->_fft_in_nx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+
+                                               init_complex(mul_param, 0.0, -1.0);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               mul_complex_f(mul_param, mul_param, o->_kx[i]);
+                                               init_complex(o->_fft_in_nx[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
                                }
+                               fftw_execute(o->_N_x_plan);
+
                        }
-                       fftw_execute(o->_N_x_plan);
-               
-               }
-       } // section 7
-       
-       #pragma omp section
-       {
-               if (o->_do_normals)
-               {       
-                       for ( i = 0 ; i  < o->_M ; ++i)
-                       {   
-                               for ( j  = 0 ; j  <= o->_N / 2 ; ++j) 
-                               {       
-                                       fftw_complex mul_param;
-                                       
-                                       init_complex(mul_param, 0.0, -1.0);
-                                       mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
-                                       mul_complex_f(mul_param, mul_param, o->_kz[i]);
-                                       init_complex(o->_fft_in_nz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+               } // section 7
+
+#pragma omp section
+               {
+                       if (o->_do_normals)
+                       {
+                               for ( i = 0 ; i  < o->_M ; ++i)
+                               {
+                                       for ( j  = 0 ; j  <= o->_N / 2 ; ++j)
+                                       {
+                                               fftw_complex mul_param;
+
+                                               init_complex(mul_param, 0.0, -1.0);
+                                               mul_complex_c(mul_param, mul_param, o->_htilda[i*(1+o->_N/2)+j]);
+                                               mul_complex_f(mul_param, mul_param, o->_kz[i]);
+                                               init_complex(o->_fft_in_nz[i*(1+o->_N/2)+j], real_c(mul_param), image_c(mul_param));
+                                       }
                                }
-                       } 
-                       fftw_execute(o->_N_z_plan);
-                       
+                               fftw_execute(o->_N_z_plan);
+
                        /*for ( i = 0 ; i  < o->_M ; ++i)
-                        {   
-                        for ( j  = 0 ; j  < o->_N ; ++j) 
+                        {
+                        for ( j  = 0 ; j  < o->_N ; ++j)
                         {
                         o->_N_y[i*o->_N+j] = 1.0f/scale;
                         }
                         }
                         (MEM01)*/
-                       o->_N_y = 1.0f/scale;        
-               }
-       } // section 8
-       
+                       o->_N_y = 1.0f/scale;
+                       }
+               } // section 8
+
        } // omp sections
-       
+
        BLI_rw_mutex_unlock(&o->oceanmutex);
 }
 
-static void set_height_normalize_factor(struct Ocean *oc) 
-{  
-    float res = 1.0;
-    float max_h = 0.0;
-       
+static void set_height_normalize_factor(struct Ocean *oc)
+{
+       float res = 1.0;
+       float max_h = 0.0;
+
        int i,j;
-       
+
        if (!oc->_do_disp_y) return;
-       
+
        oc->normalize_factor = 1.0;
-       
+
        BKE_simulate_ocean(oc, 0.0, 1.0, 0);
-       
+
        BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_READ);
-       
-    for (i = 0; i < oc->_M; ++i)
-    {
-        for (j = 0; j < oc->_N; ++j)
-        {   
-            if( max_h < fabsf(oc->_disp_y[i*oc->_N+j]))
-            {
-               max_h = fabsf(oc->_disp_y[i*oc->_N+j]);
-            }
-        } 
-    }
-       
+
+       for (i = 0; i < oc->_M; ++i)
+       {
+               for (j = 0; j < oc->_N; ++j)
+               {
+                       if( max_h < fabsf(oc->_disp_y[i*oc->_N+j]))
+                       {
+                               max_h = fabsf(oc->_disp_y[i*oc->_N+j]);
+                       }
+               }
+       }
+
        BLI_rw_mutex_unlock(&oc->oceanmutex);
-       
-    if (max_h == 0.0) max_h = 0.00001f; // just in case ...
-       
-    res = 1.0f / (max_h);
+
+       if (max_h == 0.0f) max_h = 0.00001f; // just in case ...
+
+       res = 1.0f / (max_h);
 
        oc->normalize_factor = res;
 }
@@ -780,151 +781,151 @@ struct Ocean *BKE_add_ocean(void)
        Ocean *oc = MEM_callocN(sizeof(Ocean), "ocean sim data");
 
        BLI_rw_mutex_init(&oc->oceanmutex);
-       
+
        return oc;
 }
 
-void BKE_init_ocean(struct Ocean* o, int M,int N, float Lx, float Lz, float V, float l, float A, float w, float damp, 
-                                          float alignment, float depth, float time, short do_height_field, short do_chop, short do_normals, short do_jacobian, int seed)
+void BKE_init_ocean(struct Ocean* o, int M,int N, float Lx, float Lz, float V, float l, float A, float w, float damp,
+                                       float alignment, float depth, float time, short do_height_field, short do_chop, short do_normals, short do_jacobian, int seed)
 {
        int i,j,ii;
-       
+
        BLI_rw_mutex_lock(&o->oceanmutex, THREAD_LOCK_WRITE);
-       
+
        o->_M = M;
-    o->_N = N;
-    o->_V = V;
-    o->_l = l;
-    o->_A = A;
-    o->_w = w;
-    o->_damp_reflections = 1.0 - damp;
-    o->_wind_alignment = alignment;
-    o->_depth = depth;
-    o->_Lx = Lx;
-    o->_Lz = Lz;
-    o->_wx = cos(w);
-    o->_wz = -sin(w); // wave direction
-    o->_L = V*V / GRAVITY;  // largest wave for a given velocity V
-    o->time = time;
-       
-    o->_do_disp_y = do_height_field;
-    o->_do_normals = do_normals;
-    o->_do_chop = do_chop;
-    o->_do_jacobian = do_jacobian;
-    
-    o->_k = (float*) MEM_mallocN(M * (1+N/2) * sizeof(float), "ocean_k");
-    o->_h0 = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0");
-    o->_h0_minus = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus");
-    o->_kx = (float*) MEM_mallocN(o->_M * sizeof(float), "ocean_kx");
-    o->_kz = (float*) MEM_mallocN(o->_N * sizeof(float), "ocean_kz");
-       
-    // make this robust in the face of erroneous usage
-    if (o->_Lx == 0.0)
-       o->_Lx = 0.001;
-       
-    if (o->_Lz == 0.0)
-       o->_Lz = 0.001;
-       
-    // the +ve components and DC
-    for (i = 0 ; i <= o->_M/2 ; ++i)
-       o->_kx[i] = 2.0f * M_PI * i / o->_Lx;
-       
-    // the -ve components
-    for (i = o->_M-1,ii=0 ; i > o->_M/2 ; --i,++ii)
-       o->_kx[i] = -2.0f * M_PI * ii / o->_Lx;
-       
-    // the +ve components and DC
-    for (i = 0 ; i <= o->_N/2 ; ++i)
-       o->_kz[i] = 2.0f * M_PI * i / o->_Lz;
-       
-    // the -ve components
-    for (i = o->_N-1,ii=0 ; i > o->_N/2 ; --i,++ii)
-       o->_kz[i] = -2.0f * M_PI * ii / o->_Lz;
-       
-    // pre-calculate the k matrix
-    for (i = 0 ; i  < o->_M ; ++i)
-        for (j  = 0 ; j  <= o->_N / 2 ; ++j) 
-               o->_k[i*(1+o->_N/2)+j] = sqrt(o->_kx[i]*o->_kx[i] + o->_kz[j]*o->_kz[j] );
-    
-    /*srand(seed);*/
-    BLI_srand(seed);
-       
-    for (i = 0 ; i  < o->_M ; ++i)
-    {
-        for (j = 0 ; j  < o->_N ; ++j)
-        {
-               float r1 = gaussRand();
-               float r2 = gaussRand();
-               
-            fftw_complex r1r2;
-            init_complex(r1r2, r1, r2);
-            mul_complex_f(o->_h0[i*o->_N+j], r1r2, (float)(sqrt(Ph(o,  o->_kx[i], o->_kz[j]) / 2.0f)));
-            mul_complex_f(o->_h0_minus[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i],-o->_kz[j]) / 2.0f)));
-        }
-    }
-       
-    o->_fft_in = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in");
-    o->_htilda = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_htilda");
-    
-    if (o->_do_disp_y){
-       o->_disp_y = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y");
-       o->_disp_y_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in, o->_disp_y, FFTW_ESTIMATE);
-    }
-    
-    if (o->_do_normals){
+       o->_N = N;
+       o->_V = V;
+       o->_l = l;
+       o->_A = A;
+       o->_w = w;
+       o->_damp_reflections = 1.0f - damp;
+       o->_wind_alignment = alignment;
+       o->_depth = depth;
+       o->_Lx = Lx;
+       o->_Lz = Lz;
+       o->_wx = cos(w);
+       o->_wz = -sin(w); // wave direction
+       o->_L = V*V / GRAVITY;  // largest wave for a given velocity V
+       o->time = time;
+
+       o->_do_disp_y = do_height_field;
+       o->_do_normals = do_normals;
+       o->_do_chop = do_chop;
+       o->_do_jacobian = do_jacobian;
+
+       o->_k = (float*) MEM_mallocN(M * (1+N/2) * sizeof(float), "ocean_k");
+       o->_h0 = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0");
+       o->_h0_minus = (fftw_complex*) MEM_mallocN(M * N * sizeof(fftw_complex), "ocean_h0_minus");
+       o->_kx = (float*) MEM_mallocN(o->_M * sizeof(float), "ocean_kx");
+       o->_kz = (float*) MEM_mallocN(o->_N * sizeof(float), "ocean_kz");
+
+       // make this robust in the face of erroneous usage
+       if (o->_Lx == 0.0f)
+               o->_Lx = 0.001f;
+
+       if (o->_Lz == 0.0f)
+               o->_Lz = 0.001f;
+
+       // the +ve components and DC
+       for (i = 0 ; i <= o->_M/2 ; ++i)
+               o->_kx[i] = 2.0f * (float)M_PI * i / o->_Lx;
+
+       // the -ve components
+       for (i = o->_M-1,ii=0 ; i > o->_M/2 ; --i,++ii)
+               o->_kx[i] = -2.0f * (float)M_PI * ii / o->_Lx;
+
+       // the +ve components and DC
+       for (i = 0 ; i <= o->_N/2 ; ++i)
+               o->_kz[i] = 2.0f * (float)M_PI * i / o->_Lz;
+
+       // the -ve components
+       for (i = o->_N-1,ii=0 ; i > o->_N/2 ; --i,++ii)
+               o->_kz[i] = -2.0f * (float)M_PI * ii / o->_Lz;
+
+       // pre-calculate the k matrix
+       for (i = 0 ; i  < o->_M ; ++i)
+               for (j  = 0 ; j  <= o->_N / 2 ; ++j)
+                       o->_k[i*(1+o->_N/2)+j] = sqrt(o->_kx[i]*o->_kx[i] + o->_kz[j]*o->_kz[j] );
+
+       /*srand(seed);*/
+       BLI_srand(seed);
+
+       for (i = 0 ; i  < o->_M ; ++i)
+       {
+               for (j = 0 ; j  < o->_N ; ++j)
+               {
+                       float r1 = gaussRand();
+                       float r2 = gaussRand();
+
+                       fftw_complex r1r2;
+                       init_complex(r1r2, r1, r2);
+                       mul_complex_f(o->_h0[i*o->_N+j], r1r2, (float)(sqrt(Ph(o,  o->_kx[i], o->_kz[j]) / 2.0f)));
+                       mul_complex_f(o->_h0_minus[i*o->_N+j], r1r2, (float)(sqrt(Ph(o, -o->_kx[i],-o->_kz[j]) / 2.0f)));
+               }
+       }
+
+       o->_fft_in = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in");
+       o->_htilda = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_htilda");
+
+       if (o->_do_disp_y){
+               o->_disp_y = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_y");
+               o->_disp_y_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in, o->_disp_y, FFTW_ESTIMATE);
+       }
+
+       if (o->_do_normals){
                o->_fft_in_nx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nx");
                o->_fft_in_nz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_nz");
-               
-       o->_N_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x");
-       /*o->_N_y = (float*) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01)*/
-       o->_N_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z");
-               
-       o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE);
-       o->_N_z_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_nz, o->_N_z, FFTW_ESTIMATE);
-    }
-    
-    if (o->_do_chop){
+
+               o->_N_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_x");
+               /*o->_N_y = (float*) fftwf_malloc(o->_M * o->_N * sizeof(float)); (MEM01)*/
+               o->_N_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_N_z");
+
+               o->_N_x_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_nx, o->_N_x, FFTW_ESTIMATE);
+               o->_N_z_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_nz, o->_N_z, FFTW_ESTIMATE);
+       }
+
+       if (o->_do_chop){
                o->_fft_in_x = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_x");
                o->_fft_in_z = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_z");
-               
-        o->_disp_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x");
-        o->_disp_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z");
-               
-        o->_disp_x_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_x, o->_disp_x, FFTW_ESTIMATE);
-        o->_disp_z_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_z, o->_disp_z, FFTW_ESTIMATE);
-    }
-    if (o->_do_jacobian){
+
+               o->_disp_x = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_x");
+               o->_disp_z = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_disp_z");
+
+               o->_disp_x_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_x, o->_disp_x, FFTW_ESTIMATE);
+               o->_disp_z_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_z, o->_disp_z, FFTW_ESTIMATE);
+       }
+       if (o->_do_jacobian){
                o->_fft_in_jxx = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxx");
                o->_fft_in_jzz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jzz");
                o->_fft_in_jxz = (fftw_complex*) MEM_mallocN(o->_M * (1+o->_N/2) * sizeof(fftw_complex), "ocean_fft_in_jxz");
-               
-       o->_Jxx = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx");
-       o->_Jzz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz");
-       o->_Jxz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz");
-               
-       o->_Jxx_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jxx, o->_Jxx, FFTW_ESTIMATE);
-       o->_Jzz_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jzz, o->_Jzz, FFTW_ESTIMATE);
-       o->_Jxz_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jxz, o->_Jxz, FFTW_ESTIMATE);
-    }
-       
+
+               o->_Jxx = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxx");
+               o->_Jzz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jzz");
+               o->_Jxz = (double*) MEM_mallocN(o->_M * o->_N * sizeof(double), "ocean_Jxz");
+
+               o->_Jxx_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jxx, o->_Jxx, FFTW_ESTIMATE);
+               o->_Jzz_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jzz, o->_Jzz, FFTW_ESTIMATE);
+               o->_Jxz_plan = fftw_plan_dft_c2r_2d(o->_M,o->_N, o->_fft_in_jxz, o->_Jxz, FFTW_ESTIMATE);
+       }
+
        BLI_rw_mutex_unlock(&o->oceanmutex);
-       
-    set_height_normalize_factor(o);
-       
-}  
 
-void BKE_free_ocean_data(struct Ocean *oc) 
+       set_height_normalize_factor(o);
+
+}
+
+void BKE_free_ocean_data(struct Ocean *oc)
 {
        if(!oc) return;
-       
+
        BLI_rw_mutex_lock(&oc->oceanmutex, THREAD_LOCK_WRITE);
-       
+
        if (oc->_do_disp_y)
        {
                fftw_destroy_plan(oc->_disp_y_plan);
                MEM_freeN(oc->_disp_y);
        }
-       
+
        if (oc->_do_normals)
        {
                MEM_freeN(oc->_fft_in_nx);
@@ -935,7 +936,7 @@ void BKE_free_ocean_data(struct Ocean *oc)
                /*fftwf_free(oc->_N_y); (MEM01)*/
                MEM_freeN(oc->_N_z);
        }
-       
+
        if (oc->_do_chop)
        {
                MEM_freeN(oc->_fft_in_x);
@@ -945,7 +946,7 @@ void BKE_free_ocean_data(struct Ocean *oc)
                MEM_freeN(oc->_disp_x);
                MEM_freeN(oc->_disp_z);
        }
-       
+
        if (oc->_do_jacobian)
        {
                MEM_freeN(oc->_fft_in_jxx);
@@ -958,10 +959,10 @@ void BKE_free_ocean_data(struct Ocean *oc)
                MEM_freeN(oc->_Jzz);
                MEM_freeN(oc->_Jxz);
        }
-       
+
        if (oc->_fft_in)
                MEM_freeN(oc->_fft_in);
-       
+
        /* check that ocean data has been initialised */
        if (oc->_htilda) {
                MEM_freeN(oc->_htilda);
@@ -971,17 +972,17 @@ void BKE_free_ocean_data(struct Ocean *oc)
                MEM_freeN(oc->_kx);
                MEM_freeN(oc->_kz);
        }
-       
+
        BLI_rw_mutex_unlock(&oc->oceanmutex);
 }
 
-void BKE_free_ocean(struct Ocean *oc) 
+void BKE_free_ocean(struct Ocean *oc)
 {
        if(!oc) return;
-       
+
        BKE_free_ocean_data(oc);
        BLI_rw_mutex_end(&oc->oceanmutex);
-       
+
        MEM_freeN(oc);
 }
 
@@ -999,19 +1000,19 @@ static void cache_filename(char *string, const char *path, int frame, int type)
 {
        char cachepath[FILE_MAX];
        const char *fname;
-       
+
        switch(type) {
-               case CACHE_TYPE_FOAM:
-                       fname= "foam_";
-                       break;
-               case CACHE_TYPE_NORMAL:
-                       fname= "normal_";
-                       break;
-               case CACHE_TYPE_DISPLACE:
-               default:
-                       fname= "disp_";
-                       break;
-       }               
+       case CACHE_TYPE_FOAM:
+               fname= "foam_";
+               break;
+       case CACHE_TYPE_NORMAL:
+               fname= "normal_";
+               break;
+       case CACHE_TYPE_DISPLACE:
+       default:
+               fname= "disp_";
+               break;
+       }
 
        BLI_join_dirfile(cachepath, sizeof(cachepath), path, fname);
 
@@ -1021,9 +1022,9 @@ static void cache_filename(char *string, const char *path, int frame, int type)
 void BKE_free_ocean_cache(struct OceanCache *och)
 {
        int i, f=0;
-       
+
        if (!och) return;
-       
+
        if (och->ibufs_disp) {
                for (i=och->start, f=0; i<=och->end; i++, f++)
                {
@@ -1033,7 +1034,7 @@ void BKE_free_ocean_cache(struct OceanCache *och)
                }
                MEM_freeN(och->ibufs_disp);
        }
-       
+
        if (och->ibufs_foam) {
                for (i=och->start, f=0; i<=och->end; i++, f++)
                {
@@ -1043,7 +1044,7 @@ void BKE_free_ocean_cache(struct OceanCache *och)
                }
                MEM_freeN(och->ibufs_foam);
        }
-       
+
        if (och->ibufs_norm) {
                for (i=och->start, f=0; i<=och->end; i++, f++)
                {
@@ -1053,7 +1054,7 @@ void BKE_free_ocean_cache(struct OceanCache *och)
                }
                MEM_freeN(och->ibufs_norm);
        }
-       
+
        if (och->time)
                MEM_freeN(och->time);
        MEM_freeN(och);
@@ -1064,27 +1065,27 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, in
        int res_x = och->resolution_x;
        int res_y = och->resolution_y;
        float result[4];
-       
+
        u = fmod(u, 1.0);
        v = fmod(v, 1.0);
-       
+
        if (u < 0) u += 1.0f;
-    if (v < 0) v += 1.0f;
-       
+       if (v < 0) v += 1.0f;
+
        if (och->ibufs_disp[f]) {
-               ibuf_sample(och->ibufs_disp[f], u, v, (1.0/(float)res_x), (1.0/(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];
                ocr->disp[1] = result[1];
                ocr->disp[2] = result[2];
        }
-       
+
        if (och->ibufs_foam[f]) {
-               ibuf_sample(och->ibufs_foam[f], u, v, (1.0/(float)res_x), (1.0/(float)res_y), result);
+               ibuf_sample(och->ibufs_foam[f], u, v, (1.0f/(float)res_x), (1.0f/(float)res_y), result);
                ocr->foam = result[0];
        }
-       
+
        if (och->ibufs_norm[f]) {
-               ibuf_sample(och->ibufs_norm[f], u, v, (1.0/(float)res_x), (1.0/(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];
                ocr->normal[1] = result[1];
                ocr->normal[2] = result[2];
@@ -1092,23 +1093,23 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, in
 }
 
 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;
-       
+
        i = abs(i) % res_x;
-    j = abs(j) % res_y;
+       j = abs(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];
        }
-       
+
        if (och->ibufs_foam[f]) {
                ocr->foam = och->ibufs_foam[f]->rect_float[4*(res_x*j + i) + 0];
        }
-       
+
        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];
@@ -1116,11 +1117,11 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, in
        }
 }
 
-struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, float wave_scale, 
+struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, float wave_scale,
                                                  float chop_amount, float foam_coverage, float foam_fade, int resolution)
 {
        OceanCache *och = MEM_callocN(sizeof(OceanCache), "ocean cache data");
-       
+
        och->bakepath = bakepath;
        och->start = start;
        och->end = end;
@@ -1135,9 +1136,9 @@ struct OceanCache *BKE_init_ocean_cache(char *bakepath, int start, int end, floa
        och->ibufs_disp = MEM_callocN(sizeof(ImBuf *)*och->duration, "displacement imbuf pointer array");
        och->ibufs_foam = MEM_callocN(sizeof(ImBuf *)*och->duration, "foam imbuf pointer array");
        och->ibufs_norm = MEM_callocN(sizeof(ImBuf *)*och->duration, "normal imbuf pointer array");
-       
+
        och->time = NULL;
-       
+
        return och;
 }
 
@@ -1145,26 +1146,26 @@ void BKE_simulate_ocean_cache(struct OceanCache *och, int frame)
 {
        char string[FILE_MAX];
        int f = frame;
-       
+
        /* ibufs array is zero based, but filenames are based on frame numbers */
        /* still need to clamp frame numbers to valid range of images on disk though */
        CLAMP(frame, och->start, och->end);
        f = frame - och->start; // shift to 0 based
-       
+
        /* if image is already loaded in mem, return */
        if (och->ibufs_disp[f] != NULL ) return;
-       
-       
+
+
        cache_filename(string, och->bakepath, frame, CACHE_TYPE_DISPLACE);
        och->ibufs_disp[f] = IMB_loadiffname(string, 0);
        //if (och->ibufs_disp[f] == NULL) printf("error loading %s \n", string);
        //else printf("loaded cache %s \n", string);
-       
+
        cache_filename(string, och->bakepath, frame, CACHE_TYPE_FOAM);
        och->ibufs_foam[f] = IMB_loadiffname(string, 0);
        //if (och->ibufs_foam[f] == NULL) printf("error loading %s \n", string);
        //else printf("loaded cache %s \n", string);
-       
+
        cache_filename(string, och->bakepath, frame, CACHE_TYPE_NORMAL);
        och->ibufs_norm[f] = IMB_loadiffname(string, 0);
        //if (och->ibufs_norm[f] == NULL) printf("error loading %s \n", string);
@@ -1182,91 +1183,91 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
        int res_x = och->resolution_x;
        int res_y = och->resolution_y;
        char string[FILE_MAX];
-       
+
        if (!o) return;
-       
+
        prev_foam = MEM_callocN(res_x*res_y*sizeof(float), "previous frame foam bake data");
-       
+
        BLI_srand(0);
-       
+
        for (f=och->start, i=0; f<=och->end; f++, i++) {
-               
+
                /* create a new imbuf to store image for this frame */
                ibuf_foam = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
                ibuf_disp = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
                ibuf_normal = IMB_allocImBuf(res_x, res_y, 32, IB_rectfloat);
-               
+
                ibuf_disp->profile = ibuf_foam->profile = ibuf_normal->profile = IB_PROFILE_LINEAR_RGB;
-               
+
                BKE_simulate_ocean(o, och->time[i], och->wave_scale, och->chop_amount);
-               
+
                /* add new foam */
                for (y=0; y < res_y; y++) {
                        for (x=0; x < res_x; x++) {
-                               float r, pr=0.0, foam_result;
+                               float r, pr=0.0f, foam_result;
                                float neg_disp, neg_eplus;
-                               
+
                                BKE_ocean_eval_ij(o, &ocr, x, y);
-                                                               
+
                                normalize_v3(ocr.normal);
-                               
+
                                /* foam */
                                ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, och->foam_coverage);
-                               
+
                                /* accumulate previous value for this cell */
                                if (i>0)
                                        pr = prev_foam[res_x*y + x];
 
                                r = BLI_frand();        // randomly reduce foam
-                               
+
                                //pr = pr * och->foam_fade;             // overall fade
-                               
+
                                // remember ocean coord sys is Y up!
-                               // break up the foam where height (Y) is low (wave valley), 
+                               // break up the foam where height (Y) is low (wave valley),
                                // and X and Z displacement is greatest
-                               
+
                                /*
                                 vec[0] = ocr.disp[0];
                                vec[1] = ocr.disp[2];
                                hor_stretch = len_v2(vec);
                                CLAMP(hor_stretch, 0.0, 1.0);
                                */
-                               
-                               neg_disp = ocr.disp[1]<0.0?1.0+ocr.disp[1]:1.0;
-                               neg_disp = neg_disp<0.0?0.0:neg_disp;
-                               
-                               neg_eplus = ocr.Eplus[2]<0.0?1.0+ocr.Eplus[2]:1.0;
-                               neg_eplus = neg_eplus<0.0?0.0:neg_eplus;
+
+                               neg_disp = ocr.disp[1] < 0.0f ? 1.0f+ocr.disp[1] : 1.0f;
+                               neg_disp = neg_disp < 0.0f ? 0.0f : neg_disp;
+
+                               neg_eplus = ocr.Eplus[2] < 0.0f ? 1.0f + ocr.Eplus[2]:1.0f;
+                               neg_eplus = neg_eplus<0.0f ? 0.0f : neg_eplus;
 
                                //if (ocr.disp[1] < 0.0 || r > och->foam_fade)
                                //      pr *= och->foam_fade;
-                               
-                               
+
+
                                //pr = pr * (1.0 - hor_stretch) * ocr.disp[1];
                                //pr = pr * neg_disp * neg_eplus;
-                               
-                               if (pr < 1.0) pr *=pr;
-                               
-                               pr *= och->foam_fade * (0.75+neg_eplus*0.25);
-                               
-                               
+
+                               if (pr < 1.0f) pr *=pr;
+
+                               pr *= och->foam_fade * (0.75f + neg_eplus * 0.25f);
+
+
                                foam_result = pr + ocr.foam;
-                               
+
                                prev_foam[res_x*y + x] = foam_result;
-                                                               
+
                                /* 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.0;
-                               
+                               ibuf_disp->rect_float[4*(res_x*y + x) + 3] = 1.0f;
+
                                if (o->_do_jacobian) {
                                        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;
                                }
-                               
+
                                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];
@@ -1276,38 +1277,38 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
 
                        }
                }
-               
+
                /* write the images */
                cache_filename(string, och->bakepath, f, CACHE_TYPE_DISPLACE);
                if(0 == BKE_write_ibuf(ibuf_disp, string, R_OPENEXR, R_OPENEXR_HALF, 2))  // 2 == ZIP exr codec
                        printf("Cannot save Displacement File Output to %s\n", string);
-               
+
                if (o->_do_jacobian) {
                        cache_filename(string, och->bakepath, f, CACHE_TYPE_FOAM);
                        if(0 == BKE_write_ibuf(ibuf_foam, string, R_OPENEXR, R_OPENEXR_HALF, 2))  // 2 == ZIP exr codec
                                printf("Cannot save Foam File Output to %s\n", string);
                }
-               
+
                if (o->_do_normals) {
                        cache_filename(string, och->bakepath, f, CACHE_TYPE_NORMAL);
                        if(0 == BKE_write_ibuf(ibuf_normal, string, R_OPENEXR, R_OPENEXR_HALF, 2))  // 2 == ZIP exr codec
                                printf("Cannot save Normal File Output to %s\n", string);
                }
-               
+
                IMB_freeImBuf(ibuf_disp);
                IMB_freeImBuf(ibuf_foam);
                IMB_freeImBuf(ibuf_normal);
-               
+
                progress = (f - och->start) / (float)och->duration;
-               
+
                update_cb(update_cb_data, progress, &cancel);
-               
+
                if (cancel) {
                        MEM_freeN(prev_foam);
                        return;
                }
        }
-       
+
        MEM_freeN(prev_foam);
        och->baked = 1;
 }
@@ -1316,7 +1317,7 @@ void BKE_bake_ocean(struct Ocean *o, struct OceanCache *och, void (*update_cb)(v
 
 /* stub */
 typedef struct Ocean {
-       /* need some data here, C does not allow empty struct */        
+       /* need some data here, C does not allow empty struct */
        int stub;
 } Ocean;
 
@@ -1357,16 +1358,16 @@ struct Ocean *BKE_add_ocean(void)
        return oc;
 }
 
-void BKE_init_ocean(struct Ocean* UNUSED(o), int UNUSED(M),int UNUSED(N), float UNUSED(Lx), float UNUSED(Lz), float UNUSED(V), float UNUSED(l), float UNUSED(A), float UNUSED(w), float UNUSED(damp), 
+void BKE_init_ocean(struct Ocean* UNUSED(o), int UNUSED(M),int UNUSED(N), float UNUSED(Lx), float UNUSED(Lz), float UNUSED(V), float UNUSED(l), float UNUSED(A), float UNUSED(w), float UNUSED(damp),
                                           float UNUSED(alignment), float UNUSED(depth), float UNUSED(time), short UNUSED(do_height_field), short UNUSED(do_chop), short UNUSED(do_normals), short UNUSED(do_jacobian), int UNUSED(seed))
 {
 }
 
-void BKE_free_ocean_data(struct Ocean *UNUSED(oc)) 
+void BKE_free_ocean_data(struct Ocean *UNUSED(oc))
 {
 }
 
-void BKE_free_ocean(struct Ocean *oc) 
+void BKE_free_ocean(struct Ocean *oc)
 {
        if(!oc) return;
        MEM_freeN(oc);
@@ -1379,7 +1380,7 @@ void BKE_free_ocean(struct Ocean *oc)
 void BKE_free_ocean_cache(struct OceanCache *och)
 {
        if (!och) return;
-       
+
        MEM_freeN(och);
 }
 
@@ -1388,14 +1389,14 @@ void BKE_ocean_cache_eval_uv(struct OceanCache *UNUSED(och), struct OceanResult
 }
 
 void BKE_ocean_cache_eval_ij(struct OceanCache *UNUSED(och), struct OceanResult *UNUSED(ocr), int UNUSED(f), int UNUSED(i), int UNUSED(j))
-{      
+{
 }
 
-struct OceanCache *BKE_init_ocean_cache(char *UNUSED(bakepath), int UNUSED(start), int UNUSED(end), float UNUSED(wave_scale), 
+struct OceanCache *BKE_init_ocean_cache(char *UNUSED(bakepath), int UNUSED(start), int UNUSED(end), float UNUSED(wave_scale),
                                                  float UNUSED(chop_amount), float UNUSED(foam_coverage), float UNUSED(foam_fade), int UNUSED(resolution))
 {
        OceanCache *och = MEM_callocN(sizeof(OceanCache), "ocean cache data");
-       
+
        return och;
 }
 
index 2c921f2000f96f6adbaf88279aac223eb3b9155b..9cc2d367d665894ee05c27dfaad34318d00e892e 100644 (file)
@@ -48,7 +48,7 @@
 #ifdef WITH_OCEANSIM
 static void init_cache_data(struct OceanModifierData *omd)
 {
-       omd->oceancache = BKE_init_ocean_cache(omd->cachepath, omd->bakestart, omd->bakeend, omd->wave_scale, 
+       omd->oceancache = BKE_init_ocean_cache(omd->cachepath, omd->bakestart, omd->bakeend, omd->wave_scale,
                                                                                   omd->chop_amount, omd->foam_coverage, omd->foam_fade, omd->resolution);
 }
 
@@ -63,17 +63,17 @@ static void clear_cache_data(struct OceanModifierData *omd)
 static void init_ocean_modifier(struct OceanModifierData *omd)
 {
        int do_heightfield, do_chop, do_normals, do_jacobian;
-       
-       if (!omd || !omd->ocean) return; 
-       
+
+       if (!omd || !omd->ocean) return;
+
        do_heightfield = TRUE;
        do_chop = (omd->chop_amount > 0);
        do_normals = (omd->flag & MOD_OCEAN_GENERATE_NORMALS);
        do_jacobian = (omd->flag & MOD_OCEAN_GENERATE_FOAM);
-               
+
        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, 
+       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);
@@ -82,7 +82,7 @@ static void init_ocean_modifier(struct OceanModifierData *omd)
 static void simulate_ocean_modifier(struct OceanModifierData *omd)
 {
        if (!omd || !omd->ocean) return;
-       
+
        BKE_simulate_ocean(omd->ocean, omd->time, omd->wave_scale, omd->chop_amount);
 }
 #endif // WITH_OCEANSIM
@@ -95,29 +95,29 @@ static void initData(ModifierData *md)
 {
 #ifdef WITH_OCEANSIM
        OceanModifierData *omd = (OceanModifierData*) md;
-       
-       omd->resolution = 7; 
+
+       omd->resolution = 7;
        omd->spatial_size = 50;
-       
+
        omd->wave_alignment = 0.0;
        omd->wind_velocity = 30.0;
-       
+
        omd->damp = 0.5;
        omd->smallest_wave = 0.01;
        omd->wave_direction= 0.0;
        omd->depth = 200.0;
-       
+
        omd->wave_scale = 1.0;
-       
+
        omd->chop_amount = 1.0;
-       
+
        omd->foam_coverage = 0.0;
-       
+
        omd->seed = 0;
        omd->time = 1.0;
-       
+
        omd->refresh = 0;
-       
+
        omd->size = 1.0;
        omd->repeat_x = 1;
        omd->repeat_y = 1;
@@ -129,7 +129,7 @@ static void initData(ModifierData *md)
        omd->bakeend = 250;
        omd->oceancache = NULL;
        omd->foam_fade = 0.98;
-       
+
        omd->ocean = BKE_add_ocean();
        init_ocean_modifier(omd);
        simulate_ocean_modifier(omd);
@@ -158,41 +158,41 @@ static void copyData(ModifierData *md, ModifierData *target)
 #ifdef WITH_OCEANSIM
        OceanModifierData *omd = (OceanModifierData*) md;
        OceanModifierData *tomd = (OceanModifierData*) target;
-       
+
        tomd->resolution = omd->resolution;
        tomd->spatial_size = omd->spatial_size;
-       
+
        tomd->wind_velocity = omd->wind_velocity;
-       
+
        tomd->damp = omd->damp;
        tomd->smallest_wave = omd->smallest_wave;
        tomd->depth = omd->depth;
-       
+
        tomd->wave_alignment = omd->wave_alignment;
        tomd->wave_direction = omd->wave_direction;
        tomd->wave_scale = omd->wave_scale;
-       
+
        tomd->chop_amount = omd->chop_amount;
-       tomd->foam_coverage = omd->foam_coverage;       
+       tomd->foam_coverage = omd->foam_coverage;
        tomd->time = omd->time;
-       
+
        tomd->seed = omd->seed;
        tomd->flag = omd->flag;
        tomd->output = omd->output;
-       
+
        tomd->refresh = 0;
 
-       
+
        tomd->size = omd->size;
        tomd->repeat_x = omd->repeat_x;
        tomd->repeat_y = omd->repeat_y;
-       
+
        /* XXX todo: copy cache runtime too */
        tomd->cached = 0;
        tomd->bakestart = omd->bakestart;
        tomd->bakeend = omd->bakeend;
        tomd->oceancache = NULL;
-       
+
        tomd->ocean = BKE_add_ocean();
        init_ocean_modifier(tomd);
        simulate_ocean_modifier(tomd);
@@ -224,32 +224,32 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
 #endif // WITH_OCEANSIM
 
 #if 0
-static void dm_get_bounds(DerivedMesh *dm, float *sx, float *sy, float *ox, float *oy) 
+static void dm_get_bounds(DerivedMesh *dm, float *sx, float *sy, float *ox, float *oy)
 {
        /* get bounding box of underlying dm */
        int v, totvert=dm->getNumVerts(dm);
        float min[3], max[3], delta[3];
-       
+
        MVert *mvert = dm->getVertDataArray(dm,0);
-       
+
        copy_v3_v3(min, mvert->co);
        copy_v3_v3(max, mvert->co);
-       
+
        for(v=1; v<totvert; v++, mvert++) {
                min[0]=MIN2(min[0],mvert->co[0]);
                min[1]=MIN2(min[1],mvert->co[1]);
                min[2]=MIN2(min[2],mvert->co[2]);
-               
+
                max[0]=MAX2(max[0],mvert->co[0]);
                max[1]=MAX2(max[1],mvert->co[1]);
                max[2]=MAX2(max[2],mvert->co[2]);
        }
-               
+
        sub_v3_v3v3(delta, max, min);
-       
+
        *sx = delta[0];
        *sy = delta[1];
-       
+
        *ox = min[0];
        *oy = min[1];
 }
@@ -260,47 +260,47 @@ 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.5;
+
+       return (v / (omd->size * omd->spatial_size)) + 0.5f;
 }
 
 #define OMP_MIN_RES    18
 static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
 {
        DerivedMesh *result;
-       
+
        MVert *mv;
        MFace *mf;
        MTFace *tf;
-       
+
        int cdlayer;
-       
+
        const int rx = omd->resolution*omd->resolution;
        const int ry = omd->resolution*omd->resolution;
        const int res_x = rx * omd->repeat_x;
        const int res_y = ry * omd->repeat_y;
-       
+
        const int num_verts = (res_x + 1) * (res_y + 1);
        const int num_edges = (res_x * res_y * 2) + res_x + res_y;
        const int num_faces = res_x * res_y;
-       
+
        float sx = omd->size * omd->spatial_size;
        float sy = omd->size * omd->spatial_size;
-       const float ox = -sx / 2.0;
-       const float oy = -sy / 2.0;
-       
+       const float ox = -sx / 2.0f;
+       const float oy = -sy / 2.0f;
+
        float ix, iy;
-       
+
        int x, y;
-       
+
        sx /= rx;
        sy /= ry;
-       
+
        result = CDDM_new(num_verts, num_edges, num_faces);
-       
+
        mv = CDDM_get_verts(result);
        mf = CDDM_get_faces(result);
-       
+
        /* create vertices */
        #pragma omp parallel for private(x, y) if (rx > OMP_MIN_RES)
        for (y=0; y < res_y+1; y++) {
@@ -311,7 +311,7 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
                        mv[i].co[2] = 0;
                }
        }
-       
+
        /* create faces */
        #pragma omp parallel for private(x, y) if (rx > OMP_MIN_RES)
        for (y=0; y < res_y; y++) {
@@ -322,20 +322,20 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
                        mf[fi].v2 = vi + 1;
                        mf[fi].v3 = vi + 1 + res_x+1;
                        mf[fi].v4 = vi + res_x+1;
-                       
+
                        mf[fi].flag |= ME_SMOOTH;
                }
        }
-       
+
        CDDM_calc_edges(result);
-       
+
        /* add uvs */
        cdlayer= CustomData_number_of_layers(&result->faceData, CD_MTFACE);
        if(cdlayer >= MAX_MTFACE)
                return result;
        CustomData_add_layer(&result->faceData, CD_MTFACE, CD_CALLOC, NULL, num_faces);
        tf = CustomData_get_layer(&result->faceData, CD_MTFACE);
-       
+
        ix = 1.0 / rx;
        iy = 1.0 / ry;
        #pragma omp parallel for private(x, y) if (rx > OMP_MIN_RES)
@@ -344,13 +344,13 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
                        const int i = y*res_x + x;
                        tf[i].uv[0][0] = x * ix;
                        tf[i].uv[0][1] = y * iy;
-                       
+
                        tf[i].uv[1][0] = (x+1) * ix;
                        tf[i].uv[1][1] = y * iy;
-                       
+
                        tf[i].uv[2][0] = (x+1) * ix;
                        tf[i].uv[2][1] = (y+1) * iy;
-                       
+
                        tf[i].uv[3][0] = x * ix;
                        tf[i].uv[3][1] = (y+1) * iy;
                }
@@ -364,22 +364,22 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob),
                                                          int UNUSED(useRenderParams))
 {
        OceanModifierData *omd = (OceanModifierData*) md;
-       
+
        DerivedMesh *dm=NULL;
        OceanResult ocr;
-               
+
        MVert *mv;
        MFace *mf;
-       
+
        int cdlayer;
-               
+
        int i, j;
 
        int num_verts;
        int num_faces;
 
        int cfra;
-       
+
        /* update modifier */
        if (omd->refresh & MOD_OCEAN_REFRESH_ADD)
                omd->ocean = BKE_add_ocean();
@@ -387,9 +387,9 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob),
                init_ocean_modifier(omd);
        if (omd->refresh & MOD_OCEAN_REFRESH_CLEAR_CACHE)
                clear_cache_data(omd);
-               
+
        omd->refresh = 0;
-       
+
        /* do ocean simulation */
        if (omd->cached == TRUE) {
                if (!omd->oceancache) init_cache_data(omd);
@@ -397,44 +397,44 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob),
        } else {
                simulate_ocean_modifier(omd);
        }
-       
+
        if (omd->geometry_mode == MOD_OCEAN_GEOM_GENERATE)
                dm = generate_ocean_geometry(omd);
        else if (omd->geometry_mode == MOD_OCEAN_GEOM_DISPLACE) {
                dm = CDDM_copy(derivedData);
        }
-       
+
        cfra = md->scene->r.cfra;
        CLAMP(cfra, omd->bakestart, omd->bakeend);
        cfra -= omd->bakestart; // shift to 0 based
-       
+
        num_verts = dm->getNumVerts(dm);
        num_faces = dm->getNumFaces(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(&dm->faceData, CD_MCOL, CD_CALLOC, NULL, num_faces);
-               
+
                mc = dm->getFaceDataArray(dm, CD_MCOL);
                mv = dm->getVertArray(dm);
                mf = dm->getFaceArray(dm);
-               
+
                for (i = 0; i < num_faces; i++, mf++) {
                        for (j=0; j<4; j++) {
 
                                if (j == 3 && !mf->v4) continue;
-                               
+
                                switch(j) {
                                        case 0:
                                                u = ocean_co(omd, mv[mf->v1].co[0]);
@@ -454,11 +454,11 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob),
 
                                                break;
                                }
-                               
+
                                if (omd->oceancache && omd->cached==TRUE) {
                                        BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
                                        foam = ocr.foam;
-                                       CLAMP(foam, 0.0, 1.0);
+                                       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);
@@ -470,25 +470,25 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob),
                        }
                }
        }
-       
-       
+
+
        /* 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]);
-               
+
                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];
-               
-               if (omd->chop_amount > 0.0) {
+
+               if (omd->chop_amount > 0.0f) {
                        mv[i].co[0] += ocr.disp[0];
                        mv[i].co[1] += ocr.disp[2];
                }
@@ -514,12 +514,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
                                                                  int UNUSED(isFinalCalc))
 {
        DerivedMesh *result;
-       
+
        result = doOcean(md, ob, derivedData, 0);
-       
+
        if(result != derivedData)
                CDDM_calc_normals(result);
-       
+
        return result;
 }
 
index 95985eb7f2be739801437ae3680f5350abc68b2c..fe63b51b150f5f79f34ea01a794a032e92254858 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
@@ -64,55 +64,55 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres)
        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, &ocr, cfra, u, v);
-               
+
                } else {        // non-cached
-                       
+
                        if (G.rendering)
                                BKE_ocean_eval_uv_catrom(omd->ocean, &ocr, u, v);
                        else
                                BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
-                       
+
                        ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
                }
        }
-       
-       
+
+
        switch (ot->output) {
                case TEX_OCN_DISPLACEMENT:
                        /* XYZ displacement */
                        texres->tr = 0.5f + 0.5f * ocr.disp[0];
                        texres->tg = 0.5f + 0.5f * ocr.disp[2];
                        texres->tb = 0.5f + 0.5f * ocr.disp[1];
-                       
+
                        texres->tr = MAX2(0.0f, texres->tr);
                        texres->tg = MAX2(0.0f, texres->tg);
                        texres->tb = MAX2(0.0f, texres->tb);
 
                        BRICONTRGB;
-                       
+
                        retval = TEX_RGB;
                        break;
-               
+
                case TEX_OCN_EMINUS:
                        /* -ve eigenvectors ? */
                        texres->tr = ocr.Eminus[0];
@@ -120,7 +120,7 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres)
                        texres->tb = ocr.Eminus[1];
                        retval = TEX_RGB;
                        break;
-               
+
                case TEX_OCN_EPLUS:
                        /* -ve eigenvectors ? */
                        texres->tr = ocr.Eplus[0];
@@ -128,18 +128,18 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres)
                        texres->tb = ocr.Eplus[1];
                        retval = TEX_RGB;
                        break;
-                       
+
                case TEX_OCN_JPLUS:
                        texres->tin = ocr.Jplus;
                        retval = TEX_INT;
                        break;
 
                case TEX_OCN_FOAM:
-                       
+
                        texres->tin = ocr.foam;
 
                        BRICONT;
-                       
+
                        retval = TEX_INT;
                        break;
        }
@@ -150,9 +150,8 @@ int ocean_texture(Tex *tex, float *texvec, TexResult *texres)
                normalize_v3_v3(texres->nor, ocr.normal);
                retval |= TEX_NOR;
        }
-       
+
        texres->ta = 1.0f;
-       
+
        return retval;
 }
-