99 simulate_ocean_modifier(omd);
136 simulate_ocean_modifier(tomd);
172 typedef struct GenerateOceanGeometryData {
183 } GenerateOceanGeometryData;
185 static void generate_ocean_geometry_vertices(
void *__restrict userdata,
189 GenerateOceanGeometryData *gogd = userdata;
192 for (
x = 0;
x <= gogd->res_x;
x++) {
193 const int i =
y * (gogd->res_x + 1) +
x;
194 float *co = gogd->mverts[i].co;
195 co[0] = gogd->ox + (
x * gogd->sx);
196 co[1] = gogd->oy + (
y * gogd->sy);
201 static void generate_ocean_geometry_polygons(
void *__restrict userdata,
205 GenerateOceanGeometryData *gogd = userdata;
208 for (
x = 0;
x < gogd->res_x;
x++) {
209 const int fi =
y * gogd->res_x +
x;
210 const int vi =
y * (gogd->res_x + 1) +
x;
211 MPoly *mp = &gogd->mpolys[fi];
212 MLoop *ml = &gogd->mloops[fi * 4];
218 ml->
v = vi + 1 + gogd->res_x + 1;
220 ml->
v = vi + gogd->res_x + 1;
223 mp->loopstart = fi * 4;
230 static void generate_ocean_geometry_uvs(
void *__restrict userdata,
234 GenerateOceanGeometryData *gogd = userdata;
237 for (
x = 0;
x < gogd->res_x;
x++) {
238 const int i =
y * gogd->res_x +
x;
239 MLoopUV *luv = &gogd->mloopuvs[i * 4];
241 luv->
uv[0] =
x * gogd->ix;
242 luv->
uv[1] =
y * gogd->iy;
245 luv->
uv[0] = (
x + 1) * gogd->ix;
246 luv->
uv[1] =
y * gogd->iy;
249 luv->
uv[0] = (
x + 1) * gogd->ix;
250 luv->
uv[1] = (
y + 1) * gogd->iy;
253 luv->
uv[0] =
x * gogd->ix;
254 luv->
uv[1] = (
y + 1) * gogd->iy;
263 GenerateOceanGeometryData gogd;
268 const bool use_threading = resolution > 4;
270 gogd.rx = resolution * resolution;
271 gogd.ry = resolution * resolution;
272 gogd.res_x = gogd.rx * omd->
repeat_x;
273 gogd.res_y = gogd.ry * omd->
repeat_y;
275 num_verts = (gogd.res_x + 1) * (gogd.res_y + 1);
276 num_polys = gogd.res_x * gogd.res_y;
280 gogd.ox = -gogd.sx / 2.0f;
281 gogd.oy = -gogd.sy / 2.0f;
289 gogd.mverts =
result->mvert;
290 gogd.mpolys =
result->mpoly;
291 gogd.mloops =
result->mloop;
311 gogd.ix = 1.0 / gogd.rx;
312 gogd.iy = 1.0 / gogd.ry;
328 bool allocated_ocean =
false;
345 # define OCEAN_CO(_size_co_inv, _v) ((_v * _size_co_inv) + 0.5f)
355 if (omd->
cached ==
true) {
357 init_cache_data(ob, omd, resolution);
368 simulate_ocean_modifier(omd);
372 result = generate_ocean_geometry(omd,
mesh, resolution);
379 cfra_for_cache = cfra_scene;
389 const int num_polys =
result->totpoly;
390 const int num_loops =
result->totloop;
405 for (i = 0, mp = mpolys; i < num_polys; i++, mp++) {
411 mlcolspray = &mloopcols_spray[mp->
loopstart];
414 for (j = mp->
totloop; j--; ml++, mlcol++) {
415 const float *vco = mverts[ml->
v].co;
416 const float u = OCEAN_CO(size_co_inv, vco[0]);
417 const float v = OCEAN_CO(size_co_inv, vco[1]);
423 CLAMP(foam, 0.0f, 1.0f);
430 mlcol->
r = mlcol->
g = mlcol->
b = (char)(foam * 255);
436 mlcolspray->
r = ocr.
Eminus[0] * 255;
439 mlcolspray->
r = ocr.
Eplus[0] * 255;
443 mlcolspray->
b = ocr.
Eminus[2] * 255;
446 mlcolspray->
b = ocr.
Eplus[2] * 255;
461 const int num_verts =
result->totvert;
463 for (i = 0; i < num_verts; i++) {
464 float *vco = mverts[i].co;
465 const float u = OCEAN_CO(size_co_inv, vco[0]);
466 const float v = OCEAN_CO(size_co_inv, vco[1]);
475 vco[2] += ocr.
disp[1];
478 vco[0] += ocr.
disp[0];
479 vco[1] += ocr.
disp[2];
484 if (allocated_ocean) {
533 uiItemR(sub,
ptr,
"viewport_resolution", 0,
IFACE_(
"Resolution Viewport"), ICON_NONE);
549 uiItemL(layout,
IFACE_(
"Built without Ocean modifier"), ICON_NONE);
671 "OBJECT_OT_ocean_bake",
681 uiItemO(layout,
NULL, ICON_NONE,
"OBJECT_OT_ocean_bake");
703 region_type,
"foam",
"", foam_panel_draw_header, foam_panel_draw, panel_type);
705 region_type,
"spray",
"", spray_panel_draw_header, spray_panel_draw, foam_panel);
707 region_type,
"spectrum",
"Spectrum",
NULL, spectrum_panel_draw, panel_type);
int CustomData_number_of_layers(const struct CustomData *data, int type)
void * CustomData_add_layer_named(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem, const char *name)
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
struct ID * BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag)
void BKE_mesh_ensure_normals(struct Mesh *me)
struct Mesh * BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
void BKE_mesh_calc_edges(struct Mesh *mesh, bool keep_existing_edges, const bool select_new_edges)
void BKE_mesh_copy_settings(struct Mesh *me_dst, const struct Mesh *me_src)
void BKE_modifier_path_init(char *path, int path_maxlen, const char *name)
@ eModifierTypeFlag_EnableInEditmode
@ eModifierTypeFlag_SupportsEditmode
@ eModifierTypeFlag_AcceptsMesh
const char * BKE_modifier_path_relbase_from_global(struct Object *ob)
void BKE_modifier_copydata_generic(const struct ModifierData *md, struct ModifierData *md_dst, const int flag)
@ eModifierTypeType_Constructive
void BKE_ocean_cache_eval_uv(struct OceanCache *och, struct OceanResult *ocr, int f, float u, float v)
struct OceanCache * BKE_ocean_init_cache(const char *bakepath, const char *relbase, int start, int end, float wave_scale, float chop_amount, float foam_coverage, float foam_fade, int resolution)
void BKE_ocean_simulate(struct Ocean *o, float t, float scale, float chop_amount)
float BKE_ocean_jminus_to_foam(float jminus, float coverage)
void BKE_ocean_free_cache(struct OceanCache *och)
void BKE_ocean_simulate_cache(struct OceanCache *och, int frame)
struct Ocean * BKE_ocean_add(void)
void BKE_ocean_eval_uv(struct Ocean *oc, struct OceanResult *ocr, float u, float v)
bool BKE_ocean_ensure(struct OceanModifierData *omd, const int resolution)
void BKE_ocean_free(struct Ocean *oc)
void BKE_ocean_init_from_modifier(struct Ocean *ocean, struct OceanModifierData const *omd, const int resolution)
void BLI_task_parallel_range(const int start, const int stop, void *userdata, TaskParallelRangeFunc func, const TaskParallelSettings *settings)
BLI_INLINE void BLI_parallel_range_settings_defaults(TaskParallelSettings *settings)
#define MEMCMP_STRUCT_AFTER_IS_ZERO(struct_var, member)
#define MEMCPY_STRUCT_AFTER(struct_dst, struct_src, member)
float DEG_get_ctime(const Depsgraph *graph)
#define DNA_struct_default_get(struct_name)
@ MOD_OCEAN_SPECTRUM_TEXEL_MARSEN_ARSLOE
@ MOD_OCEAN_SPECTRUM_JONSWAP
@ MOD_OCEAN_GEOM_GENERATE
@ MOD_OCEAN_GEOM_DISPLACE
struct OceanModifierData OceanModifierData
@ MOD_OCEAN_GENERATE_FOAM
@ MOD_OCEAN_GENERATE_SPRAY
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
static void blendRead(BlendDataReader *UNUSED(reader), ModifierData *md)
static void copyData(const ModifierData *md, ModifierData *target, const int flag)
static Mesh * modifyMesh(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
static void requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md), CustomData_MeshMasks *UNUSED(r_cddata_masks))
static bool dependsOnNormals(ModifierData *md)
ModifierTypeInfo modifierType_Ocean
static Mesh * doOcean(ModifierData *UNUSED(md), const ModifierEvalContext *UNUSED(ctx), Mesh *mesh)
static void panel_draw(const bContext *UNUSED(C), Panel *panel)
static void initData(ModifierData *md)
static void panelRegister(ARegionType *region_type)
static void freeData(ModifierData *md)
PointerRNA * modifier_panel_get_property_pointers(Panel *panel, PointerRNA *r_ob_ptr)
void modifier_panel_end(uiLayout *layout, PointerRNA *ptr)
PanelType * modifier_panel_register(ARegionType *region_type, ModifierType type, PanelDrawFn draw)
PanelType * modifier_subpanel_register(ARegionType *region_type, const char *name, const char *label, PanelDrawFn draw_header, PanelDrawFn draw, PanelType *parent)
Group RGB to Bright Vector Camera CLAMP
StructRNA RNA_OceanModifier
void uiLayoutSetActive(uiLayout *layout, bool active)
void uiLayoutSetEnabled(uiLayout *layout, bool enabled)
uiLayout * uiLayoutColumn(uiLayout *layout, bool align)
void uiItemFullO(uiLayout *layout, const char *opname, const char *name, int icon, struct IDProperty *properties, int context, int flag, struct PointerRNA *r_opptr)
void uiItemL(uiLayout *layout, const char *name, int icon)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
void uiItemS(uiLayout *layout)
uiLayout * uiLayoutRow(uiLayout *layout, bool align)
void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon)
void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
ATTR_WARN_UNUSED_RESULT const BMVert * v
void RNA_boolean_set(PointerRNA *ptr, const char *name, bool value)
float RNA_float_get(PointerRNA *ptr, const char *name)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
int RNA_enum_get(PointerRNA *ptr, const char *name)
struct Depsgraph * depsgraph
struct OceanCache * oceancache