]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - fractalnoise.c
fractalnoise enhancements, better smoke textures, better bubble explosions, blood...
[xonotic/darkplaces.git] / fractalnoise.c
index 68f375ed2b4e414ca13b4993bca3ac345fe1f551..c03039a74f62218f484ecd8f1416584c19a8f27b 100644 (file)
@@ -1,16 +1,28 @@
 
 #include <stdlib.h>
 
-void fractalnoise(unsigned char *noise, int size)
+void fractalnoise(unsigned char *noise, int size, int startgrid)
 {
        int x, y, g, g2, amplitude, min, max, size1 = size - 1;
        int *noisebuf;
 #define n(x,y) noisebuf[((y)&size1)*size+((x)&size1)]
+       if (startgrid > size)
+               startgrid = size;
        noisebuf = calloc(size*size, sizeof(int));
 
        amplitude = 32767;
-       g2 = size;
-       n(0,0) = 0;
+       // quick 1x1 case which the rest of the code can't handle
+       if (startgrid < 2)
+       {
+               for (x = 0;x < size*size;x++)
+                       *noise++ = (rand()&255);
+               return;
+       }
+       g2 = startgrid;
+       // clear the starting grid (the rest does not need to be cleared, it will simply be overwritten)
+       for (y = 0;y < size;y += g2)
+               for (x = 0;x < size;x += g2)
+                       n(x,y) = 0;
        for (;(g = g2 >> 1) >= 1;g2 >>= 1)
        {
                // subdivide, diamond-square algorythm (really this has little to do with squares)