From df9f72d2912a5424d37dfdb02f76aba8f1ed4df1 Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 6 Oct 2023 08:11:23 +0100 Subject: [PATCH] reduced shader bind code dupe & adjust skate uprighter strenght --- depth_compare.h | 24 ++++++++++++++++++++ entity.h | 4 ++-- font.h | 25 +++++---------------- player_render.c | 58 ++++++++++++++----------------------------------- player_skate.c | 8 +++++-- world_render.c | 42 +++++++++-------------------------- world_render.h | 9 ++++++++ world_routes.c | 12 +++++----- world_sfd.c | 37 ++++++++++--------------------- world_water.c | 31 ++++++++------------------ 10 files changed, 99 insertions(+), 151 deletions(-) create mode 100644 depth_compare.h diff --git a/depth_compare.h b/depth_compare.h new file mode 100644 index 0000000..8b64586 --- /dev/null +++ b/depth_compare.h @@ -0,0 +1,24 @@ +#ifndef DEPTH_COMPARE_H +#define DEPTH_COMPARE_H + +#include "vg/vg_m.h" +#include "render.h" + +static void depth_compare_bind( + void (*uTexSceneDepth)(int), + void (*uInverseRatioDepth)(v3f), + void (*uInverseRatioMain)(v3f), + camera *cam ){ + uTexSceneDepth( 5 ); + render_fb_bind_texture( gpipeline.fb_main, 2, 5 ); + v3f inverse; + render_fb_inverse_ratio( gpipeline.fb_main, inverse ); + inverse[2] = skaterift.cam.farz-skaterift.cam.nearz; + + uInverseRatioDepth( inverse ); + render_fb_inverse_ratio( NULL, inverse ); + inverse[2] = cam->farz-cam->nearz; + uInverseRatioMain( inverse ); +} + +#endif /* DEPTH_COMPARE_H */ diff --git a/entity.h b/entity.h index 22ee913..103e1a2 100644 --- a/entity.h +++ b/entity.h @@ -161,11 +161,11 @@ struct ent_checkpoint{ }; struct ent_route{ - union{ mdl_transform transform; u32 official_track_id; - }; + } + anon; u32 pstr_name; u16 checkpoints_start, diff --git a/font.h b/font.h index c49bc66..c00aece 100644 --- a/font.h +++ b/font.h @@ -7,6 +7,7 @@ #include "shaders/model_font.h" #include "shaders/scene_font.h" #include "world_render.h" +#include "depth_compare.h" enum efont_SRglyph{ k_SRglyph_end = 0x00, /* control characters */ @@ -147,17 +148,10 @@ static void font3d_bind( font3d *font, enum font_shader shader, shader_model_font_uDepthCompare( depth_compare ); if( depth_compare ){ - /* TODO: Compress with code in player_render.c */ - shader_model_font_uTexSceneDepth( 2 ); - render_fb_bind_texture( gpipeline.fb_main, 2, 2 ); - v3f inverse; - render_fb_inverse_ratio( gpipeline.fb_main, inverse ); - inverse[2] = skaterift.cam.farz-skaterift.cam.nearz; - - shader_model_font_uInverseRatioDepth( inverse ); - render_fb_inverse_ratio( NULL, inverse ); - inverse[2] = cam->farz-cam->nearz; - shader_model_font_uInverseRatioMain( inverse ); + depth_compare_bind( + shader_model_font_uTexSceneDepth, + shader_model_font_uInverseRatioDepth, + shader_model_font_uInverseRatioMain, cam ); } shader_model_font_uPv( cam->mtx.pv ); @@ -171,14 +165,7 @@ static void font3d_bind( font3d *font, enum font_shader shader, shader_scene_font_uPv( skaterift.cam.mtx.pv ); shader_scene_font_uTime( vg.time ); - /* TODO: Code dupe... */ - world_link_lighting_ub( world, _shader_scene_font.id ); - world_bind_position_texture( world, _shader_scene_font.id, - _uniform_scene_font_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_font.id, - _uniform_scene_font_uLightsArray, 3 ); - world_bind_light_index( world, _shader_scene_font.id, - _uniform_scene_font_uLightsIndex, 4 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_font ); bind_terrain_noise(); shader_scene_font_uCamera( skaterift.cam.transform[3] ); diff --git a/player_render.c b/player_render.c index a37e74e..2cf0e28 100644 --- a/player_render.c +++ b/player_render.c @@ -13,6 +13,7 @@ #include "shaders/model_board_view.h" #include "shaders/model_entity.h" #include "shaders/model_board_view.h" +#include "depth_compare.h" static void player_avatar_load( struct player_avatar *av, const char *path ){ mdl_open( &av->meta, path, vg_mem.rtmemory ); @@ -300,25 +301,15 @@ static void render_board( camera *cam, world_instance *world, shader_model_board_view_uTexMain( 0 ); shader_model_board_view_uCamera( cam->transform[3] ); shader_model_board_view_uPv( cam->mtx.pv ); - shader_model_board_view_uTexSceneDepth( 1 ); - render_fb_bind_texture( gpipeline.fb_main, 2, 1 ); - render_fb_inverse_ratio( gpipeline.fb_main, inverse ); + shader_model_board_view_uDepthCompare(1); + depth_compare_bind( + shader_model_board_view_uTexSceneDepth, + shader_model_board_view_uInverseRatioDepth, + shader_model_board_view_uInverseRatioMain, + cam ); - inverse[2] = skaterift.cam.farz-skaterift.cam.nearz; - - shader_model_board_view_uInverseRatioDepth( inverse ); - render_fb_inverse_ratio( NULL, inverse ); - inverse[2] = cam->farz-cam->nearz; - shader_model_board_view_uInverseRatioMain( inverse ); - - world_link_lighting_ub( world, _shader_model_board_view.id ); - world_bind_position_texture( world, _shader_model_board_view.id, - _uniform_model_board_view_g_world_depth, 2 ); - world_bind_light_array( world, _shader_model_board_view.id, - _uniform_model_board_view_uLightsArray, 3 ); - world_bind_light_index( world, _shader_model_board_view.id, - _uniform_model_board_view_uLightsIndex, 4 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_board_view ); } else if( shader == k_board_shader_entity ){ shader_model_entity_use(); @@ -326,13 +317,7 @@ static void render_board( camera *cam, world_instance *world, shader_model_entity_uCamera( cam->transform[3] ); shader_model_entity_uPv( cam->mtx.pv ); - world_link_lighting_ub( world, _shader_model_entity.id ); - world_bind_position_texture( world, _shader_model_entity.id, - _uniform_model_entity_g_world_depth, 2 ); - world_bind_light_array( world, _shader_model_entity.id, - _uniform_model_entity_uLightsArray, 3 ); - world_bind_light_index( world, _shader_model_entity.id, - _uniform_model_entity_uLightsIndex, 4 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_entity ); } mesh_bind( &board->mdl.mesh ); @@ -429,27 +414,16 @@ static void render_playermodel( camera *cam, world_instance *world, shader_model_character_view_uCamera( cam->transform[3] ); shader_model_character_view_uPv( cam->mtx.pv ); + shader_model_character_view_uDepthCompare( depth_compare ); if( depth_compare ){ - shader_model_character_view_uTexSceneDepth( 1 ); - render_fb_bind_texture( gpipeline.fb_main, 2, 1 ); - v3f inverse; - render_fb_inverse_ratio( gpipeline.fb_main, inverse ); - inverse[2] = skaterift.cam.farz-skaterift.cam.nearz; - - shader_model_character_view_uInverseRatioDepth( inverse ); - render_fb_inverse_ratio( NULL, inverse ); - inverse[2] = cam->farz-cam->nearz; - shader_model_character_view_uInverseRatioMain( inverse ); + depth_compare_bind( + shader_model_character_view_uTexSceneDepth, + shader_model_character_view_uInverseRatioDepth, + shader_model_character_view_uInverseRatioMain, + cam ); } - shader_model_character_view_uDepthCompare( depth_compare ); - world_link_lighting_ub( world, _shader_model_character_view.id ); - world_bind_position_texture( world, _shader_model_character_view.id, - _uniform_model_character_view_g_world_depth, 2 ); - world_bind_light_array( world, _shader_model_character_view.id, - _uniform_model_character_view_uLightsArray, 3 ); - world_bind_light_index( world, _shader_model_character_view.id, - _uniform_model_character_view_uLightsIndex, 4 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_character_view ); glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms, skeleton->bone_count, diff --git a/player_skate.c b/player_skate.c index b39b016..41e03a4 100644 --- a/player_skate.c +++ b/player_skate.c @@ -1493,8 +1493,12 @@ static void skate_adjust_up_direction(void){ 8.0f * player_skate.substep_delta, state->up_dir ); } else{ - v3_lerp( state->up_dir, localplayer.basis[1], - 12.0f * player_skate.substep_delta, state->up_dir ); + v3f avg; + v3_add( localplayer.rb.to_world[1], localplayer.basis[1], avg ); + v3_normalize( avg ); + + v3_lerp( state->up_dir, avg, + 6.0f * player_skate.substep_delta, state->up_dir ); } } diff --git a/world_render.c b/world_render.c index 2d23737..022556d 100644 --- a/world_render.c +++ b/world_render.c @@ -104,24 +104,21 @@ static void world_render_init(void) vg_async_call( async_world_render_init, NULL, 0 ); } -static void world_link_lighting_ub( world_instance *world, GLuint shader ) -{ +static void world_link_lighting_ub( world_instance *world, GLuint shader ){ GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" ); glUniformBlockBinding( shader, idx, world->ubo_bind_point ); } static void world_bind_position_texture( world_instance *world, GLuint shader, GLuint location, - int slot ) -{ + int slot ){ render_fb_bind_texture( &world->heightmap, 0, slot ); glUniform1i( location, slot ); } static void world_bind_light_array( world_instance *world, GLuint shader, GLuint location, - int slot ) -{ + int slot ){ glActiveTexture( GL_TEXTURE0 + slot ); glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities ); glUniform1i( location, slot ); @@ -129,8 +126,7 @@ static void world_bind_light_array( world_instance *world, static void world_bind_light_index( world_instance *world, GLuint shader, GLuint location, - int slot ) -{ + int slot ){ glActiveTexture( GL_TEXTURE0 + slot ); glBindTexture( GL_TEXTURE_3D, world->tex_light_cubes ); glUniform1i( location, slot ); @@ -267,8 +263,7 @@ static void bindpoint_diffuse1_and_cubemap10( world_instance *world, shader_scene_cubemapped_uColour( mat->info.colour ); } -static void render_world_vb( world_instance *world, camera *cam ) -{ +static void render_world_vb( world_instance *world, camera *cam ){ shader_scene_vertex_blend_use(); shader_scene_vertex_blend_uTexGarbage(0); shader_scene_vertex_blend_uTexGradients(1); @@ -627,20 +622,12 @@ static void bindpoint_override( world_instance *world, } } -static void render_terrain( world_instance *world, camera *cam ) -{ +static void render_terrain( world_instance *world, camera *cam ){ shader_scene_terrain_use(); shader_scene_terrain_uTexGarbage(0); shader_scene_terrain_uTexGradients(1); - world_link_lighting_ub( world, _shader_scene_terrain.id ); - world_bind_position_texture( world, _shader_scene_terrain.id, - _uniform_scene_terrain_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_terrain.id, - _uniform_scene_terrain_uLightsArray, 3 ); - world_bind_light_index( world, _shader_scene_terrain.id, - _uniform_scene_terrain_uLightsIndex, 4 ); - + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_terrain ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, world_render.tex_terrain_noise ); @@ -902,14 +889,7 @@ static void render_world_override( world_instance *world ){ shader_scene_override_uTexMain(1); shader_scene_override_uPv( pass.cam->mtx.pv ); - world_link_lighting_ub( world, _shader_scene_override.id ); - world_bind_position_texture( world, _shader_scene_override.id, - _uniform_scene_override_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_override.id, - _uniform_scene_override_uLightsArray, 3 ); - world_bind_light_index( world, _shader_scene_override.id, - _uniform_scene_override_uLightsIndex, 4 ); - + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_override ); bind_terrain_noise(); shader_scene_override_uCamera( pass.cam->transform[3] ); @@ -989,8 +969,7 @@ static void render_world_cubemaps( world_instance *world ){ } } -static void render_world_depth( world_instance *world, camera *cam ) -{ +static void render_world_depth( world_instance *world, camera *cam ){ m4x3f identity_matrix; m4x3_identity( identity_matrix ); @@ -1005,8 +984,7 @@ static void render_world_depth( world_instance *world, camera *cam ) mesh_draw( &world->mesh_geo ); } -static void render_world_position( world_instance *world, camera *cam ) -{ +static void render_world_position( world_instance *world, camera *cam ){ m4x3f identity_matrix; m4x3_identity( identity_matrix ); diff --git a/world_render.h b/world_render.h index ac0a0f2..3050a69 100644 --- a/world_render.h +++ b/world_render.h @@ -79,4 +79,13 @@ static void render_world( world_instance *world, camera *cam, static void render_world_cubemaps( world_instance *world ); static void bind_terrain_noise(void); +#define WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( WORLD, SHADER ) \ + world_link_lighting_ub( WORLD, _shader_##SHADER.id ); \ + world_bind_position_texture( WORLD, _shader_##SHADER.id, \ + _uniform_##SHADER##_g_world_depth, 2 ); \ + world_bind_light_array( WORLD, _shader_##SHADER.id, \ + _uniform_##SHADER##_uLightsArray, 3 ); \ + world_bind_light_index( WORLD, _shader_##SHADER.id, \ + _uniform_##SHADER##_uLightsIndex, 4 ); + #endif /* WORLD_RENDER_H */ diff --git a/world_routes.c b/world_routes.c index beb4c2c..4998cc1 100644 --- a/world_routes.c +++ b/world_routes.c @@ -27,14 +27,14 @@ void world_routes_local_set_record( world_instance *world, ent_route *route, { vg_success( " NEW LAP TIME: %f\n", lap_time ); - if( route->official_track_id != 0xffffffff ){ + if( route->anon.official_track_id != 0xffffffff ){ double time_centiseconds = lap_time * 100.0; if( time_centiseconds > (float)0xfffe ) /* skill issue */ return; - struct track_info *ti = &track_infos[ route->official_track_id ]; + struct track_info *ti = &track_infos[ route->anon.official_track_id ]; highscore_record *record = &ti->record; - record->trackid = route->official_track_id; + record->trackid = route->anon.official_track_id; record->datetime = time(NULL); record->playerid = 0; record->points = 0; @@ -889,13 +889,13 @@ static void world_gen_routes_ent_init( world_instance *world ){ for( u32 i=0; ient_route); i++ ){ ent_route *route = mdl_arritm(&world->ent_route,i); - mdl_transform_m4x3( &route->transform, route->board_transform ); + mdl_transform_m4x3( &route->anon.transform, route->board_transform ); - route->official_track_id = 0xffffffff; + route->anon.official_track_id = 0xffffffff; for( u32 j=0; jmeta,route->pstr_name))){ - route->official_track_id = j; + route->anon.official_track_id = j; } } diff --git a/world_sfd.c b/world_sfd.c index d960b0d..a92a4b0 100644 --- a/world_sfd.c +++ b/world_sfd.c @@ -4,9 +4,10 @@ #include "world_sfd.h" #include "shaders/scene_scoretext.h" #include "shaders/scene_vertex_blend.h" +#include "network.h" +#include "entity.h" -static f32 sfd_encode_glyph( char c ) -{ +static f32 sfd_encode_glyph( char c ){ int value = 0; if( c >= 'a' && c <= 'z' ) value = c-'a'+11; @@ -74,13 +75,12 @@ static void world_sfd_update( world_instance *world, v3f pos ){ } } - if( (world_sfd.active_route_board != closest) || network_scores_updated ) - { + if( (world_sfd.active_route_board != closest) || network_scores_updated ){ network_scores_updated = 0; world_sfd.active_route_board = closest; ent_route *route = mdl_arritm( &world->ent_route, closest ); - u32 id = route->official_track_id; + u32 id = route->anon.official_track_id; if( id != 0xffffffff ){ struct netmsg_board *local_board = @@ -114,19 +114,11 @@ static void world_sfd_update( world_instance *world, v3f pos ){ } static void bind_terrain_noise(void); -static void sfd_render( world_instance *world, camera *cam, m4x3f transform ) -{ +static void sfd_render( world_instance *world, camera *cam, m4x3f transform ){ mesh_bind( &world_sfd.mesh_display ); shader_scene_scoretext_use(); shader_scene_scoretext_uTexMain(1); - - world_link_lighting_ub( world, _shader_scene_scoretext.id ); - world_bind_position_texture( world, _shader_scene_scoretext.id, - _uniform_scene_scoretext_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_scoretext.id, - _uniform_scene_scoretext_uLightsArray, 3 ); - world_bind_light_index( world, _shader_scene_scoretext.id, - _uniform_scene_scoretext_uLightsIndex, 4 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_scoretext ); bind_terrain_noise(); @@ -153,13 +145,8 @@ static void sfd_render( world_instance *world, camera *cam, m4x3f transform ) shader_scene_vertex_blend_use(); shader_scene_vertex_blend_uTexGarbage(0); shader_scene_vertex_blend_uTexGradients(1); - world_link_lighting_ub( world, _shader_scene_vertex_blend.id ); - world_bind_position_texture( world, _shader_scene_vertex_blend.id, - _uniform_scene_vertex_blend_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_vertex_blend.id, - _uniform_scene_vertex_blend_uLightsArray, 3 ); - world_bind_light_index( world, _shader_scene_vertex_blend.id, - _uniform_scene_vertex_blend_uLightsIndex, 4 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_vertex_blend ); + bind_terrain_noise(); glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, world_sfd.tex_scoretex ); @@ -173,8 +160,7 @@ static void sfd_render( world_instance *world, camera *cam, m4x3f transform ) mdl_draw_submesh( &world_sfd.sm_base ); } -static int world_sfd_test( int argc, const char *argv[] ) -{ +static int world_sfd_test( int argc, const char *argv[] ){ if( argc == 2 ){ int row = vg_min( vg_max(atoi(argv[0]),0), world_sfd.h); sfd_encode( row, argv[1] ); @@ -183,8 +169,7 @@ static int world_sfd_test( int argc, const char *argv[] ) return 0; } -static void world_sfd_init(void) -{ +static void world_sfd_init(void){ vg_info( "world_sfd_init\n" ); shader_scene_scoretext_register(); vg_console_reg_cmd( "sfd", world_sfd_test, NULL ); diff --git a/world_water.c b/world_water.c index 87b5a62..980ae02 100644 --- a/world_water.c +++ b/world_water.c @@ -12,8 +12,7 @@ #include "shaders/scene_water_fast.h" #include "scene.h" -static void world_water_init(void) -{ +static void world_water_init(void){ vg_info( "world_water_init\n" ); shader_scene_water_register(); shader_scene_water_fast_register(); @@ -25,8 +24,7 @@ static void world_water_init(void) vg_success( "done\n" ); } -static void water_set_surface( world_instance *world, float height ) -{ +static void water_set_surface( world_instance *world, float height ){ world->water.height = height; v4_copy( (v4f){ 0.0f, 1.0f, 0.0f, height }, world->water.plane ); } @@ -46,8 +44,7 @@ static void world_bind_light_index( world_instance *world, * Does not write motion vectors */ static void render_water_texture( world_instance *world, camera *cam, - int layer_depth ) -{ + int layer_depth ){ if( !world->water.enabled || (vg.quality_profile == k_quality_profile_low) ) return; @@ -121,8 +118,7 @@ static void render_water_texture( world_instance *world, camera *cam, //glViewport( 0,0, g_render_x, g_render_y ); } -static void render_water_surface( world_instance *world, camera *cam ) -{ +static void render_water_surface( world_instance *world, camera *cam ){ if( !world->water.enabled ) return; @@ -141,16 +137,10 @@ static void render_water_surface( world_instance *world, camera *cam ) 1.0f / (float)vg.window_x, 1.0f / (float)vg.window_y }); - world_link_lighting_ub( world, _shader_scene_water.id ); - world_bind_position_texture( world, _shader_scene_water.id, - _uniform_scene_water_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_water.id, - _uniform_scene_water_uLightsArray, 4 ); - world_bind_light_index( world, _shader_scene_water.id, - _uniform_scene_water_uLightsIndex, 5 ); + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_water ); - render_fb_bind_texture( gpipeline.fb_water_beneath, 0, 3 ); - shader_scene_water_uTexBack( 3 ); + render_fb_bind_texture( gpipeline.fb_water_beneath, 0, 5 ); + shader_scene_water_uTexBack( 5 ); shader_scene_water_uTime( world_static.time ); shader_scene_water_uCamera( cam->transform[3] ); shader_scene_water_uSurfaceY( world->water.height ); @@ -191,11 +181,8 @@ static void render_water_surface( world_instance *world, camera *cam ) shader_scene_water_fast_uTime( world_static.time ); shader_scene_water_fast_uCamera( cam->transform[3] ); shader_scene_water_fast_uSurfaceY( world->water.height ); - world_link_lighting_ub( world, _shader_scene_water_fast.id ); - world_bind_position_texture( world, _shader_scene_water_fast.id, - _uniform_scene_water_fast_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_water_fast.id, - _uniform_scene_water_fast_uLightsArray, 4 ); + + WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, scene_water_fast ); m4x3f full; m4x3_identity( full ); -- 2.25.1