render routes in mini-world
[carveJwlIkooP6JGAAIwe30JlM.git] / world_routes.c
index e4b444a2a63f5e872ae0a9341fa78456b6ecf37a..d710e5edf82a058d90bb079d8a60e0630e6ddb9d 100644 (file)
@@ -852,11 +852,12 @@ static void world_routes_fracture( world_instance *world, ent_gate *gate,
    }
 }
 
-static void render_gate_markers( int run_id, ent_gate *gate ){
+static void render_gate_markers( m4x3f world_mmdl, int run_id, ent_gate *gate ){
    for( u32 j=0; j<4; j++ ){
       if( gate->routes[j] == run_id ){
          m4x3f mmdl;
          ent_gate_get_mdl_mtx( gate, mmdl );
+         m4x3_mul( world_mmdl, mmdl, mmdl );
          shader_model_gate_uMdl( mmdl );
          mdl_draw_submesh( &world_gates.sm_marker[j] );
          break;
@@ -864,25 +865,47 @@ static void render_gate_markers( int run_id, ent_gate *gate ){
    }
 }
 
-static void render_world_routes( world_instance *world, camera *cam, 
-                                 int viewing_from_gate ){
-   m4x3f identity_matrix;
-   m4x3_identity( identity_matrix );
+static void render_world_routes( world_instance *world, 
+                                 world_instance *host_world,
+                                 m4x3f mmdl, camera *cam, 
+                                 int viewing_from_gate, int viewing_from_hub ){
 
    shader_scene_route_use();
    shader_scene_route_uTexGarbage(0);
-   world_link_lighting_ub( world, _shader_scene_route.id );
-   world_bind_position_texture( world, _shader_scene_route.id, 
+   world_link_lighting_ub( host_world, _shader_scene_route.id );
+   world_bind_position_texture( host_world, _shader_scene_route.id, 
                         _uniform_scene_route_g_world_depth, 2 );
-   world_bind_light_array( world, _shader_scene_route.id,
+   world_bind_light_array( host_world, _shader_scene_route.id,
                         _uniform_scene_route_uLightsArray, 3 );
-   world_bind_light_index( world, _shader_scene_route.id,
+   world_bind_light_index( host_world, _shader_scene_route.id,
                                  _uniform_scene_route_uLightsIndex, 4 );
    bind_terrain_noise();
 
    shader_scene_route_uPv( cam->mtx.pv );
-   shader_scene_route_uPvmPrev( cam->mtx_prev.pv );
-   shader_scene_route_uMdl( identity_matrix );
+
+   if( viewing_from_hub ){
+      m4x4f m4mdl, pvm;
+      m4x3_expand( mmdl, m4mdl );
+      m4x4_mul( cam->mtx_prev.pv, m4mdl, pvm );
+      shader_scene_route_uMdl( mmdl );
+      shader_scene_route_uPvmPrev( pvm );
+
+      m3x3f mnormal;
+      m3x3_inv( mmdl, mnormal );
+      m3x3_transpose( mnormal, mnormal );
+      v3_normalize( mnormal[0] );
+      v3_normalize( mnormal[1] );
+      v3_normalize( mnormal[2] );
+      shader_scene_route_uNormalMtx( mnormal );
+   }
+   else{
+      shader_scene_route_uMdl( mmdl );
+      shader_scene_route_uPvmPrev( cam->mtx_prev.pv );
+      m3x3f ident;
+      m3x3_identity( ident );
+      shader_scene_route_uNormalMtx( ident );
+   }
+
    shader_scene_route_uCamera( cam->transform[3] );
 
    mesh_bind( &world->mesh_route_lines );
@@ -890,9 +913,11 @@ static void render_world_routes( world_instance *world, camera *cam,
    for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
       ent_route *route = mdl_arritm( &world->ent_route, i );
 
+      f32 t = viewing_from_hub? 1.0f: route->factive;
+
       v4f colour;
-      v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour );
-      colour[3] = route->factive*0.2f;
+      v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, t, colour );
+      colour[3] = t*0.2f;
 
       shader_scene_route_uColour( colour );
       mdl_draw_submesh( &route->sm );
@@ -900,7 +925,7 @@ static void render_world_routes( world_instance *world, camera *cam,
 
    /* timers
     * ---------------------------------------------------- */
-   if( !viewing_from_gate ){
+   if( !viewing_from_gate && !viewing_from_hub ){
       font3d_bind( &gui.font, k_font_shader_default, 0, world, cam );
 
       for( u32 i=0; i<world_render.timer_text_count; i++ ){
@@ -958,7 +983,7 @@ static void render_world_routes( world_instance *world, camera *cam,
    glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
    glDisable( GL_CULL_FACE );
 
-   if( skaterift.activity == k_skaterift_respawning ){
+   if( viewing_from_hub ){
       for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
          ent_route *route = mdl_arritm( &world->ent_route, i );
 
@@ -971,7 +996,7 @@ static void render_world_routes( world_instance *world, camera *cam,
          for( u32 j=0; j<mdl_arrcount(&world->ent_gate); j ++ ){
             ent_gate *gate = mdl_arritm( &world->ent_gate, j );
             if( !(gate->flags & k_ent_gate_nonlocal_DELETED) )
-               render_gate_markers( i, gate );
+               render_gate_markers( mmdl, i, gate );
          }
       }
    }
@@ -993,7 +1018,7 @@ static void render_world_routes( world_instance *world, camera *cam,
 
             ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next );
             ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index );
-            render_gate_markers( i, gate );
+            render_gate_markers( mmdl, i, gate );
          }
       }
    }