completed all glider stuff
[carveJwlIkooP6JGAAIwe30JlM.git] / world_render.c
index 613d3bffa6af21c473ff170938391b7357971624..2355e20bf204bd942870515167bbe75d2366e502 100644 (file)
@@ -13,6 +13,7 @@
 #include "ent_miniworld.h"
 #include "player_remote.h"
 #include "ent_skateshop.h"
+#include "shaders/model_entity.h"
 
 static int ccmd_set_time( int argc, const char *argv[] ){
    world_instance *world = world_current_instance();
@@ -70,6 +71,7 @@ static void world_render_init(void){
    VG_VAR_I32( k_debug_light_indices );
    VG_VAR_I32( k_debug_light_complexity );
    VG_VAR_I32( k_light_preview );
+   VG_VAR_I32( k_light_editor );
    vg_console_reg_cmd( "set_time", ccmd_set_time, NULL );
 
    world_render.sky_rate = 1.0;
@@ -565,19 +567,20 @@ static void world_render_challenges( world_instance *world,
    /* render texts */
    font3d_bind( &gui.font, k_font_shader_world, 0, world, &skaterift.cam );
 
-   char buf[32];
    u32 count = 0;
 
-   for( u32 i=0; i<mdl_arrcount(&world->ent_challenge); i++ ){
+   for( u32 i=0; i<mdl_arrcount(&world->ent_challenge); i++ )
+   {
       ent_challenge *challenge = mdl_arritm( &world->ent_challenge, i );
       if( challenge->status ) count ++;
    }
 
-   int c=0;
-   c+=highscore_intl( buf+c, count, 3 );
-   buf[c++] = '/';
-   c+=highscore_intl( buf+c, mdl_arrcount(&world->ent_challenge), 3 );
-   buf[c++] = '\0';
+   char buf[32];
+   vg_str str;
+   vg_strnull( &str, buf, sizeof(buf) );
+   vg_strcati32( &str, count );
+   vg_strcatch( &str, '/' );
+   vg_strcati32( &str, mdl_arrcount(&world->ent_challenge) );
 
    f32 w = font3d_string_width( 1, buf );
    m4x3f mlocal;
@@ -586,7 +589,8 @@ static void world_render_challenges( world_instance *world,
    mlocal[3][1] = 0.0f;
    mlocal[3][2] = 0.0f;
 
-   for( u32 i=0; i<challenge_count; i++ ){
+   for( u32 i=0; i<challenge_count; i++ )
+   {
       u32 index = challenge_list[ i ];
       ent_challenge *challenge = mdl_arritm( &world->ent_challenge, index );
       m4x3f mmdl;
@@ -856,6 +860,13 @@ static void world_prerender( world_instance *world ){
    state->g_debug_complexity = k_debug_light_complexity;
    state->g_time_of_day = vg_fractf( world->time );
 
+   if( vg.quality_profile == k_quality_profile_high )
+      state->g_shadow_samples = 8;
+   else if( vg.quality_profile == k_quality_profile_low )
+      state->g_shadow_samples = 2;
+   else
+      state->g_shadow_samples = 0;
+
    state->g_day_phase   = cosf( state->g_time_of_day * VG_PIf * 2.0f );
    state->g_sunset_phase= cosf( state->g_time_of_day * VG_PIf * 4.0f + VG_PIf );
 
@@ -881,6 +892,50 @@ 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 ){
+   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;
+
+   i32 idx;
+   while( bh_next( world->entity_bh, &it, &idx ) ){
+      u32 id    = world->entity_list[ idx ],
+          type  = mdl_entity_id_type( id ),
+          index = mdl_entity_id_id( id );
+
+      if( type == k_ent_glider ) {
+         if( glider_count < vg_list_size(glider_list) )
+            glider_list[ glider_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; j<glider_count; j ++ ){
+      ent_glider *glider = mdl_arritm( &world->ent_glider, glider_list[j] );
+
+      if( !(glider->flags & 0x1) )
+         continue;
+
+      m4x3f mdl;
+      mdl_transform_m4x3( &glider->transform, mdl );
+
+      f32 dist  = v3_dist( glider->transform.co, cam->pos ) * (1.0f/radius),
+          scale = vg_smoothstepf( vg_clampf( 5.0f-dist*5.0f, 0.0f,1.0f ) );
+      m3x3_scalef( mdl, scale );
+
+      render_glider_model( cam, world, mdl, k_board_shader_entity );
+   }
+}
+
 static void render_world( world_instance *world, camera *cam,
                           int stenciled, int viewing_from_gate, 
                           int with_water, int with_cubemaps ){
@@ -977,6 +1032,7 @@ static void render_world( world_instance *world, camera *cam,
    }
 
    render_remote_players( world, cam );
+   render_other_entities( world, cam );
    ent_miniworld_render( world, cam );
 
    if( stenciled ){
@@ -1179,4 +1235,48 @@ static void render_world_position( world_instance *world, camera *cam ){
    mesh_draw( &world->mesh_geo );
 }
 
+struct ui_enum_opt skybox_setting_options[] = { 
+   { 0, "g_daysky_colour" },
+   { 1, "g_nightsky_colour" },
+   { 2, "g_sunset_colour" },
+   { 3, "g_ambient_colour" },
+   { 4, "g_sun_colour" },
+};
+
+static f32 *skybox_prop_location( world_instance *world, i32 index ){
+   switch( index ){
+      case 0: return world->ub_lighting.g_daysky_colour; break;
+      case 1: return world->ub_lighting.g_nightsky_colour; break;
+      case 2: return world->ub_lighting.g_sunset_colour; break;
+      case 3: return world->ub_lighting.g_ambient_colour; break;
+      case 4: return world->ub_lighting.g_sun_colour; break;
+      default: return NULL;
+   }
+}
+
+static void imgui_world_light_edit( 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_rect_pad( panel, (ui_px[2]){ 8, 8 } );
+   vg_ui.wants_mouse = 1;
+
+   static i32 option_to_edit = 0;
+   ui_enum( panel, "option", skybox_setting_options, 5, &option_to_edit );
+   ui_colourpicker( panel, "colour", 
+                    skybox_prop_location( world, option_to_edit ) );
+
+   if( ui_button( panel, "save tweaker file ('/tmp/tweaker.txt')\n" ) == 1 ){
+      FILE *fp = fopen( "/tmp/tweaker.txt", "w" );
+      
+      for( i32 i=0; i<5; i ++ ){
+         struct ui_enum_opt *opt = &skybox_setting_options[i];
+         f32 *val = skybox_prop_location( world, i );
+         fprintf( fp, "%s = {%.3ff, %.3ff, %.3ff, %.3ff},\n",
+                  opt->alias, val[0], val[1], val[2], val[3] );
+      }
+      fclose( fp );
+   }
+}
+
 #endif