Skip to content

Commit 04c0729

Browse files
committed
add section 4
1 parent 9847a94 commit 04c0729

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4718
-10
lines changed

01-simple-screenspace/01-01-color-transform.gdshader

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void fragment() {
77

88
float i = (COLOR.r + COLOR.g + COLOR.b) / 3.0;
99

10-
//COLOR.rgb = vec3(i);
10+
COLOR.rgb = vec3(i);
1111

12-
//COLOR = mix(vec4(0,0,0,1), base, i);
12+
COLOR = mix(vec4(0,0,0,1), base, i);
1313
}

01-simple-screenspace/01-02-coordinate-transform.gdshader

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void fragment() {
55

66
//coord.x += 0.01 * cos(TIME * 5.0 + coord.y * 20.0);
77

8-
//coord = coord - mod(coord, SCREEN_PIXEL_SIZE * 10.0);
8+
coord = coord - mod(coord, SCREEN_PIXEL_SIZE * 10.0);
99

1010
COLOR = texture(SCREEN_TEXTURE, coord);
1111
}

01-simple-screenspace/01-simpe-screenspace.tscn

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ margin_bottom = 600.0
4242
[node name="01-02-coordinate-transform" type="ColorRect" parent="effect"]
4343
visible = false
4444
material = SubResource( 3 )
45-
margin_right = 800.0
46-
margin_bottom = 600.0
45+
margin_left = 179.0
46+
margin_top = 240.0
47+
margin_right = 396.0
48+
margin_bottom = 388.0
4749

4850
[node name="01-03-more-textures" type="ColorRect" parent="effect"]
4951
material = SubResource( 4 )

02-metaball/02-metaball.tscn

+2-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ margin_right = 260.002
8383
margin_bottom = 161.001
8484

8585
[node name="ball2" type="ColorRect" parent="scene"]
86-
visible = false
8786
material = ExtResource( 1 )
8887
margin_left = 460.0
8988
margin_top = 214.0
@@ -110,9 +109,9 @@ anims/1 = SubResource( 4 )
110109
anims/RESET = SubResource( 5 )
111110

112111
[node name="effect" type="Node2D" parent="."]
113-
visible = false
114112

115113
[node name="ColorRect" type="ColorRect" parent="effect"]
116114
material = SubResource( 3 )
115+
margin_top = 1.0
117116
margin_right = 800.0
118-
margin_bottom = 600.0
117+
margin_bottom = 601.0

03-sketchy/03-sketchy.gdshader

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ void fragment() {
77
vec4 sample = texture(SCREEN_TEXTURE, SCREEN_UV);
88

99
COLOR = vec4(1.0);
10-
10+
1111
vec2 random = vec2(sin(TIME*123456.78), cos(TIME*123456.78));
1212

1313
// Фон

03-sketchy/03-sketchy.tscn

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ margin_left = 323.0
5353
margin_top = 53.0
5454
margin_right = 387.0
5555
margin_bottom = 117.0
56-
rect_rotation = 118.66
56+
rect_rotation = 48.1813
5757
rect_pivot_offset = Vector2( 32, 300 )
5858
texture = SubResource( 2 )
5959

04-visual/04-01-lightning-shader.tres

+306
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,306 @@
1+
[gd_resource type="VisualShader" load_steps=17 format=2]
2+
3+
[ext_resource path="res://addons/visual_shader_node_library/shader_nodes/common/noise/perlin_2d.gd" type="Script" id=1]
4+
5+
[sub_resource type="VisualShaderNodeScalarOp" id=1]
6+
output_port_for_preview = 0
7+
operator = 9
8+
9+
[sub_resource type="VisualShaderNodeVectorInterp" id=2]
10+
11+
[sub_resource type="VisualShaderNodeColorConstant" id=3]
12+
constant = Color( 0, 0, 0, 1 )
13+
14+
[sub_resource type="VisualShaderNodeColorConstant" id=4]
15+
constant = Color( 1, 1, 1, 0 )
16+
17+
[sub_resource type="VisualShaderNodeScalarInterp" id=5]
18+
19+
[sub_resource type="VisualShaderNodeScalarOp" id=6]
20+
default_input_values = [ 0, 0.0, 1, 0.5 ]
21+
operator = 2
22+
23+
[sub_resource type="VisualShaderNodeExpression" id=9]
24+
size = Vector2( 572, 430.8 )
25+
expression = "noise_off.x = time * -0.1 + uv.x;
26+
noise_off.y = time;
27+
28+
dst = abs(uv.y - 0.5 + (noise - 0.5) * 0.5 * size.x) * 2.0 / size.x;"
29+
30+
[sub_resource type="Curve" id=15]
31+
_data = [ Vector2( 0, 0 ), 0.0, 0.0, 0, 0, Vector2( 0.169643, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.491071, 1 ), 0.0, 0.0, 0, 0, Vector2( 0.767857, 1 ), 0.0, 0.0, 0, 0, Vector2( 1, 0 ), 0.0, 0.0, 0, 0 ]
32+
33+
[sub_resource type="CurveTexture" id=16]
34+
curve = SubResource( 15 )
35+
36+
[sub_resource type="VisualShaderNodeTexture" id=17]
37+
output_port_for_preview = 0
38+
texture = SubResource( 16 )
39+
40+
[sub_resource type="VisualShaderNodeCustom" id=18]
41+
output_port_for_preview = 0
42+
default_input_values = [ 2, Vector3( 10, 0.99, 1 ) ]
43+
initialized = true
44+
script = ExtResource( 1 )
45+
46+
[sub_resource type="VisualShaderNodeExpression" id=19]
47+
size = Vector2( 503.44, 207.6 )
48+
expression = "res.x = uv.x + time * -0.5;
49+
res.y = time;"
50+
51+
[sub_resource type="VisualShaderNodeInput" id=10]
52+
output_port_for_preview = 0
53+
input_name = "uv"
54+
55+
[sub_resource type="VisualShaderNodeCustom" id=11]
56+
output_port_for_preview = 0
57+
default_input_values = [ 2, Vector3( 10, 2, 10 ) ]
58+
initialized = true
59+
script = ExtResource( 1 )
60+
61+
[sub_resource type="VisualShaderNodeInput" id=14]
62+
input_name = "time"
63+
64+
[resource]
65+
code = "shader_type canvas_item;
66+
uniform sampler2D tex_frg_19;
67+
68+
69+
// PerlinNoise2D
70+
71+
72+
// GLSL textureless classic 2D noise \\\"cnoise\\\",
73+
// with an RSL-style periodic variant \\\"pnoise\\\".
74+
// Author: Stefan Gustavson ([email protected])
75+
// Version: 2011-08-22
76+
//
77+
// Many thanks to Ian McEwan of Ashima Arts for the
78+
// ideas for permutation and gradient selection.
79+
//
80+
// Copyright (c) 2011 Stefan Gustavson. All rights reserved.
81+
// Distributed under the MIT license. See LICENSE file.
82+
// https://github.com/stegu/webgl-noise
83+
//
84+
85+
vec4 HELPER_PerlinNoise2D_mod289(vec4 x) {
86+
return x - floor(x * (1.0 / 289.0)) * 289.0;
87+
}
88+
89+
vec4 HELPER_PerlinNoise2D_permute(vec4 x) {
90+
return HELPER_PerlinNoise2D_mod289(((x * 34.0) + 1.0) * x);
91+
}
92+
93+
vec4 HELPER_PerlinNoise2D_taylorInvSqrt(vec4 r) {
94+
return 1.79284291400159 - 0.85373472095314 * r;
95+
}
96+
97+
vec2 HELPER_PerlinNoise2D_fade(vec2 t) {
98+
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
99+
}
100+
101+
// Classic Perlin noise
102+
float perlin_noise_2d_np(vec2 P) {
103+
vec4 Pi = floor(vec4(P, P)) + vec4(0.0, 0.0, 1.0, 1.0);
104+
vec4 Pf = fract(vec4(P, P)) - vec4(0.0, 0.0, 1.0, 1.0);
105+
Pi = HELPER_PerlinNoise2D_mod289(Pi); // To avoid truncation effects in permutation
106+
vec4 ix = Pi.xzxz;
107+
vec4 iy = Pi.yyww;
108+
vec4 fx = Pf.xzxz;
109+
vec4 fy = Pf.yyww;
110+
111+
vec4 i = HELPER_PerlinNoise2D_permute(HELPER_PerlinNoise2D_permute(ix) + iy);
112+
113+
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
114+
vec4 gy = abs(gx) - 0.5 ;
115+
vec4 tx = floor(gx + 0.5);
116+
gx = gx - tx;
117+
118+
vec2 g00 = vec2(gx.x,gy.x);
119+
vec2 g10 = vec2(gx.y,gy.y);
120+
vec2 g01 = vec2(gx.z,gy.z);
121+
vec2 g11 = vec2(gx.w,gy.w);
122+
123+
vec4 norm = HELPER_PerlinNoise2D_taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
124+
g00 *= norm.x;
125+
g01 *= norm.y;
126+
g10 *= norm.z;
127+
g11 *= norm.w;
128+
129+
float n00 = dot(g00, vec2(fx.x, fy.x));
130+
float n10 = dot(g10, vec2(fx.y, fy.y));
131+
float n01 = dot(g01, vec2(fx.z, fy.z));
132+
float n11 = dot(g11, vec2(fx.w, fy.w));
133+
134+
vec2 fade_xy = HELPER_PerlinNoise2D_fade(Pf.xy);
135+
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
136+
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
137+
return 1.15 * n_xy + 0.5;
138+
}
139+
140+
// Classic Perlin noise, periodic variant
141+
float perlin_noise_2d_p(vec2 P, vec2 rep) {
142+
vec4 Pi = floor(vec4(P, P)) + vec4(0.0, 0.0, 1.0, 1.0);
143+
vec4 Pf = fract(vec4(P, P)) - vec4(0.0, 0.0, 1.0, 1.0);
144+
Pi = mod(Pi, vec4(rep, rep)); // To create noise with explicit period
145+
Pi = HELPER_PerlinNoise2D_mod289(Pi); // To avoid truncation effects in permutation
146+
vec4 ix = Pi.xzxz;
147+
vec4 iy = Pi.yyww;
148+
vec4 fx = Pf.xzxz;
149+
vec4 fy = Pf.yyww;
150+
151+
vec4 i = HELPER_PerlinNoise2D_permute(HELPER_PerlinNoise2D_permute(ix) + iy);
152+
153+
vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
154+
vec4 gy = abs(gx) - 0.5 ;
155+
vec4 tx = floor(gx + 0.5);
156+
gx = gx - tx;
157+
158+
vec2 g00 = vec2(gx.x,gy.x);
159+
vec2 g10 = vec2(gx.y,gy.y);
160+
vec2 g01 = vec2(gx.z,gy.z);
161+
vec2 g11 = vec2(gx.w,gy.w);
162+
163+
vec4 norm = HELPER_PerlinNoise2D_taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
164+
g00 *= norm.x;
165+
g01 *= norm.y;
166+
g10 *= norm.z;
167+
g11 *= norm.w;
168+
169+
float n00 = dot(g00, vec2(fx.x, fy.x));
170+
float n10 = dot(g10, vec2(fx.y, fy.y));
171+
float n01 = dot(g01, vec2(fx.z, fy.z));
172+
float n11 = dot(g11, vec2(fx.w, fy.w));
173+
174+
vec2 fade_xy = HELPER_PerlinNoise2D_fade(Pf.xy);
175+
vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
176+
float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
177+
return 1.15 * n_xy + 0.5;
178+
}
179+
180+
181+
void vertex() {
182+
// Output:0
183+
184+
}
185+
186+
void fragment() {
187+
// Color:12
188+
vec3 n_out12p0 = vec3(0.000000, 0.000000, 0.000000);
189+
float n_out12p1 = 1.000000;
190+
191+
// Color:13
192+
vec3 n_out13p0 = vec3(1.000000, 1.000000, 1.000000);
193+
float n_out13p1 = 0.000000;
194+
195+
// Input:7
196+
float n_out7p0 = TIME;
197+
198+
// Input:3
199+
vec3 n_out3p0 = vec3(UV, 0.0);
200+
201+
// Texture:19
202+
vec4 tex_frg_19_read = texture(tex_frg_19, n_out3p0.xy);
203+
vec3 n_out19p0 = tex_frg_19_read.rgb;
204+
float n_out19p1 = tex_frg_19_read.a;
205+
206+
// Expression:21
207+
vec3 n_out21p0;
208+
n_out21p0 = vec3(0.0, 0.0, 0.0);
209+
{
210+
n_out21p0.x = n_out3p0.x + n_out7p0 * -0.5;
211+
n_out21p0.y = n_out7p0;
212+
}
213+
214+
// PerlinNoise2D:20
215+
vec3 n_in20p2 = vec3(10.00000, 0.99000, 1.00000);
216+
float n_out20p0;
217+
{
218+
n_out20p0 = perlin_noise_2d_np(((n_out21p0).xy).xy * (n_in20p2).xy.xy);
219+
}
220+
221+
// Expression:18
222+
vec3 n_out18p0;
223+
float n_out18p1;
224+
n_out18p0 = vec3(0.0, 0.0, 0.0);
225+
n_out18p1 = 0.0;
226+
{
227+
n_out18p0.x = n_out7p0 * -0.1 + n_out3p0.x;
228+
n_out18p0.y = n_out7p0;
229+
230+
n_out18p1 = abs(n_out3p0.y - 0.5 + (n_out20p0 - 0.5) * 0.5 * n_out19p0.x) * 2.0 / n_out19p0.x;
231+
}
232+
233+
// PerlinNoise2D:4
234+
vec3 n_in4p2 = vec3(10.00000, 2.00000, 10.00000);
235+
float n_out4p0;
236+
{
237+
n_out4p0 = perlin_noise_2d_np(((n_out18p0).xy).xy * (n_in4p2).xy.xy);
238+
}
239+
240+
// ScalarOp:15
241+
float n_in15p1 = 0.50000;
242+
float n_out15p0 = n_out4p0 * n_in15p1;
243+
244+
// ScalarOp:10
245+
float n_out10p0 = step(n_out15p0, n_out18p1);
246+
247+
// VectorMix:11
248+
vec3 n_out11p0 = mix(n_out12p0, n_out13p0, vec3(n_out10p0));
249+
250+
// ScalarMix:14
251+
float n_out14p0 = mix(n_out12p1, n_out13p1, n_out10p0);
252+
253+
// Output:0
254+
COLOR.rgb = n_out11p0;
255+
COLOR.a = n_out14p0;
256+
257+
}
258+
259+
void light() {
260+
// Output:0
261+
262+
}
263+
"
264+
graph_offset = Vector2( -1124.06, -306.77 )
265+
mode = 1
266+
flags/light_only = false
267+
nodes/fragment/0/position = Vector2( 1340, -80 )
268+
nodes/fragment/3/node = SubResource( 10 )
269+
nodes/fragment/3/position = Vector2( -1640, -40 )
270+
nodes/fragment/4/node = SubResource( 11 )
271+
nodes/fragment/4/position = Vector2( 360, -80 )
272+
nodes/fragment/7/node = SubResource( 14 )
273+
nodes/fragment/7/position = Vector2( -1680, -140 )
274+
nodes/fragment/10/node = SubResource( 1 )
275+
nodes/fragment/10/position = Vector2( 760, 20 )
276+
nodes/fragment/11/node = SubResource( 2 )
277+
nodes/fragment/11/position = Vector2( 1160, -200 )
278+
nodes/fragment/12/node = SubResource( 3 )
279+
nodes/fragment/12/position = Vector2( 940, -160 )
280+
nodes/fragment/13/node = SubResource( 4 )
281+
nodes/fragment/13/position = Vector2( 988.691, -41.6613 )
282+
nodes/fragment/14/node = SubResource( 5 )
283+
nodes/fragment/14/position = Vector2( 1140, -80 )
284+
nodes/fragment/15/node = SubResource( 6 )
285+
nodes/fragment/15/position = Vector2( 560, -80 )
286+
nodes/fragment/18/node = SubResource( 9 )
287+
nodes/fragment/18/position = Vector2( -540, 40 )
288+
nodes/fragment/18/size = Vector2( 572, 430.8 )
289+
nodes/fragment/18/input_ports = "0,0,time;1,1,uv;2,1,size;3,0,noise;"
290+
nodes/fragment/18/output_ports = "0,1,noise_off;1,0,dst;"
291+
nodes/fragment/18/expression = "noise_off.x = time * -0.1 + uv.x;
292+
noise_off.y = time;
293+
294+
dst = abs(uv.y - 0.5 + (noise - 0.5) * 0.5 * size.x) * 2.0 / size.x;"
295+
nodes/fragment/19/node = SubResource( 17 )
296+
nodes/fragment/19/position = Vector2( -860, 160 )
297+
nodes/fragment/20/node = SubResource( 18 )
298+
nodes/fragment/20/position = Vector2( -880, -340 )
299+
nodes/fragment/21/node = SubResource( 19 )
300+
nodes/fragment/21/position = Vector2( -1440, -340 )
301+
nodes/fragment/21/size = Vector2( 503.44, 207.6 )
302+
nodes/fragment/21/input_ports = "0,1,uv;1,0,time;"
303+
nodes/fragment/21/output_ports = "0,1,res;"
304+
nodes/fragment/21/expression = "res.x = uv.x + time * -0.5;
305+
res.y = time;"
306+
nodes/fragment/connections = PoolIntArray( 10, 0, 11, 2, 11, 0, 0, 0, 12, 0, 11, 0, 13, 0, 11, 1, 14, 0, 0, 1, 13, 1, 14, 1, 12, 1, 14, 0, 10, 0, 14, 2, 4, 0, 15, 0, 15, 0, 10, 0, 7, 0, 18, 0, 3, 0, 18, 1, 18, 0, 4, 0, 18, 1, 10, 1, 3, 0, 19, 0, 19, 0, 18, 2, 21, 0, 20, 0, 3, 0, 21, 0, 7, 0, 21, 1, 20, 0, 18, 3 )

04-visual/04-01-lightning.material

215 Bytes
Binary file not shown.

04-visual/04-01-lightning.tscn

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[gd_scene load_steps=2 format=2]
2+
3+
[ext_resource path="res://04-visual/04-01-lightning.material" type="Material" id=1]
4+
5+
[node name="Node2D" type="Node2D"]
6+
7+
[node name="ColorRect" type="ColorRect" parent="."]
8+
material = ExtResource( 1 )
9+
margin_right = 210.0
10+
margin_bottom = 40.0
11+
rect_rotation = 0.275466

0 commit comments

Comments
 (0)