From: hgn Date: Mon, 20 Nov 2023 10:34:44 +0000 (+0000) Subject: render routes in mini-world X-Git-Url: https://harrygodden.com/git/?a=commitdiff_plain;h=43dc3602effdf0af4f22ce78c0e76565c0be03e6;p=carveJwlIkooP6JGAAIwe30JlM.git render routes in mini-world --- diff --git a/build.c b/build.c index 0470a3b..596c698 100644 --- a/build.c +++ b/build.c @@ -249,7 +249,7 @@ void build_shaders(void){ _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" ); - _S( "scene_route", "scene.vs", "scene_route.fs" ); + _S( "scene_route", "scene_override.vs", "scene_route.fs" ); _S( "scene_depth", "scene.vs", "scene_depth.fs" ); _S( "scene_position", "scene.vs", "scene_position.fs" ); _S( "scene_cubemapped", "scene.vs", "scene_cubemapped.fs" ); diff --git a/ent_miniworld.c b/ent_miniworld.c index 9c439c7..08e7093 100644 --- a/ent_miniworld.c +++ b/ent_miniworld.c @@ -57,7 +57,7 @@ static void ent_miniworld_render( world_instance *host_world, camera *cam ){ m4x3f mmdl; mdl_transform_m4x3( &miniworld->transform, mmdl ); render_world_override( dest_world, host_world, mmdl, cam ); - //render_world_routes( , &skaterift.cam, 1 ); + render_world_routes( dest_world, host_world, mmdl, cam, 0, 1 ); } static void ent_miniworld_preupdate(void){ diff --git a/shaders/scene_route.h b/shaders/scene_route.h index 8e3cc10..eea0c75 100644 --- a/shaders/scene_route.h +++ b/shaders/scene_route.h @@ -7,7 +7,7 @@ static struct vg_shader _shader_scene_route = { .link = shader_scene_route_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_route = { "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_route = { " gl_Position = vproj0;\n" "\n" " aUv = a_uv;\n" -" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n" +" aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n" " aCo = a_co;\n" " aWorldCo = world_pos0;\n" "}\n" @@ -508,6 +509,7 @@ static struct vg_shader _shader_scene_route = { static GLuint _uniform_scene_route_uMdl; static GLuint _uniform_scene_route_uPv; static GLuint _uniform_scene_route_uPvmPrev; +static GLuint _uniform_scene_route_uNormalMtx; static GLuint _uniform_scene_route_uTexGarbage; static GLuint _uniform_scene_route_uTexGradients; static GLuint _uniform_scene_route_uCamera; @@ -524,6 +526,9 @@ static void shader_scene_route_uPv(m4x4f m){ static void shader_scene_route_uPvmPrev(m4x4f m){ glUniformMatrix4fv(_uniform_scene_route_uPvmPrev,1,GL_FALSE,(float*)m); } +static void shader_scene_route_uNormalMtx(m3x3f m){ + glUniformMatrix3fv(_uniform_scene_route_uNormalMtx,1,GL_FALSE,(float*)m); +} static void shader_scene_route_uTexGarbage(int i){ glUniform1i(_uniform_scene_route_uTexGarbage,i); } @@ -547,6 +552,7 @@ static void shader_scene_route_link(void){ _uniform_scene_route_uMdl = glGetUniformLocation( _shader_scene_route.id, "uMdl" ); _uniform_scene_route_uPv = glGetUniformLocation( _shader_scene_route.id, "uPv" ); _uniform_scene_route_uPvmPrev = glGetUniformLocation( _shader_scene_route.id, "uPvmPrev" ); + _uniform_scene_route_uNormalMtx = glGetUniformLocation( _shader_scene_route.id, "uNormalMtx" ); _uniform_scene_route_uTexGarbage = glGetUniformLocation( _shader_scene_route.id, "uTexGarbage" ); _uniform_scene_route_uTexGradients = glGetUniformLocation( _shader_scene_route.id, "uTexGradients" ); _uniform_scene_route_uCamera = glGetUniformLocation( _shader_scene_route.id, "uCamera" ); diff --git a/world_render.c b/world_render.c index cdbe37e..b63d8a7 100644 --- a/world_render.c +++ b/world_render.c @@ -847,7 +847,9 @@ static void render_world( world_instance *world, camera *cam, render_sky( world, cam ); - render_world_routes( world, cam, viewing_from_gate ); + m4x3f identity; + m4x3_identity(identity); + render_world_routes( world, world, identity, cam, viewing_from_gate, 0 ); render_world_standard( world, cam ); render_world_cubemapped( world, cam, with_cubemaps ); diff --git a/world_routes.c b/world_routes.c index e4b444a..d710e5e 100644 --- a/world_routes.c +++ b/world_routes.c @@ -852,11 +852,12 @@ static void world_routes_fracture( world_instance *world, ent_gate *gate, } } -static void render_gate_markers( int run_id, ent_gate *gate ){ +static void render_gate_markers( m4x3f world_mmdl, int run_id, ent_gate *gate ){ for( u32 j=0; j<4; j++ ){ if( gate->routes[j] == run_id ){ m4x3f mmdl; ent_gate_get_mdl_mtx( gate, mmdl ); + m4x3_mul( world_mmdl, mmdl, mmdl ); shader_model_gate_uMdl( mmdl ); mdl_draw_submesh( &world_gates.sm_marker[j] ); break; @@ -864,25 +865,47 @@ static void render_gate_markers( int run_id, ent_gate *gate ){ } } -static void render_world_routes( world_instance *world, camera *cam, - int viewing_from_gate ){ - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); +static void render_world_routes( world_instance *world, + world_instance *host_world, + m4x3f mmdl, camera *cam, + int viewing_from_gate, int viewing_from_hub ){ shader_scene_route_use(); shader_scene_route_uTexGarbage(0); - world_link_lighting_ub( world, _shader_scene_route.id ); - world_bind_position_texture( world, _shader_scene_route.id, + world_link_lighting_ub( host_world, _shader_scene_route.id ); + world_bind_position_texture( host_world, _shader_scene_route.id, _uniform_scene_route_g_world_depth, 2 ); - world_bind_light_array( world, _shader_scene_route.id, + world_bind_light_array( host_world, _shader_scene_route.id, _uniform_scene_route_uLightsArray, 3 ); - world_bind_light_index( world, _shader_scene_route.id, + world_bind_light_index( host_world, _shader_scene_route.id, _uniform_scene_route_uLightsIndex, 4 ); bind_terrain_noise(); shader_scene_route_uPv( cam->mtx.pv ); - shader_scene_route_uPvmPrev( cam->mtx_prev.pv ); - shader_scene_route_uMdl( identity_matrix ); + + if( viewing_from_hub ){ + m4x4f m4mdl, pvm; + m4x3_expand( mmdl, m4mdl ); + m4x4_mul( cam->mtx_prev.pv, m4mdl, pvm ); + shader_scene_route_uMdl( mmdl ); + shader_scene_route_uPvmPrev( pvm ); + + m3x3f mnormal; + m3x3_inv( mmdl, mnormal ); + m3x3_transpose( mnormal, mnormal ); + v3_normalize( mnormal[0] ); + v3_normalize( mnormal[1] ); + v3_normalize( mnormal[2] ); + shader_scene_route_uNormalMtx( mnormal ); + } + else{ + shader_scene_route_uMdl( mmdl ); + shader_scene_route_uPvmPrev( cam->mtx_prev.pv ); + m3x3f ident; + m3x3_identity( ident ); + shader_scene_route_uNormalMtx( ident ); + } + shader_scene_route_uCamera( cam->transform[3] ); mesh_bind( &world->mesh_route_lines ); @@ -890,9 +913,11 @@ static void render_world_routes( world_instance *world, camera *cam, for( u32 i=0; ient_route); i++ ){ ent_route *route = mdl_arritm( &world->ent_route, i ); + f32 t = viewing_from_hub? 1.0f: route->factive; + v4f colour; - v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour ); - colour[3] = route->factive*0.2f; + v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, t, colour ); + colour[3] = t*0.2f; shader_scene_route_uColour( colour ); mdl_draw_submesh( &route->sm ); @@ -900,7 +925,7 @@ static void render_world_routes( world_instance *world, camera *cam, /* timers * ---------------------------------------------------- */ - if( !viewing_from_gate ){ + if( !viewing_from_gate && !viewing_from_hub ){ font3d_bind( &gui.font, k_font_shader_default, 0, world, cam ); for( u32 i=0; ient_route); i++ ){ ent_route *route = mdl_arritm( &world->ent_route, i ); @@ -971,7 +996,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_DELETED) ) - render_gate_markers( i, gate ); + render_gate_markers( mmdl, i, gate ); } } } @@ -993,7 +1018,7 @@ static void render_world_routes( world_instance *world, camera *cam, ent_checkpoint *cp = mdl_arritm( &world->ent_checkpoint, next ); ent_gate *gate = mdl_arritm( &world->ent_gate, cp->gate_index ); - render_gate_markers( i, gate ); + render_gate_markers( mmdl, i, gate ); } } } diff --git a/world_routes.h b/world_routes.h index 636793d..5fccc9e 100644 --- a/world_routes.h +++ b/world_routes.h @@ -13,8 +13,10 @@ static void world_routes_fracture( world_instance *world, ent_gate *gate, v3f imp_co, v3f imp_v ); static void world_routes_activate_entry_gate( world_instance *world, ent_gate *rg ); -static void render_world_routes( world_instance *world, camera *cam, - int layer_depth ); +static void render_world_routes( world_instance *world, + world_instance *host_world, + m4x3f mmdl, camera *cam, + int viewing_from_gate, int viewing_from_hub ); static void world_gen_routes_ent_init( world_instance *world ); static void world_gen_routes_generate( u32 instance_id );