Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converted to use SimplexNoise, and removed progress bar #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 30 additions & 24 deletions main.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
extends WorldEnvironment

export(int,1,10) var noise_octaves = 6
export(float) var noise_period = 8.0
export(float) var noise_persistence = 0.8

onready var progress = $container/progress
onready var mesh_original = $planet/Planet.mesh

Expand Down Expand Up @@ -28,30 +32,32 @@ func make_planet():
#show the progress bar
progress.show()

var max_iterations = 145
for j in range(max_iterations):

# wait a frame to prevent freezing the game
yield(get_tree(), "idle_frame")

# show progress in the progress bar
progress.max_value = max_iterations
progress.value = j

var dir = Vector3(rand_range(-1,1), rand_range(-1,1), rand_range(-1,1)).normalized()

# push/pull all vertices (this is the slow part)
for i in range(surf.get_vertex_count()):
var v = surf.get_vertex(i)
var norm = surf.get_vertex_normal(i)

var dot = norm.normalized().dot(dir)
var sharpness = 50 # how sharp the edges are
dot = exp(dot*sharpness) / (exp(dot*sharpness) + 1) - 0.5 # sigmoid function

v += dot * norm * 0.01

surf.set_vertex(i, v)
var noise = OpenSimplexNoise.new()
noise.seed = randi()
noise.octaves = noise_octaves
noise.period = noise_period
noise.persistence = noise_persistence

# show progress in the progress bar
# progress.max_value = max_iterations
# progress.value = j

var dir = Vector3(rand_range(-1,1), rand_range(-1,1), rand_range(-1,1)).normalized()

# Add a randomness to the 4th dimension, otherwise we are only on the
# 3d points of the sphere, which are the same...
var dim = rand_range(-1,1)

# push/pull all vertices (this is the slow part)
for i in range(surf.get_vertex_count()):
var v = surf.get_vertex(i)
var norm = surf.get_vertex_normal(i)

var n = noise.get_noise_4d(v.x, v.y, v.z, dim)

v += n * norm * dim

surf.set_vertex(i, v)

var min_dist = 0.9 # deep sea
var max_dist = 1.1 # mountains
Expand Down
7 changes: 6 additions & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
; [section] ; section goes between []
; param=value ; assign values to parameters

config_version=3
config_version=4

_global_script_classes=[ ]
_global_script_class_icons={

}

[application]

Expand Down