Ocean modifier: fix changes to resolution complete changing the shape

This takes the idea from the aaOcean library to link the RNG seed to the
surface point, so that changing resolution only adds/remove surface detail.

Differential Revision: https://developer.blender.org/D6871
This commit is contained in:
Phil Stopford 2020-02-25 15:03:47 +01:00 committed by Brecht Van Lommel
parent 9cdf01085f
commit b0786d069c
1 changed files with 7 additions and 1 deletions

View File

@ -49,6 +49,8 @@
#include "RE_render_ext.h"
#include "BLI_hash.h"
#ifdef WITH_OCEANSIM
/* Ocean code */
@ -985,11 +987,15 @@ void BKE_ocean_init(struct Ocean *o,
}
}
/*srand(seed);*/
rng = BLI_rng_new(seed);
for (i = 0; i < o->_M; i++) {
for (j = 0; j < o->_N; j++) {
/* This ensures we get a value tied to the surface location, avoiding dramatic surface
* change with changing resolution. */
int new_seed = seed + BLI_hash_int_2d(o->_kx[i] * 360.0f, o->_kz[j] * 360.0f);
BLI_rng_seed(rng, new_seed);
float r1 = gaussRand(rng);
float r2 = gaussRand(rng);