[gd_scene load_steps=7 format=2]

[ext_resource path="res://sky.jpg" type="Texture" id=1]

[sub_resource type="SphereMesh" id=1]
radius = 2.0
height = 4.0

[sub_resource type="Shader" id=5]
code = "shader_type spatial;
varying vec3 world_pos;
uniform vec4 base_color : hint_color;
uniform vec4 cloud_color : hint_color;

//Van https://github.com/yiwenl/glsl-fbm/blob/master/3d.glsl

float mod289f(float x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec4 mod289v4(vec4 x){return x - floor(x * (1.0 / 289.0)) * 289.0;}
vec4 perm(vec4 x){return mod289v4(((x * 34.0) + 1.0) * x);}

float noise1(vec3 p){
    vec3 a = floor(p);
    vec3 d = p - a;
    d = d * d * (3.0 - 2.0 * d);

    vec4 b = a.xxyy + vec4(0.0, 1.0, 0.0, 1.0);
    vec4 k1 = perm(b.xyxy);
    vec4 k2 = perm(k1.xyxy + b.zzww);

    vec4 c = k2 + a.zzzz;
    vec4 k3 = perm(c);
    vec4 k4 = perm(c + 1.0);

    vec4 o1 = fract(k3 * (1.0 / 41.0));
    vec4 o2 = fract(k4 * (1.0 / 41.0));

    vec4 o3 = o2 * d.z + o1 * (1.0 - d.z);
    vec2 o4 = o3.yw * d.x + o3.xz * (1.0 - d.x);

    return o4.y * d.y + o4.x * (1.0 - d.y);
}


float fbm1(vec3 x, float t) {
	float v = 0.0;
	float a = 0.5;
	vec3 shift = t*vec3(0.1);
	for (int i = 0; i < 5; ++i) {
		v += a * noise1(x);
		x = x * 2.0 + shift;
		a *= 0.5;
	}
	return v;
}


void vertex() {
	world_pos = VERTEX;
}

void fragment() {
	ALBEDO = smoothstep(base_color.rgb, cloud_color.rgb, cloud_color.rgb*fbm1(world_pos, TIME));
}"

[sub_resource type="ShaderMaterial" id=3]
shader = SubResource( 5 )
shader_param/base_color = Color( 0.0745098, 0.215686, 0.419608, 1 )
shader_param/cloud_color = Color( 0.580392, 0.580392, 0.580392, 1 )

[sub_resource type="PanoramaSky" id=6]
panorama = ExtResource( 1 )

[sub_resource type="Environment" id=4]
background_mode = 2
background_sky = SubResource( 6 )
background_energy = 0.16
ambient_light_color = Color( 0.219608, 0.219608, 0.219608, 1 )
auto_exposure_scale = 5.28
auto_exposure_max_luma = 3.73
auto_exposure_speed = 48.95
ss_reflections_enabled = true

[node name="Spatial" type="Spatial"]

[node name="Camera" type="Camera" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 7.28376 )

[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.00204706, 4.76837e-07, 0.00108433 )
mesh = SubResource( 1 )
material/0 = SubResource( 3 )

[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
environment = SubResource( 4 )

[node name="OmniLight" type="OmniLight" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.14577, 4.93426, 5.11091 )
light_specular = 0.86
omni_range = 156.6
omni_attenuation = 2.21914
