-
- world.instance_cache = buffer_fix( world.instance_cache,
- world.instance_cache_count,
- &world.instance_cache_cap,
- sizeof( struct instance_cache ) );
-
-#if 0
- traffic_finalize( world.traffic, world.traffic_count );
- for( int i=0; i<vg_list_size(world.van_man); i++ )
- world.van_man[i].current =&world.traffic[vg_randint(world.traffic_count)];
-#endif
-
- /*
- * Compile meshes into the world scenes
- */
- scene_init( &world.geo );
-
- u32 mat_surf = 0,
- mat_surf_oob = 0,
- mat_vertex_blend = 0,
- mat_alphatest = 0,
- mat_graffiti = 0,
- mat_subworld = 0,
- mat_terrain = 0;
-
- for( int i=1; i<mworld->material_count; i++ )
- {
- mdl_material *mat = mdl_material_from_id( mworld, i );
- const char *mat_name = mdl_pstr( mworld, mat->pstr_name );
-
- if( !strcmp( "surf", mat_name ))
- mat_surf = i;
- else if( !strcmp( "surf_oob", mat_name ))
- mat_surf_oob = i;
- else if( !strcmp( "vertex_blend", mat_name ))
- mat_vertex_blend = i;
- else if( !strcmp( "alphatest", mat_name ))
- mat_alphatest = i;
- else if( !strcmp( "graffitibox", mat_name ))
- mat_graffiti = i;
- else if( !strcmp( "terrain", mat_name ) )
- mat_terrain = i;
- }
-
- m4x3f midentity;
- m4x3_identity( midentity );
-
- if( mat_terrain )
- add_all_if_material( midentity, &world.geo, mworld, mat_terrain );
- scene_copy_slice( &world.geo, &world.sm_terrain );
-
- if( mat_surf_oob )
- add_all_if_material( midentity, &world.geo, mworld, mat_surf_oob );
- else
- vg_warn( "No OOB surface\n" );
- scene_copy_slice( &world.geo, &world.sm_geo_std_oob );
-
- if( mat_surf )
- add_all_if_material( midentity, &world.geo, mworld, mat_surf );
- scene_copy_slice( &world.geo, &world.sm_geo_std );
-
- if( mat_vertex_blend )
- add_all_if_material( midentity, &world.geo, mworld, mat_vertex_blend );
- scene_copy_slice( &world.geo, &world.sm_geo_vb );
-
- scene_upload( &world.geo );
- scene_bh_create( &world.geo );
-
-
- /* Foliage /nocollide layer.
- * TODO: Probably should have material traits for this
- */
- scene_init( &world.foliage );
-
- world_apply_procedural_foliage();
- scene_copy_slice( &world.foliage, &world.sm_foliage_main );
-
- add_all_if_material( midentity, &world.foliage, mworld, mat_alphatest );
- scene_copy_slice( &world.foliage, &world.sm_foliage_alphatest );
-
- add_all_if_material( midentity, &world.foliage, mworld, mat_graffiti );
- scene_copy_slice( &world.foliage, &world.sm_graffiti );
-
- scene_upload( &world.foliage );
- world_routes_loadfrom( mworld );
-
- for( int i=0; i<world.instance_cache_count; i++ )
- free( world.instance_cache[i].mdl );
-
- free( world.instance_cache );
- free( mworld );
-
- /*
- * Rendering the depth map
- */
- m4x4f ortho;
- m4x3f camera;
-
- v3f extent;
- v3_sub( world.geo.bbx[1], world.geo.bbx[0], extent );
-
- float fl = world.geo.bbx[0][0],
- fr = world.geo.bbx[1][0],
- fb = world.geo.bbx[0][2],
- ft = world.geo.bbx[1][2],
- rl = 1.0f / (fr-fl),
- tb = 1.0f / (ft-fb);
-
- m4x4_zero( ortho );
- ortho[0][0] = 2.0f * rl;
- ortho[2][1] = 2.0f * tb;
- ortho[3][0] = (fr + fl) * -rl;
- ortho[3][1] = (ft + fb) * -tb;
- ortho[3][3] = 1.0f;
- m4x3_identity( camera );
-
- glViewport( 0, 0, 1024, 1024 );
- glDisable(GL_DEPTH_TEST);
- glBindFramebuffer( GL_FRAMEBUFFER, gpipeline.fb_depthmap );
- shader_fscolour_use();
- shader_fscolour_uColour( (v4f){-9999.0f,-9999.0f,-9999.0f,-9999.0f} );
- render_fsquad();
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE);
- glBlendEquation(GL_MAX);
- render_world_depth( ortho, camera );
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
-
- /*
- * TODO: World settings entity
- */
- struct ub_world_lighting *winfo = &gpipeline.ub_world_lighting;
- v4_copy( wrender.plane, winfo->g_water_plane );
-
- v4f bounds;
- bounds[0] = world.geo.bbx[0][0];
- bounds[1] = world.geo.bbx[0][2];
- bounds[2] = 1.0f/ (world.geo.bbx[1][0]-world.geo.bbx[0][0]);
- bounds[3] = 1.0f/ (world.geo.bbx[1][2]-world.geo.bbx[0][2]);
- v4_copy( bounds, winfo->g_depth_bounds );
-
- winfo->g_water_fog = 0.04f;
- render_update_lighting_ub();
-
-
- world.mr_ball.type = k_rb_shape_sphere;
- world.mr_ball.inf.sphere.radius = 2.0f;
- v3_copy( (v3f){ 0.0f, 110.0f, 0.0f }, world.mr_ball.co );
-
- q_identity(world.mr_ball.q);
- rb_init( &world.mr_ball );
-
- /*
- * Setup scene collider
- */
- v3_zero( world.rb_geo.co );
- q_identity( world.rb_geo.q );
-
- world.rb_geo.type = k_rb_shape_scene;
- world.rb_geo.inf.scene.pscene = &world.geo;
- world.rb_geo.is_world = 1;
- rb_init( &world.rb_geo );
-}
-
-static void world_init(void)
-{
- vg_tex2d_init( (vg_tex2d *[]){ &tex_terrain_colours,
- &tex_terrain_noise,
- &tex_alphatest,
- &tex_graffiti }, 4 );
-
- mdl_header *mcars = mdl_load( "models/rs_cars.mdl" );
- mdl_unpack_glmesh( mcars, &world.cars );
- mdl_node *nholden = mdl_node_from_name( mcars, "holden" );
- world.car_holden = *mdl_node_submesh( mcars, nholden, 0 );
- free(mcars);
-
-
- mdl_header *msky = mdl_load("models/rs_skydome.mdl");
- mdl_unpack_glmesh( msky, &world.skydome );
-
- mdl_node *nlower = mdl_node_from_name( msky, "dome_lower" ),
- *nupper = mdl_node_from_name( msky, "dome_upper" );