From a3c10b9dec1ed7136721695033ebeef30717f249 Mon Sep 17 00:00:00 2001 From: hgn Date: Sun, 6 Nov 2022 07:10:11 +0000 Subject: [PATCH] better low qual mode --- bvh.h | 9 ++++++++- play.sh | 2 +- render.h | 6 ++++++ scene.h | 2 +- shaders/alphatest.h | 6 ++++++ shaders/common_world.glsl | 6 ++++++ shaders/gpos.h | 6 ++++++ shaders/route.h | 6 ++++++ shaders/scoretext.h | 6 ++++++ shaders/standard.h | 6 ++++++ shaders/terrain.h | 6 ++++++ shaders/vblend.h | 6 ++++++ shaders/viewchar.h | 6 ++++++ shaders/water.h | 6 ++++++ shaders/water_fast.h | 6 ++++++ skaterift.c | 2 +- world_gen.h | 3 +++ 17 files changed, 86 insertions(+), 4 deletions(-) diff --git a/bvh.h b/bvh.h index 84f4c6b..9e45286 100644 --- a/bvh.h +++ b/bvh.h @@ -32,6 +32,7 @@ struct bh_tree bh_system *system; void *user; + u32 max_per_leaf; struct bh_node { @@ -77,6 +78,9 @@ VG_STATIC void bh_subdivide( bh_tree *bh, u32 inode ) { bh_node *node = &bh->nodes[ inode ]; + if( node->count <= bh->max_per_leaf ) + return; + v3f extent; v3_sub( node->bbx[1], node->bbx[0], extent ); @@ -135,8 +139,10 @@ VG_STATIC void bh_subdivide( bh_tree *bh, u32 inode ) } VG_STATIC bh_tree *bh_create( void *lin_alloc, bh_system *system, - void *user, u32 item_count ) + void *user, u32 item_count, u32 max_per_leaf ) { + assert( max_per_leaf > 0 ); + if( item_count == 0 ) { bh_tree *bh = vg_linear_alloc( lin_alloc, sizeof(bh_tree) ); @@ -150,6 +156,7 @@ VG_STATIC bh_tree *bh_create( void *lin_alloc, bh_system *system, bh_tree *bh = vg_linear_alloc( lin_alloc, totsize ); bh->system = system; bh->user = user; + bh->max_per_leaf = max_per_leaf; bh_node *root = &bh->nodes[0]; bh->node_count = 1; diff --git a/play.sh b/play.sh index 880141d..b2c57c9 100755 --- a/play.sh +++ b/play.sh @@ -1,3 +1,3 @@ cd bin/skaterift-clang/ -./skaterift +./skaterift $@ cd ../../ diff --git a/render.h b/render.h index 209bed6..317b301 100644 --- a/render.h +++ b/render.h @@ -49,6 +49,7 @@ VG_STATIC struct pipeline float g_water_fog; int g_light_count; int g_light_preview; + int g_shadow_samples; } ub_world_lighting; @@ -169,6 +170,11 @@ VG_STATIC void render_update_lighting_ub(void) winf->g_light_directions[0][3] = gpipeline.shadow_length; winf->g_light_colours[0][3] = gpipeline.shadow_spread; + if( vg.quality_profile == k_quality_profile_low ) + winf->g_shadow_samples = 0; + else + winf->g_shadow_samples = 8; + glBindBuffer( GL_UNIFORM_BUFFER, gpipeline.ubo_world_lighting ); glBufferSubData( GL_UNIFORM_BUFFER, 0, sizeof(struct ub_world_lighting), &gpipeline.ub_world_lighting ); diff --git a/scene.h b/scene.h index 3402075..5d43687 100644 --- a/scene.h +++ b/scene.h @@ -334,7 +334,7 @@ VG_STATIC int scene_raycast( scene *s, bh_tree *bh, VG_STATIC bh_tree *scene_bh_create( void *lin_alloc, scene *s ) { u32 triangle_count = s->indice_count / 3; - return bh_create( lin_alloc, &bh_system_scene, s, triangle_count ); + return bh_create( lin_alloc, &bh_system_scene, s, triangle_count, 2 ); } #endif diff --git a/shaders/alphatest.h b/shaders/alphatest.h index 9b161c1..0790840 100644 --- a/shaders/alphatest.h +++ b/shaders/alphatest.h @@ -67,6 +67,7 @@ static struct vg_shader _shader_alphatest = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -131,6 +132,11 @@ static struct vg_shader _shader_alphatest = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/common_world.glsl b/shaders/common_world.glsl index 5e1a891..d7b3ccf 100644 --- a/shaders/common_world.glsl +++ b/shaders/common_world.glsl @@ -9,6 +9,7 @@ layout (std140) uniform ub_world_lighting float g_water_fog; int g_light_count; int g_light_preview; + int g_shadow_samples; }; uniform sampler2D g_world_depth; @@ -73,6 +74,11 @@ vec3 do_light_shadowing_old( vec3 vfrag ) vec3 do_light_shadowing( vec3 vfrag ) { + if( g_shadow_samples == 0 ) + { + return vfrag; + } + float fspread = g_light_colours[0].w; vec3 vdir = g_light_directions[0].xyz; float flength = g_light_directions[0].w; diff --git a/shaders/gpos.h b/shaders/gpos.h index 8b7dbf4..3c17cbb 100644 --- a/shaders/gpos.h +++ b/shaders/gpos.h @@ -64,6 +64,7 @@ static struct vg_shader _shader_gpos = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -128,6 +129,11 @@ static struct vg_shader _shader_gpos = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/route.h b/shaders/route.h index 271a47f..6ee4761 100644 --- a/shaders/route.h +++ b/shaders/route.h @@ -67,6 +67,7 @@ static struct vg_shader _shader_route = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -131,6 +132,11 @@ static struct vg_shader _shader_route = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/scoretext.h b/shaders/scoretext.h index eea32ee..0a4bc95 100644 --- a/shaders/scoretext.h +++ b/shaders/scoretext.h @@ -85,6 +85,7 @@ static struct vg_shader _shader_scoretext = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -149,6 +150,11 @@ static struct vg_shader _shader_scoretext = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/standard.h b/shaders/standard.h index ac052b0..4f6a629 100644 --- a/shaders/standard.h +++ b/shaders/standard.h @@ -67,6 +67,7 @@ static struct vg_shader _shader_standard = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -131,6 +132,11 @@ static struct vg_shader _shader_standard = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/terrain.h b/shaders/terrain.h index 92143b1..24eb0ea 100644 --- a/shaders/terrain.h +++ b/shaders/terrain.h @@ -68,6 +68,7 @@ static struct vg_shader _shader_terrain = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -132,6 +133,11 @@ static struct vg_shader _shader_terrain = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/vblend.h b/shaders/vblend.h index 61b0cce..0364f65 100644 --- a/shaders/vblend.h +++ b/shaders/vblend.h @@ -66,6 +66,7 @@ static struct vg_shader _shader_vblend = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -130,6 +131,11 @@ static struct vg_shader _shader_vblend = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/viewchar.h b/shaders/viewchar.h index 8e6b8fc..0cd026d 100644 --- a/shaders/viewchar.h +++ b/shaders/viewchar.h @@ -75,6 +75,7 @@ static struct vg_shader _shader_viewchar = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -139,6 +140,11 @@ static struct vg_shader _shader_viewchar = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/water.h b/shaders/water.h index e334a5c..a333516 100644 --- a/shaders/water.h +++ b/shaders/water.h @@ -74,6 +74,7 @@ static struct vg_shader _shader_water = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -138,6 +139,11 @@ static struct vg_shader _shader_water = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/shaders/water_fast.h b/shaders/water_fast.h index 7b92ea8..415d477 100644 --- a/shaders/water_fast.h +++ b/shaders/water_fast.h @@ -71,6 +71,7 @@ static struct vg_shader _shader_water_fast = { " float g_water_fog;\n" " int g_light_count;\n" " int g_light_preview;\n" +" int g_shadow_samples;\n" "};\n" "\n" "uniform sampler2D g_world_depth;\n" @@ -135,6 +136,11 @@ static struct vg_shader _shader_water_fast = { "\n" "vec3 do_light_shadowing( vec3 vfrag )\n" "{\n" +" if( g_shadow_samples == 0 )\n" +" {\n" +" return vfrag;\n" +" }\n" +"\n" " float fspread = g_light_colours[0].w;\n" " vec3 vdir = g_light_directions[0].xyz;\n" " float flength = g_light_directions[0].w;\n" diff --git a/skaterift.c b/skaterift.c index e105621..91e7e01 100644 --- a/skaterift.c +++ b/skaterift.c @@ -177,8 +177,8 @@ VG_STATIC void render_main_game(void) */ int draw_solid = player.is_dead | freecam; - render_world( vg.pv, camera_mtx ); + if( draw_solid ) draw_player( camera_mtx ); diff --git a/world_gen.h b/world_gen.h index 9ee1e6b..147c9af 100644 --- a/world_gen.h +++ b/world_gen.h @@ -36,6 +36,9 @@ VG_STATIC void world_add_all_if_material( m4x3f transform, scene *pscene, /* Sprinkle foliage models over the map on terrain material */ VG_STATIC void world_apply_procedural_foliage( struct world_material *mat ) { + if( vg.quality_profile == k_quality_profile_low ) + return; + vg_linear_clear( vg_mem.scratch ); mdl_context *mfoliage = -- 2.25.1