# Noise Library v1.1 - Open Simplex (2D) Update

This bundle is marked as approved. It works and satisfies the submission rules.

### v1.0

Open Simplex (2D) Update

This resource is renamed from Perlin Noise to Noise Library since now it features two different Noise functions.

You can now use the 2D Open Simplex Noise function in JASS/vJASS/Lua/Wurst. It is port of Kurt Spencer's Open Simplex Noise. His source code can be found here.

Noise Viewer

The Noise Viewer now supports amplitude when generating Perlin Noise (Octave Perlin is not included) and Open Simplex Noise.

You can now also generate 2D Open Simplex Noise in the Noise Viewer.

Chillup Support For Wurst

wurstNoiselib can now be searched in Codemonkey11's chillup.

Warcraft III pre-1.29 Support for JASS and vJASS

You can now use Noise Library before the Bitwise operator natives are implemented in Warcraft III. You could read more about it here.

I haven't found any resources about Perlin Noise in Warcraft III, so I think this is a good start.

Perlin Noise is a type of gradient noise developed by Kenneth Perlin. For this resource, it uses his Improved Noise (2002). The source code can be found here.

This script is available for JASS, vJass, Lua, and Wurst.

Features

It features 1D, 2D, and 3D Perlin noise, the example maps only uses the 2D version.

It uses a permutation table. It represents as an array in JASS/vJass/Wurst and an integer table for Lua. As it follow Kenneth Perlin's implementation, the first 256 elements (0 - 255) contains random integer values ranges from 0 to 255. The elements from 256 - 512 only repeats the values of the first 256 elements. I think it is to avoid overflow?

You can modify the permutation table to satisfy your needs.

Popular sandbox games like Minecraft and Terraria uses a similar algorithm to create procedural generated terrain. This means you could now do the same in Warcraft III.

Sample Map

Application for custom maps

The video below is an early version of the code, written in Wurst.

Wurst Features

You can use Grill to add wurstNoiselib as a dependency to your project:

Code:
grill install https://github.com/eGlint/wurstNoiselib

wurstNoiselib is also searchable in Codemonkey11's chillup.

Requires
None (JASS/vJASS/Lua)
WurstStdlib2 (Wurst)
Bitwise (JASS pre-1.29)
Bitwise (vJASS pre-1.29)

Optional
OctavePerlin (plugin for Perlin Noise, comes along with it, original source)

Code

JASS, changelog
JASS (pre-1.29), changelog
vJASS, changelog
vJASS (pre-1.29), changelog
Lua, changelog
Wurst, changelog

Examples

### Wurst

JASS:
function GetResult takes nothing returns nothing
local real x = (udg_Offset_X + udg_World_Offset_X + I2R(udg_X)) * udg_Scale
local real y = (udg_Offset_Y + udg_World_Offset_Y + I2R(udg_Y)) * udg_Scale
if udg_IsOpenSimplex then
set udg_Result = OpenSimplex2D(x, y) * udg_Amplitude
elseif udg_IsOctavePerlin then
set udg_Result = OctavePerlin2D(x, y, udg_Octaves, udg_Persistence)
else
set udg_Result = PerlinNoise2D(x, y) * udg_Amplitude
endif
set x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
set y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
if udg_Result < 0 then
set udg_Result = udg_Result * -1
endif
if udg_Result < .1 then
call SetTerrainType(x, y, 'Ldrt', 0, 1, 0)
elseif udg_Result < .2 then
call SetTerrainType(x, y, 'Ldro', 0, 1, 0)
elseif udg_Result < .25 then
call SetTerrainType(x, y, 'Lgrs', 0, 1, 0)
elseif udg_Result < .5 then
call SetTerrainType(x, y, 'Ldrg', 0, 1, 0)
else
call SetTerrainType(x, y, 'Lrok', 0, 1, 0)
endif
endfunction

vJASS:
function GetResult takes nothing returns nothing
local real x = (udg_Offset_X + udg_World_Offset_X + I2R(udg_X)) * udg_Scale
local real y = (udg_Offset_Y + udg_World_Offset_Y + I2R(udg_Y)) * udg_Scale
if udg_IsOpenSimplex then
set udg_Result = Noise.openSimplex2D(x, y) * udg_Amplitude
elseif udg_IsOctavePerlin then
set udg_Result = Noise.octavePerlin2D(x, y, udg_Octaves, udg_Persistence)
else
set udg_Result = Noise.perlin2D(x, y) * udg_Amplitude
endif
set x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
set y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
if udg_Result < 0 then
set udg_Result = udg_Result * -1
endif
if udg_Result < .1 then
call SetTerrainType(x, y, 'Ldrt', 0, 1, 0)
elseif udg_Result < .2 then
call SetTerrainType(x, y, 'Ldro', 0, 1, 0)
elseif udg_Result < .25 then
call SetTerrainType(x, y, 'Lgrs', 0, 1, 0)
elseif udg_Result < .5 then
call SetTerrainType(x, y, 'Ldrg', 0, 1, 0)
else
call SetTerrainType(x, y, 'Lrok', 0, 1, 0)
endif
endfunction

Lua:
function GetResult ()
local x = (udg_Offset_X + udg_World_Offset_X + I2R(udg_X)) * udg_Scale
local y = (udg_Offset_Y + udg_World_Offset_Y + I2R(udg_Y)) * udg_Scale
if udg_IsOpenSimplex then
udg_Result = Noise.openSimplex2D(x, y) * udg_Amplitude
elseif udg_IsOctavePerlin then
udg_Result = Noise.octavePerlin2D(x, y,udg_Octaves, udg_Persistence)
else
udg_Result = Noise.perlin2D(x, y) * udg_Amplitude
end
x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
y = udg_World_Offset_Y + -( udg_Y * udg_PerSquare_Height)
if udg_Result < 0 then
udg_Result = udg_Result * -1.
end
if udg_Result < .1 then
SetTerrainType(x, y, FourCC("Ldrt"), 0, 1, 0)
elseif udg_Result < .2 then
SetTerrainType(x, y, FourCC("Ldro"), 0, 1, 0)
elseif udg_Result < .25 then
SetTerrainType(x, y, FourCC("Lgrs"), 0, 1, 0)
elseif udg_Result < .5 then
SetTerrainType(x, y, FourCC("Ldrg"), 0, 1, 0)
else
SetTerrainType(x, y, FourCC("Lrok"), 0, 1, 0)
end
end

Code:
function getResult()
real x
real y
let noisePos = vec2((udg_Offset_X + udg_World_Offset_X + udg_X) * udg_Scale,
(udg_Offset_Y + udg_World_Offset_Y + udg_Y) * udg_Scale)
if udg_IsOpenSimplex
udg_Result = Noise.openSimplex(noisePos) * udg_Amplitude
else if udg_IsOctavePerlin
udg_Result = octavePerlin(noisePos, udg_Octaves, udg_Persistence)
else
udg_Result = Noise.perlin(noisePos) * udg_Amplitude
x = udg_World_Offset_X + udg_X * udg_PerSquare_Width
y = udg_World_Offset_Y + -(udg_Y * udg_PerSquare_Height)
if udg_Result < 0
udg_Result *= -1
if udg_Result < .1
SetTerrainType(x, y, 'Ldrt', 0, 1, 0)
else if udg_Result < .3
SetTerrainType(x, y, 'Ldro', 0, 1, 0)
else if udg_Result < .6
SetTerrainType(x, y, 'Lgrs', 0, 1, 0)
else if udg_Result < .9
SetTerrainType(x, y, 'Ldrg', 0, 1, 0)
else
SetTerrainType(x, y, 'Lrok', 0, 1, 0)
Previews
Contents

# [vJASS] Noise Viewer (Map)

Spell Reviewer
Level 18
This … is quite an unusual resource in the Spells section. An algorithm of sorts that normally doesn't pertain to the usual ideas centered around spells. I'll reserve judgment to @Dr Super Good and @Frotty.

#### Frotty

Code Moderator
Level 18
Cool, Wurst code looks good from a first viewing. `lerp` already exists as `linear` in the Interpolation package.
Is there a git repo for it, so it can be used as dependency via grill? If not, that would be a nice addition.
Thumbs up for covering all scripting languages

#### Drake53

Level 11
Thumbs up for covering all scripting languages
You sure you're not forgetting something? Don't worry though, I got you covered.

C#:
[NativeLuaMemberContainer]
internal static class PerlinNoise
{
[NativeLuaMember("Noise.perlin1D")]
public static extern float Noise(float x);

[NativeLuaMember("Noise.perlin2D")]
public static extern float Noise(float x, float y);

[NativeLuaMember("Noise.perlin3D")]
public static extern float Noise(float x, float y, float z);

[NativeLuaMember("Noise.permutationInit")]
public static extern void Init();
}

It's probably more efficient like this anyways, compared to writing the entire library in C#.

Also, spotted a small mistake here:
Lua:
function Noise.perlin1D (x, y, z)

#### Glint

Level 5
Is there a git repo for it, so it can be used as dependency via grill? If not, that would be a nice addition.

I'll work on that one. I was just to upload the source code in Github.

`lerp` already exists as `linear` in the Interpolation package.

Oh my, I even remember using it before. Well, I'm gonna update that one once I upload it to git.

Also, spotted a small mistake here:
Lua:
function Noise.perlin1D (x, y, z)

Nice catch! I caught another one as well.

Lua:

I updated the Lua version to 1.0.1.

#### Glint

Level 5
JASS, vJASS and Lua now have a git repository.

Updated Wurst version to 1.0.1.
- Removed lerp() and used the one in the standard library: real.lerp()

Also for Wurst, you can now use Grill to add wurstNoiselib as a dependency to your project.

Code:
grill install https://github.com/eGlint/wurstNoiselib
grill install

#### Chaosy

Tutorial Reviewer
Level 37
Underrated dedication to multiple languages.

I do not have use for this right now, but I will try to keep it in mind in the future

#### Frotty

Code Moderator
Level 18
Also for Wurst, you can now use Grill to add wurstNoiselib as a dependency to your project.

Code:
grill install https://github.com/eGlint/wurstNoiselib
grill install

You don't need an 'install' after installing the dependency.
Other than that, good stuff

#### Glint

Level 5
You don't need an 'install' after installing the dependency.
Other than that, good stuff
Oh, thank you for the correction.

#### Cheezeman

Level 9
The elements from 256 - 512 only repeats the values of the first 256 elements. I think it is to avoid overflow?

Iirc perlin says in the paper it is to align the array with memory or some such. He mentions it anyway.

#### Edy

Level 9
1x1 pathing blockers and smaller tiles are the things that I hope for Wc3.
Good stuff

#### Kakerate

Level 10
Good work man, I came upon this after a GDC talk about using perlin noise to generate camera shake. Thanks!

Last edited:

#### Glint

Level 5
I just renamed this resource from Perlin Noise to Noise Library since it now features two different Noise functions for the new update (v1.1).

Check out the new changes especially the new function: 2D Open Simplex Noise.

Replies
5
Views
9K
Replies
11
Views
5K
Replies
8
Views
3K
Replies
23
Views
5K
Replies
24
Views
5K