perdugames / SoftNoise-GDScript-

GDScript function set generating noise (value noise, perlin noise, opensimplex(2d, 3d and 4d)...).
MIT License
108 stars 23 forks source link

openSimplex2D returns values below 0.0 #5

Closed shackra closed 6 years ago

shackra commented 6 years ago

I'm using your class in Godot 3.0 stable.

I notice that sometimes your openSimplex2D method generates negative numbers. You can see an example in this screenshot:

imagen

Here is part of the code I'm using with your SoftNoise class

extends TileMap

const preScript = preload("res://scripts/utils/noise.gd")
onready var softnoise = preScript.SoftNoise.new(1239)

func map2tile(value, tilemin, tilemax):
    # Check that the values were passed in correct order
    if tilemin > tilemax:
        var tmp = tilemax
        tilemax = tilemin
        tilemin = tmp

    var this = tilemin + (tilemax - tilemin - 1) * value
    if this < 0:
        breakpoint

    return this

func draw_tiles(w, h):
    # Draw tiles
    # 0: Sand, 1: Sand with grass, 2: Grass, 3: Dark grass
    for i in range(w):
        for j in range(h):
            var value = softnoise.openSimplex2D(i, j)
            var tilen = map2tile(value, 0, 4)
            set_cell(i, j, tilen)

Because of this illegal value returned by the method the end result on my game's level do not look that nice:

imagen

perdugames commented 6 years ago

That's right, opensimplex generates numbers from -1 to 1.

shackra commented 6 years ago

Uh, in such case ignore me.

I didn't known, sorry for this report.