diff options
author | 3gg <3gg@shellblade.net> | 2023-06-21 08:43:54 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2023-06-21 08:43:54 -0700 |
commit | a85b62fdb2e153195a52cef8ecad27432bf37f50 (patch) | |
tree | 71858fb2846a9b63b58ce97150ce647f3441bbef | |
parent | be63cdf390b0bdbb00ba67cff95d165d214418fb (diff) |
Flip y-coordinate in view-texture shader and use texelFetch to avoid bilinear sampling.
-rw-r--r-- | gfx/shaders/view_texture.frag | 8 | ||||
-rw-r--r-- | 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; | |||
6 | 6 | ||
7 | void main() | 7 | void main() |
8 | { | 8 | { |
9 | vec3 colour = texture(Texture, Texcoord).rgb; | 9 | // My OpenGL driver seems to be ignoring GL_NEAREST for |
10 | Colour = vec4(pow(colour, vec3(1.0 / 2.2)), 1.0); | 10 | // GL_TEXTURE_MAG_FILTER and still applies bilinear sampling. Use texelFetch |
11 | // instead of texture() instead. | ||
12 | ivec2 st = ivec2(Texcoord * vec2(textureSize(Texture, 0))); | ||
13 | vec3 colour = texelFetch(Texture, st, 0).rgb; | ||
14 | Colour = vec4(pow(colour, vec3(1.0 / 2.2)), 1.0); | ||
11 | } | 15 | } |
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; | |||
4 | 4 | ||
5 | void main() | 5 | void main() |
6 | { | 6 | { |
7 | Texcoord = Position * vec2(0.5) + vec2(0.5); // Map from [-1, +1] to [0, 1]. | 7 | Texcoord = Position * vec2(0.5) + vec2(0.5);// Map from [-1, +1] to [0, 1]. |
8 | gl_Position = vec4(Position, 0.0, 1.0); | 8 | // The Gfx library is written to work with the glTF sample models, which |
9 | // seem to want the textures loaded "as is" without flipping. Flip the | ||
10 | // y-coordinate here so that the texture appears as expected. | ||
11 | Texcoord.y = 1.0 - Texcoord.y; | ||
12 | gl_Position = vec4(Position, 0.0, 1.0); | ||
9 | } | 13 | } |