X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_render.h;h=e738d372dd59d019011595e32f80829f85ac7146;hb=aa4c26eae2208872824e0eb5b71bc05c16d43242;hp=ae9399bf8e02d711484159672c0384bd8aaabc9b;hpb=0ae443b3f6b4b753f9a2eba58da597ae8cb14b4f;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_render.h b/world_render.h index ae9399b..e738d37 100644 --- a/world_render.h +++ b/world_render.h @@ -5,10 +5,12 @@ #ifndef WORLD_RENDER_H #define WORLD_RENDER_H +#include "camera.h" #include "world.h" -vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi", - .flags = VG_TEXTURE_NEAREST }; +/* FIXME */ +VG_STATIC vg_tex2d tex_terrain_noise = { .path = "textures/garbage.qoi", + .flags = VG_TEXTURE_NEAREST }; VG_STATIC void world_render_init(void) { @@ -21,7 +23,7 @@ VG_STATIC void world_render_init(void) vg_release_thread_sync(); } -VG_STATIC void render_world_depth( m4x4f projection, m4x3f camera ); +VG_STATIC void render_world_depth( camera *cam ); /* * Rendering @@ -64,8 +66,11 @@ VG_STATIC void world_render_both_stages( enum mdl_shader shader, { mesh_bind( &world.mesh_geo ); world_render_if( shader, k_geo_type_solid, bind_point ); + + glDisable( GL_CULL_FACE ); mesh_bind( &world.mesh_no_collide ); world_render_if( shader, k_geo_type_nonsolid, bind_point ); + glEnable( GL_CULL_FACE ); } VG_STATIC void bindpoint_diffuse_texture1( struct world_material *mat ) @@ -74,58 +79,67 @@ VG_STATIC void bindpoint_diffuse_texture1( struct world_material *mat ) glBindTexture( GL_TEXTURE_2D, world.textures[ mat->info.tex_diffuse ] ); } -VG_STATIC void render_world_vb( m4x4f projection, v3f camera ) +VG_STATIC void render_world_vb( camera *cam ) { m4x3f identity_matrix; m4x3_identity( identity_matrix ); - shader_vblend_use(); - shader_vblend_uTexGarbage(0); - shader_vblend_uTexGradients(1); - shader_link_standard_ub( _shader_vblend.id, 2 ); + shader_scene_vertex_blend_use(); + shader_scene_vertex_blend_uTexGarbage(0); + shader_scene_vertex_blend_uTexGradients(1); + shader_link_standard_ub( _shader_scene_vertex_blend.id, 2 ); vg_tex2d_bind( &tex_terrain_noise, 0 ); - shader_vblend_uPv( projection ); - shader_vblend_uMdl( identity_matrix ); - shader_vblend_uCamera( camera ); + shader_scene_vertex_blend_uPv( cam->mtx.pv ); + shader_scene_vertex_blend_uPvmPrev( cam->mtx_prev.pv ); + shader_scene_vertex_blend_uMdl( identity_matrix ); + shader_scene_vertex_blend_uCamera( cam->transform[3] ); + shader_scene_vertex_blend_uBoard0( TEMP_BOARD_0 ); + shader_scene_vertex_blend_uBoard1( TEMP_BOARD_1 ); - world_render_both_stages( k_shader_standard_vertex_blend, + world_render_both_stages( k_shader_standard_vertex_blend, bindpoint_diffuse_texture1 ); } -VG_STATIC void render_world_standard( m4x4f projection, v3f camera ) +VG_STATIC void render_world_standard( camera *cam ) { m4x3f identity_matrix; m4x3_identity( identity_matrix ); - shader_standard_use(); - shader_standard_uTexGarbage(0); - shader_standard_uTexMain(1); - shader_link_standard_ub( _shader_standard.id, 2 ); + shader_scene_standard_use(); + shader_scene_standard_uTexGarbage(0); + shader_scene_standard_uTexMain(1); + shader_scene_standard_uPv( cam->mtx.pv ); + shader_scene_standard_uPvmPrev( cam->mtx_prev.pv ); + shader_link_standard_ub( _shader_scene_standard.id, 2 ); bind_terrain_noise(); - shader_standard_uPv( projection ); - shader_standard_uMdl( identity_matrix ); - shader_standard_uCamera( camera ); + shader_scene_standard_uMdl( identity_matrix ); + shader_scene_standard_uCamera( cam->transform[3] ); + shader_scene_standard_uBoard0( TEMP_BOARD_0 ); + shader_scene_standard_uBoard1( TEMP_BOARD_1 ); world_render_both_stages( k_shader_standard, bindpoint_diffuse_texture1 ); } -VG_STATIC void render_world_alphatest( m4x4f projection, v3f camera ) +VG_STATIC void render_world_alphatest( camera *cam ) { 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 ); + shader_scene_standard_alphatest_use(); + shader_scene_standard_alphatest_uTexGarbage(0); + shader_scene_standard_alphatest_uTexMain(1); + shader_scene_standard_alphatest_uPv( cam->mtx.pv ); + shader_scene_standard_alphatest_uPvmPrev( cam->mtx_prev.pv ); + shader_link_standard_ub( _shader_scene_standard_alphatest.id, 2 ); bind_terrain_noise(); - shader_alphatest_uPv( projection ); - shader_alphatest_uMdl( identity_matrix ); - shader_alphatest_uCamera( camera ); + shader_scene_standard_alphatest_uMdl( identity_matrix ); + shader_scene_standard_alphatest_uCamera( cam->transform[3] ); + shader_scene_standard_alphatest_uBoard0( TEMP_BOARD_0 ); + shader_scene_standard_alphatest_uBoard1( TEMP_BOARD_1 ); glDisable(GL_CULL_FACE); @@ -140,71 +154,68 @@ VG_STATIC void bindpoint_terrain( struct world_material *mat ) glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, world.textures[ mat->info.tex_diffuse ] ); - shader_terrain_uSandColour( mat->info.colour ); - shader_terrain_uBlendOffset( mat->info.colour1 ); + shader_scene_terrain_uSandColour( mat->info.colour ); + shader_scene_terrain_uBlendOffset( mat->info.colour1 ); } -VG_STATIC void render_terrain( m4x4f projection, v3f camera ) +VG_STATIC void render_terrain( camera *cam ) { m4x3f identity_matrix; m4x3_identity( identity_matrix ); - shader_terrain_use(); - shader_terrain_uTexGarbage(0); - shader_terrain_uTexGradients(1); - shader_link_standard_ub( _shader_terrain.id, 2 ); + shader_scene_terrain_use(); + shader_scene_terrain_uTexGarbage(0); + shader_scene_terrain_uTexGradients(1); + shader_link_standard_ub( _shader_scene_terrain.id, 2 ); vg_tex2d_bind( &tex_terrain_noise, 0 ); - shader_terrain_uPv( projection ); - shader_terrain_uMdl( identity_matrix ); - shader_terrain_uCamera( camera ); + shader_scene_terrain_uPv( cam->mtx.pv ); + shader_scene_terrain_uPvmPrev( cam->mtx_prev.pv ); - world_render_both_stages( k_shader_terrain_blend, bindpoint_terrain ); -} + shader_scene_terrain_uMdl( identity_matrix ); + shader_scene_terrain_uCamera( cam->transform[3] ); + shader_scene_terrain_uBoard0( TEMP_BOARD_0 ); + shader_scene_terrain_uBoard1( TEMP_BOARD_1 ); -VG_STATIC void render_lowerdome( m4x3f camera ) -{ - m4x4f projection, full; - pipeline_projection( projection, 0.4f, 1000.0f ); - - m4x3f inverse; - m3x3_transpose( camera, inverse ); - v3_copy((v3f){0.0f,0.0f,0.0f}, inverse[3]); - m4x3_expand( inverse, full ); - m4x4_mul( projection, full, full ); - - m4x3f identity_matrix; - m4x3_identity( identity_matrix ); - - shader_planeinf_use(); - shader_planeinf_uMdl(identity_matrix); - shader_planeinf_uPv(full); - shader_planeinf_uCamera(camera[3]); - shader_planeinf_uPlane( (v4f){0.0f,1.0f,0.0f,0.0f} ); - - mdl_draw_submesh( &world.dome_lower ); + world_render_both_stages( k_shader_terrain_blend, bindpoint_terrain ); } -VG_STATIC void render_sky(m4x3f camera) +VG_STATIC void render_sky( camera *cam ) { - m4x4f projection, full; - pipeline_projection( projection, 0.4f, 1000.0f ); - - m4x3f inverse; - m3x3_transpose( camera, inverse ); - v3_copy((v3f){0.0f,0.0f,0.0f}, inverse[3]); - m4x3_expand( inverse, full ); - m4x4_mul( projection, full, full ); + /* + * Modify matrix to remove clipping and view translation + */ + m4x4f v, + v_prev, + pv, + pv_prev; + + m4x4_copy( cam->mtx.v, v ); + m4x4_copy( cam->mtx_prev.v, v_prev ); + v3_zero( v[3] ); + v3_zero( v_prev[3] ); + + m4x4_copy( cam->mtx.p, pv ); + m4x4_copy( cam->mtx_prev.p, pv_prev ); + m4x4_reset_clipping( pv, cam->farz, cam->nearz ); + m4x4_reset_clipping( pv_prev, cam->farz, cam->nearz ); + + m4x4_mul( pv, v, pv ); + m4x4_mul( pv_prev, v_prev, pv_prev ); m4x3f identity_matrix; m4x3_identity( identity_matrix ); - shader_sky_use(); - shader_sky_uMdl(identity_matrix); - shader_sky_uPv(full); - shader_sky_uTexGarbage(0); - shader_sky_uTime( world.sky_time ); + /* + * Draw + */ + shader_model_sky_use(); + shader_model_sky_uMdl( identity_matrix ); + shader_model_sky_uPv( pv ); + shader_model_sky_uPvmPrev( pv_prev ); + shader_model_sky_uTexGarbage(0); + shader_model_sky_uTime( world.sky_time ); vg_tex2d_bind( &tex_terrain_noise, 0 ); @@ -218,7 +229,7 @@ VG_STATIC void render_sky(m4x3f camera) glDepthMask( GL_TRUE ); } -VG_STATIC void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera ) +VG_STATIC void render_world_gates( camera *cam ) { if( !world.gate_count ) return; @@ -229,7 +240,7 @@ VG_STATIC void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera for( int i=0; igate.co[0], camera[3] ); + float dist = v3_dist2( rg->gate.co[0], cam->transform[3] ); if( dist < closest ) { @@ -238,22 +249,24 @@ VG_STATIC void render_world_gates( m4x4f projection, v3f playerco, m4x3f camera } } - render_gate( &world.gates[id].gate, playerco, camera ); + render_gate( &world.gates[id].gate, cam ); v3_lerp( world.render_gate_pos, world.gates[id].gate.co[0], 1.0f, world.render_gate_pos ); } -VG_STATIC void render_world( m4x4f projection, m4x3f camera ) +VG_STATIC void render_world( camera *cam ) { - render_sky( camera ); - render_world_routes( projection, camera[3] ); - render_world_standard( projection, camera[3] ); - render_world_vb( projection, camera[3] ); - render_world_alphatest( projection, camera[3] ); - render_terrain( projection, camera[3] ); + render_sky( cam ); + + render_world_routes( cam ); + render_world_standard( cam ); + render_world_vb( cam ); + render_world_alphatest( cam ); + render_terrain( cam ); + /* Render SFD's */ int closest = 0; float min_dist = INFINITY; @@ -262,8 +275,7 @@ VG_STATIC void render_world( m4x4f projection, m4x3f camera ) for( int i=0; ipos); if( dist < min_dist ) { @@ -272,19 +284,19 @@ VG_STATIC void render_world( m4x4f projection, m4x3f camera ) } } - sfd_render( projection, camera[3], - world.routes[closest].scoreboard_transform ); + sfd_render( cam, world.routes[closest].scoreboard_transform ); } -VG_STATIC void render_world_depth( m4x4f projection, m4x3f camera ) +VG_STATIC void render_world_depth( camera *cam ) { m4x3f identity_matrix; m4x3_identity( identity_matrix ); - shader_gpos_use(); - shader_gpos_uCamera( camera[3] ); - shader_gpos_uPv( projection ); - shader_gpos_uMdl( identity_matrix ); + shader_scene_depth_use(); + shader_scene_depth_uCamera( cam->transform[3] ); + shader_scene_depth_uPv( cam->mtx.pv ); + shader_scene_depth_uPvmPrev( cam->mtx_prev.pv ); + shader_scene_depth_uMdl( identity_matrix ); mesh_bind( &world.mesh_geo ); mesh_draw( &world.mesh_geo );