#include "bvh.h"
#include "lighting.h"
#include "model.h"
-#include "traffic.h"
+
+#include "traffic.h" /*TODO: -> world_traffic.h */
+#include "world_routes.h"
#include "shaders/terrain.h"
#include "shaders/sky.h"
#include "shaders/vblend.h"
#include "shaders/gpos.h"
#include "shaders/fscolour.h"
+#include "shaders/alphatest.h"
static struct gworld
{
spawns[32];
u32 spawn_count;
+ struct subworld_routes routes;
+
+ /* ...
+ struct subworld_spawns system_spawns;
+ struct subworld_physics system_physics;
+ */
+
teleport_gate gates[64];
u32 gate_count;
traffic_node traffic[128];
u32 traffic_count;
+#if 0
traffic_driver van_man[6];
+#endif
/* Physics */
- rigidbody temp_rbs[128];
- u32 rb_count;
/* Rendering & geometry */
scene geo, foliage;
rigidbody rb_geo;
- mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb;
+ mdl_submesh sm_geo_std_oob, sm_geo_std, sm_geo_vb,
+ sm_foliage_main, sm_foliage_alphatest;
glmesh skybox, skydome;
mdl_submesh dome_upper, dome_lower;
}
world;
+static struct subworld_routes *subworld_routes(void) { return &world.routes; }
+
+
vg_tex2d tex_terrain_colours = { .path = "textures/gradients.qoi",
.flags = VG_TEXTURE_CLAMP|VG_TEXTURE_NEAREST };
vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi",
.flags = VG_TEXTURE_NEAREST };
+vg_tex2d tex_alphatest = { .path = "textures/alphatest.qoi",
+ .flags = VG_TEXTURE_NEAREST };
+
static void ray_world_get_tri( ray_hit *hit, v3f tri[3] )
{
for( int i=0; i<3; i++ )
shader_planeinf_register();
shader_gpos_register();
shader_fscolour_register();
+ shader_alphatest_register();
}
static void world_free(void)
}
}
-static void world_apply_foliage(void)
+static void world_apply_procedural_foliage(void)
{
- scene_init( &world.foliage );
mdl_header *mfoliage = mdl_load("models/rs_foliage.mdl");
v3f volume;
}
}
}
-
- scene_upload( &world.foliage );
free( mfoliage );
}
world.spawn_count = 0;
world.gate_count = 0;
- world.rb_count = 0;
world.traffic_count = 0;
world.instance_cache = NULL;
if( pnode->classtype == k_classtype_none )
{}
+#if 0
else if( pnode->classtype == k_classtype_gate )
{
struct classtype_gate *entgate = mdl_get_entdata( mworld, pnode );
gate_transform_update( gate );
}
}
- else if( pnode->classtype == k_classtype_block )
- {
- struct classtype_block *block = mdl_get_entdata( mworld, pnode );
-
- m4x3f transform;
- mdl_node_transform( pnode, transform );
-
- rigidbody *rb = &world.temp_rbs[ world.rb_count ++ ];
-
- box_copy( block->bbx, rb->bbx ); /* TODO: apply scale */
- v3_copy( pnode->co, rb->co );
- rb_init( rb );
- v4_copy( pnode->q, rb->q );
- rb_update_transform( rb );
- }
+#endif
else if( pnode->classtype == k_classtype_spawn )
{
struct respawn_point *rp = &world.spawns[ world.spawn_count ++ ];
}
}
}
-
+
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
u32 mat_surf = 0,
mat_surf_oob = 0,
- mat_vertex_blend = 0;
+ mat_vertex_blend = 0,
+ mat_alphatest = 0;
for( int i=1; i<mworld->material_count; i++ )
{
mat_surf_oob = i;
else if( !strcmp( "vertex_blend", mat_name ))
mat_vertex_blend = i;
+ else if( !strcmp( "alphatest", mat_name ))
+ mat_alphatest = i;
}
- vg_info( "surf %d\noob %d\nvert_blend %d\n", mat_surf, mat_surf_oob,
- mat_vertex_blend );
-
m4x3f midentity;
m4x3_identity( midentity );
scene_upload( &world.geo );
scene_bh_create( &world.geo );
- world_apply_foliage();
+
+ /* 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 );
+
+ scene_upload( &world.foliage );
+ world_routes_init( mworld );
+
+ for( int i=0; i<world.instance_cache_count; i++ )
+ free( world.instance_cache[i].mdl );
+
free( world.instance_cache );
free( mworld );
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 }, 2 );
+ &tex_terrain_noise,
+ &tex_alphatest }, 3 );
mdl_header *mcars = mdl_load( "models/rs_cars.mdl" );
mdl_unpack_glmesh( mcars, &world.cars );
world.dome_lower = *mdl_node_submesh( msky, nlower, 0 );
world.dome_upper = *mdl_node_submesh( msky, nupper, 0 );
free(msky);
-
- /*
- * 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_update(void)
{
+ world_routes_debug();
+
#if 0
rb_solver_reset();
rb_build_manifold_terrain_sphere( &world.mr_ball );
rb_iter( &world.mr_ball );
rb_update_transform( &world.mr_ball );
rb_debug( &world.mr_ball, 0 );
-#endif
for( int i=0; i<vg_list_size(world.van_man); i++ )
{
traffic_drive( &world.van_man[i] );
traffic_visualize_car( &world.van_man[i] );
}
+#endif
}
/*
mesh_bind( &world.cars );
+#if 0
for( int i=0; i<vg_list_size(world.van_man); i++ )
{
shader_vblend_uMdl( world.van_man[i].transform );
mdl_draw_submesh( &world.car_holden );
}
+#endif
+}
+
+static void render_world_alphatest( m4x4f projection, v3f camera )
+{
+ m4x3f identity_matrix;
+ m4x3_identity( identity_matrix );
+
+ shader_alphatest_use();
+ shader_alphatest_uTexGarbage(0);
+ shader_alphatest_uTexMain(1);
+ shader_link_standard_ub( _shader_alphatest.id, 2 );
+
+ vg_tex2d_bind( &tex_terrain_noise, 0 );
+ vg_tex2d_bind( &tex_alphatest, 1 );
+
+ shader_alphatest_uPv( projection );
+ shader_alphatest_uMdl( identity_matrix );
+ shader_alphatest_uCamera( camera );
+
+ glDisable(GL_CULL_FACE);
+ scene_bind( &world.foliage );
+ mdl_draw_submesh( &world.sm_foliage_alphatest );
+ glEnable(GL_CULL_FACE);
}
static void render_terrain( m4x4f projection, v3f camera )
mdl_draw_submesh( &world.sm_geo_std_oob );
mdl_draw_submesh( &world.sm_geo_std );
+ /* TODO: Dont draw in reflection */
glDisable(GL_CULL_FACE);
scene_bind( &world.foliage );
- scene_draw( &world.foliage );
+ mdl_draw_submesh( &world.sm_foliage_main );
glEnable(GL_CULL_FACE);
}
{
render_sky( camera );
render_world_vb( projection, camera[3] );
+ render_world_alphatest( projection, camera[3] );
render_terrain( projection, camera[3] );
}