Files
net-gunner/visuals/shaders/matrix.gdshader

35 lines
1.8 KiB
Plaintext

shader_type canvas_item;
uniform sampler2D chars;
uniform sampler2D noise_tex;
uniform float offset;
void fragment() {
// Random character
vec2 uv = fract(UV * 32.0); // loop uv 32 times for the characters (as the noise resolution is 32x32)
//vec2 uv = vec2(0,0);
float noise = texture(noise_tex, UV).g;
noise = round(noise * 0.1) / 0.1; // make sure the color value are snapped by 0.1 (so its only 0.0, 0.1, 0.2, and so on) for perfect offset
//uv.x = (uv.x / 26.0); // offset
//uv.x = UV.x;
//uv.x += noise; // offset every character by the noise value
uv.x = fract(UV.x + round(TIME * 0.1 * 26.0)/26.0);
//uv.x += round(TIME * 0.5 * 26.0)/26.0; // animate characters with TIME, then snapped by 0.1 so it doesnt slide. 0.5 is the speed, you might want to change that
// distortion
float rain = UV.y; // this is a vertical gradient
float distortion = texture(noise_tex, (UV + vec2(0,offset)) / vec2(1.0, 64.0)).g; // this will be used for distortion, using previous noise but only horizontal
distortion = round(distortion * 26.0) / 26.0; // for precision reason, you need to round your distortion too, otherwise some character wouldnt be fully shown
rain -= round((TIME + offset) * 0.2 * 32.0) / 32.0; // the 'rain' shouldn't move smoothly right? also, 0.2 is the speed
rain += distortion; // distort this gradient, turning it into a rain
rain = fract(rain); // loop the rain
rain = round(rain * 128.0) / 128.0; // pixelate the rain. Rounding by 32.0 or 8.0 is optional
rain = pow(rain, 5.0); // this is not necessary, i just think that it looks good
rain *= 2.0; // this is also not important, just making the characters brighter
COLOR.rgb = texture(chars, vec2(uv.x, uv.y)).rgb * rain * vec3(0.0, 1.0, 0.0); // finally multiply them together then multiply with green for the color
COLOR.a = rain;
}