3-point texture filtering

Very simple port of 3point texture filtering from GLideN64 ( https://github.com/gonetz/GLideN64 ) to the Godot Engine.

Texture’s filtering has to be disabled, otherwise there will be artifacts.

Texture size has to be set manually due to a GLES2 limitation, this can also be used to down or upscale textures non-destructively.

Shader code
// 3 point texture filtering.
// Original author: ArthurCarvalho
// GLSL implementation: twinaphex, mupen64plus-libretro project.
// Ported to Godot by Ed3800

shader_type spatial;
render_mode vertex_lighting, specular_disabled, ambient_light_disabled, shadows_disabled;

uniform sampler2D tex;
uniform vec2 texSize;

void fragment() {
	vec2 offset = fract(UV*texSize - vec2(0.5));
	offset -= step(1.0, offset.x + offset.y);
	vec4 c0 = texture(tex, UV - (offset)/texSize);
	vec2 c1off = vec2(offset.x - sign(offset.x), offset.y);
	vec4 c1 = texture(tex, UV - (c1off)/texSize);
	vec2 c2off = vec2(offset.x, offset.y - sign(offset.y));
	vec4 c2 = texture(tex, UV - (c2off)/texSize);
	
	ALBEDO = vec4(c0 + abs(offset.x)*(c1-c0) + abs(offset.y)*(c2-c0)).rgb;
}
Tags
filter, filtering, texture, texture filter, texture filtering
The shader code and all code snippets in this post are under GNU GPL v.3 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 Ed3800

Ramp Lighting

Related shaders

N64 3 Point Filtering

Smooth 3D pixel filtering

Slipgate texture warp

Subscribe
Notify of
guest

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Exuin
3 years ago

I have no plans to use this shader but I just want to say that thumbnail is hilarious.

Narcis234
Narcis234
6 months ago

Does this apply to lightmaps?