1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-04 10:03:36 +00:00

Fix shader compilation errors with Adreno GPUs with hybrid filter

This commit is contained in:
fzurita 2020-10-31 10:30:10 -04:00 committed by Sergey Lipskiy
parent e81022ad71
commit 1b70d5b145

View File

@ -360,48 +360,48 @@ namespace glsl {
static std::string strFilter = static std::string strFilter =
"uniform sampler2D uTex0; \n" "uniform sampler2D uTex0; \n"
" \n" " \n"
"ivec2 get_texture_size(sampler2D tex) \n" "ivec2 get_texture_size() \n"
"{ \n" "{ \n"
" return textureSize(tex, 0); \n" " return textureSize(uTex0, 0); \n"
"} \n" "} \n"
" \n" " \n"
"mediump vec2 norm2denorm(sampler2D tex, mediump vec2 uv) \n" "mediump vec2 norm2denorm(mediump vec2 uv) \n"
"{ \n" "{ \n"
" return uv * vec2(get_texture_size(tex)) - 0.5; \n" " return uv * vec2(get_texture_size()) - 0.5; \n"
"} \n" "} \n"
" \n" " \n"
"mediump vec2 denorm2norm(sampler2D tex, mediump vec2 denorm_uv) \n" "mediump vec2 denorm2norm(mediump vec2 denorm_uv) \n"
"{ \n" "{ \n"
" return (denorm_uv + 0.5) / vec2(get_texture_size(tex)); \n" " return (denorm_uv + 0.5) / vec2(get_texture_size()); \n"
"} \n" "} \n"
" \n" " \n"
"mediump vec4 hybridFilter(sampler2D tex, mediump vec2 uv) \n" "mediump vec4 hybridFilter(mediump vec2 uv) \n"
"{ \n" "{ \n"
" mediump vec2 denorm_uv = norm2denorm(tex, uv); \n" " mediump vec2 denorm_uv = norm2denorm(uv); \n"
" mediump vec2 low_corner = floor(denorm_uv); \n" " mediump vec2 low_corner = floor(denorm_uv); \n"
" mediump vec2 ratio = denorm_uv - low_corner; \n" " mediump vec2 ratio = denorm_uv - low_corner; \n"
" \n" " \n"
" /* \n" /*
" * 'radius' is the distance from the edge where interpolation happens. \n" * 'radius' is the distance from the edge where interpolation happens.
" * It's calculated based on how big a fragment is in denormalized \n" * It's calculated based on how big a fragment is in denormalized
" * texture coordinates. \n" * texture coordinates.
" * \n" *
" * E.g.: If a texel maps to 5 fragments, then each fragment is \n" * E.g.: If a texel maps to 5 fragments, then each fragment is
" * 1/5 texels big. So the smooth transition should be between one and \n" * 1/5 texels big. So the smooth transition should be between one and
" * two fragments big, since there are enough fragments to show the full \n" * two fragments big, since there are enough fragments to show the full
" * color of the texel. \n" * color of the texel.
" * \n" *
" * If a fragment is larger than one texel, we don't care, we're already \n" * If a fragment is larger than one texel, we don't care, we're already
" * sampling the wrong texels, and should be using mipmaps instead. \n" * sampling the wrong texels, and should be using mipmaps instead.
" */ \n" */
" \n"
" // Here, fwidth() is used to estimte how much denorm_uv changes per fragment.\n" // Here, fwidth() is used to estimte how much denorm_uv changes per fragment.
" // But we divide it by 2, since fwidth() is adding abs(dx) + abs(dy). \n" // But we divide it by 2, since fwidth() is adding abs(dx) + abs(dy).
" mediump vec2 fragment_size = fwidth(denorm_uv) / 2.0; \n" " mediump vec2 fragment_size = fwidth(denorm_uv) / 2.0; \n"
" \n" " \n"
" mediump float is_frag_gt1, radius; \n" " mediump float is_frag_gt1, radius; \n"
" // Do nothing if fragment is greater than 1 texel \n" // Do nothing if fragment is greater than 1 texel
" // Don't make the transition more than one fragment (+/- 0.5 fragment) \n" // Don't make the transition more than one fragment (+/- 0.5 fragment)
" is_frag_gt1 = step(1.0, fragment_size.s); \n" " is_frag_gt1 = step(1.0, fragment_size.s); \n"
" radius = min(fragment_size.s, 0.5); \n" " radius = min(fragment_size.s, 0.5); \n"
" ratio.s = ratio.s * is_frag_gt1 + smoothstep(0.5 - radius, \n" " ratio.s = ratio.s * is_frag_gt1 + smoothstep(0.5 - radius, \n"
@ -411,10 +411,10 @@ namespace glsl {
" ratio.t = ratio.t * is_frag_gt1 + smoothstep(0.5 - radius, \n" " ratio.t = ratio.t * is_frag_gt1 + smoothstep(0.5 - radius, \n"
" 0.5 + radius, ratio.t) * (1.0 - is_frag_gt1); \n" " 0.5 + radius, ratio.t) * (1.0 - is_frag_gt1); \n"
" \n" " \n"
" // now bump the coord to the texel using ratio \n" // now bump the coord to the texel using ratio
" mediump vec2 new_denorm_uv = low_corner + ratio; \n" " mediump vec2 new_denorm_uv = low_corner + ratio; \n"
" mediump vec2 new_uv = denorm2norm(tex, new_denorm_uv); \n" " mediump vec2 new_uv = denorm2norm(new_denorm_uv); \n"
" return texture2D(tex, new_uv); \n" " return texture2D(uTex0, new_uv); \n"
"} \n" "} \n"
; ;
return strFilter; return strFilter;
@ -435,7 +435,7 @@ namespace glsl {
" \n" " \n"
"void main() \n" "void main() \n"
"{ \n" "{ \n"
" fragColor = hybridFilter(uTex0, vTexCoord0); \n" " fragColor = hybridFilter(vTexCoord0); \n"
; ;
} else { } else {
m_part = m_part =
@ -484,7 +484,7 @@ namespace glsl {
" \n" " \n"
"void main() \n" "void main() \n"
"{ \n" "{ \n"
" fragColor = hybridFilter(uTex0, vTexCoord0); \n" " fragColor = hybridFilter(vTexCoord0); \n"
" gl_FragDepth = texture2D(uTex1, vTexCoord0).r; \n" " gl_FragDepth = texture2D(uTex1, vTexCoord0).r; \n"
; ;
} else { } else {