render routes in mini-world
authorhgn <hgodden00@gmail.com>
Mon, 20 Nov 2023 10:34:44 +0000 (10:34 +0000)
committerhgn <hgodden00@gmail.com>
Mon, 20 Nov 2023 10:34:44 +0000 (10:34 +0000)
build.c
ent_miniworld.c
shaders/scene_route.h
world_render.c
world_routes.c
world_routes.h

diff --git a/build.c b/build.c
index 0470a3b926f199fc6b91e3c52a86c5a33bd27b66..596c698b4f2781db29764885e27e67adfe74fc5b 100644 (file)
--- a/build.c
+++ b/build.c
@@ -249,7 +249,7 @@ void build_shaders(void){
    _S( "scene_fxglow",              "scene_fxglow.vs", "scene_fxglow.fs" );
    _S( "scene_vertex_blend",        "scene.vs", "scene_vertex_blend.fs" );
    _S( "scene_terrain",             "scene.vs", "scene_terrain.fs" );
-   _S( "scene_route",               "scene.vs", "scene_route.fs" );
+   _S( "scene_route",               "scene_override.vs", "scene_route.fs" );
    _S( "scene_depth",               "scene.vs", "scene_depth.fs" );
    _S( "scene_position",            "scene.vs", "scene_position.fs" );
    _S( "scene_cubemapped",          "scene.vs", "scene_cubemapped.fs" );
index 9c439c7c797a5c7f44bd7abc233f8d7540e93560..08e7093e31e6e40e371fe5d84a99261214d7b190 100644 (file)
@@ -57,7 +57,7 @@ static void ent_miniworld_render( world_instance *host_world, camera *cam ){
    m4x3f mmdl;
    mdl_transform_m4x3( &miniworld->transform, mmdl );
    render_world_override( dest_world, host_world, mmdl, cam );
-   //render_world_routes( , &skaterift.cam, 1 );
+   render_world_routes( dest_world, host_world, mmdl, cam, 0, 1 );
 }
 
 static void ent_miniworld_preupdate(void){
index 8e3cc10385942f9d1d493c01e15e158e0a78ebcf..eea0c75bd0211b544ac9a43f78cebd4ed4a24046 100644 (file)
@@ -7,7 +7,7 @@ static struct vg_shader _shader_scene_route = {
    .link = shader_scene_route_link,
    .vs = 
 {
-.orig_file = "shaders/scene.vs",
+.orig_file = "shaders/scene_override.vs",
 .static_src = 
 "layout (location=0) in vec3  a_co;\n"
 "layout (location=1) in vec4  a_norm;\n"
@@ -36,6 +36,7 @@ static struct vg_shader _shader_scene_route = {
 "uniform mat4x3 uMdl;\n"
 "uniform mat4   uPv;\n"
 "uniform mat4   uPvmPrev;\n"
+"uniform mat3   uNormalMtx;\n"
 "\n"
 "out vec2 aUv;\n"
 "out vec4 aNorm;\n"
@@ -53,7 +54,7 @@ static struct vg_shader _shader_scene_route = {
 "   gl_Position = vproj0;\n"
 "\n"
 "   aUv = a_uv;\n"
-"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
 "   aCo = a_co;\n"
 "   aWorldCo = world_pos0;\n"
 "}\n"
@@ -508,6 +509,7 @@ static struct vg_shader _shader_scene_route = {
 static GLuint _uniform_scene_route_uMdl;
 static GLuint _uniform_scene_route_uPv;
 static GLuint _uniform_scene_route_uPvmPrev;
+static GLuint _uniform_scene_route_uNormalMtx;
 static GLuint _uniform_scene_route_uTexGarbage;
 static GLuint _uniform_scene_route_uTexGradients;
 static GLuint _uniform_scene_route_uCamera;
@@ -524,6 +526,9 @@ static void shader_scene_route_uPv(m4x4f m){
 static void shader_scene_route_uPvmPrev(m4x4f m){
    glUniformMatrix4fv(_uniform_scene_route_uPvmPrev,1,GL_FALSE,(float*)m);
 }
+static void shader_scene_route_uNormalMtx(m3x3f m){
+   glUniformMatrix3fv(_uniform_scene_route_uNormalMtx,1,GL_FALSE,(float*)m);
+}
 static void shader_scene_route_uTexGarbage(int i){
    glUniform1i(_uniform_scene_route_uTexGarbage,i);
 }
@@ -547,6 +552,7 @@ static void shader_scene_route_link(void){
    _uniform_scene_route_uMdl = glGetUniformLocation( _shader_scene_route.id, "uMdl" );
    _uniform_scene_route_uPv = glGetUniformLocation( _shader_scene_route.id, "uPv" );
    _uniform_scene_route_uPvmPrev = glGetUniformLocation( _shader_scene_route.id, "uPvmPrev" );
+   _uniform_scene_route_uNormalMtx = glGetUniformLocation( _shader_scene_route.id, "uNormalMtx" );
    _uniform_scene_route_uTexGarbage = glGetUniformLocation( _shader_scene_route.id, "uTexGarbage" );
    _uniform_scene_route_uTexGradients = glGetUniformLocation( _shader_scene_route.id, "uTexGradients" );
    _uniform_scene_route_uCamera = glGetUniformLocation( _shader_scene_route.id, "uCamera" );
index cdbe37ebfbbfe022ed2f8eeaff1d9f8cfd5c4dd4..b63d8a78d2198e14b11ece4c41845ede50bf428a 100644 (file)
@@ -847,7 +847,9 @@ static void render_world( world_instance *world, camera *cam,
 
    render_sky( world, cam );
 
-   render_world_routes( world, cam, viewing_from_gate );
+   m4x3f identity;
+   m4x3_identity(identity);
+   render_world_routes( world, world, identity, cam, viewing_from_gate, 0 );
    render_world_standard( world, cam );
    render_world_cubemapped( world, cam, with_cubemaps );
 
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 );
          }
       }
    }
index 636793dd87d68fa75d10c10b2344e47858012b1d..5fccc9e0f2a60d09a77ac1ca59540fd5b38b4a34 100644 (file)
@@ -13,8 +13,10 @@ static void world_routes_fracture( world_instance *world, ent_gate *gate,
                                       v3f imp_co, v3f imp_v );
 static void world_routes_activate_entry_gate( world_instance *world, 
                                                  ent_gate *rg );
-static void render_world_routes( world_instance *world, camera *cam, 
-                                    int layer_depth );
+static void render_world_routes( world_instance *world, 
+                                 world_instance *host_world,
+                                 m4x3f mmdl, camera *cam, 
+                                 int viewing_from_gate, int viewing_from_hub );
 
 static void world_gen_routes_ent_init( world_instance *world );
 static void world_gen_routes_generate( u32 instance_id );