Explorar el Código

REVIEWED: `GenImagePerlinNoise()`, no change

Ray hace 2 años
padre
commit
f31df7521a
Se han modificado 1 ficheros con 12 adiciones y 7 borrados
  1. 12 7
      src/rtextures.c

+ 12 - 7
src/rtextures.c

@@ -833,18 +833,23 @@ Image GenImagePerlinNoise(int width, int height, int offsetX, int offsetY, float
     {
         for (int x = 0; x < width; x++)
         {
-            float nx = (float)(x + offsetX)*scale/(float)width;
-            float ny = (float)(y + offsetY)*scale/(float)height;
-
+            float nx = (float)(x + offsetX)*(scale/(float)width);
+            float ny = (float)(y + offsetY)*(scale/(float)height);
+            
+            // Basic perlin noise implementation (not used)
+            //float p = (stb_perlin_noise3(nx, ny, 0.0f, 0, 0, 0);
+            
+            // Calculate a better perlin noise using fbm (fractal brownian motion)
             // Typical values to start playing with:
             //   lacunarity = ~2.0   -- spacing between successive octaves (use exactly 2.0 for wrapping output)
             //   gain       =  0.5   -- relative weighting applied to each successive octave
             //   octaves    =  6     -- number of "octaves" of noise3() to sum
+            float p = stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6);
+            
+            // We need to normalize the data from [-1..1] to [0..1]
+            float np = (p + 1.0f)/2.0f;
 
-            // NOTE: We need to translate the data from [-1..1] to [0..1]
-            float p = (stb_perlin_fbm_noise3(nx, ny, 1.0f, 2.0f, 0.5f, 6) + 1.0f)/2.0f;
-
-            int intensity = (int)(p*255.0f);
+            int intensity = (int)(np*255.0f);
             pixels[y*width + x] = (Color){ intensity, intensity, intensity, 255 };
         }
     }