-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsky2.gdshader
162 lines (139 loc) · 4.89 KB
/
sky2.gdshader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
shader_type sky;
render_mode use_quarter_res_pass;
group_uniforms sky;
uniform vec3 top_color : source_color = vec3( 0.1, 0.6, 1.0 );
uniform vec3 bottom_color : source_color = vec3( 0.4, 0.8, 1.0 );
group_uniforms horizon;
uniform vec3 horizon_color : source_color = vec3( 0.0, 0.7, 0.8 );
uniform float horizon_blur : hint_range( 0.0, 1.0, 0.01 ) = 0.05;
group_uniforms sun; // First DirectionalLight3D will be the sun
uniform vec3 sun_color : source_color = vec3( 10.0, 8.0, 1.0 );
uniform float sun_size : hint_range( 0.01, 1.0 ) = 0.2;
uniform float sun_blur : hint_range( 0.01, 20.0 ) = 10.0;
group_uniforms clouds;
uniform vec3 clouds_edge_color : source_color = vec3( 0.8, 0.8, 0.98 );
uniform vec3 clouds_main_color : source_color = vec3( 1.0, 1.0, 1.0 );
uniform float clouds_speed : hint_range( 0.0, 20.0, 0.01 ) = 2.0;
uniform float clouds_scale : hint_range( 0.0, 4.0, 0.01 ) = 1.0;
uniform float clouds_cutoff : hint_range( 0.0, 1.0, 0.01 ) = 0.3;
uniform float clouds_weight : hint_range( 0.0, 1.0, 0.01 ) = 0.0;
uniform float clouds_blur : hint_range( 0.0, 1.0, 0.01 ) = 0.25;
const mat2 m = mat2(vec2( 1.6, 1.2), vec2(-1.2, 1.6));
vec2 hash( vec2 p ) {
p = vec2(dot(p, vec2(127.1, 311.7)), dot(p, vec2(269.5, 183.3)));
return -1.0 + 2.0 * fract(sin(p) * 43758.5453123);
}
float noise( in vec2 p ) {
const float K1 = 0.366025404; // (sqrt(3)-1)/2;
const float K2 = 0.211324865; // (3-sqrt(3))/6;
vec2 i = floor(p + (p.x + p.y)*K1);
vec2 a = p - i + (i.x + i.y) * K2;
vec2 o = (a.x > a.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
vec2 b = a - o + K2;
vec2 c = a - 1.0 + 2.0 * K2;
vec3 h = max(0.5 - vec3(dot(a, a), dot(b, b), dot(c, c)), 0.0 );
vec3 n = h * h * h * h * vec3(dot(a, hash(i + 0.0)), dot(b, hash(i + o)), dot(c, hash(i + 1.0)));
return dot(n, vec3(70.0));
}
float fbm(vec2 n) {
float total = 0.0, amplitude = 0.1;
for (int i = 0; i < 7; i++) {
total += noise(n) * amplitude;
n = m * n;
amplitude *= 0.4;
}
return total;
}
void sky() {
// Создаем общий time с примененным замедлением
float slow_factor = 0.01; // Задайте желаемый коэффициент замедления
float time = TIME * slow_factor; // Замедляем время
vec2 _sky_uv = EYEDIR.xz / sqrt(EYEDIR.y);
float _eyedir_y = abs(sin(EYEDIR.y * PI * 0.5));
// SKYCOLOR
vec3 _sky_color = mix(bottom_color, top_color, _eyedir_y);
_sky_color = mix(_sky_color, vec3(0.0), clamp((0.7 - clouds_cutoff) * clouds_weight, 0.0, 1.0));
COLOR = _sky_color;
// HORIZON
float _horizon_amount = 0.0;
if (EYEDIR.y < 0.0) {
_horizon_amount = clamp(abs(EYEDIR.y) / horizon_blur, 0.0, 1.0);
vec3 _horizon_color = mix(horizon_color, _sky_color, 0.9);
_horizon_color = mix(_horizon_color, vec3(0.0), (1.0 - clouds_cutoff) * clouds_weight * 0.7);
COLOR = mix(COLOR, _horizon_color, _horizon_amount);
}
// SUN
float _sun_distance = 0.0;
if (LIGHT0_ENABLED) {
_sun_distance = distance(EYEDIR, LIGHT0_DIRECTION);
float _sun_size = sun_size + cos(LIGHT0_DIRECTION.y * PI) * sun_size * 0.25;
float _sun_amount = clamp((1.0 - _sun_distance / _sun_size) / sun_blur, 0.0, 1.0);
if (_sun_amount > 0.0) {
vec3 _sun_color = sun_color;
_sun_amount *= 1.0 - _horizon_amount;
if (_sun_color.r > 1.0 || _sun_color.g > 1.0 || _sun_color.b > 1.0)
_sun_color *= _sun_amount;
COLOR = mix(COLOR, _sun_color, _sun_amount);
}
}
// CLOUDS
if (EYEDIR.y > 0.0) {
vec3 normal = normalize(EYEDIR);
vec3 plane_intersect = normal / (normal.y + clouds_cutoff);
vec2 p = plane_intersect.xz;
p.y *= -1.0;
vec2 uv = p;
// Для всех вычислений используем замедленный time
float q = fbm(uv * clouds_scale * 0.5);
// Ridged noise shape
float r = 0.0;
uv *= clouds_scale;
uv -= q - time * clouds_speed * 0.3;
float weight = 0.8;
for (int i = 0; i < 8; i++) {
r += abs(weight * noise(uv));
uv = m * uv + time;
weight *= 0.7;
}
// Noise shape
float f = 0.0;
uv = p;
uv *= clouds_scale;
uv -= q - time * clouds_speed * 0.4;
weight = 0.7;
for (int i = 0; i < 8; i++) {
f += weight * noise(uv);
uv = m * uv + time;
weight *= 0.6;
}
f *= r + f;
// Noise colour
float c = 0.0;
uv = p;
uv *= clouds_scale * 1.5;
uv -= q - time * clouds_speed * 2.0;
weight = 0.4;
for (int i = 0; i < 7; i++) {
c += weight * noise(uv);
uv = m * uv + time;
weight *= 0.6;
}
// Noise ridge colour
float c1 = 0.0;
uv = p;
uv *= clouds_scale * 3.0;
uv -= q - time * clouds_speed * 5.0;
weight = 0.4;
for (int i = 0; i < 7; i++) {
c1 += abs(weight * noise(uv));
uv = m * uv + time;
weight *= 0.6;
}
c += c1;
float _clouds_amount = clamp(c, 0.0, 1.0);
_clouds_amount *= clamp(abs(EYEDIR.y) / clouds_blur, 0.0, 1.0);
vec3 skycolour = COLOR;
vec3 clouds = mix(clouds_edge_color, clouds_main_color, pow(_clouds_amount, 2.0));
COLOR = mix(skycolour, clouds, _clouds_amount);
}
}