• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Library] Simplex Noise - Noise Generation in PAWN
#1
Simplex Noise Generator!



____________________________________________________________________________________________________





Description:



This library basically adds a bunch of noise functions that you can use for various things.



So far I've converted the following functions from C to PAWN:
Code:
// Returns a 1D simplex noise

Float:noise1D(Float:x);

// Returns a 2D simplex noise

Float:noise2D(Float:x, Float:y);

// Returns a 3D simplex noise

Float:noise3D(Float:x, Float:y, Float:z);

// Returns a 4D simplex noise

Float:noise4D(Float:x, Float:y, Float:z, Float:w);



// Returns a 1D simplex ridged noise

Float:ridgedNoise1D(Float:x);

// Returns a 2D simplex ridged noise

Float:ridgedNoise2D(Float:x, Float:y);

// Returns a 3D simplex ridged noise

Float:ridgedNoise3D(Float:x, Float:y, Float:z);

// Returns a 4D simplex ridged noise

Float:ridgedNoise4D(Float:x, Float:y, Float:z, Float:w);



// Returns a 1D simplex noise with analytical derivative.

dnoise1D(Float:x, &Float:rx, &Float:ry)

// Returns a 2D simplex noise with analytical derivatives.

dnoise2D(Float:x, Float:y, &Float:rx, &Float:ry, &Float:rz)

// Returns a 3D simplex noise with analytical derivatives.

dnoise3D(Float:x, Float:y, Float:z, &Float:rx, &Float:ry, &Float:rz, &Float:rw)



// Returns a 2D simplex cellular/worley noise

Float:worleyNoise2D(Float:x, Float:y)

// Returns a 3D simplex cellular/worley noise

Float:worleyNoise3D(Float:x, Float:y, Float:z)

// Returns a 2D simplex smooth cellular/worley noise

Float:worleyNoise2D_F(Float:x, Float:y, Float:falloff)

// Returns a 3D simplex smooth cellular/worley noise

Float:worleyNoise3D_F(Float:x, Float:y, Float:z, Float:falloff)



[Image: NoiseGallery.jpg]



I used parts of this for my forest generator.?I generated multiple forests over a 3000 unit radius, so it covers all of SA. It has random clearings, camp areas, and rubbish areas. It also has various trees in their own areas (kind of like biomes), bushes, and rocks;



[Image: plants.bmp]

____________________________________________________________________________________________________





Examples:



Code:
main() {

? ? printf("noise1D: %f", noise1D(-45.1231));

? ? printf("noise2D: %f", noise2D(-45.1231, 10.9453));

? ? printf("noise3D: %f", noise3D(-45.1231, 10.9453, 32.3621));

? ? printf("noise4D: %f", noise4D(-45.1231, 10.9453, 32.3621, 100.6343));

? ??

? ? printf("ridgedNoise1D: %f", ridgedNoise1D(-45.1231));

? ? printf("ridgedNoise2D: %f", ridgedNoise2D(-45.1231, 10.9453));

? ? printf("ridgedNoise3D: %f", ridgedNoise3D(-45.1231, 10.9453, 32.3621));

? ? printf("ridgedNoise4D: %f", ridgedNoise4D(-45.1231, 10.9453, 32.3621, 100.6343));

? ??

? ? new Float:rx, Float:ry, Float:rz, Float:rw;

? ? dnoise1D(100.5, rx, ry);

? ? printf("dnoise1D: %f, %f", rx, ry);

? ? dnoise2D(110.53, -20.5, rx, ry, rz);

? ? printf("dnoise2D: %f, %f, %f", rx, ry, rz);

? ? dnoise3D(110.53, -20.85, 9.12, rx, ry, rz, rw);

? ? printf("dnoise3D: %f, %f, %f, %f", rx, ry, rz, rw);

? ??

? ? printf("worleyNoise2D: %f", worleyNoise2D(13.0, -34.1));

? ? printf("worleyNoise3D: %f", worleyNoise3D(13.52321, -34.1, -34.4));

? ? printf("worleyNoise2D_F: %f", worleyNoise2D_F(13.0, -34.1, 10.0));

? ? printf("worleyNoise3D_F: %f", worleyNoise3D_F(13.52321, -34.1, -34.4, 10.0));

}



Output:
Quote:noise1D: 0.117055

noise2D: -0.613689

noise3D: 0.060025

noise4D: -0.237536

ridgedNoise1D: 0.882944

ridgedNoise2D: 0.386310

ridgedNoise3D: 0.939974

ridgedNoise4D: 0.762463

dnoise1D: -0.875976, 9.531250

dnoise2D: 0.325981, -2.015559, -1.042779

dnoise3D: -0.662052, 1.085515, 0.660695, 1.227718

worleyNoise2D: 0.640313

worleyNoise3D: 0.412964

worleyNoise2D_F: 0.238459

worleyNoise3D_F: 0.173266

____________________________________________________________________________________________________





Credits:



simongeilfus for the original library in C : https://github.com/simongeilfus/SimplexNoise

____________________________________________________________________________________________________?







Downloads:



https://github.com/Crayder/SimplexNoise
[Image: uc?export=view&id=1C5dMc9kb09iAUuASWBEPCK21lsedAXmB]

  Reply
#2
This is genuinely impressive. I never saw this sort of procedural generation put in practice in SA-MP before.
  Reply


Forum Jump: