[Bf-blender-cvs] [6ce709dceb8] master: Ocean: add new spectra modes to the ocean modifier

Phil Stopford noreply at git.blender.org
Thu Mar 12 05:50:24 CET 2020


Commit: 6ce709dceb8db65ec6baae21100a7ce93829b1f6
Author: Phil Stopford
Date:   Thu Mar 12 13:35:22 2020 +1100
Branches: master
https://developer.blender.org/rB6ce709dceb8db65ec6baae21100a7ce93829b1f6

Ocean: add new spectra modes to the ocean modifier

This extends the ocean modifier to add new spectra
(Pierson-Moskowitz, Jonswap, TMA).

These models are very different to the Phillips spectrum.
They are intended for more established,
large area, oceans and/or shallow water situations.

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_ocean.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/ocean.c
A	source/blender/blenkernel/intern/ocean_intern.h
A	source/blender/blenkernel/intern/ocean_spectrum.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/makesdna/DNA_modifier_types.h
M	source/blender/makesrna/intern/rna_modifier.c
M	source/blender/modifiers/intern/MOD_ocean.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 3cefbee8c17..7448fbcc145 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -725,6 +725,19 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "size")
         col.prop(md, "spatial_size")
 
+        layout.separator()
+
+        layout.prop(md, "spectrum")
+
+        if md.spectrum in {'TEXEL_MARSEN_ARSLOE', 'JONSWAP'}:
+            split = layout.split()
+
+            col = split.column()
+            col.prop(md, "sharpen_peak_jonswap")
+
+            col = split.column()
+            col.prop(md, "fetch_jonswap")
+
         layout.label(text="Waves:")
 
         split = layout.split()
diff --git a/source/blender/blenkernel/BKE_ocean.h b/source/blender/blenkernel/BKE_ocean.h
index 3ba6486e6c5..d3ac825039d 100644
--- a/source/blender/blenkernel/BKE_ocean.h
+++ b/source/blender/blenkernel/BKE_ocean.h
@@ -84,6 +84,9 @@ void BKE_ocean_init(struct Ocean *o,
                     float alignment,
                     float depth,
                     float time,
+                    int spectrum,
+                    float fetch_jonswap,
+                    float sharpen_peak_jonswap,
                     short do_height_field,
                     short do_chop,
                     short do_normals,
@@ -122,6 +125,11 @@ void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, in
 void BKE_ocean_free_cache(struct OceanCache *och);
 void BKE_ocean_free_modifier_cache(struct OceanModifierData *omd);
 
+/* ocean_spectrum.c */
+float BLI_ocean_spectrum_piersonmoskowitz(const struct Ocean *oc, const float kx, const float kz);
+float BLI_ocean_spectrum_texelmarsenarsloe(const struct Ocean *oc, const float kx, const float kz);
+float BLI_ocean_spectrum_jonswap(const struct Ocean *oc, const float kx, const float kz);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 58f05f65bef..112933e40be 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -178,6 +178,7 @@ set(SRC
   intern/object_facemap.c
   intern/object_update.c
   intern/ocean.c
+  intern/ocean_spectrum.c
   intern/outliner_treehash.c
   intern/packedFile.c
   intern/paint.c
diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c
index c27fb59835f..26485d10fbd 100644
--- a/source/blender/blenkernel/intern/ocean.c
+++ b/source/blender/blenkernel/intern/ocean.c
@@ -38,11 +38,11 @@
 #include "BLI_path_util.h"
 #include "BLI_rand.h"
 #include "BLI_task.h"
-#include "BLI_threads.h"
 #include "BLI_utildefines.h"
 
 #include "BKE_image.h"
 #include "BKE_ocean.h"
+#include "ocean_intern.h"
 
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
@@ -54,95 +54,6 @@
 #ifdef WITH_OCEANSIM
 
 /* Ocean code */
-#  include "fftw3.h"
-
-#  define GRAVITY 9.81f
-
-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;
-
-  /* mutex for threaded texture access */
-  ThreadRWMutex oceanmutex;
-
-  /* ********* sim data arrays ********* */
-
-  /* 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 */
-  fftw_complex *_fft_in_jzz; /* init w   sim w */
-  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? */
-  /* all member of this array has same values,
-   * so convert this array to a float to reduce memory usage (MEM01). */
-  /*float * _N_y; */
-  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(RNG *rng, float min, float max)
 {
@@ -285,7 +196,7 @@ 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;
+  return foam;
 }
 
 void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v)
@@ -893,6 +804,9 @@ void BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData
                  omd->wave_alignment,
                  omd->depth,
                  omd->time,
+                 omd->spectrum,
+                 omd->fetch_jonswap,
+                 omd->sharpen_peak_jonswap,
                  do_heightfield,
                  do_chop,
                  do_normals,
@@ -913,6 +827,9 @@ void BKE_ocean_init(struct Ocean *o,
                     float alignment,
                     float depth,
                     float time,
+                    int spectrum,
+                    float fetch_jonswap,
+                    float sharpen_peak_jonswap,
                     short do_height_field,
                     short do_chop,
                     short do_normals,
@@ -940,6 +857,13 @@ void BKE_ocean_init(struct Ocean *o,
   o->_L = V * V / GRAVITY; /* largest wave for a given velocity V */
   o->time = time;
 
+  /* Spectrum to use. */
+  o->_spectrum = spectrum;
+
+  /* Common JONSWAP parameters. */
+  o->_fetch_jonswap = fetch_jonswap;
+  o->_sharpen_peak_jonswap = sharpen_peak_jonswap;
+
   o->_do_disp_y = do_height_field;
   o->_do_normals = do_normals;
   o->_do_chop = do_chop;
@@ -1001,10 +925,46 @@ void BKE_ocean_init(struct Ocean *o,
 
       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)));
+      switch (o->_spectrum) {
+        case MOD_OCEAN_SPECTRUM_JONSWAP:
+          mul_complex_f(o->_h0[i * o->_N + j],
+                        r1r2,
+                        (float)(sqrt(BLI_ocean_spectrum_jonswap(o, o->_kx[i], o->_kz[j]) / 2.0f)));
+          mul_complex_f(
+              o->_h0_minus[i * o->_N + j],
+              r1r2,
+              (float)(sqrt(BLI_ocean_spectrum_jonswap(o, -o->_kx[i], -o->_kz[j]) / 2.0f)));
+          break;
+        case MOD_OCEAN_SPECTRUM_TEXEL_MARSEN_ARSLOE:
+          mul_complex_f(
+              o->_h0[i * o->_N + j],
+              r1r2,
+              (float)(sqrt(BLI_ocean_spectrum_texelmarsenarsloe(o, o->_kx[i], o->_kz[j]) / 2.0f)));
+          mul_complex_f(
+              o->_h0_minus[i * o->_N + j],
+              r1r2,
+              (float)(sqrt(BLI_ocean_spectrum_texelmarsenarsloe(o, -o->_kx[i], -o->_kz[j]) /
+                           2.0f)));
+          break;
+        case MOD_OCEAN_SPECTRUM_PIERSON_MOSKOWITZ:
+          mul_complex_f(
+              o->_h0[i * o->_N + j],
+              r1r2,
+              (float)(sqrt(BLI_ocean_spectrum_piersonmoskowitz(o, o->_kx[i], o->_kz[j]) / 2.0f)));
+          mul_complex_f(
+              o->_h0_minus[i * o->_N + j],
+              r1r2,
+              (float)(sqrt(BLI_ocean_spectrum_piersonmoskowitz(o, -o->_kx[i], -o->_kz[j]) /
+                           2.0f)));
+          break;
+        default:
+          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)));
+          break;
+      }
     }
   }
 
@@ -1517,12 +1477,6 @@ void BKE_ocean_bake(struct Ocean *o,
 
 #else /* WITH_OCEANSIM */
 
-/* stub */
-typedef struct Ocean {
-  /* need some data here, C does not allow empty struct */
-  int stub;
-} Ocean;
-
 float BKE_ocean_jminus_to_foam(float UNUSED(jminus), float UNUSED(coverage))
 {
   return 0.0f;
@@ -1591,6 +1545,9 @@ void BKE_ocean_init(struct Ocean *UNUSED(o),
                     float UNUSED(alignment),
                     float UNUSED(depth),
                     float UNUSED(time),
+                    int UNUSED(spectrum),
+                    float UNUSED(fetch_jonswap),
+                    float UNUSED(sharpen_peak_jonswap),
                     short UNUSED(do_height_field),
                     short UNUSED(do_chop),
                     short UNUSED(do_normals),
diff --git a/source/blender/b

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list