-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.tscn
245 lines (196 loc) · 6.05 KB
/
Main.tscn
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
[gd_scene load_steps=14 format=2]
[ext_resource path="res://Main.gd" type="Script" id=1]
[ext_resource path="res://palettes/Palette1.tres" type="Material" id=2]
[ext_resource path="res://Reset.gd" type="Script" id=3]
[ext_resource path="res://palettes/Palette0.tres" type="Material" id=4]
[sub_resource type="Shader" id=2]
code = "shader_type canvas_item;
uniform float size = 4.0;
uniform bool simulationActivated = false;
uniform float BactiveSumLeft = 0.26;
uniform float BactiveSumRight = 0.46;
uniform float BunactiveSumLeft = 0.27;
uniform float BunactiveSumRight = 0.36;
uniform float smoothness = 0.02;
uniform bool lerping = false;
varying float smoothnessNegative;
varying float activeSumLeft;
varying float activeSumRight;
varying float unactiveSumLeft;
varying float unactiveSumRight;
varying float set;
float getValue(float sum, float active) {
if (active >= 0.5) {
if (sum >= activeSumLeft) {
if (sum <= activeSumRight) {
return 1.0;
}
if (sum <= activeSumRight + smoothness) {
return 1.0 - (sum - activeSumRight) * smoothnessNegative;
}
}
if (sum <= activeSumRight) {
if (sum >= activeSumLeft - smoothness) {
return (sum - activeSumLeft + smoothness) * smoothnessNegative;
}
}
} else {
if (sum >= unactiveSumLeft) {
if (sum <= unactiveSumRight) {
return 1.0;
}
if (sum <= unactiveSumRight + smoothness) {
return 1.0 - (sum - unactiveSumRight) * smoothnessNegative;
}
}
if (sum <= unactiveSumRight) {
if (sum >= unactiveSumLeft - smoothness) {
return (sum - unactiveSumLeft + smoothness) * smoothnessNegative;
}
}
}
return 0.0;
}
float getPixel(sampler2D tex, vec2 coord) {
if (coord.x < 0.0) {
coord.x += size;
}
if (coord.y < 0.0) {
coord.y += size;
}
if (coord.x >= size) {
coord.x -= size;
}
if (coord.y >= size) {
coord.y -= size;
}
return texture(tex, coord / size).r;
}
void fragment() {
smoothnessNegative = 1.0 / smoothness;
if (set != 0.952) {
set = 0.952;
activeSumLeft = BactiveSumLeft / 100.0;
activeSumRight = BactiveSumRight / 100.0;
unactiveSumLeft = BunactiveSumLeft / 100.0;
unactiveSumRight = BunactiveSumRight / 100.0;
}
vec2 pixelCoord = floor(UV * size);
float value = 0.0;
float sum = 0.0;
if (!simulationActivated) {
COLOR = texture(TEXTURE, UV);
} else {
for (float x = -13.0; x <= 13.0; x += 1.0) {
for (float y = -13.0; y <= 13.0; y += 1.0) {
if (x >= -1.0 && x <= 1.0 && y >= -1.0 && y <= 1.0) continue;
float dist = sqrt(x * x + y * y);
if (dist > 13.0) continue;
sum += getPixel(TEXTURE, pixelCoord + vec2(x, y));
}
}
sum /= 489.0;
float activeSum = 0.0;
activeSum += getPixel(TEXTURE, pixelCoord + vec2(-1, -1));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(0, -1));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(1, -1));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(-1, 0));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(0, 0));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(1, 0));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(-1, 1));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(0, 1));
activeSum += getPixel(TEXTURE, pixelCoord + vec2(1, 1));
activeSum /= 9.0;
value = getValue(sum, activeSum);
if (lerping) {
float previousValue = getPixel(TEXTURE, pixelCoord);
value = (value * 0.5 + previousValue * 0.5);
}
COLOR = vec4(value, value, value, 1.0);
}
}"
[sub_resource type="ShaderMaterial" id=3]
shader = SubResource( 2 )
shader_param/size = 256.0
shader_param/simulationActivated = false
shader_param/BactiveSumLeft = 27.0
shader_param/BactiveSumRight = 45.0
shader_param/BunactiveSumLeft = 29.0
shader_param/BunactiveSumRight = 35.0
shader_param/smoothness = 0.02
shader_param/lerping = false
[sub_resource type="ViewportTexture" id=1]
viewport_path = NodePath("Viewport")
[sub_resource type="Shader" id=7]
code = "shader_type canvas_item;
void fragment() {
COLOR = texture(TEXTURE, UV);
COLOR.a = COLOR.r * 2.0;
COLOR.rgb = vec3(1.0);
}"
[sub_resource type="ShaderMaterial" id=8]
shader = SubResource( 7 )
[sub_resource type="StreamTexture" id=11]
load_path = "res://.import/Light.webp-e270c22703093373a24af83132d28d09.stex"
[sub_resource type="Shader" id=9]
code = "shader_type canvas_item;
void fragment() {
COLOR = texture(TEXTURE, UV);
COLOR.a = COLOR.r * COLOR.g * COLOR.b;
COLOR.rgb = vec3(0.0);
}"
[sub_resource type="ShaderMaterial" id=10]
shader = SubResource( 9 )
[sub_resource type="ViewportTexture" id=4]
viewport_path = NodePath("Viewport")
[node name="Main" type="Node2D"]
script = ExtResource( 1 )
[node name="Viewport" type="Viewport" parent="."]
size = Vector2( 256, 256 )
render_target_v_flip = true
render_target_clear_mode = 2
render_target_update_mode = 3
[node name="Sprite" type="Sprite" parent="Viewport"]
material = SubResource( 3 )
texture = SubResource( 1 )
centered = false
[node name="Reset" type="Node2D" parent="Viewport"]
[node name="ColorRect" type="ColorRect" parent="Viewport/Reset"]
margin_right = 512.0
margin_bottom = 512.0
color = Color( 0, 0, 0, 1 )
[node name="Node2D" type="Node2D" parent="Viewport/Reset"]
script = ExtResource( 3 )
[node name="Light" type="Sprite" parent="Viewport"]
visible = false
material = SubResource( 8 )
position = Vector2( 98, 67 )
scale = Vector2( 0.05, 0.05 )
texture = SubResource( 11 )
[node name="Dark" type="Sprite" parent="Viewport"]
visible = false
material = SubResource( 10 )
position = Vector2( 98, 67 )
scale = Vector2( 0.2, 0.2 )
texture = SubResource( 11 )
[node name="Palette1" type="Sprite" parent="."]
visible = false
material = ExtResource( 2 )
scale = Vector2( 4, 4 )
texture = SubResource( 4 )
centered = false
[node name="Palette2" type="Sprite" parent="."]
visible = false
material = ExtResource( 4 )
scale = Vector2( 4, 4 )
texture = SubResource( 4 )
centered = false
[node name="Palette3" type="Sprite" parent="."]
scale = Vector2( 4, 4 )
texture = SubResource( 4 )
centered = false
[node name="Timer" type="Timer" parent="."]
wait_time = 0.1
one_shot = true
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]