Skip to content

Commit

Permalink
Use texelFetch for the meta texture
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Mar 19, 2019
1 parent 0ed9e33 commit ee2e66c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions data/shader/surface.inc.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions data/shader/terrain_ray_old.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit ee2e66c

Please sign in to comment.