Scale2x filter

Port of a Scale2x filter from shadertoy: https://www.shadertoy.com/view/4s2BRt by Kchplr

 

Shader code
shader_type canvas_item;


void fragment()
{   
	vec2 frCoor = UV * vec2(textureSize(TEXTURE, 0)) * 2.0;
	ivec2 texPos = ivec2(frCoor.xy / 2.);
	int id = int(floor(mod(frCoor.x, 2.)) + floor(mod(frCoor.y, 2.)) * 2.); // 0-1 / 2-3

	vec4 B = texelFetch(TEXTURE, texPos + ivec2(0,-1), 0);
	vec4 D = texelFetch(TEXTURE, texPos + ivec2(-1,0), 0);
	vec4 C = texelFetch(TEXTURE, texPos, 0);
	vec4 F = texelFetch(TEXTURE, texPos + ivec2(1,0), 0);
	vec4 H = texelFetch(TEXTURE, texPos + ivec2(0,1), 0);

	vec4 result;

	if( (B != H) && (D != F) ) {
		if (id == 0) {
			result = (D == B) ? D : C;
		} else if (id == 1) {
			result = (B == F) ? F : C;
		} else if (id == 2) {
			result = (D == H) ? D : C;
		} else {
			result = (H == F) ? F : C;
		}
	} 
	else {
		result = C;
	}
	
	COLOR = result;
}
Tags
pixel-art, scale2x, upscale, upscaler
This shader is a port from an existing Shadertoy project. Shadertoy shaders are by default protected under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) license unless anything else has been stated by the author. For more info, see our License terms.

More from Firerabbit

Terrain Mesh Blending with Dithering

Dither opacity with GLES2 Support

Generalized Kuwahara

Related shaders

Laplace filter, edge detection

Pixelate Filter

Distort Filter PerlinNoise

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments