Skip to content

Commit 930e6bb

Browse files
committed
Add digital-rain.shader
1 parent 4c84c97 commit 930e6bb

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed

data/examples/digital-rain.shader

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// based on https://www.shadertoy.com/view/ldccW4 by WillKirkby
2+
3+
4+
#ifndef OPENGL
5+
#define fract frac
6+
#define mix lerp
7+
#endif
8+
9+
uniform texture2d font = "font.png";
10+
uniform texture2d noise = "noise.png";
11+
uniform float4 base_color = {.1, 1.0, .35, 1.0};
12+
uniform float rain_speed<
13+
string label = "Rain Speed";
14+
string widget_type = "slider";
15+
float minimum = 0.001;
16+
float maximum = 2.0;
17+
float step = .001;
18+
> = 1.0;
19+
20+
uniform float char_speed<
21+
string label = "Character Speed";
22+
string widget_type = "slider";
23+
float minimum = 0.0;
24+
float maximum = 2.0;
25+
float step = .001;
26+
> = 1.0;
27+
28+
uniform float glow_contrast<
29+
string label = "Glow contrast";
30+
string widget_type = "slider";
31+
float minimum = 0.0;
32+
float maximum = 2.5;
33+
float step = .001;
34+
> = 1.0;
35+
36+
37+
float mod(float x, float y)
38+
{
39+
return x - y * floor(x/y);
40+
}
41+
42+
float2 mod2(float2 x, float2 y)
43+
{
44+
return x - y * floor(x/y);
45+
}
46+
47+
float text(float2 fragCoord)
48+
{
49+
float2 uv = mod2(fragCoord, float2(16.0, 16.0) )/16.0;
50+
float2 block = (fragCoord*.0625 - uv)/uv_size*16.0;
51+
uv = uv*.8+.1; // scale the letters up a bit
52+
block += elapsed_time*.002*char_speed;
53+
uv += floor(noise.Sample(textureSampler, fract(block)).xy * 16.); // randomize letters
54+
uv *= .0625; // bring back into 0-1 range
55+
return font.Sample(textureSampler, uv).r;
56+
}
57+
58+
float3 rain(float2 fragCoord)
59+
{
60+
fragCoord.x -= mod(fragCoord.x, 16.);
61+
float offset=sin(fragCoord.x*15.);
62+
float speed=(cos(fragCoord.x*3.)*.3+.7)*rain_speed;
63+
64+
float y = fract(fragCoord.y/uv_size.y + elapsed_time*speed + offset);
65+
return base_color.rgb / pow(y*20.0, glow_contrast);
66+
}
67+
68+
float4 mainImage(VertData v_in) : TARGET
69+
{
70+
return mix(image.Sample(textureSampler, v_in.uv),float4(rain(float2(v_in.uv.x,1.0-v_in.uv.y)*uv_size),1.0), text(v_in.uv*uv_size));
71+
}

data/textures/font.png

1.26 MB
Loading

data/textures/noise.png

258 KB
Loading

0 commit comments

Comments
 (0)