From a85b62fdb2e153195a52cef8ecad27432bf37f50 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Wed, 21 Jun 2023 08:43:54 -0700 Subject: Flip y-coordinate in view-texture shader and use texelFetch to avoid bilinear sampling. --- gfx/shaders/view_texture.frag | 8 ++++++-- gfx/shaders/view_texture.vert | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/gfx/shaders/view_texture.frag b/gfx/shaders/view_texture.frag index a81263b..f01127d 100644 --- a/gfx/shaders/view_texture.frag +++ b/gfx/shaders/view_texture.frag @@ -6,6 +6,10 @@ layout (location = 0) out vec4 Colour; void main() { - vec3 colour = texture(Texture, Texcoord).rgb; - Colour = vec4(pow(colour, vec3(1.0 / 2.2)), 1.0); + // My OpenGL driver seems to be ignoring GL_NEAREST for + // GL_TEXTURE_MAG_FILTER and still applies bilinear sampling. Use texelFetch + // instead of texture() instead. + ivec2 st = ivec2(Texcoord * vec2(textureSize(Texture, 0))); + vec3 colour = texelFetch(Texture, st, 0).rgb; + Colour = vec4(pow(colour, vec3(1.0 / 2.2)), 1.0); } diff --git a/gfx/shaders/view_texture.vert b/gfx/shaders/view_texture.vert index 49a0422..4e3c7d7 100644 --- a/gfx/shaders/view_texture.vert +++ b/gfx/shaders/view_texture.vert @@ -4,6 +4,10 @@ out vec2 Texcoord; void main() { - Texcoord = Position * vec2(0.5) + vec2(0.5); // Map from [-1, +1] to [0, 1]. - gl_Position = vec4(Position, 0.0, 1.0); + Texcoord = Position * vec2(0.5) + vec2(0.5);// Map from [-1, +1] to [0, 1]. + // The Gfx library is written to work with the glTF sample models, which + // seem to want the textures loaded "as is" without flipping. Flip the + // y-coordinate here so that the texture appears as expected. + Texcoord.y = 1.0 - Texcoord.y; + gl_Position = vec4(Position, 0.0, 1.0); } -- cgit v1.2.3