X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_render.c;h=011d0415edacf62857cb81e9b83a767005c951d5;hb=ad89a3e4bba4abe99abc48b1760822ca23d03d82;hp=df0dd6b1d3717e12b84529aecaf7edb90a38dc1e;hpb=b4a83d4fcab39bee5a8cd6e8e6eec06314864e5b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_render.c b/player_render.c index df0dd6b..011d041 100644 --- a/player_render.c +++ b/player_render.c @@ -5,9 +5,12 @@ #include "player_render.h" #include "camera.h" #include "player_model.h" +#include "ent_skateshop.h" +#include "audio.h" #include "shaders/model_character_view.h" #include "shaders/model_board_view.h" +#include "shaders/model_entity.h" VG_STATIC void player_avatar_load( struct player_avatar *av, const char *path ) { @@ -59,6 +62,7 @@ VG_STATIC void player_model_load( struct player_model *mdl, const char *path ) mdl_close( &ctx ); } +/* TODO: allow error handling */ VG_STATIC void player_board_load( struct player_board *mdl, const char *path ) { vg_linear_clear( vg_mem.scratch ); @@ -93,10 +97,6 @@ VG_STATIC void player_board_load( struct player_board *mdl, const char *path ) for( u32 i=0; ientity_id, - mdl_entity_id_type( mesh->entity_id ), - mdl_entity_id_id( mesh->entity_id ) ); - if( mdl_entity_id_type( mesh->entity_id ) != k_ent_marker ) continue; @@ -125,6 +125,12 @@ VG_STATIC void player_board_load( struct player_board *mdl, const char *path ) } } +VG_STATIC void player_board_unload( struct player_board *mdl ) +{ + mesh_free( &mdl->mesh ); + glDeleteTextures( 1, &mdl->texture ); +} + VG_STATIC void player__pre_render( player_instance *player ) { if( _player_animate[ player->subsystem ] ){ @@ -156,14 +162,28 @@ VG_STATIC void player__pre_render( player_instance *player ) _player_post_animate[ player->subsystem ]( player ); struct player_avatar *av = player->playeravatar; + struct player_board *board = player_get_player_board( player ); + + v3f vp0, vp1; - v3f vp0 = {0.0f,0.1f, player->playerboard->truck_positions[0][2]}, - vp1 = {0.0f,0.1f, player->playerboard->truck_positions[1][2]}; + if( board ){ + v3_copy((v3f){0.0f,0.1f, board->truck_positions[0][2]}, vp0 ); + v3_copy((v3f){0.0f,0.1f, board->truck_positions[1][2]}, vp1 ); + } + else{ + v3_zero( vp0 ); + v3_zero( vp1 ); + } - struct ub_world_lighting *ubo = &get_active_world()->ub_lighting; + struct ub_world_lighting *ubo = &world_current_instance()->ub_lighting; m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, ubo->g_board_0 ); m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp1, ubo->g_board_1 ); + if( player->immobile ){ + player__cam_iterate( player ); + return; + } + if( player->rewinding ){ if( player->rewind_time <= 0.0f ){ double taken = vg.time - player->rewind_start; @@ -175,11 +195,11 @@ VG_STATIC void player__pre_render( player_instance *player ) player->rewind_length = 1; player->rewind_total_length = 0.0f; player->rewind_accum = 0.0f; - world_global.sky_target_rate = 1.0; - world_global.time = world_global.last_use; + world_render.sky_target_rate = 1.0; + world_static.time = world_static.last_use; } else{ - world_global.sky_target_rate = -100.0; + world_render.sky_target_rate = -100.0; float budget = vg.time_delta, overall_length = player->rewind_length; @@ -252,6 +272,7 @@ VG_STATIC void player__pre_render( player_instance *player ) vg_alerpf( fr->ang[0], fr1->ang[0], sub ); player->cam_override_angles[1] = vg_lerpf ( fr->ang[1], fr1->ang[1], sub ); + player->cam_override_fov = player->cam.fov; float blend = player->rewind_time * 0.25f; player->cam_override_strength = vg_clampf( blend, 0.0f, 1.0f ); @@ -262,82 +283,76 @@ VG_STATIC void player__pre_render( player_instance *player ) player__cam_iterate( player ); } -PLAYER_API void player__render( camera *cam, player_instance *player ) +VG_STATIC void render_board( camera *cam, world_instance *world, + struct player_board *board, m4x3f root, + enum board_shader shader ) { - shader_model_character_view_use(); + if( !board ) return; - glActiveTexture( GL_TEXTURE0 ); - glBindTexture( GL_TEXTURE_2D, player->playermodel->texture ); - shader_model_character_view_uTexMain( 0 ); - shader_model_character_view_uCamera( cam->transform[3] ); - shader_model_character_view_uPv( cam->mtx.pv ); - shader_model_character_view_uTexSceneDepth( 1 ); - render_fb_bind_texture( gpipeline.fb_main, 2, 1 ); v3f inverse; - render_fb_inverse_ratio( gpipeline.fb_main, inverse ); - inverse[2] = main_camera.farz-main_camera.nearz; - shader_model_character_view_uInverseRatioDepth( inverse ); - render_fb_inverse_ratio( NULL, inverse ); - inverse[2] = cam->farz-cam->nearz; - shader_model_character_view_uInverseRatioMain( inverse ); + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, board->texture ); - world_instance *world = get_active_world(); - world_link_lighting_ub( world, _shader_model_character_view.id ); - world_bind_position_texture( world, _shader_model_character_view.id, - _uniform_model_character_view_g_world_depth, 2 ); - world_bind_light_array( world, _shader_model_character_view.id, - _uniform_model_character_view_uLightsArray, 3 ); - world_bind_light_index( world, _shader_model_character_view.id, - _uniform_model_character_view_uLightsIndex, 4 ); + if( shader == k_board_shader_player ){ + shader_model_board_view_use(); + shader_model_board_view_uTexMain( 0 ); + shader_model_board_view_uCamera( cam->transform[3] ); + shader_model_board_view_uPv( cam->mtx.pv ); + shader_model_board_view_uTexSceneDepth( 1 ); - glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms, - player->playeravatar->sk.bone_count, - 0, - (float *)player->playeravatar->sk.final_mtx ); - - mesh_bind( &player->playermodel->mesh ); - mesh_draw( &player->playermodel->mesh ); + render_fb_inverse_ratio( gpipeline.fb_main, inverse ); - /* draw skateboard */ - shader_model_board_view_use(); - glActiveTexture( GL_TEXTURE0 ); - glBindTexture( GL_TEXTURE_2D, player->playerboard->texture ); - shader_model_board_view_uTexMain( 0 ); - shader_model_board_view_uCamera( cam->transform[3] ); - shader_model_board_view_uPv( cam->mtx.pv ); - shader_model_board_view_uTexSceneDepth( 1 ); + inverse[2] = main_camera.farz-main_camera.nearz; - render_fb_inverse_ratio( gpipeline.fb_main, inverse ); - inverse[2] = main_camera.farz-main_camera.nearz; + shader_model_board_view_uInverseRatioDepth( inverse ); + render_fb_inverse_ratio( NULL, inverse ); + inverse[2] = cam->farz-cam->nearz; + shader_model_board_view_uInverseRatioMain( inverse ); - shader_model_board_view_uInverseRatioDepth( inverse ); - render_fb_inverse_ratio( NULL, inverse ); - inverse[2] = cam->farz-cam->nearz; - shader_model_board_view_uInverseRatioMain( inverse ); - - world_link_lighting_ub( world, _shader_model_board_view.id ); - world_bind_position_texture( world, _shader_model_board_view.id, - _uniform_model_board_view_g_world_depth, 2 ); - world_bind_light_array( world, _shader_model_board_view.id, - _uniform_model_board_view_uLightsArray, 3 ); - world_bind_light_index( world, _shader_model_board_view.id, - _uniform_model_board_view_uLightsIndex, 4 ); - - m4x3f root; - m4x3_copy( player->playeravatar->sk.final_mtx[player->playeravatar->id_board] - , root ); + world_link_lighting_ub( world, _shader_model_board_view.id ); + world_bind_position_texture( world, _shader_model_board_view.id, + _uniform_model_board_view_g_world_depth, 2 ); + world_bind_light_array( world, _shader_model_board_view.id, + _uniform_model_board_view_uLightsArray, 3 ); + world_bind_light_index( world, _shader_model_board_view.id, + _uniform_model_board_view_uLightsIndex, 4 ); + } + else if( shader == k_board_shader_entity ){ + shader_model_entity_use(); + shader_model_entity_uTexMain( 0 ); + shader_model_entity_uCamera( cam->transform[3] ); + shader_model_entity_uPv( cam->mtx.pv ); + + world_link_lighting_ub( world, _shader_model_entity.id ); + world_bind_position_texture( world, _shader_model_entity.id, + _uniform_model_entity_g_world_depth, 2 ); + world_bind_light_array( world, _shader_model_entity.id, + _uniform_model_entity_uLightsArray, 3 ); + world_bind_light_index( world, _shader_model_entity.id, + _uniform_model_entity_uLightsIndex, 4 ); + } - struct player_board *board = player->playerboard; mesh_bind( &board->mesh ); + m4x4f m4mdl; + if( board->board.indice_count ){ m4x3f mlocal; m3x3_identity( mlocal ); v3_copy( board->board_position, mlocal[3] ); m4x3_mul( root, mlocal, mlocal ); - shader_model_board_view_uMdl( mlocal ); + if( shader == k_board_shader_entity ){ + /* TODO: provide a way to supply previous mdl mtx? */ + m4x3_expand( mlocal, m4mdl ); + m4x4_mul( cam->mtx_prev.pv, m4mdl, m4mdl ); + shader_model_entity_uPvmPrev( m4mdl ); + shader_model_entity_uMdl( mlocal ); + } + else + shader_model_board_view_uMdl( mlocal ); + mdl_draw_submesh( &board->board ); } @@ -350,7 +365,15 @@ PLAYER_API void player__render( camera *cam, player_instance *player ) v3_copy( board->truck_positions[i], mlocal[3] ); m4x3_mul( root, mlocal, mlocal ); - shader_model_board_view_uMdl( mlocal ); + if( shader == k_board_shader_entity ){ + m4x3_expand( mlocal, m4mdl ); + m4x4_mul( cam->mtx_prev.pv, m4mdl, m4mdl ); + shader_model_entity_uPvmPrev( m4mdl ); + shader_model_entity_uMdl( mlocal ); + } + else + shader_model_board_view_uMdl( mlocal ); + mdl_draw_submesh( &board->trucks[i] ); } @@ -363,9 +386,61 @@ PLAYER_API void player__render( camera *cam, player_instance *player ) v3_copy( board->wheel_positions[i], mlocal[3] ); m4x3_mul( root, mlocal, mlocal ); - shader_model_board_view_uMdl( mlocal ); + if( shader == k_board_shader_entity ){ + m4x3_expand( mlocal, m4mdl ); + m4x4_mul( cam->mtx_prev.pv, m4mdl, m4mdl ); + shader_model_entity_uPvmPrev( m4mdl ); + shader_model_entity_uMdl( mlocal ); + } + else + shader_model_board_view_uMdl( mlocal ); + mdl_draw_submesh( &board->wheels[i] ); } } +PLAYER_API void player__render( camera *cam, player_instance *player ) +{ + shader_model_character_view_use(); + + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, player->playermodel->texture ); + shader_model_character_view_uTexMain( 0 ); + shader_model_character_view_uCamera( cam->transform[3] ); + shader_model_character_view_uPv( cam->mtx.pv ); + shader_model_character_view_uTexSceneDepth( 1 ); + render_fb_bind_texture( gpipeline.fb_main, 2, 1 ); + v3f inverse; + render_fb_inverse_ratio( gpipeline.fb_main, inverse ); + inverse[2] = main_camera.farz-main_camera.nearz; + + shader_model_character_view_uInverseRatioDepth( inverse ); + render_fb_inverse_ratio( NULL, inverse ); + inverse[2] = cam->farz-cam->nearz; + shader_model_character_view_uInverseRatioMain( inverse ); + + world_instance *world = world_current_instance(); + world_link_lighting_ub( world, _shader_model_character_view.id ); + world_bind_position_texture( world, _shader_model_character_view.id, + _uniform_model_character_view_g_world_depth, 2 ); + world_bind_light_array( world, _shader_model_character_view.id, + _uniform_model_character_view_uLightsArray, 3 ); + world_bind_light_index( world, _shader_model_character_view.id, + _uniform_model_character_view_uLightsIndex, 4 ); + + glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms, + player->playeravatar->sk.bone_count, + 0, + (float *)player->playeravatar->sk.final_mtx ); + + mesh_bind( &player->playermodel->mesh ); + mesh_draw( &player->playermodel->mesh ); + + struct player_board *board = player_get_player_board( player ); + + render_board( cam, world, board, player->playeravatar->sk.final_mtx[ + player->playeravatar->id_board], + k_board_shader_player ); +} + #endif /* PLAYER_RENDER_C */