X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=skaterift.c;h=9d72bec2aa030060fdd7009f465715e07026e195;hb=2a238d32da833812e837cf38e16a7685c98db5c3;hp=0b3310ab44781d01dc6ab747cb5c3ae3e8a0aef9;hpb=75703291fbf045008a3b1ebb20fc46a2617b6b3b;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/skaterift.c b/skaterift.c index 0b3310a..9d72bec 100644 --- a/skaterift.c +++ b/skaterift.c @@ -2,7 +2,7 @@ * ============================================================================= * * Copyright . . . -----, ,----- ,---. .---. - * 2021-2022 |\ /| | / | | | | /| + * 2021-2023 |\ /| | / | | | | /| * | \ / | +-- / +----- +---' | / | * | \ / | | / | | \ | / | * | \/ | | / | | \ | / | @@ -12,8 +12,8 @@ */ #define SR_NETWORKED - #include "common.h" +#include "conf.h" #include "steam.h" #include "render.h" #include "audio.h" @@ -22,7 +22,9 @@ #include "network.h" #include "menu.h" -static int cl_ui = 1; +static int cl_ui = 1, + cl_view_id = 0, + cl_light_edit = 0; int main( int argc, char *argv[] ) { @@ -45,20 +47,30 @@ VG_STATIC void vg_launch_opt(void) VG_STATIC void vg_preload(void) { + g_conf_init(); + vg_convar_push( (struct vg_convar){ .name = "cl_ui", .data = &cl_ui, .data_type = k_convar_dtype_i32, .opt_i32 = { .min=0, .max=1, .clamp=1 }, - .persistent = 1 + .persistent = 0 }); vg_convar_push( (struct vg_convar){ - .name = "cl_fov", - .data = &g_fov_option, - .data_type = k_convar_dtype_f32, - .opt_f32 = { .clamp = 0 }, - .persistent = 1 + .name = "cl_view_id", + .data = &cl_view_id, + .data_type = k_convar_dtype_i32, + .opt_i32 = { .min=0, .max=1, .clamp=1 }, + .persistent = 0 + }); + + vg_convar_push( (struct vg_convar){ + .name = "ledit", + .data = &cl_light_edit, + .data_type = k_convar_dtype_i32, + .opt_i32 = { .min=0, .max=1, .clamp=1 }, + .persistent = 0 }); vg_info(" Copyright . . . -----, ,----- ,---. .---. \n" ); @@ -144,98 +156,131 @@ VG_STATIC void vg_update_post(void) VG_STATIC void vg_framebuffer_resize( int w, int h ) { render_fb_resize(); - water_fb_resize(); } -VG_STATIC void render_main_game(void) +VG_STATIC void present_view_with_post_processing(void) { - m4x4f world_4x4; - m4x3_expand( camera_mtx_inverse, world_4x4 ); + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - static float fov = 60.0f; + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); + glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + if( cl_blur ) + { + shader_blitblur_use(); + shader_blitblur_uTexMain( 0 ); + shader_blitblur_uTexMotion( 1 ); + shader_blitblur_uBlurStrength(cl_blur_strength / (vg.frame_delta*60.0f)); + + v2f menu_blurring; + v2_muls( (v2f){ 0.04f, 0.001f }, menu_opacity, menu_blurring ); + shader_blitblur_uOverrideDir( menu_blurring ); + + if( cl_view_id == 0 ) + render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); + else if( cl_view_id == 1 ) + render_fb_bind_texture( gpipeline.fb_main, 1, 0 ); + else + render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); + + render_fb_bind_texture( gpipeline.fb_main, 1, 1 ); + } + else + { + shader_blit_use(); + shader_blit_uTexMain( 0 ); + render_fb_bind_texture( gpipeline.fb_main, 0, 0 ); + } - float fov_target = vg_lerpf( 90.0f, 110.0f, g_fov_option ); + render_fsquad(); +} - if( player.phys.on_board ) - fov_target = vg_lerpf( 97.0f, 135.0f, g_fov_option ); +VG_STATIC void render_player_transparent(void) +{ + static camera small_cam; /* DOES NOT NEED TO BE STATIC BUT MINGW + SAIS OTHERWISE */ - if( cl_menu ) - fov_target = menu_fov_target; + m4x3_copy( main_camera.transform, small_cam.transform ); - fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f ); + small_cam.fov = main_camera.fov; + small_cam.nearz = 0.05f; + small_cam.farz = 60.0f; + + camera_update_view( &small_cam ); + camera_update_projection( &small_cam ); + camera_finalize( &small_cam ); - gpipeline.fov = freecam? 60.0f: fov; /* 120 */ - m4x4_projection( vg.pv, gpipeline.fov, - (float)vg.window_x / (float)vg.window_y, - 0.1f, 2100.0f ); + /* Draw player to window buffer and blend background ontop */ + + glBindFramebuffer( GL_FRAMEBUFFER, 0 ); + draw_player( &small_cam ); +} + +VG_STATIC void render_scene(void) +{ + render_fb_bind( gpipeline.fb_main ); + glClearColor( 0.0f, 0.0f, 0.0f, 1.0f ); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); - m4x4_mul( vg.pv, world_4x4, vg.pv ); + /* Draw world */ glEnable( GL_DEPTH_TEST ); - - /* - * Draw world - */ - int draw_solid = player.is_dead | freecam; - render_world( vg.pv, camera_mtx ); + render_world( &main_camera ); - if( draw_solid ) - draw_player( camera_mtx ); + int player_transparent = !(player.is_dead || freecam), + player_draw = !cl_menu; - render_water_texture( camera_mtx ); + if( !player_transparent && player_draw ) + draw_player( &main_camera ); - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - render_water_surface( vg.pv, camera_mtx ); - render_world_gates( vg.pv, player.phys.rb.co, camera_mtx ); + render_water_texture( &main_camera ); + render_fb_bind( gpipeline.fb_main ); + render_water_surface( &main_camera ); + render_world_gates( &main_camera ); + if( player_transparent && player_draw ) + render_player_transparent(); +} + +VG_STATIC void render_menu(void) +{ + glClear( GL_DEPTH_BUFFER_BIT ); + menu_render( &main_camera ); +} + +VG_STATIC void render_main_game(void) +{ + static float fov = 60.0f; + float fov_target = vg_lerpf( 90.0f, 110.0f, cl_fov ); + if( player.phys.on_board ) + fov_target = vg_lerpf( 97.0f, 135.0f, cl_fov ); if( cl_menu ) - { - glClear( GL_DEPTH_BUFFER_BIT ); - menu_render( vg.pv ); - } - - /* Copy the RGB of what we have into the background buffer */ - glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ); - glBindFramebuffer( GL_DRAW_FRAMEBUFFER, gpipeline.fb_background ); - glBlitFramebuffer( 0,0, vg.window_x, vg.window_y, - 0,0, vg.window_x, vg.window_y, - GL_COLOR_BUFFER_BIT, - GL_LINEAR ); - - /* Clear out the colour buffer, but keep depth */ - glBindFramebuffer( GL_FRAMEBUFFER, 0 ); - glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); + fov_target = menu_fov_target; + fov = vg_lerpf( fov, fov_target, vg.frame_delta * 2.0f ); + fov = freecam? 60.0f: fov; - if( !player.is_dead ) - glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); - else - glClear( GL_COLOR_BUFFER_BIT ); - - if( !draw_solid ) + main_camera.fov = fov; + main_camera.nearz = 0.1f; + main_camera.farz = 2100.0f; + + camera_update_view( &main_camera ); + camera_update_projection( &main_camera ); + camera_finalize( &main_camera ); + + /* ========== Begin Frame ========== */ + + render_scene(); + present_view_with_post_processing(); + + if( cl_menu ) { - m4x4_projection( vg.pv, gpipeline.fov, - (float)vg.window_x / (float)vg.window_y, - 0.05f, 60.0f ); - m4x4_mul( vg.pv, world_4x4, vg.pv ); - draw_player( camera_mtx ); + render_menu(); + render_player_transparent(); } - /* Draw back in the background - * - * TODO: need to disable alpha write in the terrain shader so this works - * again. - */ - glEnable(GL_BLEND); - glDisable(GL_DEPTH_TEST); - glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA); - glBlendEquation(GL_FUNC_ADD); - - shader_blit_use(); - shader_blit_uTexMain( 0 ); - glActiveTexture(GL_TEXTURE0); - glBindTexture( GL_TEXTURE_2D, gpipeline.rgb_background ); - - render_fsquad(); + /* =========== End Frame =========== */ } VG_STATIC void vg_render(void) @@ -245,29 +290,29 @@ VG_STATIC void vg_render(void) glViewport( 0,0, vg.window_x, vg.window_y ); glDisable( GL_DEPTH_TEST ); - glClearColor( 0.11f, 0.35f, 0.37f, 1.0f ); - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT ); + glClearColor( 1.0f, 0.0f, 0.0f, 0.0f ); + glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT ); render_main_game(); /* Other shite */ glDisable(GL_BLEND); glDisable( GL_DEPTH_TEST ); - vg_lines_drawall( (float *)vg.pv ); + vg_lines_drawall( (float *)main_camera.mtx.pv ); glViewport( 0,0, vg.window_x, vg.window_y ); } +VG_STATIC void run_light_widget( struct light_widget *lw ); VG_STATIC void vg_ui(void) { menu_crap_ui(); -#if 0 - if( lightedit ) + if( cl_light_edit ) { - ui_global_ctx.cursor[0] = 10; - ui_global_ctx.cursor[1] = 10; - ui_global_ctx.cursor[2] = 200; - ui_global_ctx.cursor[3] = 20; + vg_uictx.cursor[0] = 10; + vg_uictx.cursor[1] = 10; + vg_uictx.cursor[2] = 200; + vg_uictx.cursor[3] = 20; struct ub_world_lighting *wl = &gpipeline.ub_world_lighting; struct ui_slider_vector @@ -279,24 +324,23 @@ VG_STATIC void vg_ui(void) for( int i=0; i<3; i++ ) run_light_widget( &gpipeline.widgets[i] ); - - gui_text( ui_global_ctx.cursor, "Ambient", 1, 0 ); - ui_global_ctx.cursor[1] += 16; - ui_slider_vector( &ui_global_ctx, &s5 ); - - gui_text( ui_global_ctx.cursor, "Shadows", 1, 0 ); - ui_global_ctx.cursor[1] += 16; - ui_slider( &ui_global_ctx, &s8 ); - ui_slider( &ui_global_ctx, &s9 ); - - gui_text( ui_global_ctx.cursor, "Misc", 1, 0 ); - ui_global_ctx.cursor[1] += 16; + + ui_text( vg_uictx.cursor, "Ambient", 1, 0 ); + vg_uictx.cursor[1] += 16; + ui_slider_vector( &s5 ); + + ui_text( vg_uictx.cursor, "Shadows", 1, 0 ); + vg_uictx.cursor[1] += 16; + ui_slider( &s8 ); + ui_slider( &s9 ); + + ui_text( vg_uictx.cursor, "Misc", 1, 0 ); + vg_uictx.cursor[1] += 16; struct ui_checkbox c1 = {.data = &wl->g_light_preview}; - ui_checkbox( &ui_global_ctx, &c1 ); + ui_checkbox( &c1 ); render_update_lighting_ub(); } -#endif //glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); if( cl_ui ) @@ -306,14 +350,14 @@ VG_STATIC void vg_ui(void) //glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); audio_debug_soundscapes(); + render_view_framebuffer_ui(); } -#if 0 VG_STATIC void run_light_widget( struct light_widget *lw ) { struct ui_checkbox c1 = { .data=&lw->enabled }; - ui_checkbox( &ui_global_ctx, &c1 ); + ui_checkbox( &c1 ); if( lw->enabled ) { @@ -321,12 +365,11 @@ VG_STATIC void run_light_widget( struct light_widget *lw ) colour = { .min=0.0f, .max=2.0f, .len=3, .data=lw->colour }, dir = { .min=-VG_PIf, .max=VG_PIf, .len=2, .data=lw->dir }; - ui_slider_vector( &ui_global_ctx, &colour ); - ui_global_ctx.cursor[1] += 4; - ui_slider_vector( &ui_global_ctx, &dir ); + ui_slider_vector( &colour ); + vg_uictx.cursor[1] += 4; + ui_slider_vector( &dir ); } } -#endif VG_STATIC void run_debug_info(void) {