+
+static void render_world_override_pass( world_instance *world,
+ struct world_pass *pass,
+ m4x3f mmdl, m3x3f mnormal,
+ m4x4f mpvm_prev ){
+ for( int i=0; i<world->surface_count; i++ ){
+ struct world_surface *mat = &world->surfaces[i];
+ if( mat->info.flags & k_material_flag_ghosts ) continue;
+
+ mdl_submesh *sm;
+ if( pass->geo_type == k_world_geo_type_solid )
+ sm = &mat->sm_geo;
+ else
+ sm = &mat->sm_no_collide;
+
+ if( !sm->indice_count )
+ continue;
+
+ pass->fn_set_mdl( mmdl );
+ pass->fn_set_uNormalMtx( mnormal );
+ pass->fn_set_uPvmPrev( mpvm_prev );
+ pass->fn_bind_textures( world, mat );
+ mdl_draw_submesh( sm );
+ }
+}
+
+void render_world_override( world_instance *world,
+ world_instance *lighting_source,
+ m4x3f mmdl,
+ vg_camera *cam,
+ ent_spawn *dest_spawn, v4f map_info )
+{
+ struct world_pass pass = {
+ .cam = 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
+ };
+
+ shader_scene_override_use();
+ shader_scene_override_uTexGarbage(0);
+ shader_scene_override_uTexMain(1);
+ shader_scene_override_uPv( pass.cam->mtx.pv );
+ shader_scene_override_uMapInfo( map_info );
+
+ WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( lighting_source, scene_override );
+ bind_terrain_noise();
+
+ shader_scene_override_uCamera( pass.cam->transform[3] );
+
+ m4x4f mpvm_prev;
+ m4x3_expand( mmdl, mpvm_prev );
+ m4x4_mul( cam->mtx_prev.pv, mpvm_prev, mpvm_prev );
+
+ m3x3f mnormal;
+ m3x3_inv( mmdl, mnormal );
+ m3x3_transpose( mnormal, mnormal );
+ v3_normalize( mnormal[0] );
+ v3_normalize( mnormal[1] );
+ v3_normalize( mnormal[2] );
+
+ v4f uPlayerPos, uSpawnPos;
+ v4_zero( uPlayerPos );
+ v4_zero( uSpawnPos );
+
+ v3_copy( world->player_co, uPlayerPos );
+
+ if( dest_spawn && (v3_dist2(dest_spawn->transform.co,uPlayerPos) > 0.1f) )
+ v3_copy( dest_spawn->transform.co, uSpawnPos );
+ else
+ v3_add( uPlayerPos, (v3f){0,-1,0}, uSpawnPos );
+
+ uPlayerPos[3] = v3_dist(uPlayerPos,uSpawnPos);
+ uSpawnPos[3] = 1.0f/uPlayerPos[3];
+
+ shader_scene_override_uPlayerPos( uPlayerPos );
+ shader_scene_override_uSpawnPos( uSpawnPos );
+
+
+ glDisable( GL_CULL_FACE );
+ mesh_bind( &world->mesh_geo );
+ pass.geo_type = k_world_geo_type_solid;
+ 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, mmdl, mnormal, mpvm_prev );
+ glEnable( GL_CULL_FACE );
+
+ render_world_fxglow( world, world, cam, mmdl, 0, 0, 1 );
+}
+
+static void render_cubemap_side( world_instance *world, ent_cubemap *cm,
+ u32 side ){
+ vg_camera cam;
+ glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_CUBE_MAP_POSITIVE_X + side, cm->texture_id, 0 );
+ glClear( GL_DEPTH_BUFFER_BIT );
+
+ v3f forward[6] = {
+ { -1.0f, 0.0f, 0.0f },
+ { 1.0f, 0.0f, 0.0f },
+ { 0.0f, -1.0f, 0.0f },
+ { 0.0f, 1.0f, 0.0f },
+ { 0.0f, 0.0f, -1.0f },
+ { 0.0f, 0.0f, 1.0f }
+ };
+ v3f up[6] = {
+ { 0.0f, -1.0f, 0.0f },
+ { 0.0f, -1.0f, 0.0f },
+ { 0.0f, 0.0f, 1.0f },
+ { 0.0f, 0.0f, -1.0f },
+ { 0.0f, -1.0f, 0.0f },
+ { 0.0f, -1.0f, 0.0f }
+ };
+
+ v3_zero( cam.angles );
+ v3_copy( cm->co, cam.pos );
+
+ v3_copy( forward[side], cam.transform[2] );
+ v3_copy( up[side], cam.transform[1] );
+ v3_cross( up[side], forward[side], cam.transform[0] );
+ v3_copy( cm->co, cam.transform[3] );
+ m4x3_invert_affine( cam.transform, cam.transform_inverse );
+
+ vg_camera_update_view( &cam );
+
+ cam.nearz = 0.1f;
+ cam.farz = 1000.0f;
+ cam.fov = 90.0f;
+ m4x4_copy( cam.mtx.p, cam.mtx_prev.p );
+ m4x4_projection( cam.mtx.p, cam.fov, 1.0f, cam.nearz, cam.farz );
+ vg_camera_finalize( &cam );
+ vg_camera_finalize( &cam );
+
+ render_world( world, &cam, 0, 1, 1, 0 );
+}
+
+void render_world_cubemaps( world_instance *world )
+{
+ if( world->cubemap_cooldown )
+ world->cubemap_cooldown --;
+ else{
+ world->cubemap_cooldown = 60;
+
+ glViewport( 0, 0, WORLD_CUBEMAP_RES, WORLD_CUBEMAP_RES );
+ for( u32 i=0; i<mdl_arrcount( &world->ent_cubemap ); i++ ){
+ ent_cubemap *cm = mdl_arritm( &world->ent_cubemap, i );
+ glBindFramebuffer( GL_FRAMEBUFFER, cm->framebuffer_id );
+
+ world->cubemap_side ++;
+ if( world->cubemap_side >= 6 )
+ world->cubemap_side = 0;
+
+ render_cubemap_side( world, cm, world->cubemap_side );
+ }
+ }
+}
+
+/*
+ * Geo shaders
+ * ---------------------------------------------
+ */
+
+void render_world_depth( world_instance *world, vg_camera *cam )