medfall

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

commit ba673d0baf4a359002db307137e57781cc0e2549
parent b6c264dab96c59068b669e2057ad580364ad6520
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Wed Oct 12 23:14:26 +0300

Fix btt.so

Diffstat:
mod_btt.cc | 103++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------
1 file changed, 71 insertions(+), 32 deletions(-)
diff --git a/mod_btt.cc b/mod_btt.cc @@ -9,6 +9,8 @@ #include "immediate.h" #include "skybox.h" #include "stb_image.h" +#include "linear_algebra.h" +#include "lz4.h" static ImmediateTriangle triangles[ 512000 ]; static ImmediateContext imm; @@ -103,33 +105,35 @@ static glm::vec3 angles_to_vector_xy( const glm::vec3 & angles ) { return glm::vec3( sin( angles.y ), cos( angles.y ), 0 ); } -static void draw_btt( - const BTT * const btt, const Heightmap * const hm, - ImmediateContext * const imm, - const glm::ivec2 iv0, const glm::ivec2 iv1, const glm::ivec2 iv2 -) { - const glm::vec4 white( 1, 1, 1, 1 ); - const glm::vec3 offset( 0.0f, 0.0f, 0.5f ); - - const glm::vec3 v0( hm->point( iv0.x, iv0.y ) + offset ); - const glm::vec3 v1( hm->point( iv1.x, iv1.y ) + offset ); - const glm::vec3 v2( hm->point( iv2.x, iv2.y ) + offset ); - - if( btt->left ) { - assert( btt->right ); - - const glm::ivec2 mid = ( iv0 + iv2 ) / 2; - - draw_btt( btt->left, hm, imm, iv1, mid, iv0 ); - draw_btt( btt->right, hm, imm, iv2, mid, iv1 ); - } - else { - immediate_triangle( imm, v0, v1, v2, white ); - } -} +// static void draw_btt( +// const BTT * btt, const Heightmap * hm, +// ImmediateContext * imm, +// glm::ivec2 iv0, glm::ivec2 iv1, glm::ivec2 iv2 +// ) { +// const glm::vec4 white( 1, 1, 1, 1 ); +// const glm::vec3 offset( 0.0f, 0.0f, 0.5f ); +// +// glm::vec3 v0( hm->point( iv0.x, iv0.y ) + offset ); +// glm::vec3 v1( hm->point( iv1.x, iv1.y ) + offset ); +// glm::vec3 v2( hm->point( iv2.x, iv2.y ) + offset ); +// +// if( btt->left ) { +// assert( btt->right ); +// +// glm::ivec2 mid = ( iv0 + iv2 ) / 2; +// +// draw_btt( btt->left, hm, imm, iv1, mid, iv0 ); +// draw_btt( btt->right, hm, imm, iv2, mid, iv1 ); +// } +// else { +// immediate_triangle( imm, v0, v1, v2, white ); +// } +// } static const glm::mat4 P( glm::perspective( glm::radians( 120.0f ), ( float ) WIDTH / ( float ) HEIGHT, NEAR_PLANE_DEPTH, FAR_PLANE_DEPTH ) ); +static float * horizons; + extern "C" GAME_INIT( game_init ) { game->pos = glm::vec3( 100, 200, 100 ); game->angles = glm::radians( glm::vec3( -90, 45, 0 ) ); @@ -153,10 +157,34 @@ extern "C" GAME_INIT( game_init ) { u8 * pixels = stbi_load( "terrains/mountains512.png", &w, &h, NULL, 1 ); heightmap_init( &game->hm, pixels, w, h ); + size_t horizons_size = ( w + 1 ) * ( h + 1 ) * sizeof( float ); + horizons = ( float * ) malloc( horizons_size ); + assert( horizons != NULL ); + + size_t compressed_horizons_size; + u8 * compressed_horizons = file_get_contents( "terrains/mountains512.png.parts/0_0_horizons.lz4", &compressed_horizons_size ); + int ok_horizons = LZ4_decompress_safe( + ( const char * ) compressed_horizons, + ( char * ) horizons, + compressed_horizons_size, horizons_size ); + assert( ok_horizons > 0 ); + + size_t normals_size = ( w + 1 ) * ( h + 1 ) * sizeof( v3 ); + v3 * normals = ( v3 * ) malloc( normals_size ); + assert( normals != NULL ); + + size_t compressed_normals_size; + u8 * compressed_normals = file_get_contents( "terrains/mountains512.png.parts/0_0_normals.lz4", &compressed_normals_size ); + int ok_normals = LZ4_decompress_safe( + ( const char * ) compressed_normals, + ( char * ) normals, + compressed_normals_size, normals_size ); + assert( ok_normals > 0 ); + game->btt = btt_from_heightmap( &game->hm, &mem->persistent_arena ); const OffsetHeightmap ohm = { game->hm, 0, 0 }; - gpubtt_init( &mem->persistent_arena, &game->gpubtt, &ohm, game->btt, game->test_at_position ); + gpubtt_init( &mem->persistent_arena, &game->gpubtt, game->btt, &ohm, normals, horizons, game->test_at_position ); glClearColor( 0, 0.5, 0.7, 1 ); @@ -199,7 +227,6 @@ extern "C" GAME_FRAME( game_frame ) { ), -game->pos ); - const glm::vec3 sun = glm::normalize( glm::vec3( 1, 0, -0.3 ) ); glUseProgram( game->test_shader ); glUniformMatrix4fv( game->test_un_VP, 1, GL_FALSE, glm::value_ptr( VP ) ); @@ -209,17 +236,29 @@ extern "C" GAME_FRAME( game_frame ) { glUseProgram( 0 ); immediate_init( &imm, triangles, array_count( triangles ) ); - draw_btt( game->btt.left_root, &game->hm, &imm, glm::ivec2( 0, 0 ), glm::ivec2( 0, game->hm.height - 1 ), glm::ivec2( game->hm.width - 1, game->hm.height - 1 ) ); - draw_btt( game->btt.right_root, &game->hm, &imm, glm::ivec2( game->hm.width - 1, game->hm.height - 1 ), glm::ivec2( game->hm.width - 1, 0 ), glm::ivec2( 0, 0 ) ); - - glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + for( size_t i = 0; i < game->hm.width; i++ ) { + glm::vec3 origin = glm::vec3( i, 1, game->hm.point( i, 1 ).z ); + glm::vec3 direction = glm::normalize( glm::vec3( -1, 0, horizons[ 1 * game->hm.width + i ] ) ); + glm::vec4 white( 1, 1, 1, 1 ); + immediate_arrow( &imm, origin, direction, 2, white ); + } glUseProgram( game->test_outline_shader ); glUniformMatrix4fv( game->test_outline_un_vp, 1, GL_FALSE, glm::value_ptr( VP ) ); immediate_render( &imm, game->test_outline_at_position, game->test_outline_at_colour ); glUseProgram( 0 ); - glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); - skybox_render( &game->skybox, game->angles ); + // immediate_init( &imm, triangles, array_count( triangles ) ); + // draw_btt( game->btt.left_root, &game->hm, &imm, glm::ivec2( 0, 0 ), glm::ivec2( 0, game->hm.height - 1 ), glm::ivec2( game->hm.width - 1, game->hm.height - 1 ) ); + // draw_btt( game->btt.right_root, &game->hm, &imm, glm::ivec2( game->hm.width - 1, game->hm.height - 1 ), glm::ivec2( game->hm.width - 1, 0 ), glm::ivec2( 0, 0 ) ); + + // glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); + // glUseProgram( game->test_outline_shader ); + // glUniformMatrix4fv( game->test_outline_un_vp, 1, GL_FALSE, glm::value_ptr( VP ) ); + // immediate_render( &imm, game->test_outline_at_position, game->test_outline_at_colour ); + // glUseProgram( 0 ); + // glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); + + // skybox_render( &game->skybox, game->angles ); // benchmark_print_timers(); }