Add Sharp Bilinear Upscale post shader, thanks Silent

This commit is contained in:
Henrik Rydgård 2024-10-15 15:58:45 +02:00
parent 41eeb491e7
commit 7fa668fc35
3 changed files with 39 additions and 0 deletions

View File

@ -243,3 +243,8 @@ SettingDefaultValue1=0.4
SettingMaxValue1=0.8
SettingMinValue1=0.3
SettingStep1=0.05
[UpscaleSharpBilinear]
Name=Sharp Bilinear Upscaler
Fragment=upscale_sharp_bilinear.fsh
Vertex=upscale_sharp_bilinear.vsh
OutputResolution=True

View File

@ -0,0 +1,25 @@
#ifdef GL_ES
#extension GL_OES_standard_derivatives : enable
precision mediump float;
precision mediump int;
#endif
uniform sampler2D sampler0;
varying vec2 v_position;
uniform vec2 u_texelDelta; // (1.0 / bufferWidth, 1.0 / bufferHeight)
uniform vec2 u_pixelDelta; // (1.0 / targetWidth, 1.0 / targetHeight)
// Returns pixel sharpened to nearest pixel boundary.
vec2 sharpSample(vec4 texSize, vec2 coord) {
vec2 boxSize = clamp(fwidth(coord) * texSize.zw, 1e-5, 1.0);
coord = coord * texSize.zw - 0.5 * boxSize;
vec2 txOffset = smoothstep(vec2(1.0) - boxSize, vec2(1.0), fract(coord));
return (floor(coord) + 0.5 + txOffset) * texSize.xy;
}
void main() {
vec2 sharpPos = sharpSample(vec4(u_texelDelta, 1.0 / u_texelDelta), v_position);
vec4 color = texture2D(sampler0, sharpPos);
gl_FragColor = color;
}

View File

@ -0,0 +1,9 @@
attribute vec4 a_position;
attribute vec2 a_texcoord0;
varying vec2 v_position;
void main() {
gl_Position = a_position;
v_position = a_texcoord0;
}