[Bf-blender-cvs] [b0786d069ce] master: Ocean modifier: fix changes to resolution complete changing the shape

Phil Stopford noreply at git.blender.org
Tue Feb 25 15:13:33 CET 2020


Commit: b0786d069cee989a924338fd450f7b4d5e7f47ce
Author: Phil Stopford
Date:   Tue Feb 25 15:03:47 2020 +0100
Branches: master
https://developer.blender.org/rBb0786d069cee989a924338fd450f7b4d5e7f47ce

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

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

M	source/blender/blenkernel/intern/ocean.c

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

diff --git a/source/blender/blenkernel/intern/ocean.c b/source/blender/blenkernel/intern/ocean.c
index 9faa61f986d..c27fb59835f 100644
--- a/source/blender/blenkernel/intern/ocean.c
+++ b/source/blender/blenkernel/intern/ocean.c
@@ -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);



More information about the Bf-blender-cvs mailing list