Retro Fade 2D

This is a simple shader that let’s you fade in and out a sprite.

Shader code
shader_type canvas_item;
render_mode blend_mix;

#define MAX_FADE 4

uniform int fade : hint_range( 0, MAX_FADE, 1 ) = 0;
uniform int tiling = 10;


float get_line( float uv )
{
	uv *= float( tiling );
	uv += float( tiling ) / 2.0;
	return round( mod( uv , 1.0 ) );
}


float get_grid( vec2 uv )
{
	float offset = 0.5 / float( tiling );
	float grids[MAX_FADE];
	for ( int i = 0; i< MAX_FADE/2; i++)
		for ( int j = 0; j< MAX_FADE/2; j++)
		{
			grids[ i * MAX_FADE/2 + j ] = get_line( uv.x + offset*float(i) ) * get_line( uv.y + offset*float(j) );
		}

	float float_fade = float( fade );
	grids[0] *= clamp( 1.0 - float_fade, 0.0, 1.0 );
	grids[1] *= clamp( 3.0 - float_fade, 0.0, 1.0 );
	grids[2] *= clamp( 4.0 - float_fade, 0.0, 1.0 );
	grids[3] *= clamp( 2.0 - float_fade, 0.0, 1.0 );
	
	return grids[0] + grids[1] + grids[2] + grids[3];
}


void fragment()
{
	COLOR.a = COLOR.a * get_grid( UV );
}
Tags
2d, fade, retro, transition
The shader code and all code snippets in this post are under MIT license and can be used freely. Images and videos, and assets depicted in those, do not fall under this license. For more info, see our License terms.

More from MehdiTheLord

Stylised squares fade 2D

Related shaders

Fade by distance to character

Slice and Fade out

Stylised squares fade 2D

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments