From 7ea0e906782a9ed8f4bdb89c87024b318f8a529c Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Thu, 6 Oct 2016 20:15:50 +0200 Subject: [PATCH] gsdx mipmap:ogl: extend shader to support trilinear filtering --- plugins/GSdx/GSDeviceOGL.cpp | 2 ++ plugins/GSdx/GSDeviceOGL.h | 4 +++- plugins/GSdx/res/glsl/tfx_fs.glsl | 19 +++++++++++++++++++ plugins/GSdx/res/glsl_source.h | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 3913747b4d..c7d4d91d6a 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -954,6 +954,8 @@ GLuint GSDeviceOGL::CompilePS(PSSelector sel) + format("#define PS_CLR1 %d\n", sel.clr1) + format("#define PS_FBA %d\n", sel.fba) + format("#define PS_LTF %d\n", sel.ltf) + + format("#define PS_AUTOMATIC_LOD %d\n", sel.automatic_lod) + + format("#define PS_MANUAL_LOD %d\n", sel.manual_lod) + format("#define PS_COLCLIP %d\n", sel.colclip) + format("#define PS_DATE %d\n", sel.date) + format("#define PS_TCOFFSETHACK %d\n", sel.tcoffsethack) diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 60d5560916..522fb06490 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -293,8 +293,10 @@ public: uint32 urban_chaos_hle:1; uint32 tales_of_abyss_hle:1; uint32 tex_is_fb:1; // Jak Shadows + uint32 automatic_lod:1; + uint32 manual_lod:1; - uint32 _free2:13; + uint32 _free2:11; }; uint64 key; diff --git a/plugins/GSdx/res/glsl/tfx_fs.glsl b/plugins/GSdx/res/glsl/tfx_fs.glsl index 5eb59313c3..530b3d4f7b 100644 --- a/plugins/GSdx/res/glsl/tfx_fs.glsl +++ b/plugins/GSdx/res/glsl/tfx_fs.glsl @@ -78,7 +78,26 @@ vec4 sample_c(vec2 uv) #if PS_TEX_IS_FB == 1 return texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0); #else + +#if PS_AUTOMATIC_LOD == 1 return texture(TextureSampler, uv); +#elif PS_MANUAL_LOD == 1 + // FIXME add LOD: K - ( LOG2(Q) * (1 << L)) + float K = MinMax.x; + float L = MinMax.y; + float bias = MinMax.z; + float max_lod = MinMax.w; + + float gs_lod = K - log2(abs(PSin.t_float.w)) * L; + // FIXME max useful ? + //float lod = max(min(gs_lod, max_lod) - bias, 0.0f); + float lod = min(gs_lod, max_lod) - bias; + + return textureLod(TextureSampler, uv, lod); +#else + return textureLod(TextureSampler, uv, 0); // No lod +#endif + #endif } diff --git a/plugins/GSdx/res/glsl_source.h b/plugins/GSdx/res/glsl_source.h index b004cdf88e..b71f146f99 100644 --- a/plugins/GSdx/res/glsl_source.h +++ b/plugins/GSdx/res/glsl_source.h @@ -998,7 +998,26 @@ static const char* const tfx_fs_all_glsl = "#if PS_TEX_IS_FB == 1\n" " return texelFetch(RtSampler, ivec2(gl_FragCoord.xy), 0);\n" "#else\n" + "\n" + "#if PS_AUTOMATIC_LOD == 1\n" " return texture(TextureSampler, uv);\n" + "#elif PS_MANUAL_LOD == 1\n" + " // FIXME add LOD: K - ( LOG2(Q) * (1 << L))\n" + " float K = MinMax.x;\n" + " float L = MinMax.y;\n" + " float bias = MinMax.z;\n" + " float max_lod = MinMax.w;\n" + "\n" + " float gs_lod = K - log2(abs(PSin.t_float.w)) * L;\n" + " // FIXME max useful ?\n" + " //float lod = max(min(gs_lod, max_lod) - bias, 0.0f);\n" + " float lod = min(gs_lod, max_lod) - bias;\n" + "\n" + " return textureLod(TextureSampler, uv, lod);\n" + "#else\n" + " return textureLod(TextureSampler, uv, 0); // No lod\n" + "#endif\n" + "\n" "#endif\n" "}\n" "\n"