diff --git a/examples/srtm.cpp b/examples/srtm.cpp index b6623cb9..c3f81adf 100644 --- a/examples/srtm.cpp +++ b/examples/srtm.cpp @@ -40,7 +40,6 @@ // TODO: fix frustum culling // TODO: fix seams at tile borders // TODO: try a different coordinate system for closer tiles -// TODO: use closer near plane, maybe try reversed-Z // TODO: add space, stars, the sun // TODO: add atmospheric glow @@ -439,6 +438,8 @@ uniform vec3 u_p2; uniform sampler1D u_colormap; uniform sampler1D u_colormap_neg; +uniform float u_far; + layout (location = 0) in float in_height; out vec3 color; @@ -456,6 +457,8 @@ void main() vec3 p = normalize(u_p0 * t0 + u_p1 * t1 + u_p2 * t2) * (1.0 + in_height / 6400000.0); pos = p; gl_Position = u_transform * vec4(p, 1.0); + float C = 1.0; + gl_Position.z = (2.0 * log(C * gl_Position.w + 1.0) / log(C * u_far + 1.0) - 1.0) * gl_Position.w; color = (in_height > 0.0) ? texture(u_colormap, in_height / 8000.0).rgb : texture(u_colormap_neg, -in_height / 10000.0).rgb; })"; @@ -724,12 +727,14 @@ void srtm_app::present() tile_close_program["u_light"] = geom::vector{0.f, 0.f, 1.f}; tile_close_program["u_colormap"] = 0; tile_close_program["u_colormap_neg"] = 1; + tile_close_program["u_far"] = camera.far_clip; tile_far_program.bind(); tile_far_program["u_transform"] = camera_transform; tile_far_program["u_N"] = static_cast(node_size); tile_far_program["u_light"] = geom::vector{0.f, 0.f, 1.f}; tile_far_program["u_colormap"] = 0; tile_far_program["u_colormap_neg"] = 1; + tile_far_program["u_far"] = camera.far_clip; gl::ActiveTexture(gl::TEXTURE0); color_map.bind(); gl::ActiveTexture(gl::TEXTURE1);