mirror of
https://github.com/libretro/beetle-psx-libretro.git
synced 2025-02-11 12:05:58 +00:00
add jinc2 texture filter
This commit is contained in:
parent
f89b822d85
commit
a44a9ddb46
@ -3998,7 +3998,7 @@ void retro_set_environment(retro_environment_t cb)
|
||||
{ option_internal_resolution, "Internal GPU resolution; 1x(native)|2x|4x|8x" },
|
||||
#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES)
|
||||
// Only used in GL renderer for now.
|
||||
{ option_filter, "Texture filtering; nearest|SABR|xBR|bilinear|3-point" },
|
||||
{ option_filter, "Texture filtering; nearest|SABR|xBR|bilinear|3-point|JINC2" },
|
||||
{ option_depth, "Internal color depth; dithered 16bpp (native)|32bpp" },
|
||||
{ option_wireframe, "Wireframe mode; disabled|enabled" },
|
||||
{ option_display_vram, "Display full VRAM; disabled|enabled" },
|
||||
|
@ -44,6 +44,9 @@
|
||||
#define FILTER_3POINT
|
||||
#include "../rustation-libretro/src/shaders/command_fragment.glsl.h"
|
||||
#undef FILTER_3POINT
|
||||
#define FILTER_JINC2
|
||||
#include "../rustation-libretro/src/shaders/command_fragment.glsl.h"
|
||||
#undef FILTER_JINC2
|
||||
#include "../rustation-libretro/src/shaders/output_vertex.glsl.h"
|
||||
#include "../rustation-libretro/src/shaders/output_fragment.glsl.h"
|
||||
#include "../rustation-libretro/src/shaders/image_load_vertex.glsl.h"
|
||||
@ -69,7 +72,8 @@ enum FilterMode {
|
||||
FILTER_MODE_SABR,
|
||||
FILTER_MODE_XBR,
|
||||
FILTER_MODE_BILINEAR,
|
||||
FILTER_MODE_3POINT
|
||||
FILTER_MODE_3POINT,
|
||||
FILTER_MODE_JINC2
|
||||
};
|
||||
|
||||
// Main GPU instance, used to access the VRAM
|
||||
@ -289,6 +293,8 @@ GlRenderer::GlRenderer(DrawConfig* config)
|
||||
filter = FILTER_MODE_BILINEAR;
|
||||
else if (!strcmp(var.value, "3-point"))
|
||||
filter = FILTER_MODE_3POINT;
|
||||
else if (!strcmp(var.value, "JINC2"))
|
||||
filter = FILTER_MODE_JINC2;
|
||||
|
||||
this->filter_type = filter;
|
||||
}
|
||||
@ -359,6 +365,12 @@ GlRenderer::GlRenderer(DrawConfig* config)
|
||||
command_fragment_3point,
|
||||
VERTEX_BUFFER_LEN);
|
||||
break;
|
||||
case FILTER_MODE_JINC2:
|
||||
command_buffer = GlRenderer::build_buffer<CommandVertex>(
|
||||
command_vertex,
|
||||
command_fragment_jinc2,
|
||||
VERTEX_BUFFER_LEN);
|
||||
break;
|
||||
case FILTER_MODE_NEAREST:
|
||||
default:
|
||||
command_buffer = GlRenderer::build_buffer<CommandVertex>(
|
||||
@ -821,6 +833,8 @@ static bool retro_refresh_variables(GlRenderer *renderer)
|
||||
filter = FILTER_MODE_BILINEAR;
|
||||
else if (!strcmp(var.value, "3-point"))
|
||||
filter = FILTER_MODE_3POINT;
|
||||
else if (!strcmp(var.value, "JINC2"))
|
||||
filter = FILTER_MODE_JINC2;
|
||||
}
|
||||
|
||||
var.key = option_depth;
|
||||
@ -2119,7 +2133,7 @@ void rsx_gl_copy_rect(
|
||||
// duplicate the diagonal but I believe it was incorrect because of
|
||||
// the OpenGL filling convention. At least it's what TinyTiger told
|
||||
// me...
|
||||
|
||||
|
||||
GLuint fb;
|
||||
|
||||
glGenFramebuffers(1, &fb);
|
||||
|
@ -8,6 +8,8 @@ static const char * command_fragment_xbr = GLSL(
|
||||
static const char * command_fragment_bilinear = GLSL(
|
||||
#elif defined(FILTER_3POINT)
|
||||
static const char * command_fragment_3point = GLSL(
|
||||
#elif defined(FILTER_JINC2)
|
||||
static const char * command_fragment_jinc2 = GLSL(
|
||||
#else
|
||||
static const char * command_fragment = GLSL(
|
||||
#endif
|
||||
@ -513,6 +515,114 @@ vec4 get_texel_bilinear()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FILTER_JINC2
|
||||
const float JINC2_WINDOW_SINC = 0.44;
|
||||
const float JINC2_SINC = 0.82;
|
||||
const float JINC2_AR_STRENGTH = 0.8;
|
||||
|
||||
const float halfpi = 1.5707963267948966192313216916398;
|
||||
const float pi = 3.1415926535897932384626433832795;
|
||||
const float wa = 1.382300768;
|
||||
const float wb = 2.576105976;
|
||||
|
||||
// Calculates the distance between two points
|
||||
float d(vec2 pt1, vec2 pt2)
|
||||
{
|
||||
vec2 v = pt2 - pt1;
|
||||
return sqrt(dot(v,v));
|
||||
}
|
||||
|
||||
vec3 min4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return min(a, min(b, min(c, d)));
|
||||
}
|
||||
|
||||
vec3 max4(vec3 a, vec3 b, vec3 c, vec3 d)
|
||||
{
|
||||
return max(a, max(b, max(c, d)));
|
||||
}
|
||||
|
||||
vec4 resampler(vec4 x)
|
||||
{
|
||||
vec4 res;
|
||||
|
||||
res = (x==vec4(0.0, 0.0, 0.0, 0.0)) ? vec4(wa*wb) : sin(x*wa)*sin(x*wb)/(x*x);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
vec4 get_texel_jinc2()
|
||||
{
|
||||
vec3 color;
|
||||
vec4 weights[4];
|
||||
|
||||
vec2 dx = vec2(1.0, 0.0);
|
||||
vec2 dy = vec2(0.0, 1.0);
|
||||
|
||||
vec2 pc = frag_texture_coord.xy;
|
||||
|
||||
vec2 tc = (floor(pc-vec2(0.5,0.5))+vec2(0.5,0.5));
|
||||
|
||||
weights[0] = resampler(vec4(d(pc, tc -dx -dy), d(pc, tc -dy), d(pc, tc +dx -dy), d(pc, tc+2.0*dx -dy)));
|
||||
weights[1] = resampler(vec4(d(pc, tc -dx ), d(pc, tc ), d(pc, tc +dx ), d(pc, tc+2.0*dx )));
|
||||
weights[2] = resampler(vec4(d(pc, tc -dx +dy), d(pc, tc +dy), d(pc, tc +dx +dy), d(pc, tc+2.0*dx +dy)));
|
||||
weights[3] = resampler(vec4(d(pc, tc -dx+2.0*dy), d(pc, tc +2.0*dy), d(pc, tc +dx+2.0*dy), d(pc, tc+2.0*dx+2.0*dy)));
|
||||
|
||||
dx = dx;
|
||||
dy = dy;
|
||||
tc = tc;
|
||||
|
||||
vec3 c00 = sample_texel(tc -dx -dy).xyz;
|
||||
vec3 c10 = sample_texel(tc -dy).xyz;
|
||||
vec3 c20 = sample_texel(tc +dx -dy).xyz;
|
||||
vec3 c30 = sample_texel(tc+2.0*dx -dy).xyz;
|
||||
vec3 c01 = sample_texel(tc -dx ).xyz;
|
||||
vec3 c11 = sample_texel(tc ).xyz;
|
||||
vec3 c21 = sample_texel(tc +dx ).xyz;
|
||||
vec3 c31 = sample_texel(tc+2.0*dx ).xyz;
|
||||
vec3 c02 = sample_texel(tc -dx +dy).xyz;
|
||||
vec3 c12 = sample_texel(tc +dy).xyz;
|
||||
vec3 c22 = sample_texel(tc +dx +dy).xyz;
|
||||
vec3 c32 = sample_texel(tc+2.0*dx +dy).xyz;
|
||||
vec3 c03 = sample_texel(tc -dx+2.0*dy).xyz;
|
||||
vec3 c13 = sample_texel(tc +2.0*dy).xyz;
|
||||
vec3 c23 = sample_texel(tc +dx+2.0*dy).xyz;
|
||||
vec3 c33 = sample_texel(tc+2.0*dx+2.0*dy).xyz;
|
||||
|
||||
color = sample_texel(frag_texture_coord.xy).xyz;
|
||||
|
||||
// Get min/max samples
|
||||
vec3 min_sample = min4(c11, c21, c12, c22);
|
||||
vec3 max_sample = max4(c11, c21, c12, c22);
|
||||
/*
|
||||
color = mat4x3(c00, c10, c20, c30) * weights[0];
|
||||
color+= mat4x3(c01, c11, c21, c31) * weights[1];
|
||||
color+= mat4x3(c02, c12, c22, c32) * weights[2];
|
||||
color+= mat4x3(c03, c13, c23, c33) * weights[3];
|
||||
mat4 wgts = mat4(weights[0], weights[1], weights[2], weights[3]);
|
||||
vec4 wsum = wgts * vec4(1.0,1.0,1.0,1.0);
|
||||
color = color/(dot(wsum, vec4(1.0,1.0,1.0,1.0)));
|
||||
*/
|
||||
|
||||
|
||||
color = vec3(dot(weights[0], vec4(c00.x, c10.x, c20.x, c30.x)), dot(weights[0], vec4(c00.y, c10.y, c20.y, c30.y)), dot(weights[0], vec4(c00.z, c10.z, c20.z, c30.z)));
|
||||
color+= vec3(dot(weights[1], vec4(c01.x, c11.x, c21.x, c31.x)), dot(weights[1], vec4(c01.y, c11.y, c21.y, c31.y)), dot(weights[1], vec4(c01.z, c11.z, c21.z, c31.z)));
|
||||
color+= vec3(dot(weights[2], vec4(c02.x, c12.x, c22.x, c32.x)), dot(weights[2], vec4(c02.y, c12.y, c22.y, c32.y)), dot(weights[2], vec4(c02.z, c12.z, c22.z, c32.z)));
|
||||
color+= vec3(dot(weights[3], vec4(c03.x, c13.x, c23.x, c33.x)), dot(weights[3], vec4(c03.y, c13.y, c23.y, c33.y)), dot(weights[3], vec4(c03.z, c13.z, c23.z, c33.z)));
|
||||
color = color/(dot(weights[0], vec4(1,1,1,1)) + dot(weights[1], vec4(1,1,1,1)) + dot(weights[2], vec4(1,1,1,1)) + dot(weights[3], vec4(1,1,1,1)));
|
||||
|
||||
// Anti-ringing
|
||||
vec3 aux = color;
|
||||
color = clamp(color, min_sample, max_sample);
|
||||
color = mix(aux, color, JINC2_AR_STRENGTH);
|
||||
|
||||
// final sum and weight normalization
|
||||
vec4 texel = vec4(color, 1.0);
|
||||
return texel;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
vec4 color;
|
||||
|
||||
@ -534,6 +644,8 @@ void main() {
|
||||
texel = get_texel_bilinear();
|
||||
#elif defined(FILTER_3POINT)
|
||||
texel = get_texel_3point();
|
||||
#elif defined(FILTER_JINC2)
|
||||
texel = get_texel_jinc2();
|
||||
#else
|
||||
texel = texel0; //use nearest if nothing else is chosen
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user