Glitch

A glitch shader I used as a world border. I removed the logic for making it fade in when you got nearer because it was poorly implemented :3

It has a bunch of parameters to control the different glitch effects (which are animated!).

Shader code
shader_type spatial;
render_mode unshaded;

uniform sampler2D albedo_texture;

uniform float uv_scale = 1;

uniform float chromatic_abberation : hint_range(.0, .1) = .04;
uniform float noise_size : hint_range(.001, .1) = .01;
uniform float noise_speed = 5.;
uniform float noise_amount : hint_range(0., 1.) = 0.1;

float random(float seed) {
    return fract(sin(dot(vec2(seed, -seed),
        vec2(12.9898,78.233))) * 43758.5453123);
}

void fragment() {
	
	// noise
	if (random((floor(UV.x / noise_size) * noise_size) * (floor(UV.y / noise_size) * noise_size) * floor(TIME * noise_speed) / noise_speed) < noise_amount) {
		discard;
	}

	// multi-sampling for chromatic abberation
	vec4 sample_center = texture(albedo_texture, uv_scale * UV);
	
	vec4 sample_up = texture(
		albedo_texture,
		uv_scale * UV + vec2(chromatic_abberation * (1. + random(TIME)))
	);
		
	vec4 sample_down = texture(
		albedo_texture,
		uv_scale * UV - vec2(chromatic_abberation * (1. + random(TIME + 5.)))
	);

	if (sample_center.a < 0.5 && sample_up.a < 0.5 && sample_down.a < 0.5) {
		discard;
	}

	ALBEDO = vec3(sample_up.r, sample_center.g, sample_down.b);
}
Live Preview
Tags
glitch
The shader code and all code snippets in this post are under CC0 license and can be used freely without the author's permission. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from dairycultist

Related shaders

guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments