Added view distance blending in opengl renderer

This commit is contained in:
Michaël Lemaire 2013-12-24 13:22:34 +01:00 committed by Michael Lemaire
parent 74e707a989
commit 3d54ce974a
4 changed files with 13 additions and 2 deletions

View file

@ -15,6 +15,8 @@ OpenGLRenderer::OpenGLRenderer(Scenery* scenery):
functions = new OpenGLFunctions(); functions = new OpenGLFunctions();
shared_state = new OpenGLSharedState(); shared_state = new OpenGLSharedState();
shared_state->set("viewDistance", 20.0);
skybox = new OpenGLSkybox(this); skybox = new OpenGLSkybox(this);
water = new OpenGLWater(this); water = new OpenGLWater(this);
terrain = new OpenGLTerrain(this); terrain = new OpenGLTerrain(this);
@ -84,6 +86,9 @@ void OpenGLRenderer::paint()
functions->glClearColor(0.0, 0.0, 0.0, 0.0); functions->glClearColor(0.0, 0.0, 0.0, 0.0);
functions->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 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(); skybox->render();
terrain->render(); terrain->render();
water->render(); water->render();

View file

@ -57,8 +57,8 @@ void OpenGLTerrain::initialize()
program->addFragmentSource("terrain"); program->addFragmentSource("terrain");
// Add terrain chunks // Add terrain chunks
int chunks = 20; int chunks = 25;
double size = 400.0; double size = 800.0;
double chunksize = size / (double) chunks; double chunksize = size / (double) chunks;
double start = -size / 2.0; double start = -size / 2.0;
double water_height = renderer->getWaterRenderer()->getHeightInfo().base_height; double water_height = renderer->getWaterRenderer()->getHeightInfo().base_height;

View file

@ -1,5 +1,6 @@
uniform sampler2D groundTexture; uniform sampler2D groundTexture;
varying vec2 texcoord; varying vec2 texcoord;
uniform float viewDistance;
void main(void) void main(void)
{ {
@ -27,4 +28,6 @@ void main(void)
gl_FragColor = gl_FragColor * vec4(attenuation, 0.0) + vec4(inscattering, 0.0); gl_FragColor = gl_FragColor * vec4(attenuation, 0.0) + vec4(inscattering, 0.0);
gl_FragColor = _toneMappingUncharted(gl_FragColor, 2.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));
} }

View file

@ -1,4 +1,5 @@
uniform vec4 waterColor; uniform vec4 waterColor;
uniform float viewDistance;
void main(void) void main(void)
{ {
@ -26,4 +27,6 @@ void main(void)
gl_FragColor = gl_FragColor * vec4(attenuation, 0.0) + vec4(inscattering, 0.0); gl_FragColor = gl_FragColor * vec4(attenuation, 0.0) + vec4(inscattering, 0.0);
gl_FragColor = _toneMappingUncharted(gl_FragColor, 2.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));
} }