X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=player_render.c;h=171b339ebe4e88bb52b7f782d649e0504909c045;hb=872ad3e040f22df357929d3778a955ae8c4ac52b;hp=df0dd6b1d3717e12b84529aecaf7edb90a38dc1e;hpb=926a64f679a23d8b0f3594d73405d2486c398a59;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/player_render.c b/player_render.c index df0dd6b..171b339 100644 --- a/player_render.c +++ b/player_render.c @@ -8,6 +8,7 @@ #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 ) { @@ -93,10 +94,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 +122,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 ] ){ @@ -157,8 +160,18 @@ VG_STATIC void player__pre_render( player_instance *player ) struct player_avatar *av = player->playeravatar; - v3f vp0 = {0.0f,0.1f, player->playerboard->truck_positions[0][2]}, - vp1 = {0.0f,0.1f, player->playerboard->truck_positions[1][2]}; + struct player_board *board = player->board; + + v3f vp0, vp1; + + 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; m4x3_mulv( av->sk.final_mtx[ av->id_board ], vp0, ubo->g_board_0 ); @@ -262,82 +275,80 @@ VG_STATIC void player__pre_render( player_instance *player ) player__cam_iterate( player ); } -PLAYER_API void player__render( camera *cam, player_instance *player ) +enum board_shader{ + k_board_shader_player, + k_board_shader_entity +}; + +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 ); - - 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 ); - - 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 ); - - /* 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 ); - - 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 ); - - 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 ); + glActiveTexture( GL_TEXTURE0 ); + glBindTexture( GL_TEXTURE_2D, board->texture ); + + 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 ); + + 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 ); + + 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 +361,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 +382,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 = 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 ); + + 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->board; + + render_board( cam, world, board, player->playeravatar->sk.final_mtx[ + player->playeravatar->id_board], + k_board_shader_player ); +} + #endif /* PLAYER_RENDER_C */