medfall

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 5983f7477cdfed434030ea637587c620b594f5b1
parent 9418107422c6831e23caeb81cbe6b04ec2383c58
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Sat Sep 10 21:53:29 -0700

Actually use the horizons texture

Diffstat:
game.h | 1+
gpubtt.cc | 7+++++--
gpubtt.h | 3++-
mod_btt.cc | 5+++--
terrain_manager.cc | 6+++---
terrain_manager.h | 1+
6 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/game.h b/game.h @@ -57,6 +57,7 @@ struct GameState { GLint test_at_lit; GLint test_un_sun; GLint test_un_normals; + GLint test_un_horizons; GLint test_un_dimensions; GLuint test_outline_shader; diff --git a/gpubtt.cc b/gpubtt.cc @@ -63,7 +63,6 @@ static void compute_horizons( u32 hull_size = 1; hull[ 0 ] = hm->point( start.x, start.y ); - horizons[ 0 ] = 0; start += step; @@ -131,6 +130,7 @@ void gpubtt_init( glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F, ohm->hm.width, ohm->hm.height, 0, GL_RGB, GL_FLOAT, normals ); float * horizons = memarena_push_many( arena, float, ohm->hm.width * ohm->hm.height ); + memset( horizons, 0, ohm->hm.width * ohm->hm.height * sizeof( float ) ); for( u32 i = 0; i < ohm->hm.height; i++ ) { compute_horizons( arena, &ohm->hm, horizons, glm::ivec2( 0, i ), glm::ivec2( 1, 0 ) ); @@ -155,14 +155,17 @@ void gpubtt_destroy( GPUBTT * gpubtt ) { gpubtt->vbo_verts = 0; } -void gpubtt_render( const GPUBTT * gpubtt, GLuint un_normals ) { +void gpubtt_render( const GPUBTT * gpubtt, GLuint un_normals, GLuint un_horizons ) { if( gpubtt->vbo_verts == 0 ) return; glBindVertexArray( gpubtt->vao ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, gpubtt->tex_normals ); + glActiveTexture( GL_TEXTURE3 ); + glBindTexture( GL_TEXTURE_2D, gpubtt->tex_horizons ); glUniform1i( un_normals, 0 ); + glUniform1i( un_horizons, 3 ); glDrawArrays( GL_TRIANGLES, 0, gpubtt->num_verts * 3 ); diff --git a/gpubtt.h b/gpubtt.h @@ -19,6 +19,7 @@ void gpubtt_init( MemoryArena * arena, GPUBTT * gpubtt, void gpubtt_destroy( GPUBTT * gpubtt ); -void gpubtt_render( const GPUBTT * gpubtt, GLuint un_normals ); +void gpubtt_render( const GPUBTT * gpubtt, GLuint un_normals, + GLuint un_horizons ); #endif // _GPUBTT_H_ diff --git a/mod_btt.cc b/mod_btt.cc @@ -51,7 +51,7 @@ static const GLchar * frag_src = GLSL( } vec3 sunv = normalize( vec3( 1, 1, -sun ) ); - float horizon = texture( horizons, smooth_position.xy / dimensions ).x; + float horizon = texture( horizons, smooth_position.xy / dimensions ).r; float l = sun > horizon ? 1.0 : 0.0; float d = max( 0, -dot( normal, sunv ) ); @@ -141,6 +141,7 @@ extern "C" GAME_INIT( game_init ) { game->test_un_VP = glGetUniformLocation( game->test_shader, "vp" ); game->test_un_sun = glGetUniformLocation( game->test_shader, "sun" ); game->test_un_normals = glGetUniformLocation( game->test_shader, "normals" ); + game->test_un_horizons = glGetUniformLocation( game->test_shader, "horizons" ); game->test_un_dimensions = glGetUniformLocation( game->test_shader, "dimensions" ); game->test_outline_shader = compile_shader( vert_outline_src, frag_outline_src, "screen_colour" ); @@ -204,7 +205,7 @@ extern "C" GAME_FRAME( game_frame ) { glUniformMatrix4fv( game->test_un_VP, 1, GL_FALSE, glm::value_ptr( VP ) ); glUniform1f( game->test_un_sun, game->test_sun ); glUniform2f( game->test_un_dimensions, game->hm.width, game->hm.height ); - gpubtt_render( &game->gpubtt, game->test_un_normals ); + gpubtt_render( &game->gpubtt, game->test_un_normals, game->test_un_horizons ); glUseProgram( 0 ); immediate_init( &imm, triangles, array_count( triangles ) ); diff --git a/terrain_manager.cc b/terrain_manager.cc @@ -61,11 +61,10 @@ static const GLchar * frag_src = GLSL( } vec3 sunv = normalize( vec3( 1, 1, -sun ) ); - float horizon = texture( horizons, smooth_position.xy / dimensions ).x; + float horizon = texture( horizons, smooth_position.xy / dimensions ).r; float l = sun > horizon ? 1.0 : 0.0; float d = max( 0, -dot( normal, sunv ) ); - // float light = max( 0.2, l * ( d * 0 + 1 ) ); float light = max( 0.2, l * d ); // colour *= 0; @@ -217,6 +216,7 @@ void terrain_init( tm->un_VP = glGetUniformLocation( tm->shader, "vp" ); tm->un_sun = glGetUniformLocation( tm->shader, "sun" ); tm->un_normals = glGetUniformLocation( tm->shader, "normals" ); + tm->un_horizons = glGetUniformLocation( tm->shader, "horizons" ); tm->un_dimensions = glGetUniformLocation( tm->shader, "dimensions" ); // tm->un_point_light_counts_and_offsets = glGetUniformLocation( tm->shader, "point_light_counts_and_offsets" ); @@ -415,7 +415,7 @@ void terrain_render( TerrainManager * tm, glm::mat4 V, glm::mat4 VP, float sun_s u32 state = load_acquire( &tm->tile_states[ tx ][ ty ] ); if( state == TILE_ON_GPU ) { - gpubtt_render( &tm->btt_tiles[ tx ][ ty ], tm->un_normals ); + gpubtt_render( &tm->btt_tiles[ tx ][ ty ], tm->un_normals, tm->un_horizons ); } } } diff --git a/terrain_manager.h b/terrain_manager.h @@ -47,6 +47,7 @@ struct TerrainManager { GLint at_lit; GLint un_sun; GLint un_normals; + GLint un_horizons; GLint un_dimensions; // clustered shading stuff