X-Git-Url: https://harrygodden.com/git/?a=blobdiff_plain;f=world_render.c;h=31fe1beb452c15c12813ff7e4772bf6f5cc33b28;hb=refs%2Fheads%2Fmenu2;hp=c82bc47c90d8f98fc00d1313f66da3d19bcc8169;hpb=a109f126d8adab622e38fbcc2d4281e75255246a;p=carveJwlIkooP6JGAAIwe30JlM.git diff --git a/world_render.c b/world_render.c index c82bc47..7d93920 100644 --- a/world_render.c +++ b/world_render.c @@ -2,9 +2,6 @@ * Copyright (C) 2021-2023 Mt.ZERO Software, Harry Godden - All Rights Reserved */ -#ifndef WORLD_RENDER_C -#define WORLD_RENDER_C - #include "world.h" #include "world_render.h" #include "font.h" @@ -13,8 +10,11 @@ #include "ent_miniworld.h" #include "player_remote.h" #include "ent_skateshop.h" +#include "ent_npc.h" #include "shaders/model_entity.h" +struct world_render world_render; + static int ccmd_set_time( int argc, const char *argv[] ){ world_instance *world = world_current_instance(); if( argc == 1 ) @@ -24,9 +24,11 @@ static int ccmd_set_time( int argc, const char *argv[] ){ return 0; } -static void async_world_render_init( void *payload, u32 size ){ +static void async_world_render_init( void *payload, u32 size ) +{ vg_info( "Allocate uniform buffers\n" ); - for( int i=0; iubo_bind_point = i; @@ -38,35 +40,10 @@ static void async_world_render_init( void *payload, u32 size ){ glBindBufferBase( GL_UNIFORM_BUFFER, i, world->ubo_lighting ); VG_CHECK_GL_ERR(); } - - vg_info( "Allocate frame buffers\n" ); - for( int i=0; iheightmap; - - fb->display_name = NULL; - fb->link = NULL; - fb->fixed_w = 1024; - fb->fixed_h = 1024; - fb->resolution_div = 0; - - fb->attachments[0].display_name = NULL; - fb->attachments[0].purpose = k_framebuffer_attachment_type_texture; - fb->attachments[0].internalformat = GL_RG16F; - fb->attachments[0].format = GL_RG; - fb->attachments[0].type = GL_FLOAT; - fb->attachments[0].attachment = GL_COLOR_ATTACHMENT0; - - fb->attachments[1].purpose = k_framebuffer_attachment_type_none; - fb->attachments[2].purpose = k_framebuffer_attachment_type_none; - fb->attachments[3].purpose = k_framebuffer_attachment_type_none; - fb->attachments[4].purpose = k_framebuffer_attachment_type_none; - - render_fb_allocate( fb ); - } } -static void world_render_init(void){ +void world_render_init(void) +{ VG_VAR_F32( k_day_length ); VG_VAR_I32( k_debug_light_indices ); VG_VAR_I32( k_debug_light_complexity ); @@ -77,19 +54,6 @@ static void world_render_init(void){ world_render.sky_rate = 1.0; world_render.sky_target_rate = 1.0; - shader_scene_standard_register(); - shader_scene_standard_alphatest_register(); - shader_scene_foliage_register(); - shader_scene_override_register(); - shader_scene_cubemapped_register(); - shader_scene_fxglow_register(); - shader_scene_vertex_blend_register(); - shader_scene_terrain_register(); - shader_scene_depth_register(); - shader_scene_position_register(); - shader_model_sky_register(); - shader_model_sky_space_register(); - vg_info( "Loading world resources\n" ); vg_linear_clear( vg_mem.scratch ); @@ -104,6 +68,26 @@ static void world_render_init(void){ VG_TEX2D_NEAREST|VG_TEX2D_REPEAT, &world_render.tex_terrain_noise ); + vg_info( "Allocate frame buffers\n" ); + for( int i=0; iheightmap = vg_framebuffer_allocate( vg_mem.rtmemory, 1, 0 ); + world->heightmap->display_name = NULL; + world->heightmap->fixed_w = 1024; + world->heightmap->fixed_h = 1024; + world->heightmap->resolution_div = 0; + world->heightmap->attachments[0] = (vg_framebuffer_attachment) + { + NULL, k_framebuffer_attachment_type_texture, + .internalformat = GL_RG16F, + .format = GL_RG, + .type = GL_FLOAT, + .attachment = GL_COLOR_ATTACHMENT0 + }; + vg_framebuffer_create( world->heightmap ); + } + vg_async_call( async_world_render_init, NULL, 0 ); } @@ -111,35 +95,40 @@ static void world_render_init(void){ * standard uniform bindings * ---------------------------------------------------------------------------- */ -static void world_link_lighting_ub( world_instance *world, GLuint shader ){ +void world_link_lighting_ub( world_instance *world, GLuint shader ) +{ GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" ); glUniformBlockBinding( shader, idx, world->ubo_bind_point ); } -static void world_bind_position_texture( world_instance *world, - GLuint shader, GLuint location, - int slot ){ - render_fb_bind_texture( &world->heightmap, 0, slot ); +void world_bind_position_texture( world_instance *world, + GLuint shader, GLuint location, + int slot ) +{ + vg_framebuffer_bind_texture( world->heightmap, 0, slot ); glUniform1i( location, slot ); } -static void world_bind_light_array( world_instance *world, - GLuint shader, GLuint location, - int slot ){ +void world_bind_light_array( world_instance *world, + GLuint shader, GLuint location, + int slot ) +{ glActiveTexture( GL_TEXTURE0 + slot ); glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities ); glUniform1i( location, slot ); } -static void world_bind_light_index( world_instance *world, - GLuint shader, GLuint location, - int slot ){ +void world_bind_light_index( world_instance *world, + GLuint shader, GLuint location, + int slot ) +{ glActiveTexture( GL_TEXTURE0 + slot ); glBindTexture( GL_TEXTURE_3D, world->tex_light_cubes ); glUniform1i( location, slot ); } -static void bind_terrain_noise(void){ +void bind_terrain_noise(void) +{ glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, world_render.tex_terrain_noise ); } @@ -152,31 +141,24 @@ static GLuint world_get_texture( world_instance *world, u32 id ){ else return world->textures[ id ]; } -static void bindpoint_diffuse_texture1( world_instance *world, - struct world_surface *mat ){ - glActiveTexture( GL_TEXTURE1 ); - glBindTexture( GL_TEXTURE_2D, - world_get_texture(world,mat->info.tex_diffuse) ); -} - /* * Passes Rendering * ---------------------------------------------------------------------------- */ -struct world_pass{ - camera *cam; +struct world_pass +{ + vg_camera *cam; enum mdl_shader shader; enum world_geo_type geo_type; - void (*fn_bind_textures)( world_instance *world, - struct world_surface *mat ); + void (*fn_bind)( world_instance *world, struct world_surface *mat ); void (*fn_set_mdl)( m4x3f mdl ); void (*fn_set_uPvmPrev)( m4x4f pvm ); void (*fn_set_uNormalMtx)( m3x3f mnorm ); }; -static void render_world_depth( world_instance *world, camera *cam ); +void render_world_depth( world_instance *world, vg_camera *cam ); /* * Render a run of submeshes, only of those which match material_id @@ -184,10 +166,13 @@ static void render_world_depth( world_instance *world, camera *cam ); static void world_render_submeshes( world_instance *world, struct world_pass *pass, mdl_transform *transform, - u32 start, u32 count, u32 material_id ){ - for( u32 k=0; kmeta.submeshs, start+k ); - if( sm->material_id != material_id ) continue; + if( sm->material_id != material_id ) + continue; m4x3f mmdl; mdl_transform_m4x3( transform, mmdl ); @@ -207,11 +192,12 @@ static void world_render_submeshes( world_instance *world, * Render props attached to this material */ static void world_render_props( world_instance *world, u32 material_id, - struct world_pass *pass ){ + struct world_pass *pass ) +{ struct world_surface *mat = &world->surfaces[ material_id ]; if( !(mat->flags & WORLD_SURFACE_HAS_PROPS) ) return; - pass->fn_bind_textures( world, mat ); + pass->fn_bind( world, mat ); for( u32 j=0; jent_prop ); j++ ){ ent_prop *prop = mdl_arritm( &world->ent_prop, j ); @@ -226,11 +212,12 @@ static void world_render_props( world_instance *world, u32 material_id, * Render traffic models attactched to this material */ static void world_render_traffic( world_instance *world, u32 material_id, - struct world_pass *pass ){ + struct world_pass *pass ) +{ struct world_surface *mat = &world->surfaces[ material_id ]; if( !(mat->flags & WORLD_SURFACE_HAS_TRAFFIC) ) return; - pass->fn_bind_textures( world, mat ); + pass->fn_bind( world, mat ); for( u32 j=0; jent_traffic ); j++ ){ ent_traffic *traffic = mdl_arritm( &world->ent_traffic, j ); @@ -245,17 +232,22 @@ static void world_render_traffic( world_instance *world, u32 material_id, * Iterate and render all materials which match the passes shader and geometry * type. Includes props/traffic. */ -static void world_render_pass( world_instance *world, struct world_pass *pass ){ - for( int i=0; isurface_count; i++ ){ +static void world_render_pass( world_instance *world, struct world_pass *pass ) +{ + for( int i=0; isurface_count; i++ ) + { struct world_surface *mat = &world->surfaces[i]; - if( mat->info.shader == pass->shader ){ + if( mat->info.shader == pass->shader ) + { mdl_submesh *sm; - if( pass->geo_type == k_world_geo_type_solid ){ + if( pass->geo_type == k_world_geo_type_solid ) + { sm = &mat->sm_geo; } - else{ + else + { world_render_traffic( world, i, pass ); world_render_props( world, i, pass ); sm = &mat->sm_no_collide; @@ -268,8 +260,7 @@ static void world_render_pass( world_instance *world, struct world_pass *pass ){ m4x3_identity( mmdl ); pass->fn_set_mdl( mmdl ); pass->fn_set_uPvmPrev( pass->cam->mtx_prev.pv ); - - pass->fn_bind_textures( world, mat ); + pass->fn_bind( world, mat ); mdl_draw_submesh( sm ); } } @@ -281,7 +272,8 @@ static void world_render_pass( world_instance *world, struct world_pass *pass ){ */ static void world_render_both_stages( world_instance *world, - struct world_pass *pass ){ + struct world_pass *pass ) +{ mesh_bind( &world->mesh_geo ); pass->geo_type = k_world_geo_type_solid; world_render_pass( world, pass ); @@ -293,7 +285,21 @@ static void world_render_both_stages( world_instance *world, glEnable( GL_CULL_FACE ); } -static void render_world_vb( world_instance *world, camera *cam ){ +static void bindpoint_world_vb( world_instance *world, + struct world_surface *mat ) +{ + struct shader_props_vertex_blend *props = mat->info.props.compiled; + + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, world_get_texture(world, props->tex_diffuse) ); + +#if 0 + shader_scene_vertex_blend_uOffset( props->blend_offset ); +#endif +} + +static void render_world_vb( world_instance *world, vg_camera *cam ) +{ shader_scene_vertex_blend_use(); shader_scene_vertex_blend_uTexGarbage(0); shader_scene_vertex_blend_uTexGradients(1); @@ -305,10 +311,11 @@ static void render_world_vb( world_instance *world, camera *cam ){ shader_scene_vertex_blend_uPv( cam->mtx.pv ); shader_scene_vertex_blend_uCamera( cam->transform[3] ); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_standard_vertex_blend, .cam = cam, - .fn_bind_textures = bindpoint_diffuse_texture1, + .fn_bind = bindpoint_world_vb, .fn_set_mdl = shader_scene_vertex_blend_uMdl, .fn_set_uPvmPrev = shader_scene_vertex_blend_uPvmPrev, }; @@ -316,7 +323,8 @@ static void render_world_vb( world_instance *world, camera *cam ){ world_render_both_stages( world, &pass ); } -static void world_shader_standard_bind( world_instance *world, camera *cam ){ +static void world_shader_standard_bind( world_instance *world, vg_camera *cam ) +{ shader_scene_standard_use(); shader_scene_standard_uTexGarbage(0); shader_scene_standard_uTexMain(1); @@ -327,12 +335,23 @@ static void world_shader_standard_bind( world_instance *world, camera *cam ){ shader_scene_standard_uCamera( cam->transform[3] ); } -static void render_world_standard( world_instance *world, camera *cam ){ +static void bindpoint_standard( world_instance *world, + struct world_surface *mat ) +{ + struct shader_props_standard *props = mat->info.props.compiled; + + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, world_get_texture(world, props->tex_diffuse) ); +} + +static void render_world_standard( world_instance *world, vg_camera *cam ) +{ world_shader_standard_bind( world, cam ); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_standard, .cam = cam, - .fn_bind_textures = bindpoint_diffuse_texture1, + .fn_bind = bindpoint_standard, .fn_set_mdl = shader_scene_standard_uMdl, .fn_set_uPvmPrev = shader_scene_standard_uPvmPrev, }; @@ -340,16 +359,20 @@ static void render_world_standard( world_instance *world, camera *cam ){ world_render_both_stages( world, &pass ); } -static void bindpoint_diffuse1_and_cubemap10( world_instance *world, - struct world_surface *mat ){ +static void bindpoint_world_cubemapped( world_instance *world, + struct world_surface *mat ) +{ + struct shader_props_cubemapped *props = mat->info.props.compiled; + glActiveTexture( GL_TEXTURE1 ); glBindTexture( GL_TEXTURE_2D, - world_get_texture(world,mat->info.tex_diffuse) ); + world_get_texture( world,props->tex_diffuse ) ); - u32 cubemap_id = mat->info.tex_none0, + u32 cubemap_id = props->cubemap_entity, cubemap_index = 0; - if( mdl_entity_id_type( cubemap_id ) == k_ent_cubemap ){ + if( mdl_entity_id_type( cubemap_id ) == k_ent_cubemap ) + { cubemap_index = mdl_entity_id_id( cubemap_id ); } @@ -357,28 +380,42 @@ static void bindpoint_diffuse1_and_cubemap10( world_instance *world, glActiveTexture( GL_TEXTURE10 ); glBindTexture( GL_TEXTURE_CUBE_MAP, cm->texture_id ); - shader_scene_cubemapped_uColour( mat->info.colour ); + shader_scene_cubemapped_uColour( props->tint ); } -static void render_world_cubemapped( world_instance *world, camera *cam, - int enabled ){ +static void bindpoint_world_cubemapped_disabled( world_instance *world, + struct world_surface *mat ) +{ + struct shader_props_cubemapped *props = mat->info.props.compiled; + + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, + world_get_texture( world, props->tex_diffuse ) ); +} + +static void render_world_cubemapped( world_instance *world, vg_camera *cam, + int enabled ) +{ if( !mdl_arrcount( &world->ent_cubemap ) ) return; - if( !enabled ){ + if( !enabled ) + { world_shader_standard_bind( world, cam ); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_cubemap, .cam = cam, - .fn_bind_textures = bindpoint_diffuse_texture1, + .fn_bind = bindpoint_world_cubemapped_disabled, .fn_set_mdl = shader_scene_standard_uMdl, .fn_set_uPvmPrev = shader_scene_standard_uPvmPrev, }; world_render_both_stages( world, &pass ); } - else { + else + { shader_scene_cubemapped_use(); shader_scene_cubemapped_uTexGarbage(0); shader_scene_cubemapped_uTexMain(1); @@ -390,10 +427,11 @@ static void render_world_cubemapped( world_instance *world, camera *cam, bind_terrain_noise(); shader_scene_cubemapped_uCamera( cam->transform[3] ); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_cubemap, .cam = cam, - .fn_bind_textures = bindpoint_diffuse1_and_cubemap10, + .fn_bind = bindpoint_world_cubemapped, .fn_set_mdl = shader_scene_cubemapped_uMdl, .fn_set_uPvmPrev = shader_scene_cubemapped_uPvmPrev, }; @@ -402,7 +440,8 @@ static void render_world_cubemapped( world_instance *world, camera *cam, } } -static void render_world_alphatest( world_instance *world, camera *cam ){ +static void render_world_alphatest( world_instance *world, vg_camera *cam ) +{ shader_scene_standard_alphatest_use(); shader_scene_standard_alphatest_uTexGarbage(0); shader_scene_standard_alphatest_uTexMain(1); @@ -414,10 +453,11 @@ static void render_world_alphatest( world_instance *world, camera *cam ){ shader_scene_standard_alphatest_uCamera( cam->transform[3] ); glDisable(GL_CULL_FACE); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_standard_cutout, .cam = cam, - .fn_bind_textures = bindpoint_diffuse_texture1, + .fn_bind = bindpoint_standard, .fn_set_mdl = shader_scene_standard_alphatest_uMdl, .fn_set_uPvmPrev = shader_scene_standard_alphatest_uPvmPrev, }; @@ -426,7 +466,8 @@ static void render_world_alphatest( world_instance *world, camera *cam ){ glEnable(GL_CULL_FACE); } -static void render_world_foliage( world_instance *world, camera *cam ){ +static void render_world_foliage( world_instance *world, vg_camera *cam ) +{ shader_scene_foliage_use(); shader_scene_foliage_uTexGarbage(0); shader_scene_foliage_uTexMain(1); @@ -438,10 +479,11 @@ static void render_world_foliage( world_instance *world, camera *cam ){ shader_scene_foliage_uCamera( cam->transform[3] ); glDisable(GL_CULL_FACE); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_foliage, .cam = cam, - .fn_bind_textures = bindpoint_diffuse_texture1, + .fn_bind = bindpoint_standard, .fn_set_mdl = shader_scene_foliage_uMdl, .fn_set_uPvmPrev = shader_scene_foliage_uPvmPrev, }; @@ -450,7 +492,8 @@ static void render_world_foliage( world_instance *world, camera *cam ){ } static void world_render_challenges( world_instance *world, - struct world_pass *pass, v3f pos ){ + struct world_pass *pass, v3f pos ) +{ if( !world ) return; if( skaterift.activity == k_skaterift_replay ) return; if( world != world_current_instance() ) return; @@ -522,7 +565,8 @@ static void world_render_challenges( world_instance *world, glDisable( GL_CULL_FACE ); mesh_bind( &world->mesh_no_collide ); u32 last_material = 0; - for( u32 i=0; ient_objective, index ); if( (objective->flags & k_ent_objective_hidden) && @@ -530,7 +574,8 @@ static void world_render_challenges( world_instance *world, f32 scale = 1.0f; - if( running ){ + if( running ) + { u32 passed = objective->flags & k_ent_objective_passed; f32 target = passed? 0.0f: 1.0f; vg_slewf(&objective->transform.s[0], target, vg.time_frame_delta*4.0f); @@ -541,7 +586,8 @@ static void world_render_challenges( world_instance *world, else shader_scene_fxglow_uUvOffset( (v2f){ 8.0f/256.0f, 0.0f } ); } - else { + else + { f32 dist = v3_dist( objective->transform.co, pos ) * (1.0f/radius); scale = vg_smoothstepf( vg_clampf( 5.0f-dist*5.0f, 0.0f,1.0f ) ); } @@ -552,20 +598,22 @@ static void world_render_challenges( world_instance *world, v3_copy( objective->transform.co, mmdl[3] ); shader_scene_fxglow_uMdl( mmdl ); - for( u32 j=0; jsubmesh_count; j++ ){ + for( u32 j=0; jsubmesh_count; j++ ) + { mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, objective->submesh_start + j ); - if( sm->material_id != last_material ){ + if( sm->material_id != last_material ) + { last_material = sm->material_id; - pass->fn_bind_textures( world, &world->surfaces[sm->material_id] ); + pass->fn_bind( world, &world->surfaces[sm->material_id] ); } mdl_draw_submesh( sm ); } } /* render texts */ - font3d_bind( &gui.font, k_font_shader_world, 0, world, &skaterift.cam ); + font3d_bind( &gui.font, k_font_shader_world, 0, world, &g_render.cam ); u32 count = 0; @@ -608,14 +656,24 @@ static void world_render_challenges( world_instance *world, shader_scene_font_uOpacity( scale ); shader_scene_font_uColourize( colour ); - font3d_simple_draw( 1, buf, &skaterift.cam, mmdl ); + font3d_simple_draw( 1, buf, &g_render.cam, mmdl ); } } +static void bindpoint_fxglow( world_instance *world, + struct world_surface *mat ) +{ + struct shader_props_standard *props = mat->info.props.compiled; + + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, world_get_texture(world, props->tex_diffuse) ); +} + static void render_world_fxglow( world_instance *host_world, - world_instance *world, camera *cam, + world_instance *world, vg_camera *cam, m4x3f world_mmdl, - int generic, int challenges, int regions ){ + int generic, int challenges, int regions ) +{ shader_scene_fxglow_use(); shader_scene_fxglow_uUvOffset( (v2f){ 0.0f, 0.0f } ); shader_scene_fxglow_uTexMain(1); @@ -625,10 +683,11 @@ static void render_world_fxglow( world_instance *host_world, shader_scene_fxglow_uCamera( cam->transform[3] ); glDisable(GL_CULL_FACE); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_fxglow, .cam = cam, - .fn_bind_textures = bindpoint_diffuse_texture1, + .fn_bind = bindpoint_fxglow, .fn_set_mdl = shader_scene_fxglow_uMdl, .fn_set_uPvmPrev = shader_scene_fxglow_uPvmPrev, }; @@ -657,13 +716,15 @@ static void render_world_fxglow( world_instance *host_world, m4x3_mul( world_mmdl, mmdl, mmdl ); shader_scene_fxglow_uMdl( mmdl ); - for( u32 j=0; jsubmesh_count; j++ ){ + for( u32 j=0; jsubmesh_count; j++ ) + { mdl_submesh *sm = mdl_arritm( &world->meta.submeshs, region->submesh_start + j ); - if( sm->material_id != last_material ){ + if( sm->material_id != last_material ) + { last_material = sm->material_id; - pass.fn_bind_textures(world,&world->surfaces[sm->material_id]); + pass.fn_bind( world, &world->surfaces[sm->material_id] ); } mdl_draw_submesh( sm ); } @@ -677,30 +738,33 @@ static void render_world_fxglow( world_instance *host_world, } static void bindpoint_terrain( world_instance *world, - struct world_surface *mat ) + struct world_surface *mat ) { - glActiveTexture( GL_TEXTURE1 ); - glBindTexture( GL_TEXTURE_2D, - world_get_texture(world,mat->info.tex_diffuse) ); + struct shader_props_terrain *props = mat->info.props.compiled; - shader_scene_terrain_uSandColour( mat->info.colour ); - shader_scene_terrain_uBlendOffset( mat->info.colour1 ); + glActiveTexture( GL_TEXTURE1 ); + glBindTexture( GL_TEXTURE_2D, world_get_texture(world, props->tex_diffuse) ); + shader_scene_terrain_uBlendOffset( props->blend_offset ); + shader_scene_terrain_uSandColour( props->sand_colour ); } static void bindpoint_override( world_instance *world, - struct world_surface *mat ){ - if( mat->info.flags & k_material_flag_collision ){ + struct world_surface *mat ) +{ + if( mat->info.flags & k_material_flag_collision ) + { shader_scene_override_uAlphatest(0); } - else{ + else + { glActiveTexture( GL_TEXTURE1 ); - glBindTexture( GL_TEXTURE_2D, - world_get_texture(world,mat->info.tex_diffuse) ); + glBindTexture( GL_TEXTURE_2D, world_get_texture(world, mat->alpha_tex) ); shader_scene_override_uAlphatest(1); } } -static void render_terrain( world_instance *world, camera *cam ){ +static void render_terrain( world_instance *world, vg_camera *cam ) +{ shader_scene_terrain_use(); shader_scene_terrain_uTexGarbage(0); shader_scene_terrain_uTexGradients(1); @@ -712,10 +776,11 @@ static void render_terrain( world_instance *world, camera *cam ){ shader_scene_terrain_uPv( cam->mtx.pv ); shader_scene_terrain_uCamera( cam->transform[3] ); - struct world_pass pass = { + struct world_pass pass = + { .shader = k_shader_terrain_blend, .cam = cam, - .fn_bind_textures = bindpoint_terrain, + .fn_bind = bindpoint_terrain, .fn_set_mdl = shader_scene_terrain_uMdl, .fn_set_uPvmPrev = shader_scene_terrain_uPvmPrev, }; @@ -723,7 +788,8 @@ static void render_terrain( world_instance *world, camera *cam ){ world_render_both_stages( world, &pass ); } -static void render_sky( world_instance *world, camera *cam ){ +static void render_sky( world_instance *world, vg_camera *cam ) +{ /* * Modify matrix to remove clipping and view translation */ @@ -793,7 +859,8 @@ static void render_sky( world_instance *world, camera *cam ){ glDepthMask( GL_TRUE ); } -static void render_world_gates( world_instance *world, camera *cam ){ +void render_world_gates( world_instance *world, vg_camera *cam ) +{ float closest = INFINITY; struct ent_gate *gate = NULL; @@ -838,7 +905,8 @@ static void render_world_gates( world_instance *world, camera *cam ){ } } -static void world_prerender( world_instance *world ){ +void world_prerender( world_instance *world ) +{ if( mdl_arrcount( &world->ent_light ) ){ f32 rate = vg_maxf(0.1f, fabsf(k_day_length)) * vg_signf(k_day_length); world->time += vg.time_frame_delta * (1.0/(rate*60.0)); @@ -892,13 +960,16 @@ static void world_prerender( world_instance *world ){ sizeof(struct ub_world_lighting), &world->ub_lighting ); } -static void render_other_entities( world_instance *world, camera *cam ){ +static void render_other_entities( world_instance *world, vg_camera *cam ) +{ f32 radius = 40.0f; bh_iter it; bh_iter_init_range( 0, &it, cam->pos, radius+10.0f ); u32 glider_list[4], - glider_count = 0; + glider_count = 0, + npc_list[4], + npc_count = 0; i32 idx; while( bh_next( world->entity_bh, &it, &idx ) ){ @@ -906,20 +977,26 @@ static void render_other_entities( world_instance *world, camera *cam ){ type = mdl_entity_id_type( id ), index = mdl_entity_id_id( id ); - if( type == k_ent_glider ) { + if( type == k_ent_glider ) + { if( glider_count < vg_list_size(glider_list) ) glider_list[ glider_count ++ ] = index; } + else if( type == k_ent_npc ) + { + if( npc_count < vg_list_size(npc_list) ) + npc_list[ npc_count ++ ] = index; + } } shader_model_entity_use(); shader_model_entity_uTexMain( 0 ); shader_model_entity_uCamera( cam->transform[3] ); shader_model_entity_uPv( cam->mtx.pv ); - WORLD_BIND_LIGHT_BUFFERS_UB0_TEX234( world, model_entity ); - for( u32 j=0; jent_glider, glider_list[j] ); if( !(glider->flags & 0x1) ) @@ -934,11 +1011,20 @@ static void render_other_entities( world_instance *world, camera *cam ){ render_glider_model( cam, world, mdl, k_board_shader_entity ); } + + for( u32 j=0; jent_npc, npc_list[j] ); + npc_update( npc ); + npc_render( npc, world, cam ); + } } -static void render_world( world_instance *world, camera *cam, - int stenciled, int viewing_from_gate, - int with_water, int with_cubemaps ){ +void render_world( world_instance *world, vg_camera *cam, + int stenciled, int viewing_from_gate, + int with_water, int with_cubemaps ) +{ if( stenciled ){ glClear( GL_DEPTH_BUFFER_BIT ); glStencilFunc( GL_EQUAL, 1, 0xFF ); @@ -1015,19 +1101,22 @@ static void render_world( world_instance *world, camera *cam, render_world_fxglow( world, world, cam, NULL, 1, 1, 0 ); } - if( with_water ){ + if( with_water ) + { render_water_texture( world, cam ); - render_fb_bind( gpipeline.fb_main, 1 ); + vg_framebuffer_bind( g_render.fb_main, k_render_scale ); } - if( stenciled ){ + if( stenciled ) + { glStencilFunc( GL_EQUAL, 1, 0xFF ); glStencilMask( 0x00 ); glEnable( GL_CULL_FACE ); glEnable( GL_STENCIL_TEST ); } - if( with_water ){ + if( with_water ) + { render_water_surface( world, cam ); } @@ -1035,7 +1124,8 @@ static void render_world( world_instance *world, camera *cam, render_other_entities( world, cam ); ent_miniworld_render( world, cam ); - if( stenciled ){ + if( stenciled ) + { glStencilMask( 0xFF ); glStencilFunc( GL_ALWAYS, 1, 0xFF ); glDisable( GL_STENCIL_TEST ); @@ -1046,8 +1136,10 @@ static void render_world( world_instance *world, camera *cam, static void render_world_override_pass( world_instance *world, struct world_pass *pass, m4x3f mmdl, m3x3f mnormal, - m4x4f mpvm_prev ){ - for( int i=0; isurface_count; i++ ){ + m4x4f mpvm_prev ) +{ + for( int i=0; isurface_count; i++ ) + { struct world_surface *mat = &world->surfaces[i]; if( mat->info.flags & k_material_flag_ghosts ) continue; @@ -1063,19 +1155,21 @@ static void render_world_override_pass( world_instance *world, pass->fn_set_mdl( mmdl ); pass->fn_set_uNormalMtx( mnormal ); pass->fn_set_uPvmPrev( mpvm_prev ); - pass->fn_bind_textures( world, mat ); + pass->fn_bind( world, mat ); mdl_draw_submesh( sm ); } } -static void render_world_override( world_instance *world, - world_instance *lighting_source, - m4x3f mmdl, - camera *cam, - ent_spawn *dest_spawn, v4f map_info ){ - struct world_pass pass = { +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_bind = bindpoint_override, .fn_set_mdl = shader_scene_override_uMdl, .fn_set_uPvmPrev = shader_scene_override_uPvmPrev, .fn_set_uNormalMtx = shader_scene_override_uNormalMtx, @@ -1107,7 +1201,6 @@ static void render_world_override( world_instance *world, 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) ) @@ -1136,7 +1229,7 @@ static void render_world_override( world_instance *world, static void render_cubemap_side( world_instance *world, ent_cubemap *cm, u32 side ){ - camera cam; + 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 ); @@ -1167,20 +1260,21 @@ static void render_cubemap_side( world_instance *world, ent_cubemap *cm, v3_copy( cm->co, cam.transform[3] ); m4x3_invert_affine( cam.transform, cam.transform_inverse ); - camera_update_view( &cam ); + 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 ); - camera_finalize( &cam ); - camera_finalize( &cam ); + vg_camera_finalize( &cam ); + vg_camera_finalize( &cam ); render_world( world, &cam, 0, 1, 1, 0 ); } -static void render_world_cubemaps( world_instance *world ){ +void render_world_cubemaps( world_instance *world ) +{ if( world->cubemap_cooldown ) world->cubemap_cooldown --; else{ @@ -1205,7 +1299,8 @@ static void render_world_cubemaps( world_instance *world ){ * --------------------------------------------- */ -static void render_world_depth( world_instance *world, camera *cam ){ +void render_world_depth( world_instance *world, vg_camera *cam ) +{ m4x3f identity_matrix; m4x3_identity( identity_matrix ); @@ -1220,7 +1315,8 @@ static void render_world_depth( world_instance *world, camera *cam ){ mesh_draw( &world->mesh_geo ); } -static void render_world_position( world_instance *world, camera *cam ){ +void render_world_position( world_instance *world, vg_camera *cam ) +{ m4x3f identity_matrix; m4x3_identity( identity_matrix ); @@ -1254,19 +1350,21 @@ static f32 *skybox_prop_location( world_instance *world, i32 index ){ } } -static void imgui_world_light_edit( world_instance *world ){ +void imgui_world_light_edit( ui_context *ctx, world_instance *world ) +{ ui_rect panel = { vg.window_x-400, 0, 400, vg.window_y }; - ui_fill( panel, ui_colour( k_ui_bg+1 ) ); - ui_outline( panel, 1, ui_colour( k_ui_bg+7 ), 0 ); + ui_fill( ctx, panel, ui_colour( ctx, k_ui_bg+1 ) ); + ui_outline( ctx, panel, 1, ui_colour( ctx, k_ui_bg+7 ), 0 ); ui_rect_pad( panel, (ui_px[2]){ 8, 8 } ); - vg_ui.wants_mouse = 1; + ui_capture_mouse(ctx, 1); static i32 option_to_edit = 0; - ui_enum( panel, "option", skybox_setting_options, 5, &option_to_edit ); - ui_colourpicker( panel, "colour", + ui_enum( ctx, panel, "option", skybox_setting_options, 5, &option_to_edit ); + ui_colourpicker( ctx, panel, "colour", skybox_prop_location( world, option_to_edit ) ); - if( ui_button( panel, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 ){ + if( ui_button( ctx, panel, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 ) + { FILE *fp = fopen( "/tmp/tweaker.txt", "w" ); for( i32 i=0; i<5; i ++ ){ @@ -1278,5 +1376,3 @@ static void imgui_world_light_edit( world_instance *world ){ fclose( fp ); } } - -#endif