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

Controlling time from game loop instead of shader #1

Open
wants to merge 1 commit into
base: main
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
5 changes: 5 additions & 0 deletions GUI.gd
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,8 @@ func _seed_random():

func _on_Button_pressed():
_seed_random()

func _process(_delta):
var time = OS.get_ticks_msec() * 0.001
$Light.material.set_shader_param("time_elapsed", time)

32 changes: 16 additions & 16 deletions GUI.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ code = "shader_type canvas_item;
render_mode blend_mix;

uniform vec2 offset = vec2(0.0);

uniform float time_elapsed;

float rand(vec2 coord) {
return fract(sin(dot(coord.xy ,vec2(12.9898,78.233))) * 43758.5453);
Expand All @@ -22,14 +22,14 @@ vec2 rotate(vec2 coord, float angle){
}

void fragment() {
vec2 uv = rotate(UV, TIME * 0.2);
vec2 uv = rotate(UV, time_elapsed * 0.2);

vec4 col = vec4(1.0) + rand(UV + vec2(time_elapsed*0.0000001,0.0)) * 0.03;

vec4 col = vec4(1.0) + rand(UV + vec2(TIME*0.0000001,0.0)) * 0.03;

col = col* vec4(
abs(sin(uv.x * cos(offset.x)+ TIME * 0.105)),
abs(sin((cos(uv.x + uv.y) + cos(offset.x + offset.y) + TIME * 0.059))) ,
abs(cos(uv.y * sin(offset.y) + TIME * 0.0253)) ,
abs(sin(uv.x * cos(offset.x)+ time_elapsed * 0.105)),
abs(sin((cos(uv.x + uv.y) + cos(offset.x + offset.y) + time_elapsed * 0.059))) ,
abs(cos(uv.y * sin(offset.y) + time_elapsed * 0.0253)) ,
1.0);

COLOR = col;
Expand All @@ -38,6 +38,7 @@ void fragment() {
[sub_resource type="ShaderMaterial" id=2]
shader = SubResource( 1 )
shader_param/offset = Vector2( 0, 0 )
shader_param/time_elapsed = null

[sub_resource type="CanvasItemMaterial" id=3]
particles_animation = true
Expand Down Expand Up @@ -65,7 +66,7 @@ hue_variation_random = 1.0
anim_offset = 1.0
anim_offset_random = 1.0

[sub_resource type="Shader" id=10]
[sub_resource type="Shader" id=7]
code = "shader_type canvas_item;
render_mode unshaded;

Expand All @@ -84,8 +85,8 @@ void fragment () {
COLOR = color;
}"

[sub_resource type="ShaderMaterial" id=11]
shader = SubResource( 10 )
[sub_resource type="ShaderMaterial" id=8]
shader = SubResource( 7 )
shader_param/abberation = 0.001

[node name="GUI" type="Control"]
Expand Down Expand Up @@ -139,10 +140,10 @@ rect_pivot_offset = Vector2( 150, 150 )
[node name="Control" parent="HBoxContainer/PlanetHolder" instance=ExtResource( 3 )]
anchor_right = 0.0
anchor_bottom = 0.0
margin_left = 49.0
margin_top = 49.0
margin_right = 249.0
margin_bottom = 249.0
margin_left = 50.0
margin_top = 50.0
margin_right = 250.0
margin_bottom = 250.0

[node name="Settings" type="Control" parent="HBoxContainer"]
margin_left = 304.0
Expand Down Expand Up @@ -243,11 +244,10 @@ margin_right = 203.0
margin_bottom = 155.0
theme = ExtResource( 2 )
min_value = 30.0
max_value = 100.0
value = 70.0

[node name="Abberation" type="ColorRect" parent="."]
material = SubResource( 11 )
material = SubResource( 8 )
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
Expand Down
6 changes: 6 additions & 0 deletions Planets/GasPlanet/GasPlanet.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ func set_seed(sd):
$Cloud.material.set_shader_param("seed", converted_seed)
$Cloud2.material.set_shader_param("seed", converted_seed)
$Cloud2.material.set_shader_param("cloud_cover", rand_range(0.28, 0.5))

func _process(_delta):
var time = OS.get_ticks_msec() * 0.001
$Cloud.material.set_shader_param("time_elapsed", time)
$Cloud2.material.set_shader_param("time_elapsed", time)

23 changes: 12 additions & 11 deletions Planets/GasPlanet/GasPlanet.shader
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ uniform vec4 outline_color : hint_color;
uniform vec4 shadow_base_color : hint_color;
uniform vec4 shadow_outline_color : hint_color;

uniform float time_elapsed;
uniform float size = 50.0;
uniform int OCTAVES : hint_range(0, 20, 1);
uniform float seed: hint_range(1, 10);
Expand All @@ -26,7 +27,7 @@ float rand(vec2 coord) {
float noise(vec2 coord){
vec2 i = floor(coord);
vec2 f = fract(coord);

float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
Expand Down Expand Up @@ -66,14 +67,14 @@ float circleNoise(vec2 uv) {

float cloud_alpha(vec2 uv, float time) {
float c_noise = 0.0;


// more iterations for more turbulence
for (int i = 0; i < 15; i++) {
c_noise += circleNoise((uv * size *0.3) + (float(i+1)*10.) + (vec2(time*0.1, 0.0)));
}
float fbm = fbm(uv*size+c_noise + vec2(time*0.5, 0.0));

return fbm;//step(a_cutoff, fbm);
}

Expand All @@ -91,18 +92,18 @@ vec2 spherify(vec2 uv) {
void fragment() {
// pixelize uv
vec2 uv = floor(UV*pixels)/pixels;

// distance to light source
float d_light = distance(uv , light_origin);

// map to sphere
uv = spherify(uv);
// slightly make uv go down on the right, and up in the left
uv.y += smoothstep(0.0, cloud_curve, abs(uv.x-0.4));
float c = cloud_alpha(uv*vec2(1.0, stretch), TIME*time_speed);


float c = cloud_alpha(uv*vec2(1.0, stretch), time_elapsed*time_speed);

// assign some colors based on cloud depth & distance from light
vec3 col = base_color.rgb;
if (c < cloud_cover + 0.1) {
Expand All @@ -115,6 +116,6 @@ void fragment() {
if (d_light + c*0.2 > light_border_2) {
col = shadow_outline_color.rgb;
}

COLOR = vec4(col, step(cloud_cover, c));
}
27 changes: 15 additions & 12 deletions Planets/GasPlanet/GasPlanet.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uniform vec4 outline_color : hint_color;
uniform vec4 shadow_base_color : hint_color;
uniform vec4 shadow_outline_color : hint_color;

uniform float time_elapsed;
uniform float size = 50.0;
uniform int OCTAVES : hint_range(0, 20, 1);
uniform float seed: hint_range(1, 10);
Expand All @@ -32,7 +33,7 @@ float rand(vec2 coord) {
float noise(vec2 coord){
vec2 i = floor(coord);
vec2 f = fract(coord);

float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
Expand Down Expand Up @@ -72,14 +73,14 @@ float circleNoise(vec2 uv) {

float cloud_alpha(vec2 uv, float time) {
float c_noise = 0.0;


// more iterations for more turbulence
for (int i = 0; i < 15; i++) {
c_noise += circleNoise((uv * size *0.3) + (float(i+1)*10.) + (vec2(time*0.1, 0.0)));
}
float fbm = fbm(uv*size+c_noise + vec2(time*0.5, 0.0));

return fbm;//step(a_cutoff, fbm);
}

Expand All @@ -97,18 +98,18 @@ vec2 spherify(vec2 uv) {
void fragment() {
// pixelize uv
vec2 uv = floor(UV*pixels)/pixels;

// distance to light source
float d_light = distance(uv , light_origin);

// map to sphere
uv = spherify(uv);
// slightly make uv go down on the right, and up in the left
uv.y += smoothstep(0.0, cloud_curve, abs(uv.x-0.4));
float c = cloud_alpha(uv*vec2(1.0, stretch), TIME*time_speed);


float c = cloud_alpha(uv*vec2(1.0, stretch), time_elapsed*time_speed);

// assign some colors based on cloud depth & distance from light
vec3 col = base_color.rgb;
if (c < cloud_cover + 0.03) {
Expand All @@ -121,9 +122,9 @@ void fragment() {
if (d_light + c*0.2 > light_border_2) {
col = shadow_outline_color.rgb;
}





COLOR = vec4(col, step(cloud_cover, c));
}
"
Expand All @@ -142,6 +143,7 @@ shader_param/base_color = Color( 0.231373, 0.12549, 0.152941, 1 )
shader_param/outline_color = Color( 0.231373, 0.12549, 0.152941, 1 )
shader_param/shadow_base_color = Color( 0.129412, 0.0941176, 0.105882, 1 )
shader_param/shadow_outline_color = Color( 0.129412, 0.0941176, 0.105882, 1 )
shader_param/time_elapsed = null
shader_param/size = 9.0
shader_param/OCTAVES = 5
shader_param/seed = 5.939
Expand All @@ -160,6 +162,7 @@ shader_param/base_color = Color( 0.941176, 0.709804, 0.254902, 1 )
shader_param/outline_color = Color( 0.811765, 0.458824, 0.168627, 1 )
shader_param/shadow_base_color = Color( 0.670588, 0.317647, 0.188235, 1 )
shader_param/shadow_outline_color = Color( 0.490196, 0.219608, 0.2, 1 )
shader_param/time_elapsed = null
shader_param/size = 9.0
shader_param/OCTAVES = 5
shader_param/seed = 5.939
Expand Down
25 changes: 13 additions & 12 deletions Planets/LandMasses/Clouds.shader
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ uniform vec4 outline_color : hint_color;
uniform vec4 shadow_base_color : hint_color;
uniform vec4 shadow_outline_color : hint_color;

uniform float time_elapsed;
uniform float size = 50.0;
uniform int OCTAVES : hint_range(0, 20, 1);
uniform float seed: hint_range(1, 10);
Expand All @@ -26,7 +27,7 @@ float rand(vec2 coord) {
float noise(vec2 coord){
vec2 i = floor(coord);
vec2 f = fract(coord);

float a = rand(i);
float b = rand(i + vec2(1.0, 0.0));
float c = rand(i + vec2(0.0, 1.0));
Expand Down Expand Up @@ -66,14 +67,14 @@ float circleNoise(vec2 uv) {

float cloud_alpha(vec2 uv, float time) {
float c_noise = 0.0;


// more iterations for more turbulence
for (int i = 0; i < 9; i++) {
c_noise += circleNoise((uv * size *0.3) + (float(i+1)*10.) + (vec2(time*0.1, 0.0)));
}
float fbm = fbm(uv*size+c_noise + vec2(time*0.5, 0.0));

return fbm;//step(a_cutoff, fbm);
}

Expand All @@ -91,18 +92,18 @@ vec2 spherify(vec2 uv) {
void fragment() {
// pixelize uv
vec2 uv = floor(UV*pixels)/pixels;

// distance to light source
float d_light = distance(uv , light_origin);

// map to sphere
uv = spherify(uv);
// slightly make uv go down on the right, and up in the left
uv.y += smoothstep(0.0, cloud_curve, abs(uv.x-0.4));
float c = cloud_alpha(uv*vec2(1.0, stretch), TIME*time_speed);


float c = cloud_alpha(uv*vec2(1.0, stretch), time_elapsed*time_speed);

// assign some colors based on cloud depth & distance from light
vec3 col = base_color.rgb;
if (c < cloud_cover + 0.03) {
Expand All @@ -115,8 +116,8 @@ void fragment() {
if (d_light + c*0.2 > light_border_2) {
col = shadow_outline_color.rgb;
}





COLOR = vec4(col, step(cloud_cover, c));
}
9 changes: 8 additions & 1 deletion Planets/LandMasses/LandMasses.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends "res://Planets/Planet.gd"

func set_pixels(amount):
func set_pixels(amount):
$Water.material.set_shader_param("pixels", amount)
$Land.material.set_shader_param("pixels", amount)
$Cloud.material.set_shader_param("pixels", amount)
Expand All @@ -16,3 +16,10 @@ func set_seed(sd):
$Water.material.set_shader_param("seed", converted_seed)
$Land.material.set_shader_param("seed", converted_seed)
$Cloud.material.set_shader_param("cloud_cover", rand_range(0.35, 0.6))

func _process(_delta):
var time = OS.get_ticks_msec() * 0.001
$Cloud.material.set_shader_param("time_elapsed", time)
$Water.material.set_shader_param("time_elapsed", time)
$Land.material.set_shader_param("time_elapsed", time)

3 changes: 3 additions & 0 deletions Planets/LandMasses/LandMasses.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ shader_param/light_border_2 = 0.6
shader_param/color1 = Color( 0.572549, 0.909804, 0.752941, 1 )
shader_param/color2 = Color( 0.309804, 0.643137, 0.721569, 1 )
shader_param/color3 = Color( 0.172549, 0.207843, 0.301961, 1 )
shader_param/time_elapsed = null
shader_param/size = 5.228
shader_param/OCTAVES = 3
shader_param/seed = 10.0
Expand All @@ -33,6 +34,7 @@ shader_param/col1 = Color( 0.784314, 0.831373, 0.364706, 1 )
shader_param/col2 = Color( 0.388235, 0.670588, 0.247059, 1 )
shader_param/col3 = Color( 0.184314, 0.341176, 0.32549, 1 )
shader_param/col4 = Color( 0.156863, 0.207843, 0.25098, 1 )
shader_param/time_elapsed = null
shader_param/size = 4.292
shader_param/OCTAVES = 6
shader_param/seed = 7.947
Expand All @@ -51,6 +53,7 @@ shader_param/base_color = Color( 0.87451, 0.878431, 0.909804, 1 )
shader_param/outline_color = Color( 0.639216, 0.654902, 0.760784, 1 )
shader_param/shadow_base_color = Color( 0.407843, 0.435294, 0.6, 1 )
shader_param/shadow_outline_color = Color( 0.25098, 0.286275, 0.45098, 1 )
shader_param/time_elapsed = null
shader_param/size = 7.745
shader_param/OCTAVES = 2
shader_param/seed = 5.939
Expand Down
Loading