From: hgn Date: Wed, 19 Jul 2023 01:07:50 +0000 (+0100) Subject: fix rendering bugs X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=7d8f90d019453ff1186f16c2d36a08d5a53ad638;p=carveJwlIkooP6JGAAIwe30JlM.git fix rendering bugs --- diff --git a/player_skate.c b/player_skate.c index f971b18..ac14239 100644 --- a/player_skate.c +++ b/player_skate.c @@ -2781,7 +2781,7 @@ VG_STATIC void player__skate_animate( player_instance *player ){ if( fabsf(lean1)>fabsf(lean2) ) lean = lean1; else lean = lean2; - if( ((int)roundf(animator->board_euler[0])) % 2 ) lean = -lean; + if( ((int)roundf(animator->board_euler[0]/VG_PIf)) % 2 ) lean = -lean; lean = vg_clampf( lean, -1.0f, 1.0f ); animator->board_lean = vg_lerpf(animator->board_lean, lean, vg.time_delta*18.0f); diff --git a/world_render.c b/world_render.c index 950e35f..ac0df1a 100644 --- a/world_render.c +++ b/world_render.c @@ -154,21 +154,59 @@ struct world_pass{ void (*fn_set_uPvmPrev)( m4x4f pvm ); }; -/* TODO: high level control pass renders. */ +VG_STATIC +void world_render_traffic( world_instance *world, u32 material_id, + struct world_pass *pass ){ + if( !mdl_arrcount( &world->ent_traffic ) ) return; + + /* HACK: use the first material for every traffic entity */ + ent_traffic *first = mdl_arritm( &world->ent_traffic, 0 ); + if( !first->submesh_count ) return; + + mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, first->submesh_start ); + if( sm->material_id != material_id ) return; + + struct world_surface *mat = &world->surfaces[ material_id ]; + pass->fn_bind_textures( world, mat ); + + for( u32 j=0; jent_traffic ); j++ ){ + ent_traffic *traffic = mdl_arritm( &world->ent_traffic, j ); + + for( u32 k=0; ksubmesh_count; k++ ){ + sm = mdl_arritm( &world->meta.submeshs, + traffic->submesh_start+k ); + + m4x3f mmdl; + q_m3x3( traffic->transform.q, mmdl ); + v3_copy( traffic->transform.co, mmdl[3] ); + + m4x4f m4mdl; + m4x3_expand( mmdl, m4mdl ); + m4x4_mul( pass->cam->mtx_prev.pv, m4mdl, m4mdl ); + + pass->fn_set_mdl( mmdl ); + pass->fn_set_uPvmPrev( m4mdl ); + + mdl_draw_submesh( sm ); + } + } +} VG_STATIC -void world_render_if( world_instance *world, struct world_pass *pass ) -{ +void world_render_pass( world_instance *world, struct world_pass *pass ){ for( int i=0; isurface_count; i++ ){ struct world_surface *mat = &world->surfaces[i]; if( mat->info.shader == pass->shader ){ mdl_submesh *sm; - if( pass->geo_type == k_world_geo_type_solid ) + if( pass->geo_type == k_world_geo_type_solid ){ sm = &mat->sm_geo; - else + } + else{ + world_render_traffic( world, i, pass ); sm = &mat->sm_no_collide; + } if( !sm->indice_count ) continue; @@ -180,27 +218,6 @@ void world_render_if( world_instance *world, struct world_pass *pass ) pass->fn_bind_textures( world, mat ); mdl_draw_submesh( sm ); - - for( u32 j=0; jent_traffic ); j++ ){ - ent_traffic *traffic = mdl_arritm( &world->ent_traffic, j ); - - for( u32 k=0; ksubmesh_count; k++ ){ - sm = mdl_arritm( &world->meta.submeshs, - traffic->submesh_start+k ); - - q_m3x3( traffic->transform.q, mmdl ); - v3_copy( traffic->transform.co, mmdl[3] ); - - m4x4f m4mdl; - m4x3_expand( mmdl, m4mdl ); - m4x4_mul( pass->cam->mtx_prev.pv, m4mdl, m4mdl ); - - pass->fn_set_mdl( mmdl ); - pass->fn_set_uPvmPrev( m4mdl ); - - mdl_draw_submesh( sm ); - } - } } } } @@ -224,12 +241,12 @@ void world_render_both_stages( world_instance *world, struct world_pass *pass ) { mesh_bind( &world->mesh_geo ); pass->geo_type = k_world_geo_type_solid; - world_render_if( world, pass ); + world_render_pass( world, pass ); glDisable( GL_CULL_FACE ); mesh_bind( &world->mesh_no_collide ); pass->geo_type = k_world_geo_type_nonsolid; - world_render_if( world, pass ); + world_render_pass( world, pass ); glEnable( GL_CULL_FACE ); }