commit 7f660d353b08b724b486feb2d5da6e676b690d14
parent 7651cd98b8d8a2f3cfd86e1854914b5d994d0526
Author: Michael Savage <mikejsavage@gmail.com>
Date: Fri, 10 Nov 2017 21:40:24 +0200
Sample from texture centres instead of their corners
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/shaders/clipmap.glsl b/shaders/clipmap.glsl
@@ -33,8 +33,9 @@ out VSOut v2f;
void main() {
vec2 xy = offset + position.xy * scale + camera_pos.xy;
vec2 snapped_xy = floor( xy / scale ) * scale;
- vec2 uv = snapped_xy / textureSize( heightmap, 0 );
- float z = 256.0 * texture( heightmap, uv ).r + texture( heightmap, uv ).g;
+ vec2 uv = ( snapped_xy + 0.5 ) / textureSize( heightmap, 0 );
+ vec2 height_sample = texelFetch( heightmap, ivec2( snapped_xy ), 0 ).rg;
+ float z = 256.0 * height_sample.r + height_sample.g;
v2f.view_position = V * vec4( snapped_xy, z, 1.0 );
v2f.world_position = vec3( xy, z );