float scale = 0.2f,
thickness = 0.03f;
- font3d_bind( &gui.font, &skaterift.cam );
+ font3d_bind( &gui.font, k_font_shader_default, 0, world, &skaterift.cam );
shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
/* Selection counter
i+=highscore_intl( buf+i, addon_count(k_addon_type_board), 3 );
buf[i++] = '\0';
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- buf, &skaterift.cam, mmdl );
+ font3d_simple_draw( 0, buf, &skaterift.cam, mmdl );
}
else{
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- "Nothing installed", &skaterift.cam, mmdl );
+ font3d_simple_draw( 0, "Nothing installed", &skaterift.cam, mmdl );
}
u16 cache_id = skateshop_selected_cache_id();
* ----------------------------------------------------------------- */
m3x3_zero( mlocal );
m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0,
- global_skateshop.render.item_title );
+ mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_title );
mlocal[3][0] *= scale*0.5f;
mlocal[3][1] = 0.1f;
mlocal[3][2] = 0.0f;
m4x3_mul( mtext, mlocal, mmdl );
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- global_skateshop.render.item_title,
+ font3d_simple_draw( 0, global_skateshop.render.item_title,
&skaterift.cam, mmdl );
/* Author name
* ----------------------------------------------------------------- */
scale *= 0.4f;
m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0,
- global_skateshop.render.item_desc );
+ mlocal[3][0] = -font3d_string_width( 0, global_skateshop.render.item_desc );
mlocal[3][0] *= scale*0.5f;
mlocal[3][1] = 0.0f;
mlocal[3][2] = 0.0f;
m4x3_mul( mtext, mlocal, mmdl );
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- global_skateshop.render.item_desc,
+ font3d_simple_draw( 0, global_skateshop.render.item_desc,
&skaterift.cam, mmdl );
SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
m4x3f mtext,mlocal,mtextmdl;
mdl_transform_m4x3( &mark_info->transform, mtext );
- font3d_bind( &gui.font, &skaterift.cam );
+ font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &skaterift.cam );
shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
float scale = 0.2f, thickness = 0.015f, scale1 = 0.08f;
m3x3_zero( mlocal );
m3x3_setdiagonalv3( mlocal, (v3f){ scale, scale, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0, buftext );
+ mlocal[3][0] = -font3d_string_width( 0, buftext );
mlocal[3][0] *= scale*0.5f;
mlocal[3][1] = 0.1f;
mlocal[3][2] = 0.0f;
m4x3_mul( mtext, mlocal, mtextmdl );
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- buftext, &skaterift.cam, mtextmdl );
+ font3d_simple_draw( 0, buftext, &skaterift.cam, mtextmdl );
m3x3_setdiagonalv3( mlocal, (v3f){ scale1, scale1, thickness } );
- mlocal[3][0] = -font3d_string_width( &gui.font, 0, bufsubtext );
+ mlocal[3][0] = -font3d_string_width( 0, bufsubtext );
mlocal[3][0] *= scale1*0.5f;
mlocal[3][1] = -scale1*0.3f;
m4x3_mul( mtext, mlocal, mtextmdl );
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- bufsubtext, &skaterift.cam, mtextmdl );
+ font3d_simple_draw( 0, bufsubtext, &skaterift.cam, mtextmdl );
/* pointcloud */
m4x3f mmdl;
#include "camera.h"
#include "shaders/model_font.h"
#include "shaders/scene_font.h"
+#include "world_render.h"
enum efont_SRglyph{
k_SRglyph_end = 0x00, /* control characters */
glyphs;
};
-static void font3d_load( font3d *font, const char *mdl_path, void *alloc )
-{
+static void font3d_load( font3d *font, const char *mdl_path, void *alloc ){
mdl_open( &font->mdl, mdl_path, alloc );
mdl_load_metadata_block( &font->mdl, alloc );
mdl_close( &font->mdl );
}
-static void font3d_init(void)
-{
+static void font3d_init(void){
shader_model_font_register();
shader_scene_font_register();
}
-static u32 font3d_find_variant( font3d *font, const char *name )
-{
+static u32 font3d_find_variant( font3d *font, const char *name ){
for( u32 i=0; i<mdl_arrcount( &font->font_variants ); i ++ ){
ent_font_variant *variant = mdl_arritm( &font->font_variants, i );
return 0;
}
-static void font3d_bind( font3d *font, camera *cam )
-{
- shader_model_font_use();
- shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
- shader_model_font_uTexMain( 1 );
- glActiveTexture( GL_TEXTURE1 );
- glBindTexture( GL_TEXTURE_2D, font->texture );
+struct _font3d_render{
+ v4f offset;
+ font3d *font;
+ u32 variant_id;
- shader_model_font_uPv( cam->mtx.pv );
+ enum font_shader {
+ k_font_shader_default,
+ k_font_shader_world
+ }
+ shader;
+}
+static gui_font3d;
+
+/*
+ * world can be null if not using world shader
+ */
+static void font3d_bind( font3d *font, enum font_shader shader,
+ int depth_compare, world_instance *world,
+ camera *cam ){
+ gui_font3d.shader = shader;
+ gui_font3d.font = font;
+ glActiveTexture( GL_TEXTURE1 );
+ glBindTexture( GL_TEXTURE_2D, font->texture );
+
+ if( shader == k_font_shader_default ){
+ shader_model_font_use();
+ shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+ shader_model_font_uTexMain( 1 );
+
+ shader_model_font_uDepthCompare( depth_compare );
+ if( depth_compare ){
+ /* TODO: Compress with code in player_render.c */
+ shader_model_font_uTexSceneDepth( 2 );
+ render_fb_bind_texture( gpipeline.fb_main, 2, 2 );
+ v3f inverse;
+ render_fb_inverse_ratio( gpipeline.fb_main, inverse );
+ inverse[2] = skaterift.cam.farz-skaterift.cam.nearz;
+
+ shader_model_font_uInverseRatioDepth( inverse );
+ render_fb_inverse_ratio( NULL, inverse );
+ inverse[2] = cam->farz-cam->nearz;
+ shader_model_font_uInverseRatioMain( inverse );
+ }
+
+ shader_model_font_uPv( cam->mtx.pv );
+ }
+ else if( shader == k_font_shader_world ){
+ assert( world );
+ shader_scene_font_use();
+ shader_scene_font_uTexGarbage(0);
+ shader_scene_font_uTexMain(1);
+
+ shader_scene_font_uPv( skaterift.cam.mtx.pv );
+ shader_scene_font_uTime( vg.time );
+
+ /* TODO: Code dupe... */
+ world_link_lighting_ub( world, _shader_scene_font.id );
+ world_bind_position_texture( world, _shader_scene_font.id,
+ _uniform_scene_font_g_world_depth, 2 );
+ world_bind_light_array( world, _shader_scene_font.id,
+ _uniform_scene_font_uLightsArray, 3 );
+ world_bind_light_index( world, _shader_scene_font.id,
+ _uniform_scene_font_uLightsIndex, 4 );
+
+ bind_terrain_noise();
+ shader_scene_font_uCamera( skaterift.cam.transform[3] );
+ }
mesh_bind( &font->mesh );
}
-static ent_glyph *font3d_glyph( font3d *font, u32 variant_id, u32 utf32 )
-{
+static ent_glyph *font3d_glyph( font3d *font, u32 variant_id, u32 utf32 ){
if( utf32 < font->info.glyph_utf32_base ) return NULL;
if( utf32 >= font->info.glyph_utf32_base+font->info.glyph_count) return NULL;
return mdl_arritm( &font->glyphs, index );
}
-struct font3d_render{
- v4f offset;
- font3d *font;
- const u8 *u8pch;
- u32 variant_id;
-
- enum font_shader {
- k_font_shader_default,
- k_font_shader_world
- }
- shader;
-};
-
-static
-void font3d_begin( const char *text,
- camera *cam, m4x3f transform, struct font3d_render *render )
-{
- v4_copy( (v4f){0.0f,0.0f,0.0f,1.0f}, render->offset );
+static void font3d_set_transform( const char *text,
+ camera *cam, m4x3f transform ){
+ v4_copy( (v4f){0.0f,0.0f,0.0f,1.0f}, gui_font3d.offset );
m4x4f prev_mtx;
m4x3_expand( transform, prev_mtx );
m4x4_mul( cam->mtx_prev.pv, prev_mtx, prev_mtx );
- if( render->shader == k_font_shader_default ){
+ if( gui_font3d.shader == k_font_shader_default ){
shader_model_font_uPvmPrev( prev_mtx );
shader_model_font_uMdl( transform );
}
- else if( render->shader == k_font_shader_world ){
+ else if( gui_font3d.shader == k_font_shader_world ){
shader_scene_font_uPvmPrev( prev_mtx );
shader_scene_font_uMdl( transform );
}
-
- render->u8pch = (u8*)text;
}
-static void font3d_setoffset( struct font3d_render *render, v4f offset ){
- if( render->shader == k_font_shader_default )
+static void font3d_setoffset( v4f offset ){
+ if( gui_font3d.shader == k_font_shader_default )
shader_model_font_uOffset( offset );
- else if( render->shader == k_font_shader_world )
+ else if( gui_font3d.shader == k_font_shader_world )
shader_scene_font_uOffset( offset );
}
-static void font3d_draw( struct font3d_render *render )
-{
+static void font3d_setcolour( v4f colour ){
+ if( gui_font3d.shader == k_font_shader_default )
+ shader_model_font_uColour( colour );
+#if 0
+ else if( gui_font3d.shader == k_font_shader_world )
+ shader_scene_font_uColour( colour );
+#endif
+}
+
+static void font3d_draw( const char *text ){
+ u8 *u8pch = (u8*)text;
+
u32 max_chars = 512;
- while( render->u8pch && max_chars ){
+ while( u8pch && max_chars ){
max_chars --;
- u32 c0 = *render->u8pch, c1;
- render->u8pch ++;
+ u32 c0 = *u8pch, c1;
+ u8pch ++;
if( !c0 ) break;
- ent_glyph *glyph0 = font3d_glyph( render->font, render->variant_id, c0 ),
+ ent_glyph *glyph0 = font3d_glyph( gui_font3d.font,
+ gui_font3d.variant_id, c0 ),
*glyph1 = NULL;
/* multibyte characters */
if( c0 >= 1 && c0 < k_SRglyph_ascii_min ){
- c1 = *render->u8pch;
+ c1 = *u8pch;
if( !c1 ) break;
- glyph1 = font3d_glyph( render->font, render->variant_id, c1 );
+ glyph1 = font3d_glyph( gui_font3d.font, gui_font3d.variant_id, c1 );
}
if( c0 == k_SRglyph_ctrl_variant ){
- render->variant_id = c1;
- render->u8pch ++;
+ gui_font3d.variant_id = c1;
+ u8pch ++;
continue;
}
else if( c0 == k_SRglyph_ctrl_size ){
- render->offset[3] = (float)c1 * (1.0f/255.0f);
- render->u8pch ++;
+ gui_font3d.offset[3] = (float)c1 * (1.0f/255.0f);
+ u8pch ++;
continue;
}
else if( c0 == k_SRglyph_ctrl_baseline ){
- render->offset[1] = 0.0f;
+ gui_font3d.offset[1] = 0.0f;
continue;
}
else if( c0 == k_SRglyph_ctrl_center ){
if( glyph1 ){
- float diff = glyph1->size[1] - glyph1->size[1]*render->offset[3];
- render->offset[1] = diff * 0.5f;
+ float diff = glyph1->size[1] - glyph1->size[1]*gui_font3d.offset[3];
+ gui_font3d.offset[1] = diff * 0.5f;
}
continue;
}
else if( c0 == k_SRglyph_ctrl_top ){
if( glyph1 ){
- float diff = glyph1->size[1] - glyph1->size[1]*render->offset[3];
- render->offset[1] = diff;
+ float diff = glyph1->size[1] - glyph1->size[1]*gui_font3d.offset[3];
+ gui_font3d.offset[1] = diff;
}
continue;
}
if( glyph1 && (c0 == k_SRglyph_mod_square || c0 == k_SRglyph_mod_circle)){
v4f v0;
v2_sub( glyph0->size, glyph1->size, v0 );
- v2_muladds( render->offset, v0, -0.5f, v0 );
- v0[2] = render->offset[2];
- v0[3] = render->offset[3];
+ v2_muladds( gui_font3d.offset, v0, -0.5f, v0 );
+ v0[2] = gui_font3d.offset[2];
+ v0[3] = gui_font3d.offset[3];
- font3d_setoffset( render, v0 );
+ font3d_setoffset( v0 );
mesh_drawn( glyph0->indice_start, glyph0->indice_count );
continue;
}
else{
- font3d_setoffset( render, render->offset );
+ font3d_setoffset( gui_font3d.offset );
mesh_drawn( glyph0->indice_start, glyph0->indice_count );
}
- render->offset[0] += glyph0->size[0]*render->offset[3];
+ gui_font3d.offset[0] += glyph0->size[0]*gui_font3d.offset[3];
}
-
- render->u8pch = NULL;
}
-static
-float font3d_simple_draw( font3d *font, u32 variant_id, enum font_shader shader,
- const char *text,
- camera *cam, m4x3f transform )
-{
+static f32 font3d_simple_draw( u32 variant_id, const char *text,
+ camera *cam, m4x3f transform ){
if( !text ) return 0.0f;
- struct font3d_render render = {
- .font = font,
- .variant_id = variant_id,
- .shader = shader,
- };
-
- font3d_begin( text, cam, transform, &render );
- font3d_draw( &render );
- return render.offset[0];
+ gui_font3d.variant_id = variant_id;
+ font3d_set_transform( text, cam, transform );
+ font3d_draw( text );
+ return gui_font3d.offset[0];
}
-static
-float font3d_string_width( font3d *font, u32 variant_id, const char *text )
-{
+static f32 font3d_string_width( u32 variant_id, const char *text ){
if( !text ) return 0.0f;
float width = 0.0f;
u32 c = buf[i];
if(!c) break;
- ent_glyph *glyph = font3d_glyph( font, variant_id, c );
+ ent_glyph *glyph = font3d_glyph( gui_font3d.font, variant_id, c );
if( !glyph ) continue;
width += glyph->size[0];
camera_finalize( &ortho );
-
-
-
/* icons */
- font3d_bind( &gui.font, &ortho );
+ font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &ortho );
+ mesh_bind( &gui.icons_mesh );
+
m4x3f mmdl;
m4x3_identity( mmdl );
shader_model_font_uMdl( mmdl );
- mesh_bind( &gui.icons_mesh );
shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, gui.icons_texture );
-
-
gui.factive = vg_lerpf( gui.factive, gui.helper_count?1.0f:0.0f,
vg.time_frame_delta*2.0f );
v3_zero( mmdl[3] );
f32 pad = dy*0x1p-4f*0.125f;
- f32 w = font3d_string_width( &gui.font,2,gui.location );
+ f32 w = font3d_string_width( 2, gui.location );
mmdl[3][0] = fr*0.5f - w*scale*0.5f;
mmdl[3][1] = 0.3f*ft+pad*2.0f;
- font3d_bind( &gui.font, &ortho );
+ font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &ortho );
shader_model_font_uColour( (v4f){1.2f,1.2f,1.2f,o} );
- font3d_simple_draw( &gui.font, 2, k_font_shader_default,
- gui.location, &ortho, mmdl );
+ font3d_simple_draw( 2, gui.location, &ortho, mmdl );
}
-
- font3d_bind( &gui.font, &ortho );
+ else
+ font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &ortho );
float dy = ft/0.79f,
scale = dy*0x1p-4f*0.75f;
for( u32 i=0; i<gui.helper_count; i++ ){
struct gui_helper *helper = &gui.helpers[i];
- shader_model_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
-
- struct font3d_render render = {
- .font = &gui.font,
- .variant_id = 2,
- .shader = k_font_shader_default
- };
- font3d_begin( helper->bindstr, &ortho, mmdl, &render );
- font3d_draw( &render );
+ font3d_setcolour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+ font3d_simple_draw( 2, helper->bindstr, &ortho, mmdl );
const char *make_smaller = "\x02\xaf\x03 ";
- render.u8pch = (const u8*)make_smaller;
- font3d_draw( &render );
-
- render.u8pch = (u8*)helper->text;
- font3d_draw( &render );
+ font3d_draw( make_smaller );
+ font3d_draw( helper->text );
- float w = render.offset[0]+1.0f;
+ float w = gui_font3d.offset[0]+1.0f;
mmdl[3][0] += w*scale;
}
m4x3f local;
m4x3_identity( local );
- font3d_bind( &gui.font, &menu.view );
+ font3d_bind( &gui.font, k_font_shader_default, 0, NULL, &menu.view );
for( u32 i=0; i<text_count; i++ ){
ent_menuitem *item = text_list[ i ];
m4x3f transform;
u32 variant = item->binding.font_variant;
menu_binding_string( buf, item->binding.pstr_bind );
- f32 offset = font3d_string_width( &gui.font, variant, buf );
+ f32 offset = font3d_string_width( variant, buf );
local[3][0] = -0.5f * offset;
m4x3_mul( transform, local, transform );
- font3d_simple_draw( &gui.font, variant, k_font_shader_default, buf,
- &menu.view, transform );
+ font3d_simple_draw( variant, buf, &menu.view, transform );
}
}
#include "player_render.h"
#include "network_common.h"
#include "addon.h"
+#include "font.h"
+#include "gui.h"
static void player_remote_clear( struct network_player *player ){
addon_cache_unwatch( k_addon_type_player, player->playermodel_view_slot );
}
static void remote_player_nametag( m4x4f pv, v3f co, const char *name ){
+ return;
vg_ui.font = &vg_ui_font_big;
v4f wpos;
v3_copy( co, wpos );
* Draw remote players
*/
static void render_remote_players( world_instance *world, camera *cam ){
-
SDL_AtomicLock( &addon_system.sl_cache_using_resources );
for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
SDL_AtomicUnlock( &addon_system.sl_cache_using_resources );
}
+static void render_remote_player_nametag( v3f co, const char *name ){
+ m4x3f mlocal;
+ m4x3_identity( mlocal );
+ mlocal[3][0] -= font3d_string_width( 2, name ) * 0.5f;
+
+ m4x3f mmdl;
+ m3x3_identity( mmdl );
+ for( int i=0; i<3; i++ )
+ v3_muls( skaterift.cam.mtx.v[i], 0.2f, mmdl[i] );
+ m3x3_transpose( mmdl, mmdl );
+ v3_add( co, (v3f){0.0f,2.0f,0.0f}, mmdl[3] );
+
+ m4x3_mul( mmdl, mlocal, mmdl );
+ font3d_simple_draw( 2, name, &skaterift.cam, mmdl );
+}
+
+static void render_remote_players_tags( world_instance *world, camera *cam ){
+ glEnable(GL_BLEND);
+ glEnable(GL_DEPTH_TEST);
+ glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+ glBlendEquation(GL_FUNC_ADD);
+
+ font3d_bind( &gui.font, k_font_shader_default, 1, NULL, &skaterift.cam );
+ font3d_setcolour( (v4f){1.0f,1.0f,1.0f,1.0f} );
+
+ render_remote_player_nametag(
+ localplayer.final_mtx[0][3],
+ steam_username_at_startup );
+
+ for( u32 i=0; i<NETWORK_MAX_PLAYERS; i ++ ){
+ struct network_player *player = &netplayers.list[i];
+ if( !player->active ) continue;
+ if( player->active_world != world ) continue;
+
+ struct player_avatar *av = localplayer.playeravatar;
+ render_remote_player_nametag(
+ netplayers.final_mtx[av->sk.bone_count*i][3],
+ player->username );
+ }
+
+ glDisable(GL_BLEND);
+}
+
static void remote_players_init(void){
for( u32 i=0; i<NETWORK_SFX_QUEUE_LENGTH; i ++ ){
netplayers.sfx_queue[i].system = k_player_subsystem_invalid;
#include "shaders/model_character_view.h"
#include "shaders/model_board_view.h"
#include "shaders/model_entity.h"
+#include "shaders/model_board_view.h"
static void player_avatar_load( struct player_avatar *av, const char *path ){
mdl_open( &av->meta, path, vg_mem.rtmemory );
{
if( !board ) return;
+ /* TODO:
+ * adding depth compare to this shader
+ */
+
v3f inverse;
glActiveTexture( GL_TEXTURE0 );
--- /dev/null
+uniform sampler2D uTexSceneDepth;
+uniform vec3 uInverseRatioDepth;
+uniform vec3 uInverseRatioMain;
+uniform bool uDepthCompare;
+
+float linear_depth( float depth, float near, float far ) {
+ float z = depth * 2.0 - 1.0;
+ return (2.0 * near * far) / (far + near - z * (far - near));
+}
+
+void depth_compare_dither(){
+ if( uDepthCompare ){
+ vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy
+ * uInverseRatioDepth.xy;
+ float back_depth = texture( uTexSceneDepth, back_coord ).r;
+ float front_depth = gl_FragCoord.z/gl_FragCoord.w;
+
+ back_depth = linear_depth( back_depth, 0.1, 2100.0 );
+ float diff = back_depth - front_depth;
+
+ vec2 ssuv = gl_FragCoord.xy;
+ vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
+ float dither = fract( vDither.g / 71.0 ) - 0.5;
+
+ if( step(0.0,diff)+dither<0.3 )
+ discard;
+ }
+}
.orig_file = "shaders/model_character_view.fs",
.static_src =
"uniform sampler2D uTexMain;\n"
-"uniform sampler2D uTexSceneDepth;\n"
"uniform vec3 uCamera;\n"
-"uniform vec3 uInverseRatioDepth;\n"
-"uniform vec3 uInverseRatioMain;\n"
-"uniform bool uDepthCompare;\n"
"\n"
"in vec4 aColour;\n"
"in vec2 aUv;\n"
" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
"}\n"
"\n"
-"#line 15 0 \n"
+"#line 11 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 16 0 \n"
+"#line 12 0 \n"
+"#line 1 3 \n"
+"uniform sampler2D uTexSceneDepth;\n"
+"uniform vec3 uInverseRatioDepth;\n"
+"uniform vec3 uInverseRatioMain;\n"
+"uniform bool uDepthCompare;\n"
"\n"
-"float linear_depth( float depth, float near, float far ) \n"
-"{\n"
+"float linear_depth( float depth, float near, float far ) {\n"
" float z = depth * 2.0 - 1.0;\n"
" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
"}\n"
"\n"
-"void main()\n"
-"{\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec3 qnorm = aNorm;\n"
-" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
-" vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
-"\n"
-" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
-" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
-"\n"
+"void depth_compare_dither(){\n"
" if( uDepthCompare ){\n"
" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
" * uInverseRatioDepth.xy;\n"
" if( step(0.0,diff)+dither<0.3 )\n"
" discard;\n"
" }\n"
+"}\n"
+"\n"
+"#line 13 0 \n"
+"\n"
+"void main(){\n"
+" depth_compare_dither();\n"
+" compute_motion_vectors();\n"
+"\n"
+" vec3 qnorm = aNorm;\n"
+" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
+" vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
+"\n"
+" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
+" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
"\n"
" oColour = vec4( composite, opacity );\n"
"}\n"
static GLuint _uniform_model_board_view_uPv;
static GLuint _uniform_model_board_view_uPvmPrev;
static GLuint _uniform_model_board_view_uTexMain;
-static GLuint _uniform_model_board_view_uTexSceneDepth;
static GLuint _uniform_model_board_view_uCamera;
-static GLuint _uniform_model_board_view_uInverseRatioDepth;
-static GLuint _uniform_model_board_view_uInverseRatioMain;
-static GLuint _uniform_model_board_view_uDepthCompare;
static GLuint _uniform_model_board_view_g_world_depth;
static GLuint _uniform_model_board_view_uLightsArray;
static GLuint _uniform_model_board_view_uLightsIndex;
+static GLuint _uniform_model_board_view_uTexSceneDepth;
+static GLuint _uniform_model_board_view_uInverseRatioDepth;
+static GLuint _uniform_model_board_view_uInverseRatioMain;
+static GLuint _uniform_model_board_view_uDepthCompare;
static void shader_model_board_view_uMdl(m4x3f m){
glUniformMatrix4x3fv(_uniform_model_board_view_uMdl,1,GL_FALSE,(float*)m);
}
static void shader_model_board_view_uTexMain(int i){
glUniform1i(_uniform_model_board_view_uTexMain,i);
}
-static void shader_model_board_view_uTexSceneDepth(int i){
- glUniform1i(_uniform_model_board_view_uTexSceneDepth,i);
-}
static void shader_model_board_view_uCamera(v3f v){
glUniform3fv(_uniform_model_board_view_uCamera,1,v);
}
+static void shader_model_board_view_g_world_depth(int i){
+ glUniform1i(_uniform_model_board_view_g_world_depth,i);
+}
+static void shader_model_board_view_uTexSceneDepth(int i){
+ glUniform1i(_uniform_model_board_view_uTexSceneDepth,i);
+}
static void shader_model_board_view_uInverseRatioDepth(v3f v){
glUniform3fv(_uniform_model_board_view_uInverseRatioDepth,1,v);
}
static void shader_model_board_view_uDepthCompare(int b){
glUniform1i(_uniform_model_board_view_uDepthCompare,b);
}
-static void shader_model_board_view_g_world_depth(int i){
- glUniform1i(_uniform_model_board_view_g_world_depth,i);
-}
static void shader_model_board_view_register(void){
vg_shader_register( &_shader_model_board_view );
}
_uniform_model_board_view_uPv = glGetUniformLocation( _shader_model_board_view.id, "uPv" );
_uniform_model_board_view_uPvmPrev = glGetUniformLocation( _shader_model_board_view.id, "uPvmPrev" );
_uniform_model_board_view_uTexMain = glGetUniformLocation( _shader_model_board_view.id, "uTexMain" );
- _uniform_model_board_view_uTexSceneDepth = glGetUniformLocation( _shader_model_board_view.id, "uTexSceneDepth" );
_uniform_model_board_view_uCamera = glGetUniformLocation( _shader_model_board_view.id, "uCamera" );
- _uniform_model_board_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioDepth" );
- _uniform_model_board_view_uInverseRatioMain = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioMain" );
- _uniform_model_board_view_uDepthCompare = glGetUniformLocation( _shader_model_board_view.id, "uDepthCompare" );
_uniform_model_board_view_g_world_depth = glGetUniformLocation( _shader_model_board_view.id, "g_world_depth" );
_uniform_model_board_view_uLightsArray = glGetUniformLocation( _shader_model_board_view.id, "uLightsArray" );
_uniform_model_board_view_uLightsIndex = glGetUniformLocation( _shader_model_board_view.id, "uLightsIndex" );
+ _uniform_model_board_view_uTexSceneDepth = glGetUniformLocation( _shader_model_board_view.id, "uTexSceneDepth" );
+ _uniform_model_board_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioDepth" );
+ _uniform_model_board_view_uInverseRatioMain = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioMain" );
+ _uniform_model_board_view_uDepthCompare = glGetUniformLocation( _shader_model_board_view.id, "uDepthCompare" );
}
#endif /* SHADER_model_board_view_H */
uniform sampler2D uTexMain;
-uniform sampler2D uTexSceneDepth;
uniform vec3 uCamera;
-uniform vec3 uInverseRatioDepth;
-uniform vec3 uInverseRatioMain;
-uniform bool uDepthCompare;
in vec4 aColour;
in vec2 aUv;
#include "common_world.glsl"
#include "motion_vectors_fs.glsl"
+#include "depth_compare.glsl"
-float linear_depth( float depth, float near, float far )
-{
- float z = depth * 2.0 - 1.0;
- return (2.0 * near * far) / (far + near - z * (far - near));
-}
-
-void main()
-{
+void main(){
+ depth_compare_dither();
compute_motion_vectors();
vec3 qnorm = aNorm;
float dist = distance( aWorldCo, uCamera ) - 0.08;
float opacity = clamp( dist*dist, 0.0, 1.0 );
- if( uDepthCompare ){
- vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy
- * uInverseRatioDepth.xy;
- float back_depth = texture( uTexSceneDepth, back_coord ).r;
- float front_depth = gl_FragCoord.z/gl_FragCoord.w;
-
- back_depth = linear_depth( back_depth, 0.1, 2100.0 );
- float diff = back_depth - front_depth;
-
- vec2 ssuv = gl_FragCoord.xy;
- vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
- float dither = fract( vDither.g / 71.0 ) - 0.5;
-
- if( step(0.0,diff)+dither<0.3 )
- discard;
- }
-
oColour = vec4( composite, opacity );
}
.orig_file = "shaders/model_character_view.fs",
.static_src =
"uniform sampler2D uTexMain;\n"
-"uniform sampler2D uTexSceneDepth;\n"
"uniform vec3 uCamera;\n"
-"uniform vec3 uInverseRatioDepth;\n"
-"uniform vec3 uInverseRatioMain;\n"
-"uniform bool uDepthCompare;\n"
"\n"
"in vec4 aColour;\n"
"in vec2 aUv;\n"
" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
"}\n"
"\n"
-"#line 15 0 \n"
+"#line 11 0 \n"
"#line 1 2 \n"
"const float k_motion_lerp_amount = 0.01;\n"
"\n"
" oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
"}\n"
"\n"
-"#line 16 0 \n"
+"#line 12 0 \n"
+"#line 1 3 \n"
+"uniform sampler2D uTexSceneDepth;\n"
+"uniform vec3 uInverseRatioDepth;\n"
+"uniform vec3 uInverseRatioMain;\n"
+"uniform bool uDepthCompare;\n"
"\n"
-"float linear_depth( float depth, float near, float far ) \n"
-"{\n"
+"float linear_depth( float depth, float near, float far ) {\n"
" float z = depth * 2.0 - 1.0;\n"
" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
"}\n"
"\n"
-"void main()\n"
-"{\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec3 qnorm = aNorm;\n"
-" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
-" vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
-"\n"
-" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
-" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
-"\n"
+"void depth_compare_dither(){\n"
" if( uDepthCompare ){\n"
" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
" * uInverseRatioDepth.xy;\n"
" if( step(0.0,diff)+dither<0.3 )\n"
" discard;\n"
" }\n"
+"}\n"
+"\n"
+"#line 13 0 \n"
+"\n"
+"void main(){\n"
+" depth_compare_dither();\n"
+" compute_motion_vectors();\n"
+"\n"
+" vec3 qnorm = aNorm;\n"
+" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
+" vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
+"\n"
+" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
+" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
"\n"
" oColour = vec4( composite, opacity );\n"
"}\n"
static GLuint _uniform_model_character_view_uPv;
static GLuint _uniform_model_character_view_uTransforms;
static GLuint _uniform_model_character_view_uTexMain;
-static GLuint _uniform_model_character_view_uTexSceneDepth;
static GLuint _uniform_model_character_view_uCamera;
-static GLuint _uniform_model_character_view_uInverseRatioDepth;
-static GLuint _uniform_model_character_view_uInverseRatioMain;
-static GLuint _uniform_model_character_view_uDepthCompare;
static GLuint _uniform_model_character_view_g_world_depth;
static GLuint _uniform_model_character_view_uLightsArray;
static GLuint _uniform_model_character_view_uLightsIndex;
+static GLuint _uniform_model_character_view_uTexSceneDepth;
+static GLuint _uniform_model_character_view_uInverseRatioDepth;
+static GLuint _uniform_model_character_view_uInverseRatioMain;
+static GLuint _uniform_model_character_view_uDepthCompare;
static void shader_model_character_view_uPv(m4x4f m){
glUniformMatrix4fv(_uniform_model_character_view_uPv,1,GL_FALSE,(float*)m);
}
static void shader_model_character_view_uTexMain(int i){
glUniform1i(_uniform_model_character_view_uTexMain,i);
}
-static void shader_model_character_view_uTexSceneDepth(int i){
- glUniform1i(_uniform_model_character_view_uTexSceneDepth,i);
-}
static void shader_model_character_view_uCamera(v3f v){
glUniform3fv(_uniform_model_character_view_uCamera,1,v);
}
+static void shader_model_character_view_g_world_depth(int i){
+ glUniform1i(_uniform_model_character_view_g_world_depth,i);
+}
+static void shader_model_character_view_uTexSceneDepth(int i){
+ glUniform1i(_uniform_model_character_view_uTexSceneDepth,i);
+}
static void shader_model_character_view_uInverseRatioDepth(v3f v){
glUniform3fv(_uniform_model_character_view_uInverseRatioDepth,1,v);
}
static void shader_model_character_view_uDepthCompare(int b){
glUniform1i(_uniform_model_character_view_uDepthCompare,b);
}
-static void shader_model_character_view_g_world_depth(int i){
- glUniform1i(_uniform_model_character_view_g_world_depth,i);
-}
static void shader_model_character_view_register(void){
vg_shader_register( &_shader_model_character_view );
}
_uniform_model_character_view_uPv = glGetUniformLocation( _shader_model_character_view.id, "uPv" );
_uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" );
_uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" );
- _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" );
_uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" );
- _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" );
- _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" );
- _uniform_model_character_view_uDepthCompare = glGetUniformLocation( _shader_model_character_view.id, "uDepthCompare" );
_uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" );
_uniform_model_character_view_uLightsArray = glGetUniformLocation( _shader_model_character_view.id, "uLightsArray" );
_uniform_model_character_view_uLightsIndex = glGetUniformLocation( _shader_model_character_view.id, "uLightsIndex" );
+ _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" );
+ _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" );
+ _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" );
+ _uniform_model_character_view_uDepthCompare = glGetUniformLocation( _shader_model_character_view.id, "uDepthCompare" );
}
#endif /* SHADER_model_character_view_H */
in vec3 aCo;
#include "motion_vectors_fs.glsl"
+#include "depth_compare.glsl"
-void main()
-{
+void main(){
+ depth_compare_dither();
compute_motion_vectors();
oColour = texture( uTexMain, aUv ) * uColour;
}
"}\n"
"\n"
"#line 11 0 \n"
+"#line 1 2 \n"
+"uniform sampler2D uTexSceneDepth;\n"
+"uniform vec3 uInverseRatioDepth;\n"
+"uniform vec3 uInverseRatioMain;\n"
+"uniform bool uDepthCompare;\n"
+"\n"
+"float linear_depth( float depth, float near, float far ) {\n"
+" float z = depth * 2.0 - 1.0;\n"
+" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
+"}\n"
"\n"
-"void main()\n"
-"{\n"
+"void depth_compare_dither(){\n"
+" if( uDepthCompare ){\n"
+" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
+" * uInverseRatioDepth.xy;\n"
+" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
+" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
+"\n"
+" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
+" float diff = back_depth - front_depth;\n"
+"\n"
+" vec2 ssuv = gl_FragCoord.xy;\n"
+" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
+" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
+"\n"
+" if( step(0.0,diff)+dither<0.3 )\n"
+" discard;\n"
+" }\n"
+"}\n"
+"\n"
+"#line 12 0 \n"
+"\n"
+"void main(){\n"
+" depth_compare_dither();\n"
" compute_motion_vectors();\n"
" oColour = texture( uTexMain, aUv ) * uColour;\n"
"}\n"
static GLuint _uniform_model_font_uOffset;
static GLuint _uniform_model_font_uTexMain;
static GLuint _uniform_model_font_uColour;
+static GLuint _uniform_model_font_uTexSceneDepth;
+static GLuint _uniform_model_font_uInverseRatioDepth;
+static GLuint _uniform_model_font_uInverseRatioMain;
+static GLuint _uniform_model_font_uDepthCompare;
static void shader_model_font_uMdl(m4x3f m){
glUniformMatrix4x3fv(_uniform_model_font_uMdl,1,GL_FALSE,(float*)m);
}
static void shader_model_font_uColour(v4f v){
glUniform4fv(_uniform_model_font_uColour,1,v);
}
+static void shader_model_font_uTexSceneDepth(int i){
+ glUniform1i(_uniform_model_font_uTexSceneDepth,i);
+}
+static void shader_model_font_uInverseRatioDepth(v3f v){
+ glUniform3fv(_uniform_model_font_uInverseRatioDepth,1,v);
+}
+static void shader_model_font_uInverseRatioMain(v3f v){
+ glUniform3fv(_uniform_model_font_uInverseRatioMain,1,v);
+}
+static void shader_model_font_uDepthCompare(int b){
+ glUniform1i(_uniform_model_font_uDepthCompare,b);
+}
static void shader_model_font_register(void){
vg_shader_register( &_shader_model_font );
}
_uniform_model_font_uOffset = glGetUniformLocation( _shader_model_font.id, "uOffset" );
_uniform_model_font_uTexMain = glGetUniformLocation( _shader_model_font.id, "uTexMain" );
_uniform_model_font_uColour = glGetUniformLocation( _shader_model_font.id, "uColour" );
+ _uniform_model_font_uTexSceneDepth = glGetUniformLocation( _shader_model_font.id, "uTexSceneDepth" );
+ _uniform_model_font_uInverseRatioDepth = glGetUniformLocation( _shader_model_font.id, "uInverseRatioDepth" );
+ _uniform_model_font_uInverseRatioMain = glGetUniformLocation( _shader_model_font.id, "uInverseRatioMain" );
+ _uniform_model_font_uDepthCompare = glGetUniformLocation( _shader_model_font.id, "uDepthCompare" );
}
#endif /* SHADER_model_font_H */
/* Draw player to window buffer and blend background ontop */
player__render( &small_cam );
+ render_remote_players_tags( localplayer.viewable_world, &skaterift.cam );
}
static void render_scene(void){
* Rendering
*/
-static void bind_terrain_noise(void)
-{
+static void bind_terrain_noise(void){
glActiveTexture( GL_TEXTURE0 );
glBindTexture( GL_TEXTURE_2D, world_render.tex_terrain_noise );
}
}
/* render texts */
- shader_scene_font_use();
- shader_scene_font_uTexGarbage(0);
- shader_scene_font_uTexMain(1);
-
- shader_scene_font_uPv( skaterift.cam.mtx.pv );
- shader_scene_font_uTime( vg.time );
-
- /* TODO: Code dupe... */
- world_link_lighting_ub( world, _shader_scene_font.id );
- world_bind_position_texture( world, _shader_scene_font.id,
- _uniform_scene_font_g_world_depth, 2 );
- world_bind_light_array( world, _shader_scene_font.id,
- _uniform_scene_font_uLightsArray, 3 );
- world_bind_light_index( world, _shader_scene_font.id,
- _uniform_scene_font_uLightsIndex, 4 );
-
- bind_terrain_noise();
- shader_scene_font_uCamera( skaterift.cam.transform[3] );
-
- //shader_scene_font_uColour( (v4f){1.0f,1.0f,1.0f,1.0f} );
- glActiveTexture( GL_TEXTURE1 );
- glBindTexture( GL_TEXTURE_2D, gui.font.texture );
-
- mesh_bind( &gui.font.mesh );
+ font3d_bind( &gui.font, k_font_shader_world, 0, world, &skaterift.cam );
char buf[32];
u32 count = 0;
c+=highscore_intl( buf+c, mdl_arrcount(&world->ent_challenge), 3 );
buf[c++] = '\0';
- f32 w = font3d_string_width( &gui.font, 1, buf );
+ f32 w = font3d_string_width( 1, buf );
m4x3f mlocal;
m3x3_identity( mlocal );
mlocal[3][0] = -w*0.5f;
shader_scene_font_uOpacity( scale );
shader_scene_font_uColourize( colour );
-
- struct font3d_render render = {
- .font = &gui.font,
- .variant_id = 1,
- .shader = k_font_shader_world
- };
-
- font3d_begin( buf, &skaterift.cam, mmdl, &render );
- font3d_draw( &render );
+ font3d_simple_draw( 1, buf, &skaterift.cam, mmdl );
}
}
static void render_world( world_instance *world, camera *cam,
int layer_depth );
static void render_world_cubemaps( world_instance *world );
+static void bind_terrain_noise(void);
#endif /* WORLD_RENDER_H */
GLuint shader, GLuint location,
int slot );
-static void world_routes_update_timer_texts( world_instance *world )
-{
+static void world_routes_update_timer_texts( world_instance *world ){
world_render.timer_text_count = 0;
for( u32 i=0; i<mdl_arrcount(&world->ent_route); i++ ){
highscore_intr( text->text+2, route->checkpoints_count+1, 1, ' ' );
text->text[3] = '\0';
}
-
- float align_r = font3d_string_width( &gui.font, 0, text->text );
+
+ gui_font3d.font = &gui.font;
+ float align_r = font3d_string_width( 0, text->text );
align_r *= size;
v3f positions[] = {
/* timers
* ---------------------------------------------------- */
if( layer_depth == 0 ){
- font3d_bind( &gui.font, cam );
+ font3d_bind( &gui.font, k_font_shader_default, 0, world, cam );
for( u32 i=0; i<world_render.timer_text_count; i++ ){
struct timer_text *text = &world_render.timer_texts[i];
colour[3] = 1.0f-text->route->factive;
shader_model_font_uColour( colour );
- font3d_simple_draw( &gui.font, 0, k_font_shader_default,
- text->text, cam, text->transform );
+ font3d_simple_draw( 0, text->text, cam, text->transform );
}
shader_model_font_uOffset( (v4f){0.0f,0.0f,0.0f,1.0f} );