#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 )
{
for( u32 i=0; i<mdl_arrcount(&ctx.meshs); i++ ){
mdl_mesh *mesh = mdl_arritm( &ctx.meshs, i );
- vg_info( "[%u]=%u:%u\n", mesh->entity_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;
}
}
+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 ] ){
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 );
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;
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 );
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 );
}
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] );
}
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 */