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

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

v1.1

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

JASS

vJASS

Lua

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

WurstNoiseViewer (Map)

[JASS] Noise Viewer (Map)

[Lua] Noise Viewer (Map)

[vJASS] Noise Viewer (Map)

Level 11
Joined
Jan 1, 2018
Messages
520
Thumbs up for covering all scripting languages :thumbs_up:
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)
 
Level 5
Joined
Dec 28, 2014
Messages
78
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:
function Noise.grad1D (hash, x, y)

I updated the Lua version to 1.0.1.
 
Top