diff --git a/src/render/opengl/OpenGLRenderer.cpp b/src/render/opengl/OpenGLRenderer.cpp index 311de4d..d06fd5c 100644 --- a/src/render/opengl/OpenGLRenderer.cpp +++ b/src/render/opengl/OpenGLRenderer.cpp @@ -15,6 +15,8 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery): functions = new OpenGLFunctions(); shared_state = new OpenGLSharedState(); + shared_state->set("viewDistance", 20.0); + skybox = new OpenGLSkybox(this); water = new OpenGLWater(this); terrain = new OpenGLTerrain(this); @@ -84,6 +86,9 @@ void OpenGLRenderer::paint() functions->glClearColor(0.0, 0.0, 0.0, 0.0); functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + functions->glEnable(GL_BLEND); + functions->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + skybox->render(); terrain->render(); water->render(); diff --git a/src/render/opengl/OpenGLTerrain.cpp b/src/render/opengl/OpenGLTerrain.cpp index 73b29c5..1a02fc2 100644 --- a/src/render/opengl/OpenGLTerrain.cpp +++ b/src/render/opengl/OpenGLTerrain.cpp @@ -57,8 +57,8 @@ void OpenGLTerrain::initialize() program->addFragmentSource("terrain"); // Add terrain chunks - int chunks = 20; - double size = 400.0; + int chunks = 25; + double size = 800.0; double chunksize = size / (double) chunks; double start = -size / 2.0; double water_height = renderer->getWaterRenderer()->getHeightInfo().base_height; diff --git a/src/render/opengl/shaders/terrain.frag b/src/render/opengl/shaders/terrain.frag index 77054be..4ba3625 100644 --- a/src/render/opengl/shaders/terrain.frag +++ b/src/render/opengl/shaders/terrain.frag @@ -1,5 +1,6 @@ uniform sampler2D groundTexture; varying vec2 texcoord; +uniform float viewDistance; void main(void) { @@ -27,4 +28,6 @@ void main(void) gl_FragColor = gl_FragColor * vec4(attenuation, 0.0) + vec4(inscattering, 0.0); gl_FragColor = _toneMappingUncharted(gl_FragColor, 2.0); + + gl_FragColor.a = mix(1.0, 0.0, clamp((t - viewDistance * 0.8) / (viewDistance * 0.2), 0.0, 1.0)); } diff --git a/src/render/opengl/shaders/water.frag b/src/render/opengl/shaders/water.frag index a4318fc..9f5f361 100644 --- a/src/render/opengl/shaders/water.frag +++ b/src/render/opengl/shaders/water.frag @@ -1,4 +1,5 @@ uniform vec4 waterColor; +uniform float viewDistance; void main(void) { @@ -26,4 +27,6 @@ void main(void) gl_FragColor = gl_FragColor * vec4(attenuation, 0.0) + vec4(inscattering, 0.0); gl_FragColor = _toneMappingUncharted(gl_FragColor, 2.0); + + gl_FragColor.a = mix(1.0, 0.0, clamp((t - viewDistance * 0.8) / (viewDistance * 0.2), 0.0, 1.0)); }