respawn UI
authorhgn <hgodden00@gmail.com>
Wed, 23 Aug 2023 15:17:52 +0000 (16:17 +0100)
committerhgn <hgodden00@gmail.com>
Wed, 23 Aug 2023 15:17:52 +0000 (16:17 +0100)
16 files changed:
build.c
camera.h
gui.h
maps_src/mp_spawn/main.mdl
menu.h
model.h
models_src/rs_menu.mdl
player.c
respawn.c [new file with mode: 0644]
respawn.h [new file with mode: 0644]
shaders/scene_override.fs [new file with mode: 0644]
shaders/scene_override.h [new file with mode: 0644]
skaterift.c
skaterift.h
world_render.c
world_render.h

diff --git a/build.c b/build.c
index a0a253f1a037626ab7f4987b9306a20a500e4aa9..1c17f14e2be01a5814faf0088244f2f7015a53f3 100644 (file)
--- a/build.c
+++ b/build.c
@@ -190,6 +190,7 @@ void build_shaders(void)
    /* Scene */
    _S( "scene_standard",            "scene.vs", "scene_standard.fs" );
    _S( "scene_standard_alphatest",  "scene.vs", "scene_standard_alphatest.fs" );
+   _S( "scene_override",            "scene.vs", "scene_override.fs" );
    _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" );
index 7d720f7ca0f18214cb2735af044dbb72cd7f323b..63743935e871a51b59108af102a1470320c067c4 100644 (file)
--- a/camera.h
+++ b/camera.h
@@ -23,15 +23,13 @@ struct camera{
    mtx_prev;
 };
 
-VG_STATIC void camera_lerp_angles( v3f a, v3f b, float t, v3f d )
-{
+VG_STATIC void camera_lerp_angles( v3f a, v3f b, float t, v3f d ){
    d[0] = vg_alerpf( a[0], b[0], t );
    d[1] = vg_lerpf(  a[1], b[1], t );
    d[2] = vg_lerpf(  a[2], b[2], t );
 }
 
-VG_STATIC void camera_lerp( camera *a, camera *b, float t, camera *d )
-{
+VG_STATIC void camera_lerp( camera *a, camera *b, float t, camera *d ){
    v3_lerp( a->pos, b->pos, t, d->pos );
    d->angles[0] = vg_alerpf( a->angles[0], b->angles[0], t );
    d->angles[1] = vg_lerpf( a->angles[1], b->angles[1], t );
@@ -39,6 +37,12 @@ VG_STATIC void camera_lerp( camera *a, camera *b, float t, camera *d )
    d->fov = vg_lerpf( a->fov, b->fov, t );
 }
 
+VG_STATIC void camera_copy( camera *a, camera *d ){
+   v3_copy( a->pos, d->pos );
+   v3_copy( a->angles, d->angles );
+   d->fov = a->fov;
+}
+
 /*
  * 1) [angles, pos] -> transform 
  */
diff --git a/gui.h b/gui.h
index 5684e4c925860bed643eba6dc661aebdef40130e..8013cb014da3e099f0e8d674a9ea5a2505cba09c 100644 (file)
--- a/gui.h
+++ b/gui.h
@@ -90,7 +90,7 @@ void gui_draw(void)
    camera_finalize( &ortho );
 
    gui.factive = vg_lerpf( gui.factive, gui.helper_count?1.0f:0.0f,
-                           vg.time_delta*2.0f );
+                           vg.time_frame_delta*2.0f );
 
    if( gui.factive > 0.01f ){
       /* draw bottom bar */
@@ -104,7 +104,7 @@ void gui_draw(void)
       render_fsquad1();
    }
 
-   f64 loc_t = (vg.time - gui.location_time) / 5.0;
+   f64 loc_t = (vg.time_real - gui.location_time) / 5.0;
    if( (loc_t < 1.0) && (gui.location_time != 0.0) ){
       /* yep this code is a mess, i dont care anymore */
       glEnable(GL_BLEND);
@@ -192,7 +192,7 @@ int gui_location_print_ccmd( int argc, const char *argv[] ){
       }
       if( !strcmp(gui.location,new_loc) ) return 0;
       vg_strncpy( new_loc, gui.location, 64, k_strncpy_always_add_null );
-      gui.location_time = vg.time;
+      gui.location_time = vg.time_real;
    }
    return 0;
 }
index 97e890efdd832df4a223f8ac9f2cf08bffe9dda8..ca1d3aa12e416f07b8213c1f221aee001b6e3800 100644 (file)
Binary files a/maps_src/mp_spawn/main.mdl and b/maps_src/mp_spawn/main.mdl differ
diff --git a/menu.h b/menu.h
index 59c01f61a0b7ec7423db6232c48e6fd9ff95a604..71b3570d06190c70a133d386719f92369267be5d 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -9,6 +9,7 @@
 #include "audio.h"
 #include "input.h"
 #include "workshop.h"
+#include "respawn.h"
 
 #define MENU_STACK_SIZE 8
 
@@ -210,16 +211,25 @@ static void menu_trigger_item( ent_menuitem *item )
       if( MDL_CONST_PSTREQ( &menu.model, q, "quit" ) ){
          vg.window_should_close = 1;
       }
+
+      /* DEPRECATED? */
       else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_nearest" ) ){
          localplayer_cmd_respawn( 0, NULL );
          menu_close();
       }
+      /* DEPRECATED? */
       else if( MDL_CONST_PSTREQ( &menu.model, q, "reset_home" ) ){
          world_set_active_instance( 0 );
          localplayer.viewable_world = world_current_instance();
          localplayer_cmd_respawn( 1, (const char *[]){"start"} );
          menu_close();
       }
+
+      else if( MDL_CONST_PSTREQ( &menu.model, q, "reset" ) ){
+         menu_close();
+         respawn_begin_chooser();
+      }
+
       else if( MDL_CONST_PSTREQ( &menu.model, q, "credits" ) ){
          menu.credits_open = 1;
       }
diff --git a/model.h b/model.h
index 9f5bdb5451e39a826b97304bd85635db04c059a1..87755d6fade8cb32768474b9c32863aec851fbbe 100644 (file)
--- a/model.h
+++ b/model.h
@@ -19,7 +19,8 @@ enum mdl_shader{
    k_shader_invisible               = 5,
    k_shader_boundary                = 6,
    k_shader_fxglow                  = 7,
-   k_shader_cubemap                 = 8
+   k_shader_cubemap                 = 8,
+   k_shader_override                = 30000
 };
 
 enum mdl_surface_prop{
index dc18773f4eab3fbb81f1fca917295900eab483d1..4810d7cf259dffb43fbac44d1ce67cebf01a26cd 100644 (file)
Binary files a/models_src/rs_menu.mdl and b/models_src/rs_menu.mdl differ
index f5176eb21e69701b0f45aa887d1a8d7a4736d216..c79132f7e53fa6c2ed5db5809ee180108326999b 100644 (file)
--- a/player.c
+++ b/player.c
@@ -246,7 +246,8 @@ PLAYER_API void player__im_gui( player_instance *player ){
                      (const char *[]){ [k_skaterift_menu]      = "menu",
                                        [k_skaterift_replay]    = "replay",
                                        [k_skaterift_ent_focus] = "ent_focus",
-                                       [k_skaterift_default]   = "default" 
+                                       [k_skaterift_default]   = "default",
+                                       [k_skaterift_respawning]= "respawning",
                      } [skaterift.activity] );
    player__debugtext( 1, "time_rate: %.4f", skaterift.time_rate );
 
diff --git a/respawn.c b/respawn.c
new file mode 100644 (file)
index 0000000..98b9bcd
--- /dev/null
+++ b/respawn.c
@@ -0,0 +1,222 @@
+#ifndef RESPAWN_C
+#define RESPAWN_C
+
+#include "respawn.h"
+#include "skaterift.h"
+#include "world.h"
+#include "input.h"
+#include "gui.h"
+#include "menu.h"
+#include "scene.h"
+
+VG_STATIC void respawn_chooser_get_dir( v3f dir ){
+   /* idk */
+   dir[0] = -sqrtf(0.5f);
+   dir[2] =  sqrtf(0.5f);
+   dir[1] =  1.0f;
+   v3_normalize(dir);
+}
+
+VG_STATIC void respawn_chooser_get_plane( v4f plane ){
+   world_instance *world = &world_static.instances[ respawn_chooser.world_id ];
+   f32 h = localplayer.rb.co[1];
+   if( respawn_chooser.world_id != world_static.active_instance )
+      h = (world->scene_geo.bbx[0][1] + world->scene_geo.bbx[1][1]) * 0.5f;
+
+   v4_copy( (v4f){0.0f,1.0f,0.0f,h}, plane );
+}
+
+VG_STATIC void respawn_world_to_plane_pos( v3f pos, v2f plane_pos ){
+   v3f dir;
+   respawn_chooser_get_dir( dir );
+   v3_negate(dir,dir);
+   v4f plane;
+   respawn_chooser_get_plane( plane );
+
+   v3f co;
+   f32 t = ray_plane( plane, pos, dir );
+   v3_muladds( pos, dir, t, co );
+   plane_pos[0] = co[0];
+   plane_pos[1] = co[2];
+}
+
+VG_STATIC void respawn_chooser_setworld( u32 next ){
+   world_instance *nw = &world_static.instances[next];
+   if( nw->status == k_world_status_loaded ){
+      respawn_chooser.world_id = next;
+
+      v3f target;
+      if( next == world_static.active_instance )
+         v3_copy( localplayer.rb.co, target );
+      else {
+         scene_context *sc = &nw->scene_geo;
+         v3_lerp( sc->bbx[0], sc->bbx[1], 0.5f, target );
+      }
+      respawn_world_to_plane_pos( target, respawn_chooser.plane_pos );
+   }
+}
+
+VG_STATIC void respawn_chooser_gohome(void){
+   respawn_chooser_setworld(0);
+   world_instance *world = &world_static.instances[ respawn_chooser.world_id ];
+   
+   const char **alias = respawn_homes[respawn_chooser.home_select];
+   ent_spawn *spawn = world_find_spawn_by_name( world, alias[0] );
+
+   if( spawn ){
+      respawn_world_to_plane_pos( spawn->transform.co, 
+                                  respawn_chooser.plane_pos );
+
+      gui_location_print_ccmd( 1, (const char *[]){ alias[1] } );
+   }
+   else
+      gui_location_print_ccmd( 1, (const char *[]){ "Invalid home ID" } );
+}
+
+
+VG_STATIC void respawn_chooser_pre_update(void){
+   if( skaterift.activity != k_skaterift_respawning ) return;
+
+   gui_helper_action( joystick_display_string(k_srjoystick_steer,2), "move" );
+   if( world_static.instances[0].status == k_world_status_loaded )
+      gui_helper_action( axis_display_string(k_sraxis_mbrowse_h), "world" );
+   gui_helper_action( button_display_string(k_srbind_maccept), "spawn" );
+   gui_helper_action( axis_display_string(k_sraxis_mbrowse_v), "home" );
+
+   if( button_down( k_srbind_mback ) ){
+      srinput.enabled = 0;
+      skaterift.activity = k_skaterift_menu;
+      menu.page = 0xffffffff;
+      menu_open_page( "Main Menu" );
+      return;
+   }
+
+   if( button_down( k_srbind_maccept ) ){
+      skaterift.activity = k_skaterift_default;
+      srinput.enabled = 0;
+
+      if( respawn_chooser.spawn ){
+         world_static.active_instance = respawn_chooser.world_id;
+         localplayer.viewable_world = 
+            &world_static.instances[ respawn_chooser.world_id ];
+         player__spawn( &localplayer, respawn_chooser.spawn );
+      }
+      return;
+   }
+
+   if( button_down( k_srbind_mleft ) ){
+      if( respawn_chooser.world_id > 0 )
+         respawn_chooser_setworld( respawn_chooser.world_id-1 );
+   }
+
+   if( button_down( k_srbind_mright ) ){
+      u32 next = respawn_chooser.world_id+1;
+      if( next < vg_list_size(world_static.instances) )
+         respawn_chooser_setworld( next );
+   }
+
+   if( button_down(k_srbind_mup) ){
+      respawn_chooser.home_select ++;
+      if( respawn_chooser.home_select >= vg_list_size(respawn_homes) )
+         respawn_chooser.home_select = 0;
+      respawn_chooser_gohome();
+   }
+   else if( button_down(k_srbind_mdown) ){
+      if( respawn_chooser.home_select == 0 )
+         respawn_chooser.home_select = vg_list_size(respawn_homes)-1;
+      else
+         respawn_chooser.home_select --;
+      respawn_chooser_gohome();
+   }
+
+   world_instance *world = &world_static.instances[ respawn_chooser.world_id ];
+   v3f *bbx = world->scene_geo.bbx;
+   f32 *pos = respawn_chooser.plane_pos;
+
+   v2f steer;
+   joystick_state( k_srjoystick_steer, steer );
+   v2_normalize_clamp( steer );
+
+   m2x2f rm;
+   m2x2_create_rotation( rm, -0.25f*VG_PIf );
+   m2x2_mulv( rm, steer, steer );
+
+   v2_muladds( pos, steer, vg.time_frame_delta * 200.0f, pos );
+   v2_minv( (v2f){ bbx[1][0], bbx[1][2] }, pos, pos );
+   v2_maxv( (v2f){ bbx[0][0], bbx[0][2] }, pos, pos );
+
+   /* update camera */
+   camera *cam = &respawn_chooser.cam;
+   v3f dir;
+   respawn_chooser_get_dir(dir);
+
+   v4f plane;
+   respawn_chooser_get_plane( plane );
+
+   v3f co = { pos[0], plane[3]*plane[1], pos[1] };
+   v3_muladds( co, dir, respawn_chooser.boom_dist, cam->pos );
+
+   vg_line_cross( co, VG__RED, 10.0f );
+
+   cam->angles[0] = 0.25f * VG_PIf;
+   cam->angles[1] = 0.25f * VG_PIf;
+   cam->farz = 5000.0f;
+   cam->nearz = 10.0f;
+   cam->fov = 40.0f;
+
+   camera_update_transform( cam );
+   camera_update_view( cam );
+   camera_update_projection( cam );
+   camera_finalize( cam );
+
+   /* pick spawn */
+   respawn_chooser.spawn = NULL;
+   f32 closest2 = INFINITY;
+
+   for( u32 i=0; i<mdl_arrcount(&world->ent_spawn); i++ ){
+      ent_spawn *spawn = mdl_arritm(&world->ent_spawn,i);
+
+      v4f v;
+      v3_copy( spawn->transform.co, v );
+      v[3] = 1.0f;
+      m4x4_mulv( cam->mtx.pv, v, v );
+
+      f32 d2 = v2_length2(v);
+      if( d2 < closest2 ){
+         respawn_chooser.spawn = spawn;
+         closest2 = d2;
+      }
+   }
+
+   if( respawn_chooser.spawn ){
+      vg_line_cross( respawn_chooser.spawn->transform.co, VG__GREEN, 5.0f );
+   }
+}
+
+VG_STATIC void respawn_begin_chooser(void){
+   skaterift.activity = k_skaterift_respawning;
+   respawn_chooser.world_id = world_static.active_instance;
+
+   world_instance *world = &world_static.instances[ respawn_chooser.world_id ];
+   v3f *bbx = world->scene_geo.bbx;
+
+   respawn_world_to_plane_pos( localplayer.rb.co, respawn_chooser.plane_pos );
+   respawn_chooser.boom_dist = 400.0f;
+   respawn_chooser.home_select = 0;
+}
+
+VG_STATIC void respawn_chooser_shader_uniforms(void){
+   v4f uPlayerPos, uSpawnPos;
+   v4_zero( uPlayerPos );
+   v4_zero( uSpawnPos );
+
+   v3_copy( localplayer.rb.co, uPlayerPos );
+   
+   if( respawn_chooser.spawn )
+      v3_copy( respawn_chooser.spawn->transform.co, uSpawnPos );
+
+   shader_scene_override_uPlayerPos( uPlayerPos );
+   shader_scene_override_uSpawnPos( uSpawnPos );
+}
+
+#endif /* RESPAWN_C */
diff --git a/respawn.h b/respawn.h
new file mode 100644 (file)
index 0000000..002ffff
--- /dev/null
+++ b/respawn.h
@@ -0,0 +1,25 @@
+#ifndef RESPAWN_H
+#define RESPAWN_H
+
+#include "skaterift.h"
+
+struct {
+   v2f plane_pos;
+   f32 boom_dist;
+   u32 world_id;
+   u32 home_select;
+
+   ent_spawn *spawn;
+   camera cam;
+}
+static respawn_chooser;
+
+static const char *respawn_homes[][2] = {
+   { "skateshop", "Skateshop" },
+   { "world_select", "World Selector" },
+};
+
+VG_STATIC void respawn_begin_chooser(void);
+VG_STATIC void respawn_chooser_shader_uniforms(void);
+
+#endif /* RESPAWN_H */
diff --git a/shaders/scene_override.fs b/shaders/scene_override.fs
new file mode 100644 (file)
index 0000000..a182654
--- /dev/null
@@ -0,0 +1,67 @@
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexMain;
+uniform vec3 uCamera;
+uniform vec4 uPlane;
+
+uniform vec4 uPlayerPos;
+uniform vec4 uSpawnPos;
+
+#include "common_scene.glsl"
+#include "motion_vectors_fs.glsl"
+
+vec2 smin( float a, float b, float k )
+{
+   float h = max( k-abs(a-b), 0.0 )/k;
+   float m = h*h*0.5;
+   float s = m*k*(1.0/2.0);
+
+   if( a < b )
+      return vec2(a-s,m);
+   else
+      return vec2(b-s,1.0-m);
+}
+
+void main()
+{
+   vec2 ssuv = gl_FragCoord.xy;
+   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
+   float dither = fract( vDither.g / 71.0 ) - 0.5;
+
+   if( (aWorldCo.y*0.1 + dither) > ((uPlayerPos.y+40.0)*0.1) )
+      discard;
+
+   compute_motion_vectors();
+
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+   vec3 qnorm = aNorm.xyz;
+
+   if( !gl_FrontFacing ){
+      qnorm *= -1.0;
+   }
+
+   vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );
+
+   float d0 = distance( aWorldCo, uPlayerPos.xyz )*2.0;
+   float d1 = distance( aWorldCo, uSpawnPos.xyz );
+
+   vec2 dm = smin( d0, d1, 10.0 );
+   float dd = fract(dm.x*0.2-g_realtime*0.5)*max(0.0,1.0-dm.x*0.04)*max(0.0,qnorm.y);
+
+   vec3 emit = mix(vec3(1.0,0.0,0.0),vec3(0.0,1.0,0.0),dm.y)*dd;
+
+
+
+
+   vec3 v0 = normalize(uSpawnPos.xyz-uPlayerPos.xyz);
+   float t = min(max(dot(aWorldCo-uPlayerPos.xyz,v0),0.0),
+   distance(uSpawnPos.xyz,uPlayerPos.xyz));
+
+   vec3 p0 = uPlayerPos.xyz + v0*t;
+   float d3 = distance(p0,aWorldCo);
+
+   float lp = fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2);
+
+   emit += vec3(lp);
+
+   oColour = vec4( vfrag+emit, 1.0 );
+}
diff --git a/shaders/scene_override.h b/shaders/scene_override.h
new file mode 100644 (file)
index 0000000..d43acca
--- /dev/null
@@ -0,0 +1,551 @@
+#ifndef SHADER_scene_override_H
+#define SHADER_scene_override_H
+static void shader_scene_override_link(void);
+static void shader_scene_override_register(void);
+static struct vg_shader _shader_scene_override = {
+   .name = "scene_override",
+   .link = shader_scene_override_link,
+   .vs = 
+{
+.orig_file = "shaders/scene.vs",
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      6        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"}\n"
+""},
+   .fs = 
+{
+.orig_file = "shaders/scene_override.fs",
+.static_src = 
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexMain;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec4 uPlane;\n"
+"\n"
+"uniform vec4 uPlayerPos;\n"
+"uniform vec4 uSpawnPos;\n"
+"\n"
+"#line       1        1 \n"
+"// :D\n"
+"\n"
+"in vec2 aUv;\n"
+"in vec4 aNorm;\n"
+"in vec3 aCo;\n"
+"in vec3 aWorldCo;\n"
+"\n"
+"#line       1        1 \n"
+"layout (location = 0) out vec4 oColour;\n"
+"\n"
+"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
+"layout (std140) uniform ub_world_lighting\n"
+"{\n"
+"   vec4 g_cube_min;\n"
+"   vec4 g_cube_inv_range;\n"
+"\n"
+"   vec4 g_water_plane;\n"
+"   vec4 g_depth_bounds;\n"
+"\n"
+"   vec4 g_daysky_colour;\n"
+"   vec4 g_nightsky_colour;\n"
+"   vec4 g_sunset_colour;\n"
+"   vec4 g_ambient_colour;\n"
+"   vec4 g_sunset_ambient;\n"
+"   vec4 g_sun_colour;\n"
+"   vec4 g_sun_dir;\n"
+"   vec4 g_board_0;\n"
+"   vec4 g_board_1;\n"
+"\n"
+"   float g_water_fog;\n"
+"   float g_time;\n"
+"   float g_realtime;\n"
+"   float g_shadow_length;\n"
+"   float g_shadow_spread;\n"
+"\n"
+"   float g_time_of_day;\n"
+"   float g_day_phase;\n"
+"   float g_sunset_phase;\n"
+"\n"
+"   int g_light_preview;\n"
+"   int g_shadow_samples;\n"
+"\n"
+"   int g_debug_indices;\n"
+"   int g_debug_complexity;\n"
+"};\n"
+"\n"
+"uniform sampler2D g_world_depth;\n"
+"uniform samplerBuffer uLightsArray;\n"
+"uniform usampler3D uLightsIndex;\n"
+"\n"
+"#line       1        1 \n"
+"//const vec3  DAYSKY_COLOUR   = vec3( 0.37, 0.54, 0.97 );\n"
+"//const vec3  NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
+"//const vec3  SUNSET_COLOUR   = vec3( 1.00, 0.32, 0.01 );\n"
+"//const vec3  AMBIENT_COLOUR  = vec3( 0.13, 0.17, 0.35 );\n"
+"//const vec3  SUNSET_AMBIENT  = vec3( 0.25, 0.17, 0.51 );\n"
+"//const vec3  SUN_COLOUR      = vec3( 1.10, 0.89, 0.35 );\n"
+"\n"
+"const float SUN_ANGLE       = 0.0001;\n"
+"const float PI              = 3.14159265;\n"
+"\n"
+"//struct world_info\n"
+"//{\n"
+"//   float time,\n"
+"//         time_of_day,\n"
+"//         day_phase,\n"
+"//         sunset_phase;\n"
+"//   \n"
+"//   vec3 sun_dir;\n"
+"//};\n"
+"\n"
+"float luminance( vec3 v )\n"
+"{\n"
+"   return dot( v, vec3(0.2126, 0.7152, 0.0722) );\n"
+"}\n"
+"\n"
+"vec3 clearskies_ambient( vec3 dir )\n"
+"{\n"
+"   float sun_azimuth  = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
+"   float sky_gradient = dir.y;\n"
+"   \n"
+"   /* Blend phase colours */\n"
+"   vec3 ambient  = g_daysky_colour.rgb   * (g_day_phase-g_sunset_phase*0.1);\n"
+"        ambient += g_sunset_colour.rgb   * (1.0-dir.y*0.5)*sun_azimuth;\n"
+"        ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
+"   \n"
+"   /* Add gradient */\n"
+"        ambient -= sky_gradient * luminance(ambient);\n"
+"        \n"
+"   return ambient;\n"
+"}\n"
+"\n"
+"vec3 clearskies_sky( vec3 ray_dir )\n"
+"{\n"
+"   ray_dir.y = abs( ray_dir.y );\n"
+"   vec3 sky_colour  = clearskies_ambient( ray_dir );\n"
+"   \n"
+"   /* Sun */\n"
+"   float sun_theta  = dot( ray_dir, g_sun_dir.xyz );\n"
+"   float sun_size   = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
+"   float sun_shape  = pow( sun_size, 2000.0 );\n"
+"         sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
+"         \n"
+"   vec3 sun_colour  = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
+"        sun_colour *= sun_shape;\n"
+"   \n"
+"   vec3 composite   = sky_colour + sun_colour;\n"
+"   return composite;\n"
+"}\n"
+"\n"
+"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
+"{\n"
+"   float fresnel = 1.0 - abs(dot(normal,halfview));\n"
+"\n"
+"   vec3  reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
+"                               g_sunset_phase );\n"
+"\n"
+"   vec3  sky_reflection = 0.5 * fresnel * reflect_colour;\n"
+"   vec3  light_sun      = max(0.0,dot(normal,g_sun_dir.xyz)*0.75+0.25) \n"
+"                           * g_sun_colour.rgb * g_day_phase;\n"
+"\n"
+"   float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
+"   vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
+"                       g_sunset_phase );\n"
+"\n"
+"   return ambient + (light_sun + sky_reflection) * shadow;\n"
+"}\n"
+"\n"
+"#line     44        0 \n"
+"\n"
+"float world_depth_sample( vec3 pos )\n"
+"{\n"
+"   vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
+"   return texture( g_world_depth, depth_coord ).r;\n"
+"}\n"
+"\n"
+"float world_water_depth( vec3 pos )\n"
+"{\n"
+"   float ref_depth = g_water_plane.y*g_water_plane.w;\n"
+"   return world_depth_sample( pos ) - ref_depth;\n"
+"}\n"
+"\n"
+"float shadow_sample( vec3 vdir )\n"
+"{\n"
+"   vec3 sample_pos = aWorldCo + vdir;\n"
+"   float height_sample = world_depth_sample( sample_pos );\n"
+"\n"
+"   float fdelta = height_sample - sample_pos.y;\n"
+"   return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
+"}\n"
+"\n"
+"float newlight_compute_sun_shadow( vec3 dir )\n"
+"{\n"
+"   if( g_shadow_samples == 0 )\n"
+"   {\n"
+"      return 1.0;\n"
+"   }\n"
+"\n"
+"   float fspread = g_shadow_spread;\n"
+"   float flength = g_shadow_length;\n"
+"\n"
+"   float famt = 0.0;\n"
+"   famt += shadow_sample((dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
+"   famt += shadow_sample((dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
+"   famt += shadow_sample((dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
+"   famt += shadow_sample((dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
+"\n"
+"   //famt+=shadow_sample((dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
+"   //famt+=shadow_sample((dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
+"   //famt+=shadow_sample((dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
+"   //famt+=shadow_sample((dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
+"\n"
+"   return 1.0 - famt;\n"
+"}\n"
+"\n"
+"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
+"{\n"
+"   vec3 specdir = reflect( -dir, wnormal );\n"
+"   return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
+"}\n"
+"\n"
+"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist )\n"
+"{\n"
+"   float dist = pow(fdist*0.0010,0.78);\n"
+"   return mix( vfrag, colour, min( 1.0, dist ) );\n"
+"}\n"
+"\n"
+"vec3 rand33(vec3 p3)\n"
+"{\n"
+"      p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
+"   p3 += dot(p3, p3.yxz+33.33);\n"
+"   return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
+"}\n"
+"\n"
+"vec3 scene_calculate_light( int light_index, \n"
+"                            vec3 halfview, vec3 co, vec3 normal )\n"
+"{\n"
+"   vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
+"   vec4 light_co     = texelFetch( uLightsArray, light_index+1 );\n"
+"   vec4 light_dir    = texelFetch( uLightsArray, light_index+2 );\n"
+"\n"
+"   vec3 light_delta = light_co.xyz-co;\n"
+"   float dist2 = dot(light_delta,light_delta);\n"
+"\n"
+"   light_delta = normalize( light_delta );\n"
+"\n"
+"   float quadratic = dist2*100.0;\n"
+"   float attenuation  = 1.0/( 1.0 + quadratic );\n"
+"         attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
+"\n"
+"   float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
+"\n"
+"   if( light_dir.w < 0.999999 ){\n"
+"      float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
+"      falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
+"   }\n"
+"\n"
+"   return light_colour.rgb * attenuation * falloff \n"
+"            * step( g_day_phase, light_colour.w );\n"
+"}\n"
+"\n"
+"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
+"                                         vec3 halfview, vec3 co, vec3 normal )\n"
+"{\n"
+"   uint light_count = packed_index & 0x3u;\n"
+"\n"
+"   vec3 l = vec3(0.0);\n"
+"\n"
+"   if( light_count >= 1u ){\n"
+"      int index_0 = int( ((packed_index >>  2u) & 0x3ffu) * 3u );\n"
+"      int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
+"      int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
+"\n"
+"      l += scene_calculate_light( index_0, halfview, co, normal );\n"
+"\n"
+"      if( light_count >= 2u ){\n"
+"         l += scene_calculate_light( index_1, halfview, co, normal );\n"
+"\n"
+"         if( light_count >= 3u ){\n"
+"            l += scene_calculate_light( index_2, halfview, co, normal );\n"
+"         }\n"
+"      }\n"
+"   }\n"
+"\n"
+"   return l;\n"
+"}\n"
+"\n"
+"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
+"                             float light_mask )\n"
+"{\n"
+"   if( g_light_preview == 1 )\n"
+"      diffuse = vec3(0.75);\n"
+"\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - co;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow( g_sun_dir.xyz \n"
+"                                    * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
+"\n"
+"   vec3 total_light = clearskies_lighting( \n"
+"                           normal, min( light_mask, world_shadow ), halfview );\n"
+"\n"
+"   vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
+"        cube_coord = floor( cube_coord );\n"
+"\n"
+"   if( g_debug_indices == 1 )\n"
+"   {\n"
+"      return rand33(cube_coord);\n"
+"   }\n"
+"\n"
+"   if( g_debug_complexity == 1 )\n"
+"   {\n"
+"      ivec3 coord = ivec3( cube_coord );\n"
+"      uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+"      uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
+"      return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
+"   }\n"
+"\n"
+"   // FIXME: this coord should absolutely must be clamped!\n"
+"   \n"
+"   ivec3 coord = ivec3( cube_coord );\n"
+"   uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+"   total_light += \n"
+"      scene_calculate_packed_light_patch( index_sample.x,\n"
+"                                          halfview, co, normal ) \n"
+"                                          * light_mask;\n"
+"   total_light += \n"
+"      scene_calculate_packed_light_patch( index_sample.y,\n"
+"                                          halfview, co, normal )\n"
+"                                          * light_mask;\n"
+"\n"
+"   // Take a section of the sky function to give us a matching fog colour\n"
+"\n"
+"   vec3 fog_colour  = clearskies_ambient( -halfview );\n"
+"   float sun_theta  = dot( -halfview, g_sun_dir.xyz );\n"
+"   float sun_size   = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
+"   float sun_shape  = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
+"         \n"
+"   vec3 sun_colour  = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
+"        sun_colour *= sun_shape;\n"
+"\n"
+"   fog_colour += sun_colour;\n"
+"   return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
+"}\n"
+"\n"
+"#line      9        0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+"  vec3 pa = p - a;\n"
+"  vec3 ba = b - a;\n"
+"\n"
+"  float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+"  return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+"   // player shadow\n"
+"   float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
+"                                                      g_board_1.xyz )-0.1 );\n"
+"   float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+"   player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+"   return 1.0 - player_shadow*0.8;\n"
+"}\n"
+"\n"
+"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
+"{\n"
+"   return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
+"}\n"
+"\n"
+"#line     10        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     11        0 \n"
+"\n"
+"vec2 smin( float a, float b, float k )\n"
+"{\n"
+"   float h = max( k-abs(a-b), 0.0 )/k;\n"
+"   float m = h*h*0.5;\n"
+"   float s = m*k*(1.0/2.0);\n"
+"\n"
+"   if( a < b )\n"
+"      return vec2(a-s,m);\n"
+"   else\n"
+"      return vec2(b-s,1.0-m);\n"
+"}\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec2 ssuv = gl_FragCoord.xy;\n"
+"   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
+"   float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
+"\n"
+"   if( (aWorldCo.y*0.1 + dither) > ((uPlayerPos.y+40.0)*0.1) )\n"
+"      discard;\n"
+"\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"   vec3 qnorm = aNorm.xyz;\n"
+"\n"
+"   if( !gl_FrontFacing ){\n"
+"      qnorm *= -1.0;\n"
+"   }\n"
+"\n"
+"   vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
+"\n"
+"   float d0 = distance( aWorldCo, uPlayerPos.xyz )*2.0;\n"
+"   float d1 = distance( aWorldCo, uSpawnPos.xyz );\n"
+"\n"
+"   vec2 dm = smin( d0, d1, 10.0 );\n"
+"   float dd = fract(dm.x*0.2-g_realtime*0.5)*max(0.0,1.0-dm.x*0.04)*max(0.0,qnorm.y);\n"
+"\n"
+"   vec3 emit = mix(vec3(1.0,0.0,0.0),vec3(0.0,1.0,0.0),dm.y)*dd;\n"
+"\n"
+"\n"
+"\n"
+"\n"
+"   vec3 v0 = normalize(uSpawnPos.xyz-uPlayerPos.xyz);\n"
+"   float t = min(max(dot(aWorldCo-uPlayerPos.xyz,v0),0.0),\n"
+"   distance(uSpawnPos.xyz,uPlayerPos.xyz));\n"
+"\n"
+"   vec3 p0 = uPlayerPos.xyz + v0*t;\n"
+"   float d3 = distance(p0,aWorldCo);\n"
+"\n"
+"   float lp = fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2);\n"
+"\n"
+"   emit += vec3(lp);\n"
+"\n"
+"   oColour = vec4( vfrag+emit, 1.0 );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_scene_override_uMdl;
+static GLuint _uniform_scene_override_uPv;
+static GLuint _uniform_scene_override_uPvmPrev;
+static GLuint _uniform_scene_override_uTexGarbage;
+static GLuint _uniform_scene_override_uTexMain;
+static GLuint _uniform_scene_override_uCamera;
+static GLuint _uniform_scene_override_uPlane;
+static GLuint _uniform_scene_override_uPlayerPos;
+static GLuint _uniform_scene_override_uSpawnPos;
+static GLuint _uniform_scene_override_g_world_depth;
+static GLuint _uniform_scene_override_uLightsArray;
+static GLuint _uniform_scene_override_uLightsIndex;
+static void shader_scene_override_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_override_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_override_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_override_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_override_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_override_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_override_uTexGarbage(int i){
+   glUniform1i(_uniform_scene_override_uTexGarbage,i);
+}
+static void shader_scene_override_uTexMain(int i){
+   glUniform1i(_uniform_scene_override_uTexMain,i);
+}
+static void shader_scene_override_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_override_uCamera,1,v);
+}
+static void shader_scene_override_uPlane(v4f v){
+   glUniform4fv(_uniform_scene_override_uPlane,1,v);
+}
+static void shader_scene_override_uPlayerPos(v4f v){
+   glUniform4fv(_uniform_scene_override_uPlayerPos,1,v);
+}
+static void shader_scene_override_uSpawnPos(v4f v){
+   glUniform4fv(_uniform_scene_override_uSpawnPos,1,v);
+}
+static void shader_scene_override_g_world_depth(int i){
+   glUniform1i(_uniform_scene_override_g_world_depth,i);
+}
+static void shader_scene_override_register(void){
+   vg_shader_register( &_shader_scene_override );
+}
+static void shader_scene_override_use(void){ glUseProgram(_shader_scene_override.id); }
+static void shader_scene_override_link(void){
+   _uniform_scene_override_uMdl = glGetUniformLocation( _shader_scene_override.id, "uMdl" );
+   _uniform_scene_override_uPv = glGetUniformLocation( _shader_scene_override.id, "uPv" );
+   _uniform_scene_override_uPvmPrev = glGetUniformLocation( _shader_scene_override.id, "uPvmPrev" );
+   _uniform_scene_override_uTexGarbage = glGetUniformLocation( _shader_scene_override.id, "uTexGarbage" );
+   _uniform_scene_override_uTexMain = glGetUniformLocation( _shader_scene_override.id, "uTexMain" );
+   _uniform_scene_override_uCamera = glGetUniformLocation( _shader_scene_override.id, "uCamera" );
+   _uniform_scene_override_uPlane = glGetUniformLocation( _shader_scene_override.id, "uPlane" );
+   _uniform_scene_override_uPlayerPos = glGetUniformLocation( _shader_scene_override.id, "uPlayerPos" );
+   _uniform_scene_override_uSpawnPos = glGetUniformLocation( _shader_scene_override.id, "uSpawnPos" );
+   _uniform_scene_override_g_world_depth = glGetUniformLocation( _shader_scene_override.id, "g_world_depth" );
+   _uniform_scene_override_uLightsArray = glGetUniformLocation( _shader_scene_override.id, "uLightsArray" );
+   _uniform_scene_override_uLightsIndex = glGetUniformLocation( _shader_scene_override.id, "uLightsIndex" );
+}
+#endif /* SHADER_scene_override_H */
index c2fc2664d0263c16d33f66e4c40d9452da4f2652..983ca9ba99c5fddc1b7d112fa7d36b5053ecf259 100644 (file)
@@ -50,6 +50,7 @@
 #include "addon.c"
 #include "highscores.c"
 #include "save.c"
+#include "respawn.c"
 
 static struct player_avatar localplayer_avatar;
 
@@ -297,8 +298,10 @@ VG_STATIC void vg_pre_update(void){
 
    /* time rate */
    f32 target = 1;
-   if( skaterift.activity & (k_skaterift_replay|k_skaterift_menu) ) 
+   if( skaterift.activity & (k_skaterift_replay|k_skaterift_menu|
+                             k_skaterift_respawning) ) {
       target = 0;
+   }
 
    vg_slewf( &skaterift.time_rate, target, vg.time_frame_delta * (1.0f/0.3f) );
    vg.time_rate = vg_smoothstepf( skaterift.time_rate );
@@ -309,6 +312,7 @@ VG_STATIC void vg_pre_update(void){
 
    world_update( world_current_instance(), localplayer.rb.co );
    audio_ambient_sprites_update( world_current_instance(), localplayer.rb.co );
+   respawn_chooser_pre_update();
 }
 
 VG_STATIC void vg_fixed_update(void){
@@ -456,17 +460,28 @@ VG_STATIC void render_scene(void){
       }
    }
 
-   render_world( view_world, &skaterift.cam, 0 );
-
-   render_water_texture( view_world, &skaterift.cam, 0 );
-   render_fb_bind( gpipeline.fb_main, 1 );
-   render_water_surface( view_world, &skaterift.cam );
+   if( skaterift.activity == k_skaterift_respawning ){
+      glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } );
+      glClearColor( 0.624f, 0.659f, 0.769f, 0.0f );
+      glClear( GL_COLOR_BUFFER_BIT );
+      glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, 
+                                    GL_COLOR_ATTACHMENT1 } );
+      view_world = &world_static.instances[respawn_chooser.world_id];
+      render_world_override( view_world );
+   }
+   else{
+      render_world( view_world, &skaterift.cam, 0 );
+      render_water_texture( view_world, &skaterift.cam, 0 );
+      render_fb_bind( gpipeline.fb_main, 1 );
+      render_water_surface( view_world, &skaterift.cam );
+   }
 }
 
 VG_STATIC void render_scene_gate_subview(void){
    render_fb_bind( gpipeline.fb_main, 1 );
    world_instance *view_world = localplayer.viewable_world;
    if( !view_world ) return; /* ??? */
+   if( skaterift.activity == k_skaterift_respawning ) return;
 
    int depth = 1;
    if( localplayer.gate_waiting ) depth = 0;
@@ -484,15 +499,23 @@ VG_STATIC void skaterift_composite_maincamera(void){
    skaterift.cam.nearz = 0.1f;
    skaterift.cam.farz  = 2100.0f;
 
+   if( skaterift.activity == k_skaterift_respawning ){
+      camera_copy( &respawn_chooser.cam, &skaterift.cam );
+      skaterift.cam.nearz = 4.0f;
+      skaterift.cam.farz  = 3100.0f;
+   }
+
    camera_update_transform( &skaterift.cam );
 
-   if( localplayer.gate_waiting ){
-      m3x3_mul( localplayer.basis_gate, skaterift.cam.transform, 
-                skaterift.cam.transform );
-   }
-   else{
-      m3x3_mul( localplayer.basis, skaterift.cam.transform, 
-                skaterift.cam.transform );
+   if( skaterift.activity != k_skaterift_respawning ){
+      if( localplayer.gate_waiting ){
+         m3x3_mul( localplayer.basis_gate, skaterift.cam.transform, 
+                   skaterift.cam.transform );
+      }
+      else{
+         m3x3_mul( localplayer.basis, skaterift.cam.transform, 
+                   skaterift.cam.transform );
+      }
    }
    
    camera_update_view( &skaterift.cam );
index 15a17dec5b05501385619f9c2bd31eff4febddd0..7624fd4846170d765fb2b75346e84abb334f15ef 100644 (file)
@@ -49,7 +49,8 @@ struct{
       k_skaterift_default    = 0x00,
       k_skaterift_replay     = 0x01,
       k_skaterift_ent_focus  = 0x02,
-      k_skaterift_menu       = 0x04
+      k_skaterift_menu       = 0x04,
+      k_skaterift_respawning = 0x08
    }
    activity;
 
index 12728799bf2cbd4b0d1ae33b559bde16720793c9..a7bb6939c6b5d02b07f76e6c5eb29fd2d997afc1 100644 (file)
@@ -9,6 +9,7 @@
 #include "world_render.h"
 #include "font.h"
 #include "gui.h"
+#include "respawn.h"
 
 static int ccmd_set_time( int argc, const char *argv[] ){
    if( argc == 1 ){
@@ -77,6 +78,7 @@ VG_STATIC void world_render_init(void)
 
    shader_scene_standard_register();
    shader_scene_standard_alphatest_register();
+   shader_scene_override_register();
    shader_scene_cubemapped_register();
    shader_scene_fxglow_register();
    shader_scene_vertex_blend_register();
@@ -644,6 +646,11 @@ VG_STATIC void bindpoint_terrain( world_instance *world,
    shader_scene_terrain_uBlendOffset( mat->info.colour1 );
 }
 
+VG_STATIC void bindpoint_none( world_instance *world,
+                               struct world_surface *mat ){
+   
+}
+
 VG_STATIC void render_terrain( world_instance *world, camera *cam )
 {
    shader_scene_terrain_use();
@@ -779,11 +786,16 @@ VG_STATIC void world_prerender( world_instance *world )
    struct ub_world_lighting *state = &world->ub_lighting;
 
    state->g_time = world->time;
-   state->g_realtime = vg.time;
+   state->g_realtime = vg.time_real;
    state->g_debug_indices = k_debug_light_indices;
    state->g_light_preview = k_light_preview;
    state->g_debug_complexity = k_debug_light_complexity;
-   state->g_time_of_day = vg_fractf( world->time );
+
+   if( skaterift.activity == k_skaterift_respawning )
+      state->g_time_of_day = 0.1f;
+   else
+      state->g_time_of_day = vg_fractf( world->time );
+
    state->g_day_phase   = cosf( state->g_time_of_day * VG_PIf * 2.0f );
    state->g_sunset_phase= cosf( state->g_time_of_day * VG_PIf * 4.0f + VG_PIf );
 
@@ -872,6 +884,69 @@ VG_STATIC void render_world( world_instance *world, camera *cam,
    render_world_fxglow( world, cam, layer_depth );
 }
 
+
+VG_STATIC 
+void render_world_override_pass( world_instance *world,
+                                 struct world_pass *pass ){
+   for( int i=0; i<world->surface_count; i++ ){
+      struct world_surface *mat = &world->surfaces[i];
+
+      if( mat->info.flags & k_material_flag_ghosts ) continue;
+
+      mdl_submesh *sm;
+      if( pass->geo_type == k_world_geo_type_solid )
+         sm = &mat->sm_geo;
+      else
+         sm = &mat->sm_no_collide;
+
+      if( !sm->indice_count )
+         continue;
+
+      m4x3f mmdl;
+      m4x3_identity( mmdl );
+      pass->fn_set_mdl( mmdl );
+      pass->fn_set_uPvmPrev( pass->cam->mtx_prev.pv );
+      pass->fn_bind_textures( world, mat );
+      mdl_draw_submesh( sm );
+   }
+}
+
+VG_STATIC void render_world_override( world_instance *world ){
+   struct world_pass pass = {
+      .cam = &skaterift.cam,
+      .fn_bind_textures = bindpoint_none,
+      .fn_set_mdl = shader_scene_override_uMdl,
+      .fn_set_uPvmPrev = shader_scene_override_uPvmPrev,
+      .shader = k_shader_override
+   };
+
+   shader_scene_override_use();
+   respawn_chooser_shader_uniforms();
+   shader_scene_override_uTexGarbage(0);
+   shader_scene_override_uTexMain(1);
+   shader_scene_override_uPv( pass.cam->mtx.pv );
+
+   world_link_lighting_ub( world, _shader_scene_override.id );
+   world_bind_position_texture( world, _shader_scene_override.id, 
+                                _uniform_scene_override_g_world_depth, 2 );
+   world_bind_light_array( world, _shader_scene_override.id,
+                                _uniform_scene_override_uLightsArray, 3 );
+   world_bind_light_index( world, _shader_scene_override.id,
+                                _uniform_scene_override_uLightsIndex, 4 );
+
+   bind_terrain_noise();
+   shader_scene_override_uCamera( pass.cam->transform[3] );
+
+   glDisable( GL_CULL_FACE );
+   mesh_bind( &world->mesh_geo );
+   pass.geo_type = k_world_geo_type_solid;
+   render_world_override_pass( world, &pass );
+   mesh_bind( &world->mesh_no_collide );
+   pass.geo_type = k_world_geo_type_nonsolid;
+   render_world_override_pass( world, &pass );
+   glEnable( GL_CULL_FACE );
+}
+
 VG_STATIC void render_cubemap_side( world_instance *world, ent_cubemap *cm, 
                                     u32 side ){
    camera cam;
index d71b44e448fedbbe70dbdf463579f60717585008..d90c01b26f9bbc332329d3a010d81883977d5778 100644 (file)
@@ -12,6 +12,7 @@
 
 #include "shaders/scene_standard.h"
 #include "shaders/scene_standard_alphatest.h"
+#include "shaders/scene_override.h"
 #include "shaders/scene_cubemapped.h"
 #include "shaders/scene_vertex_blend.h"
 #include "shaders/scene_terrain.h"