1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
19 #include <stdbool.h>
20 
21 /** \file
22  * \ingroup bli
23  */
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct OceanModifierData;
30 
31 typedef struct OceanResult {
32   float disp[3];
33   float normal[3];
34   float foam;
35 
36   /* raw eigenvalues/vectors */
37   float Jminus;
38   float Jplus;
39   float Eminus[3];
40   float Eplus[3];
41 } OceanResult;
42 
43 typedef struct OceanCache {
44   struct ImBuf **ibufs_disp;
45   struct ImBuf **ibufs_foam;
46   struct ImBuf **ibufs_norm;
47   /* spray is Eplus */
48   struct ImBuf **ibufs_spray;
49   /* spray_inverse is Eminus */
50   struct ImBuf **ibufs_spray_inverse;
51 
52   const char *bakepath;
53   const char *relbase;
54 
55   /* precalculated for time range */
56   float *time;
57 
58   /* constant for time range */
59   float wave_scale;
60   float chop_amount;
61   float foam_coverage;
62   float foam_fade;
63 
64   int start;
65   int end;
66   int duration;
67   int resolution_x;
68   int resolution_y;
69 
70   int baked;
71 } OceanCache;
72 
73 struct Ocean *BKE_ocean_add(void);
74 void BKE_ocean_free_data(struct Ocean *oc);
75 void BKE_ocean_free(struct Ocean *oc);
76 bool BKE_ocean_ensure(struct OceanModifierData *omd, const int resolution);
77 void BKE_ocean_init_from_modifier(struct Ocean *ocean,
78                                   struct OceanModifierData const *omd,
79                                   const int resolution);
80 
81 void BKE_ocean_init(struct Ocean *o,
82                     int M,
83                     int N,
84                     float Lx,
85                     float Lz,
86                     float V,
87                     float l,
88                     float A,
89                     float w,
90                     float damp,
91                     float alignment,
92                     float depth,
93                     float time,
94                     int spectrum,
95                     float fetch_jonswap,
96                     float sharpen_peak_jonswap,
97                     short do_height_field,
98                     short do_chop,
99                     short do_spray,
100                     short do_normals,
101                     short do_jacobian,
102                     int seed);
103 void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount);
104 
105 /* sampling the ocean surface */
106 float BKE_ocean_jminus_to_foam(float jminus, float coverage);
107 void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v);
108 void BKE_ocean_eval_uv_catrom(struct Ocean *oc, struct OceanResult *ocr, float u, float v);
109 void BKE_ocean_eval_xz(struct Ocean *oc, struct OceanResult *ocr, float x, float z);
110 void BKE_ocean_eval_xz_catrom(struct Ocean *oc, struct OceanResult *ocr, float x, float z);
111 void BKE_ocean_eval_ij(struct Ocean *oc, struct OceanResult *ocr, int i, int j);
112 
113 /* ocean cache handling */
114 struct OceanCache *BKE_ocean_init_cache(const char *bakepath,
115                                         const char *relbase,
116                                         int start,
117                                         int end,
118                                         float wave_scale,
119                                         float chop_amount,
120                                         float foam_coverage,
121                                         float foam_fade,
122                                         int resolution);
123 void BKE_ocean_simulate_cache(struct OceanCache *och, int frame);
124 
125 void BKE_ocean_bake(struct Ocean *o,
126                     struct OceanCache *och,
127                     void (*update_cb)(void *, float progress, int *cancel),
128                     void *update_cb_data);
129 void BKE_ocean_cache_eval_uv(
130     struct OceanCache *och, struct OceanResult *ocr, int f, float u, float v);
131 void BKE_ocean_cache_eval_ij(struct OceanCache *och, struct OceanResult *ocr, int f, int i, int j);
132 
133 void BKE_ocean_free_cache(struct OceanCache *och);
134 void BKE_ocean_free_modifier_cache(struct OceanModifierData *omd);
135 
136 /* ocean_spectrum.c */
137 float BLI_ocean_spectrum_piersonmoskowitz(const struct Ocean *oc, const float kx, const float kz);
138 float BLI_ocean_spectrum_texelmarsenarsloe(const struct Ocean *oc, const float kx, const float kz);
139 float BLI_ocean_spectrum_jonswap(const struct Ocean *oc, const float kx, const float kz);
140 
141 #ifdef __cplusplus
142 }
143 #endif
144