From ee2e66cf9f410265f3e76e6643df198f7ab36972 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Tue, 19 Mar 2019 10:32:38 -0400 Subject: [PATCH] Use texelFetch for the meta texture --- data/shader/surface.inc.glsl | 7 ++++--- data/shader/terrain_ray_old.glsl | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/data/shader/surface.inc.glsl b/data/shader/surface.inc.glsl index d2cb8e76..9a665640 100644 --- a/data/shader/surface.inc.glsl +++ b/data/shader/surface.inc.glsl @@ -58,8 +58,9 @@ Surface get_surface(vec2 pos) { Surface suf; vec2 tc = suf.tex_coord = pos / u_TextureScale.xy; + ivec2 tci = ivec2(mod(pos + 0.5, u_TextureScale.xy)); - uint meta = texture(usampler2D(t_Meta, s_MainSampler), tc).x; + uint meta = texelFetch(usampler2D(t_Meta, s_MainSampler), tci, 0).x; suf.is_shadowed = (meta & c_ShadowMask) != 0U; suf.low_type = get_terrain_type(meta); @@ -68,13 +69,13 @@ Surface get_surface(vec2 pos) { // so this can be more efficient with a boolean param uint delta; if (mod(pos.x, 2.0) >= 1.0) { - uint meta_low = textureOffset(usampler2D(t_Meta, s_MainSampler), tc, ivec2(-1, 0)).x; + uint meta_low = texelFetch(usampler2D(t_Meta, s_MainSampler), tci + ivec2(-1, 0), 0).x; suf.high_type = suf.low_type; suf.low_type = get_terrain_type(meta_low); delta = (get_delta(meta_low) << c_DeltaBits) + get_delta(meta); } else { - uint meta_high = textureOffset(usampler2D(t_Meta, s_MainSampler), tc, ivec2(1, 0)).x; + uint meta_high = texelFetch(usampler2D(t_Meta, s_MainSampler), tci + ivec2(1, 0), 0).x; suf.tex_coord.x += 1.0 / u_TextureScale.x; suf.high_type = get_terrain_type(meta_high); diff --git a/data/shader/terrain_ray_old.glsl b/data/shader/terrain_ray_old.glsl index 7e2e29e7..de0204e5 100644 --- a/data/shader/terrain_ray_old.glsl +++ b/data/shader/terrain_ray_old.glsl @@ -11,10 +11,10 @@ layout(set = 0, binding = 0) uniform c_Globals { #ifdef SHADER_VS -layout(location = 0) attribute vec4 a_Pos; +layout(location = 0) attribute ivec4 a_Pos; void main() { - gl_Position = u_ViewProj * a_Pos; + gl_Position = u_ViewProj * vec4(a_Pos); // convert from -1,1 Z to 0,1 gl_Position.z = 0.5 * (gl_Position.z + gl_Position.w); }