medfall

A super great game engine
Log | Files | Refs

commit 3bcab8fafd77f2d34a1ed353d21dbb5bf9b0102e
parent 07e89fa7d5461b6410047c70115312793357d07a
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat, 18 Nov 2017 17:51:17 +0200

Simplify and optimise tile/skirt rendering

Diffstat:
clipmap.cc | 57++++++++++++++++++++++++---------------------------------
1 file changed, 24 insertions(+), 33 deletions(-)

diff --git a/clipmap.cc b/clipmap.cc @@ -319,17 +319,22 @@ GAME_INIT( game_init ) { // generate skirt mesh { + float scale = checked_cast< float >( u32( 1 ) << ( NUM_LODS - 1 ) ); + v2 base = -v2( checked_cast< float >( PATCH_RESOLUTION << NUM_LODS ) ); + + v2 clipmap_tl = base; + v2 clipmap_br = clipmap_tl + v2( ( 4.0f * PATCH_RESOLUTION + 1.0f ) * scale ); + StaticArray< v3, 8 > vertices; float big = 10000000.0; vertices[ 0 ] = v3( -1, -1, 0 ) * big; vertices[ 1 ] = v3( +1, -1, 0 ) * big; vertices[ 2 ] = v3( -1, +1, 0 ) * big; vertices[ 3 ] = v3( +1, +1, 0 ) * big; - // these get moved to the edge of the terrain in the vertex shader - vertices[ 4 ] = v3( 0, 0, 0 ); - vertices[ 5 ] = v3( 0, 0, 0 ); - vertices[ 6 ] = v3( 0, 0, 0 ); - vertices[ 7 ] = v3( 0, 0, 0 ); + vertices[ 4 ] = v3( clipmap_tl.x, clipmap_tl.y, 0 ); + vertices[ 5 ] = v3( clipmap_br.x, clipmap_tl.y, 0 ); + vertices[ 6 ] = v3( clipmap_tl.x, clipmap_br.y, 0 ); + vertices[ 7 ] = v3( clipmap_br.x, clipmap_br.y, 0 ); u32 indices[] = { 0, 1, 4, 4, 1, 5, @@ -579,10 +584,6 @@ GAME_FRAME( game_frame ) { UniformBinding inf_view_uniforms = renderer_uniforms( V, Pinf, game->pos ); UniformBinding sun_uniforms = renderer_uniforms( sun_dir, game->sun_angle ); - v2 clipmap_tl; - float scale = 1.0f; - v2 base = v2( -float( PATCH_RESOLUTION * 2 ) ); - // draw terrain { RenderState render_state; @@ -596,7 +597,9 @@ GAME_FRAME( game_frame ) { render_state.wireframe = game->draw_wireframe; for( u32 l = 0; l < NUM_LODS; l++ ) { - v2 tile_size = v2( scale * float( PATCH_RESOLUTION ) ); + float scale = checked_cast< float >( u32( 1 ) << l ); + v2 tile_size = v2( checked_cast< float >( PATCH_RESOLUTION << l ) ); + v2 base = -v2( checked_cast< float >( PATCH_RESOLUTION << ( l + 1 ) ) ); // draw tiles for( int x = 0; x < 4; x++ ) { @@ -645,34 +648,22 @@ GAME_FRAME( game_frame ) { } } - - clipmap_tl = base + game->pos.xy(); - scale *= 2.0f; - base *= 2.0f; + // TODO draw seams } } - scale /= 2.0f; - clipmap_tl.x = floorf( clipmap_tl.x / scale ) * scale; - clipmap_tl.y = floorf( clipmap_tl.y / scale ) * scale; - v2 clipmap_br = clipmap_tl + v2( ( 4.0f * PATCH_RESOLUTION + 1.0f ) * scale ); - // draw skirts { - // need to be v4 because bounds is an array! - v4 bounds0 = v4( clipmap_tl.x, clipmap_tl.y, 0.0, 0.0 ); - v4 bounds1 = v4( clipmap_br.x, clipmap_tl.y, 0.0, 0.0 ); - v4 bounds2 = v4( clipmap_tl.x, clipmap_br.y, 0.0, 0.0 ); - v4 bounds3 = v4( clipmap_br.x, clipmap_br.y, 0.0, 0.0 ); - - RenderState render_state; - render_state.shader = get_shader( SHADER_CLIPMAP_SKIRT ); - render_state.uniforms[ UNIFORMS_VIEW ] = inf_view_uniforms; - render_state.uniforms[ UNIFORMS_SUN ] = sun_uniforms; - render_state.uniforms[ UNIFORMS_CLIPMAP_SKIRT ] = renderer_uniforms( bounds0, bounds1, bounds2, bounds3 ); - render_state.textures[ 0 ] = renderer_blue_noise(); - render_state.wireframe = game->draw_wireframe; - renderer_draw_mesh( clipmap.gpu.skirt, render_state ); + float scale = checked_cast< float >( u32( 1 ) << ( NUM_LODS - 1 ) ); + + RenderState skirt_render_state; + skirt_render_state.shader = get_shader( SHADER_CLIPMAP_SKIRT ); + skirt_render_state.uniforms[ UNIFORMS_VIEW ] = inf_view_uniforms; + skirt_render_state.uniforms[ UNIFORMS_SUN ] = sun_uniforms; + skirt_render_state.uniforms[ UNIFORMS_CLIPMAP_SKIRT ] = renderer_uniforms( scale ); + skirt_render_state.textures[ 0 ] = renderer_blue_noise(); + skirt_render_state.wireframe = game->draw_wireframe; + renderer_draw_mesh( clipmap.gpu.skirt, skirt_render_state ); } // draw trees