From: hgn Date: Sat, 18 Nov 2023 09:08:17 +0000 (+0000) Subject: chaos pt 1 X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;ds=sidebyside;h=2c91a71533b4ce86b9e7fd708420ae05c74d8f52;p=carveJwlIkooP6JGAAIwe30JlM.git chaos pt 1 --- diff --git a/addon.c b/addon.c index ef92b00..4d1e903 100644 --- a/addon.c +++ b/addon.c @@ -116,7 +116,7 @@ static void invalidate_addon_alias( addon_alias *alias ){ /* * parse uid to alias. returns 1 if successful */ -static int addon_uid_to_alias( char uid[ADDON_UID_MAX], addon_alias *alias ){ +static int addon_uid_to_alias( const char *uid, addon_alias *alias ){ /* 1 * 01234567890123 * sr&&&-@@@@@-#* diff --git a/addon.h b/addon.h index f63566e..8d2409a 100644 --- a/addon.h +++ b/addon.h @@ -76,7 +76,7 @@ static int addon_get_content_folder( addon_reg *reg, vg_str *folder ); static u32 addon_match( addon_alias *alias ); static int addon_alias_eq( addon_alias *a, addon_alias *b ); static void addon_alias_uid( addon_alias *alias, char buf[ADDON_UID_MAX] ); -static int addon_uid_to_alias( char uid[ADDON_UID_MAX], addon_alias *alias ); +static int addon_uid_to_alias( const char *uid, addon_alias *alias ); static void invalidate_addon_alias( addon_alias *alias ); static void addon_mount_content_folder( enum addon_type type, const char *base_folder, diff --git a/blender_export.py b/blender_export.py index 1646d83..51b25dd 100644 --- a/blender_export.py +++ b/blender_export.py @@ -39,12 +39,14 @@ sr_entity_list = [ ('ent_ccmd', 'CCmd', '', 17 ), ('ent_objective', 'Objective', '', 18 ), ('ent_challenge', 'Challenge', '', 19 ), - ('ent_relay', 'Relay', '', 20 ) + ('ent_relay', 'Relay', '', 20 ), + ('ent_miniworld', 'Mini World', '', 22 ) ] MDL_VERSION_NR = 103 SR_TRIGGERABLE = [ 'ent_audio', 'ent_ccmd', 'ent_gate', 'ent_challenge', \ - 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route' ] + 'ent_relay', 'ent_skateshop', 'ent_objective', 'ent_route',\ + 'ent_miniworld' ] def get_entity_enum_id( alias ): #{ @@ -521,6 +523,14 @@ class ent_cubemap(Structure):#{ ("placeholder",c_uint32*2)] #} +class ent_miniworld(Structure):#{ + _fields_ = [("transform",mdl_transform), + ("pstr_world",c_uint32), + ("purpose",c_int32)] + + sr_functions = { 0: 'zone' } +#} + def obj_ent_type( obj ): #{ if obj.type == 'ARMATURE': return 'mdl_armature' @@ -1942,6 +1952,14 @@ def sr_compile( collection ): cubemap.live = 60 sr_ent_push( cubemap ) #} + elif ent_type == 'ent_miniworld':#{ + miniworld = ent_miniworld() + obj_data = obj.SR_data.ent_miniworld[0] + + compile_obj_transform( obj, miniworld.transform ) + miniworld.pstr_world = sr_compile_string( obj_data.world ) + sr_ent_push( miniworld ) + #} #} #} @@ -2578,6 +2596,11 @@ class SR_OBJECT_ENT_ROUTE_ENTRY(bpy.types.PropertyGroup): poll=lambda self,obj: sr_filter_ent_type(obj,['ent_gate'])) #} +class SR_OBJECT_ENT_MINIWORLD(bpy.types.PropertyGroup): +#{ + world: bpy.props.StringProperty( name='world UID' ) +#} + class SR_UL_ROUTE_NODE_LIST(bpy.types.UIList): #{ bl_idname = 'SR_UL_ROUTE_NODE_LIST' @@ -3370,6 +3393,7 @@ class SR_OBJECT_PROPERTIES(bpy.types.PropertyGroup): ent_objective: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_OBJECTIVE) ent_challenge: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_CHALLENGE) ent_relay: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_RELAY) + ent_miniworld: bpy.props.CollectionProperty(type=SR_OBJECT_ENT_MINIWORLD) ent_type: bpy.props.EnumProperty( name="Type", @@ -4597,7 +4621,7 @@ classes = [ SR_INTERFACE, SR_MATERIAL_PANEL,\ SR_OBJECT_ENT_WORKSHOP_PREVIEW,SR_OBJECT_ENT_MENU_ITEM,\ SR_OBJECT_ENT_WORLD_INFO,SR_OBJECT_ENT_CCMD,\ SR_OBJECT_ENT_OBJECTIVE,SR_OBJECT_ENT_CHALLENGE,\ - SR_OBJECT_ENT_RELAY,\ + SR_OBJECT_ENT_RELAY,SR_OBJECT_ENT_MINIWORLD,\ \ SR_OBJECT_PROPERTIES, SR_LIGHT_PROPERTIES, SR_BONE_PROPERTIES, SR_MESH_PROPERTIES, SR_MATERIAL_PROPERTIES \ diff --git a/build.c b/build.c index 28e7909..417c319 100644 --- a/build.c +++ b/build.c @@ -245,7 +245,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_override", "scene_override.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" ); diff --git a/ent_miniworld.c b/ent_miniworld.c new file mode 100644 index 0000000..414b2f6 --- /dev/null +++ b/ent_miniworld.c @@ -0,0 +1,36 @@ +#include "entity.h" +#include "ent_miniworld.h" +#include "world_render.h" + +static void ent_miniworld_call( world_instance *world, ent_call *call ){ + ent_miniworld *miniworld = mdl_arritm( &world->ent_miniworld, + mdl_entity_id_id(call->id) ); + + int world_id = world - world_static.instances; + + if( call->function == 0 ){ /* zone() */ + const char *uid = mdl_pstr( &world->meta, miniworld->pstr_world ); + skaterift_load_world_command( 1, (const char *[]){ uid } ); + + global_miniworld.active_id = call->id; + } +} + +static void ent_miniworld_render( world_instance *host_world ){ + u32 entity_id = global_miniworld.active_id; + + if( !entity_id ) + return; + + ent_miniworld *miniworld = mdl_arritm( &host_world->ent_miniworld, + mdl_entity_id_id(entity_id) ); + + if( miniworld->purpose == k_world_purpose_invalid ) + return; + + m4x3f mmdl; + mdl_transform_m4x3( &miniworld->transform, mmdl ); + render_world_override( &world_static.instances[miniworld->purpose], mmdl ); + + //render_world_routes( , &skaterift.cam, 1 ); +} diff --git a/ent_miniworld.h b/ent_miniworld.h new file mode 100644 index 0000000..693a157 --- /dev/null +++ b/ent_miniworld.h @@ -0,0 +1,13 @@ +#ifndef ENT_MINIWORLD_H +#define ENT_MINIWORLD_H + +#include "entity.h" + +struct { + u32 active_id; /* TODO: world references in entity ID */ +} +static global_miniworld; + +static void ent_miniworld_call( world_instance *world, ent_call *call ); + +#endif /* ENT_MINIWORLD_H */ diff --git a/ent_portal.c b/ent_portal.c new file mode 100644 index 0000000..7d8c22f --- /dev/null +++ b/ent_portal.c @@ -0,0 +1,80 @@ +#if 0 +#include "ent_portal.h" +#include "addon.h" +#include "pointcloud.h" + +static void ent_portal_pointcloud_load_thread(void *_){ + char path_buf[4096]; + vg_str path; + vg_strnull( &path, path_buf, 4096 ); + addon_get_content_folder( global_portal.display_world, &path ); + vg_strcat( &path, "/preview.bin" ); + + vg_linear_clear(vg_mem.scratch); + u32 size; + + void *data = vg_file_read( vg_mem.scratch, path_buf, &size ); + if( data ){ + if( size < sizeof(pointcloud_buffer) ){ + vg_async_call( pointcloud_clear_async, NULL, 0 ); + return; + } + + vg_async_item *call = vg_async_alloc(size); + pointcloud_buffer *pcbuf = call->payload; + memcpy( pcbuf, data, size ); + + u32 point_count = (size-sizeof(pointcloud_buffer)) / + sizeof(struct pointcloud_vert); + pcbuf->max = point_count; + pcbuf->count = point_count; + pcbuf->op = k_pointcloud_op_clear; + + vg_async_dispatch( call, async_pointcloud_sub ); + vg_async_call( pointcloud_async_end, NULL, 0 ); + } + else{ + vg_async_call( pointcloud_clear_async, NULL, 0 ); + } +} + +/* + * Set new world to be loaded into portal + */ +static void ent_portal_set_world( addon_reg *reg ){ + global_portal.display_world = reg; + global_portal.dirty = 1; +} + +/* VG Events */ + +static void ent_portal_preupdate(void){ + if( global_portal.dirty && vg_loader_availible() ){ + global_portal.dirty = 0; + vg_loader_start( ent_portal_pointcloud_load_thread, NULL ); + } +} + +static void ent_portal_render(void){ + if( !global_portal.active ) + return; + + m4x3f mmdl; +#if 0 + mdl_transform_m4x3( &mark_display->transform, mmdl ); + m4x3_rotate_y( mmdl, vg.time * 0.2 ); +#endif + m3x3_identity( mmdl ); + m3x3_diagonal( mmdl, 20.0f ); + v3_copy( global_portal.display_co, mmdl[3] ); + mmdl[3][1] += 2.0f; + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE); + glDisable(GL_DEPTH_TEST); + pointcloud_render( &skaterift.cam, mmdl ); + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); +} + +#endif diff --git a/ent_portal.h b/ent_portal.h new file mode 100644 index 0000000..2301012 --- /dev/null +++ b/ent_portal.h @@ -0,0 +1,16 @@ +#ifndef ENT_PORTAL_H +#define ENT_PORTAL_H + +#include "addon.h" + +/* world portals */ + +struct { + addon_reg *display_world; + int dirty, active; + + v3f display_co; +} +static global_portal = { .display_co = { 12,1,0 }, .active = 1 }; + +#endif /* ENT_PORTAL_H */ diff --git a/ent_skateshop.c b/ent_skateshop.c index 8a03ff1..842d814 100644 --- a/ent_skateshop.c +++ b/ent_skateshop.c @@ -10,7 +10,6 @@ #include "player.h" #include "gui.h" #include "menu.h" -#include "pointcloud.h" #include "highscores.h" #include "steam.h" #include "addon.h" @@ -122,63 +121,6 @@ static u16 skateshop_selected_cache_id(void){ else return 0; } -static void pointcloud_async_end(void *_, u32 __) -{ - pointcloud_animate( k_pointcloud_anim_opening ); -} - -static void pointcloud_clear_async(void *_, u32 __) -{ - pointcloud.count = 0; - pointcloud_animate( k_pointcloud_anim_opening ); -} - -static void skateshop_world_preview_loader_thread( void *_data ) -{ - addon_reg *reg = _data; - - char path_buf[4096]; - vg_str path; - vg_strnull( &path, path_buf, 4096 ); - addon_get_content_folder( reg, &path ); - vg_strcat( &path, "/preview.bin" ); - - vg_linear_clear(vg_mem.scratch); - u32 size; - - void *data = vg_file_read( vg_mem.scratch, path_buf, &size ); - if( data ){ - if( size < sizeof(pointcloud_buffer) ){ - vg_async_call( pointcloud_clear_async, NULL, 0 ); - return; - } - - vg_async_item *call = vg_async_alloc(size); - pointcloud_buffer *pcbuf = call->payload; - memcpy( pcbuf, data, size ); - - u32 point_count = (size-sizeof(pointcloud_buffer)) / - sizeof(struct pointcloud_vert); - pcbuf->max = point_count; - pcbuf->count = point_count; - pcbuf->op = k_pointcloud_op_clear; - - vg_async_dispatch( call, async_pointcloud_sub ); - vg_async_call( pointcloud_async_end, NULL, 0 ); - } - else{ - vg_async_call( pointcloud_clear_async, NULL, 0 ); - } -} - -static void skateshop_world_preview_loader_thread_and_end( void *_data ){ - skateshop_world_preview_loader_thread( _data ); -} - -static void skateshop_load_world_preview( addon_reg *reg ){ - vg_loader_start( skateshop_world_preview_loader_thread_and_end, reg ); -} - /* * VG event preupdate */ @@ -337,6 +279,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ } } +#if 0 if( change && pointcloud_idle() ){ pointcloud_animate( k_pointcloud_anim_hiding ); } @@ -374,6 +317,7 @@ static void ent_skateshop_preupdate( ent_skateshop *shop, int active ){ } } } +#endif } else{ vg_fatal_error( "Unknown store (%u)\n", shop->type ); @@ -633,6 +577,7 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ m4x3_mul( mtext, mlocal, mtextmdl ); font3d_simple_draw( 0, bufsubtext, &skaterift.cam, mtextmdl ); +#if 0 /* pointcloud */ m4x3f mmdl; mdl_transform_m4x3( &mark_display->transform, mmdl ); @@ -644,6 +589,7 @@ static void skateshop_render_worldshop( ent_skateshop *shop ){ pointcloud_render( world, &skaterift.cam, mmdl ); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); +#endif } /* @@ -706,7 +652,6 @@ static void ent_skateshop_call( world_instance *world, ent_call *call ){ } else if( shop->type == k_skateshop_type_worldshop ){ ent_skateshop_helpers_pickable( "open rift" ); - pointcloud_animate( k_pointcloud_anim_opening ); skateshop_op_world_scan(); } } diff --git a/entity.c b/entity.c index 287016a..85557b1 100644 --- a/entity.c +++ b/entity.c @@ -10,6 +10,8 @@ #include "ent_challenge.c" #include "ent_relay.c" #include "ent_route.c" +#include "ent_portal.c" +#include "ent_miniworld.c" typedef void (*fn_entity_call_handler)( world_instance *, ent_call *); @@ -25,7 +27,8 @@ static void entity_call( world_instance *world, ent_call *call ){ [k_ent_gate] = ent_gate_call, [k_ent_relay] = ent_relay_call, [k_ent_challenge] = ent_challenge_call, - [k_ent_route] = ent_route_call + [k_ent_route] = ent_route_call, + [k_ent_miniworld] = ent_miniworld_call }; if( type >= vg_list_size(table) ){ diff --git a/entity.h b/entity.h index 0423791..72a6667 100644 --- a/entity.h +++ b/entity.h @@ -30,6 +30,7 @@ typedef struct ent_objective ent_objective; typedef struct ent_challenge ent_challenge; typedef struct ent_relay ent_relay; typedef struct ent_cubemap ent_cubemap; +typedef struct ent_miniworld ent_miniworld; enum entity_alias{ k_ent_none = 0, @@ -53,7 +54,8 @@ enum entity_alias{ k_ent_objective = 18, k_ent_challenge = 19, k_ent_relay = 20, - k_ent_cubemap = 21 + k_ent_cubemap = 21, + k_ent_miniworld = 22 }; static u32 mdl_entity_id_type( u32 entity_id ){ @@ -109,7 +111,7 @@ enum gate_type{ /* v102+ */ enum ent_gate_flag{ k_ent_gate_linked = 0x1, /* this is a working portal */ - k_ent_gate_nonlocal = 0x2, /* use the key string to link this portal. + k_ent_gate_nonlocal_DELETED = 0x2, /* use the key string to link this portal. NOTE: if set, it adds the flip flag. */ k_ent_gate_flip = 0x4, /* flip direction 180* for exiting portal */ k_ent_gate_custom_mesh = 0x8, /* use a custom submesh instead of default */ @@ -496,6 +498,13 @@ struct ent_call{ void *data; }; +struct ent_miniworld { + mdl_transform transform; + u32 pstr_world; + + i32 purpose; +}; + #include "world.h" static void entity_call( world_instance *world, ent_call *call ); diff --git a/maps_src/dev_hub/main.mdl b/maps_src/dev_hub/main.mdl new file mode 100644 index 0000000..4925d9f Binary files /dev/null and b/maps_src/dev_hub/main.mdl differ diff --git a/menu.h b/menu.h index 5218485..c2a963e 100644 --- a/menu.h +++ b/menu.h @@ -245,19 +245,6 @@ static void menu_trigger_item( ent_menuitem *item ){ 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(); diff --git a/models_src/rs_gate.mdl b/models_src/rs_gate.mdl index 9d22e2c..1cae7c1 100644 Binary files a/models_src/rs_gate.mdl and b/models_src/rs_gate.mdl differ diff --git a/models_src/rs_portal.mdl b/models_src/rs_portal.mdl new file mode 100644 index 0000000..73fd2f2 Binary files /dev/null and b/models_src/rs_portal.mdl differ diff --git a/player.c b/player.c index 5bd4332..b1788c6 100644 --- a/player.c +++ b/player.c @@ -142,9 +142,6 @@ static void player__pass_gate( u32 id ){ m4x3_mulv( gate->transport, localplayer.cam.pos, localplayer.cam.pos ); - if( gate->flags & k_ent_gate_nonlocal ) - world_set_active_instance( gate->target ); - audio_lock(); audio_oneshot( &audio_gate_pass, 1.0f, 0.0f ); audio_unlock(); @@ -219,18 +216,22 @@ static void player__im_gui(void){ skaterift_replay_debug_info(); } - static void player__setpos( v3f pos ){ v3_copy( pos, localplayer.rb.co ); v3_zero( localplayer.rb.v ); rb_update_transform( &localplayer.rb ); } -static void player__spawn( ent_spawn *rp ){ +static void player__reset(void){ replay_clear( &skaterift.replay ); - player__setpos( rp->transform.co ); + + v3_zero( localplayer.rb.v ); v3_zero( localplayer.rb.w ); - q_identity( localplayer.rb.q ); + + f32 l = v4_length( localplayer.rb.q ); + if( (l < 0.9f) || (l > 1.1f) ) + q_identity( localplayer.rb.q ); + rb_update_transform( &localplayer.rb ); q_identity( localplayer.qbasis ); @@ -238,17 +239,19 @@ static void player__spawn( ent_spawn *rp ){ m3x3_identity( localplayer.invbasis ); localplayer.subsystem = k_player_subsystem_walk; + player__walk_reset(); + localplayer.immobile = 0; localplayer.gate_waiting = NULL; - world_static.last_use = 0.0; - world_static.focused_entity = 0; + localplayer.viewable_world = world_current_instance(); + world_static.challenge_target = NULL; world_static.challenge_timer = 0.0f; + world_static.focused_entity = 0; + world_static.active_trigger_volume_count = 0; + world_static.last_use = 0.0; world_entity_unfocus(); - if( player_subsystems[ localplayer.subsystem ]->reset ) - player_subsystems[ localplayer.subsystem ]->reset( rp ); - localplayer.boundary_hash ^= NETMSG_BOUNDARY_BIT; for( u32 i=0; itransform.co ); + player__reset(); +} + static void player__kill(void){ } diff --git a/player.h b/player.h index 9757030..2b7519a 100644 --- a/player.h +++ b/player.h @@ -36,7 +36,6 @@ struct player_cam_controller { struct player_subsystem_interface{ void(*system_register)(void); void(*bind)(void); - void(*reset)( ent_spawn *rp ); void(*pre_update)(void); void(*update)(void); void(*post_update)(void); @@ -191,6 +190,7 @@ static void player__pass_gate( u32 id ); static void player__im_gui(void); static void player__setpos( v3f pos ); static void player__spawn( ent_spawn *rp ); +static void player__reset(void); static void player__kill(void); static void player__begin_holdout( v3f offset ); diff --git a/player_drive.c b/player_drive.c index 0d97e3b..38b7e58 100644 --- a/player_drive.c +++ b/player_drive.c @@ -65,7 +65,4 @@ static void player__drive_bind(void){ player_drive.anim_drive = skeleton_get_anim( sk, "idle_cycle+y" ); } -static void player__drive_reset( ent_spawn *rp ){ -} - #endif /* PLAYER_DRIVE_C */ diff --git a/player_drive.h b/player_drive.h index 46eedba..0dd135c 100644 --- a/player_drive.h +++ b/player_drive.h @@ -19,7 +19,6 @@ static void player__drive_pose( void *animator, player_pose *pose ); static void player__drive_post_animate(void); static void player__drive_im_gui(void); static void player__drive_bind(void); -static void player__drive_reset( ent_spawn *rp ); struct player_subsystem_interface static player_subsystem_drive = { .pre_update = player__drive_pre_update, @@ -30,7 +29,6 @@ struct player_subsystem_interface static player_subsystem_drive = { .post_animate = player__drive_post_animate, .im_gui = player__drive_im_gui, .bind = player__drive_bind, - .reset = player__drive_reset, .animator_data = NULL, .animator_size = 0, diff --git a/player_skate.c b/player_skate.c index 745a6ff..7466828 100644 --- a/player_skate.c +++ b/player_skate.c @@ -495,10 +495,6 @@ static void player__approximate_best_trajectory(void){ m3x3_mulv( gate->transport, launch_v, launch_v); m4x3_mulv( gate->transport, launch_co, launch_co ); m3x3_mul( gate->transport, basis, basis ); - - if( gate->flags & k_ent_gate_nonlocal ){ - trace_world = &world_static.instances[ gate->target ]; - } } } @@ -3182,21 +3178,6 @@ static void player__skate_clear_mechanics(void){ v3_zero( player_skate.weight_distribution ); } -static void player__skate_reset( ent_spawn *rp ){ - struct player_skate_state *state = &player_skate.state; - v3_zero( localplayer.rb.v ); - v4_copy( rp->transform.q, localplayer.rb.q ); - - state->activity = k_skate_activity_air; - state->activity_prev = k_skate_activity_air; - - player__skate_clear_mechanics(); - player__skate_reset_animator(); - - v3_zero( state->head_position ); - state->head_position[1] = 1.8f; -} - #include "network_compression.h" static void player__skate_animator_exchange( bitpack_ctx *ctx, void *data ){ diff --git a/player_skate.h b/player_skate.h index 0f5c70c..ba2cfce 100644 --- a/player_skate.h +++ b/player_skate.h @@ -294,7 +294,6 @@ static void player__skate_im_gui (void); static void player__skate_animate (void); static void player__skate_pose (void *animator, player_pose *pose); static void player__skate_post_animate (void); -static void player__skate_reset (ent_spawn *rp); static void player__skate_animator_exchange( bitpack_ctx *ctx, void *data ); static void player__skate_sfx_oneshot ( u8 id, v3f pos, f32 volume ); @@ -305,7 +304,6 @@ static void player__approximate_best_trajectory(void); struct player_subsystem_interface static player_subsystem_skate = { .system_register = player__skate_register, .bind = player__skate_bind, - .reset = player__skate_reset, .pre_update = player__skate_pre_update, .update = player__skate_update, .post_update = player__skate_post_update, diff --git a/player_walk.c b/player_walk.c index 100e21f..ebd9dad 100644 --- a/player_walk.c +++ b/player_walk.c @@ -302,7 +302,7 @@ static void player__walk_pre_update(void){ } } else if( button_down( k_srbind_use ) && !localplayer.immobile ){ - if( v3_dist2( localplayer.rb.co, gzoomer.obj.rb.co ) <= 4.0f*4.0f ){ + if( 0 && (v3_dist2(localplayer.rb.co,gzoomer.obj.rb.co) <= 4.0f*4.0f) ){ localplayer.subsystem = k_player_subsystem_drive; } else{ @@ -1063,7 +1063,7 @@ static void player__walk_transition(void){ rb_update_transform( &localplayer.rb ); } -static void player__walk_reset( ent_spawn *rp ){ +static void player__walk_reset(void){ struct player_walk *w = &player_walk; w->state.activity = k_walk_activity_air; w->state.outro_type = k_walk_outro_none; diff --git a/player_walk.h b/player_walk.h index a8dd9fa..7d3c0eb 100644 --- a/player_walk.h +++ b/player_walk.h @@ -105,14 +105,13 @@ static void player__walk_post_animate(void); static void player__walk_im_gui (void); static void player__walk_bind (void); static void player__walk_transition (void); -static void player__walk_reset (ent_spawn *rp ); +static void player__walk_reset (void); static void player__walk_restore (void); static void player__walk_animator_exchange( bitpack_ctx *ctx, void *data ); struct player_subsystem_interface static player_subsystem_walk = { .system_register = player__walk_register, .bind = player__walk_bind, - .reset = player__walk_reset, .pre_update = player__walk_pre_update, .update = player__walk_update, .post_update = player__walk_post_update, diff --git a/pointcloud.h b/pointcloud.h index 427548c..89621a4 100644 --- a/pointcloud.h +++ b/pointcloud.h @@ -1,4 +1,5 @@ -#ifndef POINTCLOUD_H +#if 0 +//#ifndef POINTCLOUD_H #define POINTCLOUD_H #include "common.h" @@ -111,8 +112,7 @@ static int pointcloud_idle(void){ else return 0; } -static -void pointcloud_render( world_instance *world, camera *cam, m4x3f model ){ +static void pointcloud_render( camera *cam, m4x3f model ){ if( pointcloud.anim < k_pointcloud_anim_idle_any ){ f32 const k_transition = 0.6f; f32 t = (vg.time - pointcloud.anim_start) / k_transition; @@ -160,4 +160,13 @@ static void pointcloud_packvert( pointcloud_vert *vert, v3f pos, v4f colour ){ vert->colour[i] = colour[i] * 255.0f; } +static void pointcloud_async_end(void *_, u32 __){ + pointcloud_animate( k_pointcloud_anim_opening ); +} + +static void pointcloud_clear_async(void *_, u32 __){ + pointcloud.count = 0; + pointcloud_animate( k_pointcloud_anim_opening ); +} + #endif /* POINTCLOUD_H */ diff --git a/respawn.c b/respawn.c index b7594db..df1c66b 100644 --- a/respawn.c +++ b/respawn.c @@ -208,13 +208,6 @@ static void respawn_chooser_pre_update(void){ } } - for( u32 i=0; ient_gate); i++ ){ - ent_gate *gate = mdl_arritm( &world->ent_gate, i ); - if( gate->flags & k_ent_gate_nonlocal ){ - respawn_map_draw_icon( cam, k_gui_icon_rift, gate->co[0] ); - } - } - for( u32 i=0; ient_route); i++ ){ ent_route *route = mdl_arritm( &world->ent_route, i ); diff --git a/shaders/cloud.vs b/shaders/cloud.vs index 66a2bdf..580dc20 100644 --- a/shaders/cloud.vs +++ b/shaders/cloud.vs @@ -46,7 +46,7 @@ void main() vs_motion_out( vproj0, vproj1 ); gl_Position = vproj0; - gl_PointSize = (9.0*scaler) / (gl_Position.z + 0.01); + gl_PointSize = (9.0*scaler) / (max( gl_Position.z, 2.0 )); aWorldCo = world_pos0; aColour = a_colour*scaler*(1.0-uAnim.y*uAnim.y); aCo = co; diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index cb68f35..b734743 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -54,19 +54,15 @@ float world_water_depth( vec3 pos ) return world_depth_sample( pos ) - ref_depth; } -float shadow_sample( vec3 vdir ) -{ - vec3 sample_pos = aWorldCo + vdir; - float height_sample = world_depth_sample( sample_pos ); +float shadow_sample( vec3 co ){ + float height_sample = world_depth_sample( co ); - float fdelta = height_sample - sample_pos.y; + float fdelta = height_sample - co.y; return clamp( fdelta, 0.2, 0.4 )-0.2; } -float newlight_compute_sun_shadow( vec3 dir ) -{ - if( g_shadow_samples == 0 ) - { +float newlight_compute_sun_shadow( vec3 co, vec3 dir ){ + if( g_shadow_samples == 0 ){ return 1.0; } @@ -74,15 +70,15 @@ float newlight_compute_sun_shadow( vec3 dir ) float flength = g_shadow_length; float famt = 0.0; - famt += shadow_sample((dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1); - famt += shadow_sample((dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2); - famt += shadow_sample((dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3); - famt += shadow_sample((dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4); + famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1); + famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2); + famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3); + famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4); - //famt+=shadow_sample((dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5); - //famt+=shadow_sample((dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6); - //famt+=shadow_sample((dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7); - //famt+=shadow_sample((dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8); + //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5); + //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6); + //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7); + //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8); return 1.0 - famt; } @@ -170,8 +166,8 @@ vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co, float fdist = length(halfview); halfview /= fdist; - float world_shadow = newlight_compute_sun_shadow( g_sun_dir.xyz - * (1.0/(max(g_sun_dir.y,0.0)+0.2)) ); + float world_shadow = newlight_compute_sun_shadow( + co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) ); vec3 total_light = clearskies_lighting( normal, min( light_mask, world_shadow ), halfview ); diff --git a/shaders/model_board_view.h b/shaders/model_board_view.h index 3a1ba9c..3f08cf0 100644 --- a/shaders/model_board_view.h +++ b/shaders/model_board_view.h @@ -210,19 +210,15 @@ static struct vg_shader _shader_model_board_view = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -230,15 +226,15 @@ static struct vg_shader _shader_model_board_view = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -326,8 +322,8 @@ static struct vg_shader _shader_model_board_view = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/model_character_view.h b/shaders/model_character_view.h index 060e5b2..bbfee78 100644 --- a/shaders/model_character_view.h +++ b/shaders/model_character_view.h @@ -218,19 +218,15 @@ static struct vg_shader _shader_model_character_view = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -238,15 +234,15 @@ static struct vg_shader _shader_model_character_view = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -334,8 +330,8 @@ static struct vg_shader _shader_model_character_view = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/model_entity.h b/shaders/model_entity.h index 712efc9..581cbff 100644 --- a/shaders/model_entity.h +++ b/shaders/model_entity.h @@ -210,19 +210,15 @@ static struct vg_shader _shader_model_entity = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -230,15 +226,15 @@ static struct vg_shader _shader_model_entity = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -326,8 +322,8 @@ static struct vg_shader _shader_model_entity = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/model_sky.h b/shaders/model_sky.h index abe4de7..9d2131e 100644 --- a/shaders/model_sky.h +++ b/shaders/model_sky.h @@ -212,19 +212,15 @@ static struct vg_shader _shader_model_sky = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -232,15 +228,15 @@ static struct vg_shader _shader_model_sky = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -328,8 +324,8 @@ static struct vg_shader _shader_model_sky = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/point_map.h b/shaders/point_map.h index 5c674cd..006c98f 100644 --- a/shaders/point_map.h +++ b/shaders/point_map.h @@ -75,7 +75,7 @@ static struct vg_shader _shader_point_map = { " vs_motion_out( vproj0, vproj1 );\n" "\n" " gl_Position = vproj0;\n" -" gl_PointSize = (9.0*scaler) / (gl_Position.z + 0.01);\n" +" gl_PointSize = (9.0*scaler) / (max( gl_Position.z, 2.0 ));\n" " aWorldCo = world_pos0;\n" " aColour = a_colour*scaler*(1.0-uAnim.y*uAnim.y);\n" " aCo = co;\n" diff --git a/shaders/scene_cubemapped.h b/shaders/scene_cubemapped.h index 78a8e7d..1d59884 100644 --- a/shaders/scene_cubemapped.h +++ b/shaders/scene_cubemapped.h @@ -212,19 +212,15 @@ static struct vg_shader _shader_scene_cubemapped = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -232,15 +228,15 @@ static struct vg_shader _shader_scene_cubemapped = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -328,8 +324,8 @@ static struct vg_shader _shader_scene_cubemapped = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_depth.h b/shaders/scene_depth.h index 42613c0..efe52b8 100644 --- a/shaders/scene_depth.h +++ b/shaders/scene_depth.h @@ -211,19 +211,15 @@ static struct vg_shader _shader_scene_depth = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -231,15 +227,15 @@ static struct vg_shader _shader_scene_depth = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -327,8 +323,8 @@ static struct vg_shader _shader_scene_depth = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_font.h b/shaders/scene_font.h index eec4b6c..f0a9829 100644 --- a/shaders/scene_font.h +++ b/shaders/scene_font.h @@ -214,19 +214,15 @@ static struct vg_shader _shader_scene_font = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -234,15 +230,15 @@ static struct vg_shader _shader_scene_font = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -330,8 +326,8 @@ static struct vg_shader _shader_scene_font = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_fxglow.h b/shaders/scene_fxglow.h index a86f520..b54f58f 100644 --- a/shaders/scene_fxglow.h +++ b/shaders/scene_fxglow.h @@ -209,19 +209,15 @@ static struct vg_shader _shader_scene_fxglow = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -229,15 +225,15 @@ static struct vg_shader _shader_scene_fxglow = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -325,8 +321,8 @@ static struct vg_shader _shader_scene_fxglow = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_override.fs b/shaders/scene_override.fs index 45ac33e..6d10a40 100644 --- a/shaders/scene_override.fs +++ b/shaders/scene_override.fs @@ -26,14 +26,17 @@ void main(){ 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; + float dcam = (-8.0+distance( aCo, uCamera ))/4.0; + if( min(aCo.y*0.5 + dither, dcam + dither) < 0.51 ) discard; compute_motion_vectors(); - vec3 vfrag = vec3(0.5,0.5,0.5); + vec3 vfrag = vec3(0.6); vec3 qnorm = aNorm.xyz; + qnorm = normalize(floor(aNorm.xyz*4.0)*0.25); + qnorm += vec3(0.001,0.0,0.0); + if( uAlphatest ){ vec4 vSample = texture( uTexMain, aUv ); if( vSample.a < 0.5 ) @@ -45,7 +48,7 @@ void main(){ } } - vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo ); + vfrag = scene_compute_lighting( vfrag, qnorm, aCo ); // dots float d0 = distance( aWorldCo, uPlayerPos.xyz )*2.0; @@ -65,4 +68,5 @@ void main(){ emit += vec3(fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2)); oColour = vec4( vfrag+emit, 1.0 ); + oColour = vec4( vfrag, 1.0 ); } diff --git a/shaders/scene_override.h b/shaders/scene_override.h index 3f59770..8bea02e 100644 --- a/shaders/scene_override.h +++ b/shaders/scene_override.h @@ -7,7 +7,7 @@ static struct vg_shader _shader_scene_override = { .link = shader_scene_override_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_override = { "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_override = { " gl_Position = vproj0;\n" "\n" " aUv = a_uv;\n" -" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n" +" aNorm = vec4( a_norm.xyz, a_norm.w );\n" " aCo = a_co;\n" " aWorldCo = world_pos0;\n" "}\n" @@ -214,19 +215,15 @@ static struct vg_shader _shader_scene_override = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -234,15 +231,15 @@ static struct vg_shader _shader_scene_override = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -330,8 +327,8 @@ static struct vg_shader _shader_scene_override = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" @@ -446,14 +443,17 @@ static struct vg_shader _shader_scene_override = { " 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" +" float dcam = (-8.0+distance( aCo, uCamera ))/4.0;\n" +" if( min(aCo.y*0.5 + dither, dcam + dither) < 0.51 ) discard;\n" "\n" " compute_motion_vectors();\n" "\n" -" vec3 vfrag = vec3(0.5,0.5,0.5);\n" +" vec3 vfrag = vec3(0.6);\n" " vec3 qnorm = aNorm.xyz;\n" "\n" +" qnorm = normalize(floor(aNorm.xyz*4.0)*0.25);\n" +" qnorm += vec3(0.001,0.0,0.0);\n" +"\n" " if( uAlphatest ){\n" " vec4 vSample = texture( uTexMain, aUv );\n" " if( vSample.a < 0.5 )\n" @@ -465,7 +465,7 @@ static struct vg_shader _shader_scene_override = { " }\n" " }\n" "\n" -" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n" +" vfrag = scene_compute_lighting( vfrag, qnorm, aCo );\n" " \n" " // dots\n" " float d0 = distance( aWorldCo, uPlayerPos.xyz )*2.0;\n" @@ -485,6 +485,7 @@ static struct vg_shader _shader_scene_override = { " emit += vec3(fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2));\n" "\n" " oColour = vec4( vfrag+emit, 1.0 );\n" +" oColour = vec4( vfrag, 1.0 );\n" "}\n" ""}, }; @@ -492,6 +493,7 @@ static struct vg_shader _shader_scene_override = { static GLuint _uniform_scene_override_uMdl; static GLuint _uniform_scene_override_uPv; static GLuint _uniform_scene_override_uPvmPrev; +static GLuint _uniform_scene_override_uNormalMtx; static GLuint _uniform_scene_override_uTexGarbage; static GLuint _uniform_scene_override_uTexMain; static GLuint _uniform_scene_override_uCamera; @@ -511,6 +513,9 @@ static void shader_scene_override_uPv(m4x4f m){ static void shader_scene_override_uPvmPrev(m4x4f m){ glUniformMatrix4fv(_uniform_scene_override_uPvmPrev,1,GL_FALSE,(float*)m); } +static void shader_scene_override_uNormalMtx(m3x3f m){ + glUniformMatrix3fv(_uniform_scene_override_uNormalMtx,1,GL_FALSE,(float*)m); +} static void shader_scene_override_uTexGarbage(int i){ glUniform1i(_uniform_scene_override_uTexGarbage,i); } @@ -543,6 +548,7 @@ 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_uNormalMtx = glGetUniformLocation( _shader_scene_override.id, "uNormalMtx" ); _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" ); diff --git a/shaders/scene_override.vs b/shaders/scene_override.vs new file mode 100644 index 0000000..88fa7dd --- /dev/null +++ b/shaders/scene_override.vs @@ -0,0 +1,31 @@ +layout (location=0) in vec3 a_co; +layout (location=1) in vec4 a_norm; +layout (location=2) in vec2 a_uv; + +#include "motion_vectors_vs.glsl" + +uniform mat4x3 uMdl; +uniform mat4 uPv; +uniform mat4 uPvmPrev; +uniform mat3 uNormalMtx; + +out vec2 aUv; +out vec4 aNorm; +out vec3 aCo; +out vec3 aWorldCo; + +void main() +{ + vec3 world_pos0 = uMdl * vec4( a_co, 1.0 ); + vec4 vproj0 = uPv * vec4( world_pos0, 1.0 ); + vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 ); + + vs_motion_out( vproj0, vproj1 ); + + gl_Position = vproj0; + + aUv = a_uv; + aNorm = vec4( a_norm.xyz, a_norm.w ); + aCo = a_co; + aWorldCo = world_pos0; +} diff --git a/shaders/scene_position.h b/shaders/scene_position.h index 3fe8c7e..985d34c 100644 --- a/shaders/scene_position.h +++ b/shaders/scene_position.h @@ -211,19 +211,15 @@ static struct vg_shader _shader_scene_position = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -231,15 +227,15 @@ static struct vg_shader _shader_scene_position = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -327,8 +323,8 @@ static struct vg_shader _shader_scene_position = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_route.h b/shaders/scene_route.h index b37cf62..bfa31df 100644 --- a/shaders/scene_route.h +++ b/shaders/scene_route.h @@ -210,19 +210,15 @@ static struct vg_shader _shader_scene_route = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -230,15 +226,15 @@ static struct vg_shader _shader_scene_route = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -326,8 +322,8 @@ static struct vg_shader _shader_scene_route = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_scoretext.h b/shaders/scene_scoretext.h index 75e4ca8..1d82be3 100644 --- a/shaders/scene_scoretext.h +++ b/shaders/scene_scoretext.h @@ -230,19 +230,15 @@ static struct vg_shader _shader_scene_scoretext = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -250,15 +246,15 @@ static struct vg_shader _shader_scene_scoretext = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -346,8 +342,8 @@ static struct vg_shader _shader_scene_scoretext = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_standard.h b/shaders/scene_standard.h index d28f7d1..ae03331 100644 --- a/shaders/scene_standard.h +++ b/shaders/scene_standard.h @@ -210,19 +210,15 @@ static struct vg_shader _shader_scene_standard = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -230,15 +226,15 @@ static struct vg_shader _shader_scene_standard = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -326,8 +322,8 @@ static struct vg_shader _shader_scene_standard = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_standard_alphatest.h b/shaders/scene_standard_alphatest.h index 19a42cf..594fb86 100644 --- a/shaders/scene_standard_alphatest.h +++ b/shaders/scene_standard_alphatest.h @@ -210,19 +210,15 @@ static struct vg_shader _shader_scene_standard_alphatest = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -230,15 +226,15 @@ static struct vg_shader _shader_scene_standard_alphatest = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -326,8 +322,8 @@ static struct vg_shader _shader_scene_standard_alphatest = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_terrain.h b/shaders/scene_terrain.h index e37e624..6d40ebd 100644 --- a/shaders/scene_terrain.h +++ b/shaders/scene_terrain.h @@ -211,19 +211,15 @@ static struct vg_shader _shader_scene_terrain = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -231,15 +227,15 @@ static struct vg_shader _shader_scene_terrain = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -327,8 +323,8 @@ static struct vg_shader _shader_scene_terrain = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_vertex_blend.h b/shaders/scene_vertex_blend.h index 2302cc7..aba9d8b 100644 --- a/shaders/scene_vertex_blend.h +++ b/shaders/scene_vertex_blend.h @@ -209,19 +209,15 @@ static struct vg_shader _shader_scene_vertex_blend = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -229,15 +225,15 @@ static struct vg_shader _shader_scene_vertex_blend = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -325,8 +321,8 @@ static struct vg_shader _shader_scene_vertex_blend = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_water.h b/shaders/scene_water.h index 588477e..669f96d 100644 --- a/shaders/scene_water.h +++ b/shaders/scene_water.h @@ -219,19 +219,15 @@ static struct vg_shader _shader_scene_water = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -239,15 +235,15 @@ static struct vg_shader _shader_scene_water = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -335,8 +331,8 @@ static struct vg_shader _shader_scene_water = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/shaders/scene_water_fast.h b/shaders/scene_water_fast.h index 318a37a..1be0926 100644 --- a/shaders/scene_water_fast.h +++ b/shaders/scene_water_fast.h @@ -216,19 +216,15 @@ static struct vg_shader _shader_scene_water_fast = { " 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" +"float shadow_sample( vec3 co ){\n" +" float height_sample = world_depth_sample( co );\n" "\n" -" float fdelta = height_sample - sample_pos.y;\n" +" float fdelta = height_sample - co.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" +"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n" +" if( g_shadow_samples == 0 ){\n" " return 1.0;\n" " }\n" "\n" @@ -236,15 +232,15 @@ static struct vg_shader _shader_scene_water_fast = { " 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" +" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n" +" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n" +" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n" +" famt += shadow_sample(co+(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" +" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n" +" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n" "\n" " return 1.0 - famt;\n" "}\n" @@ -332,8 +328,8 @@ static struct vg_shader _shader_scene_water_fast = { " 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" +" float world_shadow = newlight_compute_sun_shadow( \n" +" co, g_sun_dir.xyz * (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" diff --git a/skaterift.c b/skaterift.c index 49fdc88..8ed749c 100644 --- a/skaterift.c +++ b/skaterift.c @@ -37,7 +37,6 @@ #include "network.h" #include "menu.h" #include "vehicle.h" -#include "pointcloud.h" #include "save.h" #include "player_remote.h" @@ -109,8 +108,7 @@ static void load_playermodels(void){ } static void async_skaterift_player_start( void *payload, u32 size ){ - localplayer.viewable_world = world_current_instance(); - localplayer_cmd_respawn( 1, (const char *[]){ "start" } ); + world_switch_instance(0); } static void async_call_ready( void *payload, u32 size ){ @@ -153,6 +151,8 @@ static void skaterift_restore_state(void){ addon_cache_create_viewer( k_addon_type_player, player_reg_id ); kvsav.cur = orig; + +#if 0 if( vg_msg_seekframe( &kvsav, "world" ) ){ addon_alias q; @@ -180,6 +180,7 @@ static void skaterift_restore_state(void){ if( v3_length2(pos) > 1.0f ) player__setpos( pos ); } +#endif } static void vg_load(void){ @@ -188,11 +189,12 @@ static void vg_load(void){ return; } - vg_console_reg_cmd( "changeworld", skaterift_change_world_command, NULL ); + vg_console_reg_cmd( "load_world", skaterift_load_world_command, NULL ); + vg_console_reg_cmd( "switch_active_instance", + skaterift_switch_instance_cmd, NULL ); vg_loader_step( render_init, NULL ); vg_loader_step( menu_init, NULL ); - vg_loader_step( pointcloud_init, NULL ); vg_loader_step( world_init, NULL ); vg_loader_step( vehicle_init, NULL ); vg_loader_step( font3d_init, NULL ); @@ -231,6 +233,11 @@ static void vg_load(void){ * ------------------------------------- */ + /* hub world */ + addon_reg *hub = + addon_mount_local_addon( "maps/dev_hub", k_addon_type_world, ".mdl" ); + hub->metadata_len = 0; + /* understate diy. */ addon_reg *spawn = addon_mount_local_addon( "maps/mp_spawn", k_addon_type_world, @@ -261,20 +268,16 @@ static void vg_load(void){ /* load home/permanent world manually */ world_static.load_state = k_world_loader_load; + struct world_load_args args = { .purpose = k_world_purpose_hub, - .reg = spawn + .reg = hub }; skaterift_world_load_thread( &args ); vg_async_call( async_skaterift_player_start, NULL, 0 ); vg_async_stall(); - - global_skateshop.selected_world_id=1; - global_skateshop.pointcloud_world_id=1; - skateshop_world_preview_loader_thread( mtzero ); /* HACK */ - vg_console_load_autos(); menu_link(); @@ -329,6 +332,7 @@ static void vg_pre_update(void){ vg_slewf( &skaterift.time_rate, target, vg.time_frame_delta * (1.0f/0.3f) ); vg.time_rate = vg_smoothstepf( skaterift.time_rate ); + /* TODO: how can we compress this? */ player__pre_update(); world_entity_focus_preupdate(); skaterift_replay_pre_update(); @@ -489,12 +493,15 @@ static void render_scene(void){ if( skaterift.activity == k_skaterift_respawning ){ glDrawBuffers( 1, (GLenum[]){ GL_COLOR_ATTACHMENT0 } ); glClearColor( 0.624f, 0.659f, 0.769f, 0.0f ); + glClearColor( 0.824f, 0.0f, 0.1f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT ); glDrawBuffers( 2, (GLenum[]){ GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1 } ); +#if 0 view_world = &world_static.instances[respawn_chooser.world_id]; render_world_override( view_world ); render_world_routes( view_world, &skaterift.cam, 1 ); +#endif } else{ render_world( view_world, &skaterift.cam, 0 ); @@ -502,7 +509,9 @@ static void render_scene(void){ render_fb_bind( gpipeline.fb_main, 1 ); render_water_surface( view_world, &skaterift.cam ); render_remote_players( view_world, &skaterift.cam ); + ent_miniworld_render( view_world ); } + } static void render_scene_gate_subview(void){ @@ -569,14 +578,6 @@ static void render_main_game(void){ world_instance *view_world = localplayer.viewable_world; if( (view_world != NULL) && (skaterift.activity != k_skaterift_respawning) ){ render_world_cubemaps( view_world ); - - ent_gate *gate = view_world->rendering_gate; - if( gate ){ - if( gate->flags & k_ent_gate_nonlocal ){ - world_instance *dest = &world_static.instances[ gate->target ]; - render_world_cubemaps( dest ); - } - } } /* variable res target */ diff --git a/vehicle.h b/vehicle.h index 74408e4..bdd12f0 100644 --- a/vehicle.h +++ b/vehicle.h @@ -37,7 +37,8 @@ struct drivable_vehicle } static gzoomer = { - .obj = { .type = k_rb_shape_sphere, .inf.sphere.radius = 1.0f } + .obj = { .type = k_rb_shape_sphere, .inf.sphere.radius = 1.0f, + .rb.co = {-2000,-2000,-2000}} }; static int spawn_car( int argc, const char *argv[] ); diff --git a/world.c b/world.c index 40f3d75..def59a3 100644 --- a/world.c +++ b/world.c @@ -26,13 +26,44 @@ static void world_init(void) VG_MEMORY_SYSTEM ); } -static void world_set_active_instance( u32 index ){ - world_static.challenge_target = NULL; - world_static.challenge_timer = 0.0f; - world_static.focused_entity = 0; - world_static.focus_strength = 0.0f; - world_static.active_trigger_volume_count = 0; +static void world_switch_instance( u32 index ){ + assert( localplayer.subsystem == k_player_subsystem_walk ); + + if( index >= vg_list_size(world_static.instances) ){ + vg_error( "Instance ID out of range (%u)\n", index ); + return; + } + + world_instance *new = &world_static.instances[ index ]; + + if( new->status != k_world_status_loaded ){ + vg_error( "Instance is not loaded (%u)\n", index ); + return; + } + + if( index != world_static.active_instance ){ + world_instance *current = + &world_static.instances[ world_static.active_instance ]; + v3_copy( localplayer.rb.co, current->player_co ); + v3_copy( localplayer.angles, current->player_angles ); + current->player_angles[3] = player_get_heading_yaw(); + } + + v3_copy( new->player_co, localplayer.rb.co ); + v3_copy( new->player_angles, localplayer.angles ); + q_axis_angle( localplayer.rb.q, (v3f){0,1,0}, new->player_angles[3] ); + world_static.active_instance = index; + + player__reset(); +} + +static int skaterift_switch_instance_cmd( int argc, const char *argv[] ){ + if( argc ) + world_switch_instance( atoi(argv[0]) ); + else + vg_info( "switch_active_instance \n" ); + return 0; } static void skaterift_world_get_save_path( enum world_purpose which, diff --git a/world.h b/world.h index 98b9df9..c81d9ed 100644 --- a/world.h +++ b/world.h @@ -18,6 +18,7 @@ enum world_geo_type{ }; enum world_purpose{ + k_world_purpose_invalid = -1, k_world_purpose_hub = 0, k_world_purpose_client = 1, k_world_max @@ -62,6 +63,8 @@ struct world_instance { * ------------------------------------------------------- */ + v4f player_co, player_angles; + void *heap; enum world_status{ k_world_status_unloaded = 0, @@ -176,7 +179,8 @@ struct world_instance { ent_objective, ent_challenge, ent_relay, - ent_cubemap; + ent_cubemap, + ent_miniworld; ent_gate *rendering_gate; @@ -243,6 +247,6 @@ static world_static; static void world_init(void); static world_instance *world_current_instance(void); -static void world_set_active_instance( u32 index ); +static void world_switch_instance( u32 index ); #endif /* WORLD_H */ diff --git a/world_entity.c b/world_entity.c index e0c67d8..73caa0b 100644 --- a/world_entity.c +++ b/world_entity.c @@ -120,11 +120,10 @@ static void world_gen_entities_init( world_instance *world ){ for( u32 j=0; jent_gate); j ++ ){ ent_gate *gate = mdl_arritm( &world->ent_gate, j ); - if( !(gate->flags & k_ent_gate_nonlocal) ) { + if( !(gate->flags & k_ent_gate_nonlocal_DELETED) ) { gate_transform_update( gate ); } } - vg_async_call( world_link_nonlocal_async, world, 0 ); /* water */ for( u32 j=0; jent_water); j++ ){ @@ -596,6 +595,36 @@ static void world_entity_start( world_instance *world, vg_msg *sav ){ } } +/* + * used for relinking multi-world data. ran anytime the world setup changes + */ +static void world_entity_relink( world_instance *world ){ + vg_info( "entity_relink(%d)\n", world - world_static.instances ); + for( u32 i=0; ient_miniworld); i++ ){ + ent_miniworld *miniworld = mdl_arritm( &world->ent_miniworld, i ); + miniworld->purpose = k_world_purpose_invalid; + + const char *uid = mdl_pstr( &world->meta, miniworld->pstr_world ); + addon_alias q; + addon_uid_to_alias( uid, &q ); + + u32 addon_id = addon_match( &q ); + if( addon_id != 0xffffffff ){ + addon_reg *reg = get_addon_from_index( k_addon_type_world, addon_id ); + + for( int j=0; jstatus == k_world_status_loaded) && + (world_static.instance_addons[j] == reg) ){ + miniworld->purpose = j; + break; + } + } + } + } +} + static void world_entity_serialize( world_instance *world, vg_msg *sav ){ for( u32 i=0; ient_challenge); i++ ){ ent_challenge *challenge = mdl_arritm(&world->ent_challenge,i); diff --git a/world_entity.h b/world_entity.h index 1e5e70c..fc66d74 100644 --- a/world_entity.h +++ b/world_entity.h @@ -13,6 +13,7 @@ static ent_spawn *world_find_spawn_by_name( world_instance *world, static ent_spawn *world_find_closest_spawn( world_instance *world, v3f position ); static void world_entity_start( world_instance *world, vg_msg *sav ); +static void world_entity_relink( world_instance *world ); static void world_entity_serialize( world_instance *world, vg_msg *sav ); static void ent_volume_call( world_instance *world, ent_call *call ); diff --git a/world_gate.c b/world_gate.c index 4c76b07..96317c1 100644 --- a/world_gate.c +++ b/world_gate.c @@ -65,6 +65,10 @@ static void world_gates_init(void) world_gates.sm_marker[i] = *sm; } + mdl_mesh *icosphere = mdl_find_mesh( &mgate, "rs_icosphere" ); + world_gates.sm_icosphere = + *((mdl_submesh *)mdl_arritm( &mgate.submeshs, icosphere->submesh_start )); + mdl_async_load_glmesh( &mgate, &world_gates.mesh ); mdl_close( &mgate ); } @@ -272,9 +276,8 @@ static u32 world_intersect_gates( world_instance *world, v3f pos, v3f last ){ if( !(gate->flags & k_ent_gate_linked) ) continue; if( gate->flags & k_ent_gate_locked ) continue; - if( gate->flags & k_ent_gate_nonlocal ) - if( world_static.load_state != k_world_loader_none ) - continue; + if( gate->flags & k_ent_gate_nonlocal_DELETED ) + continue; if( gate_intersect( gate, pos, last ) ) return mdl_entity_id( k_ent_gate, i ); @@ -283,88 +286,6 @@ static u32 world_intersect_gates( world_instance *world, v3f pos, v3f last ){ return 0; } -/* - * detatches any nonlocal gates - */ -static void world_unlink_nonlocal( world_instance *world ){ - for( u32 j=0; jent_gate); j ++ ){ - ent_gate *gate = mdl_arritm( &world->ent_gate, j ); - - if( gate->flags & k_ent_gate_nonlocal ){ - gate->flags &= ~k_ent_gate_linked; - } - } -} - -/* - * attatches nonlocal gates, to be called from main thread ONLY! - */ -static void world_link_nonlocal_async( void *payload, u32 size ){ - world_instance *world = payload; - u32 world_id = world - world_static.instances; - - for( u32 j=0; jent_gate); j ++ ){ - ent_gate *gate = mdl_arritm( &world->ent_gate, j ); - - if( !(gate->flags & k_ent_gate_nonlocal) ) continue; - if( gate->flags & k_ent_gate_linked ) continue; - - const char *key = mdl_pstr( &world->meta, gate->key ); - vg_info( "key: %s\n", key ); - - for( u32 i=0; istatus != k_world_status_loaded ) continue; - vg_info( "Checking world %u for key matches\n", i ); - - for( u32 k=0; kent_gate ); k++ ){ - ent_gate *gate2 = mdl_arritm( &other->ent_gate, k ); - - if( !(gate2->flags & k_ent_gate_nonlocal) ) continue; - if( gate2->flags & k_ent_gate_linked ) continue; - - const char *key2 = mdl_pstr( &other->meta, gate2->key ); - vg_info( " key2: %s\n", key2 ); - - if( strcmp( key, key2 ) ) continue; - - vg_success( "Non-local matching pair '%s' found. (%u:%u)\n", - key, world_id, i ); - - gate->flags |= k_ent_gate_linked; - gate2->flags |= k_ent_gate_linked; - gate->target = i; - gate2->target = world_id; - - v3_copy( gate->co[0], gate2->co[1] ); - v3_copy( gate2->co[0], gate->co[1] ); - v4_copy( gate->q[0], gate2->q[1] ); - v4_copy( gate2->q[0], gate->q[1] ); - - if( world->meta.info.version < 102 ){ - /* LEGACY BEHAVIOUR: v101 - * this would flip both the client worlds portal's entrance and - * exit. effectively the clients portal would be the opposite - * to the hub worlds one. new behaviour is to just flip the - * destinations so the rules are consistent in each world. - */ - v4f qflip; - q_axis_angle( qflip, (v3f){0.0f,1.0f,0.0f}, VG_PIf ); - q_mul( gate->q[0], qflip, gate->q[0] ); - q_mul( gate->q[1], qflip, gate->q[1] ); - q_mul( gate2->q[1], qflip, gate2->q[1] ); - } - - gate_transform_update( gate ); - gate_transform_update( gate2 ); - - goto matched; - } - } matched:; - } -} - static void ent_gate_call( world_instance *world, ent_call *call ){ u32 index = mdl_entity_id_id( call->id ); ent_gate *gate = mdl_arritm( &world->ent_gate, index ); diff --git a/world_gate.h b/world_gate.h index 5663c29..201187c 100644 --- a/world_gate.h +++ b/world_gate.h @@ -11,15 +11,15 @@ struct world_gates{ glmesh mesh; - mdl_submesh sm_surface, sm_marker[4]; + mdl_submesh sm_surface, sm_marker[4], sm_icosphere; camera cam; + + v3f userportal_co; } static world_gates; static void world_gates_init(void); static void gate_transform_update( ent_gate *gate ); -static void world_link_nonlocal_async( void *payload, u32 size ); -static void world_unlink_nonlocal( world_instance *world ); static int render_gate( world_instance *world, world_instance *world_inside, ent_gate *gate, camera *cam, int layer_depth ); diff --git a/world_gen.c b/world_gen.c index 0b0c344..7d3cc81 100644 --- a/world_gen.c +++ b/world_gen.c @@ -652,7 +652,6 @@ static void async_world_postprocess( void *payload, u32 _size ){ } glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - world->status = k_world_status_loaded; } /* Loads textures from the pack file */ diff --git a/world_load.c b/world_load.c index f1308c1..e8f545c 100644 --- a/world_load.c +++ b/world_load.c @@ -45,6 +45,7 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){ mdl_load_animation_block( meta, world->heap ); mdl_load_mesh_block( meta, world->heap ); + /* TODO: Make this a table? */ mdl_load_array( meta, &world->ent_gate, "ent_gate", heap ); mdl_load_array( meta, &world->ent_camera, "ent_camera", heap ); mdl_load_array( meta, &world->ent_spawn, "ent_spawn", heap ); @@ -66,6 +67,7 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){ mdl_load_array( meta, &world->ent_challenge, "ent_challenge", heap ); mdl_load_array( meta, &world->ent_relay, "ent_relay", heap ); mdl_load_array( meta, &world->ent_cubemap, "ent_cubemap", heap ); + mdl_load_array( meta, &world->ent_miniworld, "ent_miniworld", heap ); mdl_array_ptr infos; mdl_load_array( meta, &infos, "ent_worldinfo", vg_mem.scratch ); @@ -95,6 +97,16 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){ world_gen_compute_light_indices( world ); mdl_close( meta ); + /* init player position. + * - this is overriden by the save state when(if) it loads */ + v3_zero( world->player_angles ); + ent_spawn *rp = world_find_spawn_by_name( world, "start" ); + if( !rp ) rp = world_find_closest_spawn( world, (v3f){0.0f,0.0f,0.0f} ); + + /* TODO: fallback to searching for a safe location using raycasts */ + assert(rp); + v3_copy( rp->transform.co, world->player_co ); + /* allocate leaderboard buffers */ u32 bs = mdl_arrcount(&world->ent_route)*sizeof(struct leaderboard_cache); world->leaderboard_cache = vg_linear_alloc( heap, bs ); @@ -113,21 +125,27 @@ static void world_instance_load_mdl( u32 instance_id, const char *path ){ struct world_load_complete_data{ savedata_file save; - u32 instance_start, instance_count; + enum world_purpose purpose; }; static void skaterift_world_load_done( void *payload, u32 size ){ struct world_load_complete_data *data = payload; + /* TODO(W2): Load player position from this save file */ vg_msg sav; vg_msg_init( &sav, data->save.buf, data->save.len ); - for( u32 i=0; iinstance_count; i++ ){ - world_instance *world = &world_static.instances[ data->instance_start+i ]; - world_entity_start( world, &sav ); - } - + world_instance *world = &world_static.instances[ data->purpose ]; + world_entity_start( world, &sav ); + world->status = k_world_status_loaded; world_static.load_state = k_world_loader_none; + + for( int i=0; istatus == k_world_status_loaded ) + world_entity_relink( wi ); + } } struct world_load_args { @@ -139,10 +157,15 @@ struct world_load_args { * Does a complete world switch using the remaining free slots */ static void skaterift_world_load_thread( void *_args ){ - struct world_load_args *args = _args; + /* FIXME: we need to check all threads that take args. args can dissapear! */ + struct world_load_args args = *((struct world_load_args *)_args); + + addon_reg *reg = args.reg; + world_static.instance_addons[ args.purpose ] = reg; - addon_reg *reg = args->reg; - world_static.instance_addons[ args->purpose ] = reg; + char uid[ADDON_UID_MAX]; + addon_alias_uid( ®->alias, uid ); + vg_info( "LOAD WORLD %s @%d\n", uid, args.purpose ); char path_buf[4096]; vg_str path; @@ -206,30 +229,15 @@ static void skaterift_world_load_thread( void *_args ){ } } - u32 instance_start = 0, instance_count = 1; - if( args->purpose == k_world_purpose_client ) instance_start = 1; - - world_instance_load_mdl( instance_start, worlds[first_index] ); - - /* TODO: Support multiply packed worlds */ -#if 0 - world_loader.generate_point_cloud = 0; - for( u32 j=0; jpayload; - data->instance_start = instance_start; - data->instance_count = instance_count; + data->purpose = args.purpose; - skaterift_world_get_save_path( args->purpose, data->save.path ); + skaterift_world_get_save_path( args.purpose, data->save.path ); savedata_file_read( &data->save ); vg_async_dispatch( final_call, skaterift_world_load_done ); @@ -287,7 +295,6 @@ static void skaterift_change_world_start( addon_reg *reg ){ vg_linear_clear( vg_mem.scratch ); /* ?? */ vg_info( "unloading old worlds\n" ); - world_unlink_nonlocal( &world_static.instances[0] ); for( u32 i=1; ialias, buf ); + vg_info( " %s\n", buf ); } } diff --git a/world_load.h b/world_load.h index c4e1d84..3e4722a 100644 --- a/world_load.h +++ b/world_load.h @@ -12,5 +12,6 @@ static void world_free( world_instance *world ); static int world_freeable( world_instance *world ); +static int skaterift_load_world_command( int argc, const char *argv[] ); #endif /* WORLD_LOAD_H */ diff --git a/world_render.c b/world_render.c index aa74bbf..1e99566 100644 --- a/world_render.c +++ b/world_render.c @@ -150,6 +150,7 @@ struct world_pass{ struct world_surface *mat ); void (*fn_set_mdl)( m4x3f mdl ); void (*fn_set_uPvmPrev)( m4x4f pvm ); + void (*fn_set_uNormalMtx)( m3x3f mnorm ); }; static @@ -701,7 +702,8 @@ static void render_world_gates( world_instance *world, camera *cam, for( u32 i=0; ient_gate); i++ ){ ent_gate *gi = mdl_arritm( &world->ent_gate, i ); - if( !(gi->flags & k_ent_gate_linked) ) + if( !(gi->flags & (k_ent_gate_linked|k_ent_gate_nonlocal_DELETED| + k_ent_gate_locked)) ) continue; float dist = v3_dist2( gi->co[0], cam->transform[3] ); @@ -715,22 +717,8 @@ static void render_world_gates( world_instance *world, camera *cam, } world->rendering_gate = gate; - if( gate ){ - if( gate->flags & k_ent_gate_locked ) return; - - if( gate->flags & k_ent_gate_nonlocal ){ - if( world_static.load_state != k_world_loader_none ){ - world->rendering_gate = NULL; - return; - } - - world_instance *dest_world = &world_static.instances[ gate->target ]; - render_gate( world, dest_world, gate, cam, layer_depth ); - } - else{ - render_gate( world, world, gate, cam, layer_depth ); - } - } + if( gate ) + render_gate( world, world, gate, cam, layer_depth ); } static void world_prerender( world_instance *world ){ @@ -844,9 +832,10 @@ static void render_world( world_instance *world, camera *cam, } -static -void render_world_override_pass( world_instance *world, - struct world_pass *pass ){ +static void render_world_override_pass( world_instance *world, + struct world_pass *pass, + m4x3f mmdl, m3x3f mnormal, + m4x4f mpvm_prev ){ for( int i=0; isurface_count; i++ ){ struct world_surface *mat = &world->surfaces[i]; @@ -861,21 +850,21 @@ void render_world_override_pass( world_instance *world, 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_set_uNormalMtx( mnormal ); + pass->fn_set_uPvmPrev( mpvm_prev ); pass->fn_bind_textures( world, mat ); mdl_draw_submesh( sm ); } } -static void render_world_override( world_instance *world ){ +static void render_world_override( world_instance *world, m4x3f mmdl ){ struct world_pass pass = { .cam = &skaterift.cam, .fn_bind_textures = bindpoint_override, .fn_set_mdl = shader_scene_override_uMdl, .fn_set_uPvmPrev = shader_scene_override_uPvmPrev, + .fn_set_uNormalMtx = shader_scene_override_uNormalMtx, .shader = k_shader_override }; @@ -887,15 +876,32 @@ static void render_world_override( world_instance *world ){ WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_override ); bind_terrain_noise(); - shader_scene_override_uCamera( pass.cam->transform[3] ); + + m4x3f mmdl_inv; + m4x3_invert_full( mmdl, mmdl_inv ); + + v3f cam_pos; + m4x3_mulv( mmdl_inv, pass.cam->transform[3], cam_pos ); + shader_scene_override_uCamera( cam_pos ); + + m4x4f mpvm_prev; + m4x3_expand( mmdl, mpvm_prev ); + m4x4_mul( skaterift.cam.mtx_prev.pv, mpvm_prev, mpvm_prev ); + + m3x3f mnormal; + m3x3_inv( mmdl_inv, mnormal ); + m3x3_transpose( mnormal, mnormal ); + v3_normalize( mnormal[0] ); + v3_normalize( mnormal[1] ); + v3_normalize( mnormal[2] ); glDisable( GL_CULL_FACE ); mesh_bind( &world->mesh_geo ); pass.geo_type = k_world_geo_type_solid; - render_world_override_pass( world, &pass ); + render_world_override_pass( world, &pass, mmdl, mnormal, mpvm_prev ); mesh_bind( &world->mesh_no_collide ); pass.geo_type = k_world_geo_type_nonsolid; - render_world_override_pass( world, &pass ); + render_world_override_pass( world, &pass, mmdl, mnormal, mpvm_prev ); glEnable( GL_CULL_FACE ); } diff --git a/world_render.h b/world_render.h index 3050a69..1810400 100644 --- a/world_render.h +++ b/world_render.h @@ -78,6 +78,7 @@ static void render_world( world_instance *world, camera *cam, int layer_depth ); static void render_world_cubemaps( world_instance *world ); static void bind_terrain_noise(void); +static void render_world_override( world_instance *world, m4x3f mmdl ); #define WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( WORLD, SHADER ) \ world_link_lighting_ub( WORLD, _shader_##SHADER.id ); \ diff --git a/world_routes.c b/world_routes.c index f4de14c..9dc678e 100644 --- a/world_routes.c +++ b/world_routes.c @@ -14,7 +14,6 @@ #include "network.h" #include "font.h" -#include "pointcloud.h" #include "gui.h" #include "steam.h" #include "network_msg.h" @@ -119,16 +118,6 @@ static void world_routes_activate_entry_gate( world_instance *world, ent_gate *rg ) { world_static.last_use = world_static.time; - - /* disable all routes and leave the world */ - if( rg->flags & k_ent_gate_nonlocal ){ - for( u32 i=0; ient_route); i++ ){ - ent_route *route = mdl_arritm( &world->ent_route, i ); - route->active_checkpoint = 0xffff; - } - return; - } - ent_gate *dest = mdl_arritm( &world->ent_gate, rg->target ); for( u32 i=0; ient_route); i++ ){ @@ -212,90 +201,10 @@ static void world_routes_debug( world_instance *world ) } } -static -void world_routes_pointcloud_spot( world_instance *world, - pointcloud_buffer *pcbuf, - v3f co, f32 radius, u32 samples, v4f colour ) -{ - v3f inv_ext; - v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext ); - v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext ); - - for( u32 j=0; jcount >= pcbuf->max ) - return; - - pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ]; - - v3f sample, jitter, point; - vg_rand_sphere( jitter ); - v3_muladds( co, jitter, radius, sample ); - - if( bh_closest_point( world->geo_bh, sample, point, radius*1.5f ) == -1 ){ - v3_copy( sample, point ); - } - - v3f pos; - v3_sub( point, pcbuf->boundary[0], pos ); - v3_mul( pos, inv_ext, pos ); - - float dist = 1.0f-(v3_length(jitter)); - - v4f final_colour; - v4_muls( colour, dist*dist, final_colour ); - - pointcloud_packvert( vert, pos, final_colour ); - } -} - -/* - * ' - * . - * | - * | - * /#\ - * -'###`- - */ -static -void world_routes_pointcloud_tower( world_instance *world, - pointcloud_buffer *pcbuf, - v3f co, f32 radius, f32 height, - u32 samples, v4f colour ) -{ - v3f inv_ext; - v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext ); - v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext ); - - for( u32 j=0; jcount >= pcbuf->max ) - return; - - pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ]; - - v3f point; - point[0] = vg_randf64()*2.0f-1.0f; - point[1] = 0.0f; - point[2] = vg_randf64()*2.0f-1.0f; - v3_normalize( point ); - v3_muls( point, sqrtf(vg_randf64()), point ); - - f32 h = vg_randf64(); - point[1] = h*h*h*height; - point[0] *= radius; - point[2] *= radius; - - v3_add( point, co, point ); - v3_sub( point, pcbuf->boundary[0], point ); - v3_mul( point, inv_ext, point ); - - pointcloud_packvert( vert, point, colour ); - } -} static void world_routes_place_curve( world_instance *world, ent_route *route, - v4f h[3], v3f n0, v3f n2, scene_context *scene, - pointcloud_buffer *pcbuf ) + v4f h[3], v3f n0, v3f n2, scene_context *scene ) { float t; v3f p, pd; @@ -355,11 +264,6 @@ void world_routes_place_curve( world_instance *world, ent_route *route, int resa = ray_world( world, sa, down, &ha, k_material_flag_ghosts ), resb = ray_world( world, sb, down, &hb, k_material_flag_ghosts ); - - if( pcbuf && resa ){ - world_routes_pointcloud_spot( world, pcbuf, ha.pos, - 12.0f, 10, route->colour ); - } if( resa && resb ){ struct world_surface *surfa = ray_hit_surface( world, &ha ), @@ -415,8 +319,7 @@ void world_routes_place_curve( world_instance *world, ent_route *route, } static void world_routes_gen_meshes( world_instance *world, u32 route_id, - scene_context *sc, - pointcloud_buffer *pcbuf ) + scene_context *sc ) { ent_route *route = mdl_arritm( &world->ent_route, route_id ); u8 colour[4]; @@ -527,7 +430,7 @@ static void world_routes_gen_meshes( world_instance *world, u32 route_id, v3_normalize( n0 ); v3_normalize( n2 ); - world_routes_place_curve( world, route, p, n0, n2, sc, pcbuf ); + world_routes_place_curve( world, route, p, n0, n2, sc ); /* --- */ v4_copy( p[2], p[0] ); @@ -541,223 +444,6 @@ static struct world_surface *world_tri_index_surface( world_instance *world, u32 index ); -static f64 world_routes_scatter_surface_points( world_instance *world, - pointcloud_buffer *pcbuf, - f32 rate ) -{ - static f32 densities[] = { - [k_surface_prop_concrete] = 2.0f, - [k_surface_prop_grass] = 0.8f, - [k_surface_prop_metal] = 1.0f, - [k_surface_prop_wood] = 2.5f, - [k_surface_prop_tiles] = 4.0f - }; - - /* calculate total area */ - f64 total_area = 0.0f; - for( u32 i=0; iscene_geo.indice_count/3; i++ ){ - u32 *tri = &world->scene_geo.arrindices[i*3]; - struct world_surface *surf = world_tri_index_surface( world, tri[0] ); - - if( surf->info.shader == k_shader_boundary || - surf->info.shader == k_shader_invisible ) continue; - - if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue; - - scene_vert *va = &world->scene_geo.arrvertices[tri[0]], - *vb = &world->scene_geo.arrvertices[tri[1]], - *vc = &world->scene_geo.arrvertices[tri[2]]; - - v3f v0, v1, vn; - v3_sub( vb->co, va->co, v0 ); - v3_sub( vc->co, va->co, v1 ); - v3_cross( v0, v1, vn ); - if( vn[1] < 0.0f ) continue; - - f32 density = 1.0f; - if( surf->info.surface_prop < vg_list_size(densities) ) - density = densities[surf->info.surface_prop]; - total_area += v3_length(vn)*0.5f*density; - } - - f32 accum = 0.0f; - - u8 colour[] = { 80,80,80,255 }; - v3f light_dir = {0.3f,0.8f,0.1f}; - v3_normalize( light_dir ); - - v3f inv_ext; - v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext ); - v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext ); - - for( u32 i=0; iscene_geo.indice_count/3; i++ ){ - u32 *tri = &world->scene_geo.arrindices[i*3]; - struct world_surface *surf = world_tri_index_surface( world, tri[0] ); - - if( surf->info.shader == k_shader_boundary || - surf->info.shader == k_shader_invisible ) continue; - - if( !(surf->info.flags & k_material_flag_preview_visibile) ) continue; - - scene_vert *va = &world->scene_geo.arrvertices[tri[0]], - *vb = &world->scene_geo.arrvertices[tri[1]], - *vc = &world->scene_geo.arrvertices[tri[2]]; - - v3f v0, v1, vn; - v3_sub( vb->co, va->co, v0 ); - v3_sub( vc->co, va->co, v1 ); - v3_cross( v0, v1, vn ); - if( vn[1] < 0.0f ) continue; - - f32 density = 1.0f; - if( surf->info.surface_prop < vg_list_size(densities) ) - density = densities[surf->info.surface_prop]; - - f32 area = v3_length(vn)*0.5f*density; - accum += area; - - v3_normalize( vn ); - - while( accum > rate ){ - accum -= rate; - - if( pcbuf->count >= pcbuf->max ) return total_area; - - v2f co = { vg_randf64(), vg_randf64() }; - if( v2_length2(co) > 0.5f ){ - co[0] = 1.0f-co[0]; - co[1] = 1.0f-co[1]; - } - - v3f pt; - v3_muls( v0, co[0], pt ); - v3_muladds( pt, v1, co[1], pt ); - v3_add( va->co, pt, pt ); - - if( pt[1] < world->water.height ) continue; - pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ]; - - v3f pos; - v3_sub( pt, pcbuf->boundary[0], pos ); - v3_mul( pos, inv_ext, pos ); - - static v4f colours[] = { - [k_surface_prop_concrete] = { 0.13, 0.15, 0.17, 1.0 }, - [k_surface_prop_grass] = { 0.07, 0.1, 0.14, 1.0 }, - [k_surface_prop_metal] = { 0.15, 0.19, 0.22, 1.0 }, - [k_surface_prop_wood] = { 0.1, 0.13, 0.17, 1.0 }, - [k_surface_prop_tiles] = { 0.05, 0.06, 0.07, 1.0 }, - }; - - v4f col = {0.0f,0.0f,0.0f,0.0f}; - if( surf->info.surface_prop < vg_list_size(colours) ) - v4_copy( colours[surf->info.surface_prop], col ); - - f32 brightness = v3_dot(vn,light_dir)*0.5f+0.5f; - v3_muls( col, brightness, col ); - - pointcloud_packvert( vert, pos, col ); - } - } - - return total_area; -} - -static void world_routes_surface_grid( world_instance *world, - pointcloud_buffer *pcbuf ) -{ - i32 const k_gridlines = 32, - k_gridres = 255; - - v3f inv_ext; - v3_sub( pcbuf->boundary[1], pcbuf->boundary[0], inv_ext ); - v3_div( (v3f){1.0f,1.0f,1.0f}, inv_ext, inv_ext ); - v4f colour = {0.2f,0.2f,0.2f,1.0f}; - v3f dir = {0.0f,-1.0f,0.0f}; - - for( u32 k=0; k<2; k++ ){ - u32 a = k*2, - b = (k^0x1)*2; - - for( i32 x=0; x<=k_gridlines; x++ ){ - f32 t = (float)x / (float)k_gridlines, - px = vg_lerpf( pcbuf->boundary[0][a], pcbuf->boundary[1][a], t ); - - for( i32 z=0; z<=k_gridres; z++ ){ - f32 tz = (float)z / (float)k_gridres, - pz = vg_lerpf(pcbuf->boundary[0][b],pcbuf->boundary[1][b], tz); - - v3f ro, hit; - ro[a] = px; - ro[1] = 1000.0f; - ro[b] = pz; - - bh_iter it; - bh_iter_init_ray( 0, &it, ro, dir, INFINITY ); - i32 idx; - - while( bh_next( world->geo_bh, &it, &idx ) ){ - u32 *tri = &world->scene_geo.arrindices[ idx*3 ]; - v3f vs[3]; - - u16 mask = k_material_flag_preview_visibile; - if( !(world->scene_geo.arrvertices[tri[0]].flags & mask) ) - continue; - - for( u32 i=0; i<3; i++ ){ - v3_copy( world->scene_geo.arrvertices[tri[i]].co, vs[i] ); - } - - f32 t; - if( ray_tri( vs, ro, dir, &t ) ){ - v3_muladds( ro, dir, t, hit ); - - if( world->water.enabled ) - if( hit[1] < world->water.height ) - continue; - - if( pcbuf->count >= pcbuf->max ) return; - - pointcloud_vert *vert = &pcbuf->buf[ pcbuf->count ++ ]; - - v3f co; - v3_sub( hit, pcbuf->boundary[0], co ); - v3_mul( co, inv_ext, co ); - - pointcloud_packvert( vert, co, colour ); - } - } - } - } - } -} - -static void world_write_preview( addon_reg *reg, pointcloud_buffer *pcbuf ){ - if( reg->alias.workshop_id ) return; - - /* - * FIXME: BUG: cannot correctly handle workshop because there is a stalling - * call below, which deadlocks the scene upload. TODO: improve the async - * stack to handle out of order execution. MAYBE - */ - - char path_buf[4096]; - vg_str path; - vg_strnull( &path, path_buf, 4096 ); - - addon_get_content_folder( reg, &path ); - vg_strcat( &path, "/preview.bin" ); - - if( !vg_strgood( &path ) ) vg_fatal_error( "Path too long\n" ); - FILE *fp = fopen( path_buf, "wb" ); - if( !fp ) vg_fatal_error( "Cannot open '%s' for writing\n", path_buf ); - - fwrite( pcbuf, sizeof(struct pointcloud_buffer) + - sizeof(struct pointcloud_vert)*pcbuf->count, 1, fp ); - fclose( fp ); - vg_info( "written %s\n", path_buf ); -} - /* * Create the strips of colour that run through the world along course paths */ @@ -771,27 +457,6 @@ static void world_gen_routes_generate( u32 instance_id ){ &world->mesh_route_lines, 200000, 300000 ); - vg_async_item *call_pointcloud = NULL; - pointcloud_buffer *pcbuf = NULL; - - if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){ - call_pointcloud = vg_async_alloc( - sizeof(pointcloud_buffer) + - sizeof(pointcloud_vert)*POINTCLOUD_POINTS ); - pcbuf = call_pointcloud->payload; - pcbuf->count = 0; - pcbuf->max = POINTCLOUD_POINTS; - pcbuf->op = k_pointcloud_op_clear; - - v3f ext, mid, v0; - v3_sub( world->scene_geo.bbx[1], world->scene_geo.bbx[0], ext ); - f32 maxe = v3_maxf( ext ); - v3_fill( v0, maxe * 0.5f ); - v3_muladds( world->scene_geo.bbx[0], ext, 0.5f, mid ); - v3_add( mid, v0, pcbuf->boundary[1] ); - v3_sub( mid, v0, pcbuf->boundary[0] ); - } - for( u32 i=0; ient_gate); i++ ){ ent_gate *gate = mdl_arritm( &world->ent_gate, i ); gate->ref_count = 0; @@ -832,28 +497,7 @@ static void world_gen_routes_generate( u32 instance_id ){ } for( u32 i=0; ient_route); i++ ){ - world_routes_gen_meshes( world, i, &world->scene_lines, pcbuf ); - } - - if( instance_id <= 1 /*world_loader.generate_point_cloud*/ ){ - f64 area = 0.0; - - area = world_routes_scatter_surface_points( world, pcbuf, 16.0f ); - world_routes_surface_grid( world, pcbuf ); - - for( u32 i=0; ient_gate ); i++ ){ - ent_gate *gate = mdl_arritm( &world->ent_gate, i ); - - world_routes_pointcloud_tower( world, pcbuf, gate->co[0], - 2.0f, 50.0f, 128, - (v4f){0.2f,0.2f,0.2f,1.0f} ); - } - - vg_info( "Distributed %u points over %fkm^2!\n", - pcbuf->count, area/1e6f ); - - world_write_preview( world_static.instance_addons[ instance_id ], pcbuf ); - vg_async_dispatch( call_pointcloud, async_pointcloud_sub ); + world_routes_gen_meshes( world, i, &world->scene_lines ); } vg_async_dispatch( call_scene, async_scene_upload ); @@ -897,7 +541,7 @@ static void world_gen_routes_ent_init( world_instance *world ){ } if( (gate->flags & k_ent_gate_linked) & - !(gate->flags & k_ent_gate_nonlocal) ){ + !(gate->flags & k_ent_gate_nonlocal_DELETED) ){ gate = mdl_arritm(&world->ent_gate, gate->target ); for( u32 k=0; k<4; k++ ){ @@ -1326,7 +970,7 @@ static void render_world_routes( world_instance *world, camera *cam, for( u32 j=0; jent_gate); j ++ ){ ent_gate *gate = mdl_arritm( &world->ent_gate, j ); - if( !(gate->flags & k_ent_gate_nonlocal) ) + if( !(gate->flags & k_ent_gate_nonlocal_DELETED) ) render_gate_markers( i, gate ); } }