cool font shader and entity bvh fix
authorhgn <hgodden00@gmail.com>
Tue, 8 Aug 2023 17:58:51 +0000 (18:58 +0100)
committerhgn <hgodden00@gmail.com>
Tue, 8 Aug 2023 17:59:40 +0000 (18:59 +0100)
blender_export.py
highscores.c
maps_src/mp_spawn/main.mdl
shaders/model_font.h
shaders/model_font.vs
shaders/scene_font.fs
shaders/scene_font.h
world_entity.c
world_render.c

index 52f674f73ba4042a0b308ce01822e23daeb42bb5..8d4c12fb12e5148289065050db153ce0f3d1346c 100644 (file)
@@ -4260,6 +4260,20 @@ def cv_draw():#{
             data = obj.SR_data.ent_unlock[0]
             if data.target:
                cv_draw_arrow( obj.location, data.target.location, (0,1.0,0.0) )
+            cc1 = (0.4,0.3,0.2)
+            info_cu = Vector((1.2,0.01,0.72))*0.5
+            info_co = Vector((0.0,0.0,0.72))*0.5
+            cv_draw_ucube( obj.matrix_world, cc1, info_cu, info_co)
+
+            vs = [Vector((-0.2,0.0,0.10)),Vector((-0.2,0.0,0.62)),\
+                  Vector(( 0.2,0.0,0.62)),Vector((-0.2,0.0,0.30)),\
+                  Vector(( 0.1,0.0,0.30))]
+            for v in range(len(vs)):#{
+               vs[v] = obj.matrix_world @ vs[v]
+            #}
+
+            cv_view_verts += [vs[0],vs[1],vs[1],vs[2],vs[3],vs[4]]
+            cv_view_colours += [cc1,cc1,cc1,cc1,cc1,cc1]
          #}
          elif ent_type == 'ent_audio':#{
             if obj.SR_data.ent_audio[0].flag_3d:
index 77ffc412de82d4a32c9246d304a89cf692b02ad5..6593b9a47696c20382aac41b192fd424d03dffbb 100644 (file)
@@ -402,26 +402,30 @@ VG_STATIC int highscore_intr( char *buf, int value, int len, char alt )
 
 /* Print integer into buffer with max length len 
  * retuns the number of digits written to buf */
-VG_STATIC int highscore_intl( char *buf, int value, int len )
-{
-   char temp[32];
+VG_STATIC int highscore_intl( char *buf, int value, int len ){
+   if( value ){
+      char temp[32];
+      int i=0;
+      while(value){
+         if( i>=len ) 
+            break;
+
+         temp[ i ++ ] = '0' + (value % 10);
+         value /= 10;
+      }
 
-   int i=0;
-   while(value){
-      if( i>=len ) 
-         break;
+      if( i>len )
+         i = len;
 
-      temp[ i ++ ] = '0' + (value % 10);
-      value /= 10;
-   }
-   
-   if( i>len )
-      i = len;
-
-   for( int j=0; j<i; j ++ )
-      buf[j] = temp[ i-1-j ];
+      for( int j=0; j<i; j ++ )
+         buf[j] = temp[ i-1-j ];
 
-   return i;
+      return i;
+   }
+   else{
+      buf[ 0 ] = '0';
+      return 1;
+   }
 }
 
 /* Clear buffer with length using clr character */
index 6c489f8bbf0592fffd58110788b0bc065d2c2dbd..6acac827112e9de92f7721115b0cab679138c8e1 100644 (file)
Binary files a/maps_src/mp_spawn/main.mdl and b/maps_src/mp_spawn/main.mdl differ
index 48753a9706c6e59aeabb9fc06670eb6ab9ada331..e3361ab8c6e91d199d9a3313416167472e7befae 100644 (file)
@@ -56,7 +56,7 @@ static struct vg_shader _shader_model_font = {
 "\n"
 "   aUv = a_uv;\n"
 "   aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
-"   aCo = a_co;\n"
+"   aCo = co;\n"
 "   aWorldCo = world_pos0;\n"
 "}\n"
 ""},
index 2ec8c3e9a1325658b27686c2b66b94008024a30e..6f7d3ca980932cf67c8656fe1f23e8bfd1f76eeb 100644 (file)
@@ -27,6 +27,6 @@ void main()
 
    aUv = a_uv;
    aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );
-   aCo = a_co;
+   aCo = co;
    aWorldCo = world_pos0;
 }
index 27241fee83b488710d782d6ce234c05bcd5cf71b..03d6b20c59a067998bec9361a861843a513f17d4 100644 (file)
@@ -1,23 +1,51 @@
 uniform sampler2D uTexGarbage; // unused
-uniform sampler2D uTexMain;
+uniform sampler2D uTexMain;    // unused
 uniform vec3 uCamera;
-uniform vec4 uPlane;
+uniform float uTime;
+uniform float uOpacity;
+uniform float uColourize;
 
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
-void main()
-{
+vec3 pal( float t ){
+   vec3 a = vec3(0.30,0.3,0.3);
+   vec3 b = vec3(0.8);
+   vec3 c = vec3(0.28,0.3,0.4);
+   vec3 d = vec3(0.00,0.1,0.1);
+   return a + b*cos( 6.28318*(c*t+d) );
+}
+
+void main(){
    compute_motion_vectors();
 
    vec3 vfrag = vec3(0.5,0.5,0.5);
-   vec4 vsamplemain = texture( uTexMain, aUv );
    vec3 qnorm = aNorm.xyz;
 
-   vfrag = vsamplemain.rgb;
+   //vec4 vsamplemain = texture( uTexMain, aUv );
+   //vfrag = vsamplemain.rgb;
+
+   vec4 spread0 = uTime*0.0002*vec4(  17.3,-19.6, 23.2,-47.7 );
+   vec4 spread1 = uTime*0.0002*vec4( -13.3, 12.6,-28.2, 14.7 );
+
+   vec2 p = aCo.xy + vec2(0.3);
+   float a = atan( p.y/p.x );
+   vec4 v0 = step( vec4(0.5), fract(vec4(a) + spread0) );
+   vec4 v1 = step( vec4(0.5), fract(vec4(a) + spread1) );
+
+   float d = ( v0.x+v0.y+v0.z+v0.w +
+               v1.x+v1.y+v1.z+v1.w ) * 0.125f;
+   
+   float dither = fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0);
+   float x = d*0.8+length(p)*0.3;
+   x = (floor(x*8.0) + step(dither, fract(x * 8.0))) / 8.0;
+
+   if( x + (uOpacity*2.0-1.0) < 0.5 ) 
+      discard;
+
+   vfrag = mix( vec3(x), pal( x ), uColourize );
 
-   if( g_light_preview == 1 )
-   {
+   if( g_light_preview == 1 ){
       vfrag = vec3(0.5);
    }
 
index 7c338a5b60fdafde8b9ac5b432f43cf900e6666b..747175a6f9ca6b0913ce1f59e5130a830165f955 100644 (file)
@@ -56,7 +56,7 @@ static struct vg_shader _shader_scene_font = {
 "\n"
 "   aUv = a_uv;\n"
 "   aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
-"   aCo = a_co;\n"
+"   aCo = co;\n"
 "   aWorldCo = world_pos0;\n"
 "}\n"
 ""},
@@ -67,7 +67,9 @@ static struct vg_shader _shader_scene_font = {
 "uniform sampler2D uTexGarbage; // unused\n"
 "uniform sampler2D uTexMain;\n"
 "uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
+"uniform float uTime;\n"
+"uniform float uOpacity;\n"
+"uniform float uColourize;\n"
 "\n"
 "#line       1        1 \n"
 "// :D\n"
@@ -406,7 +408,7 @@ static struct vg_shader _shader_scene_font = {
 "   return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
 "}\n"
 "\n"
-"#line      7        0 \n"
+"#line      9        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -426,25 +428,53 @@ static struct vg_shader _shader_scene_font = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line      8        0 \n"
+"#line     10        0 \n"
+"\n"
+"vec3 pal( float t ){\n"
+"   vec3 a = vec3(0.3,0.3,0.3);\n"
+"   vec3 b = vec3(1.00,1.0,1.0);\n"
+"   vec3 c = vec3(0.28,0.3,0.4);\n"
+"   vec3 d = vec3(0.00,0.1,0.1);\n"
+"   return a + b*cos( 6.28318*(c*t+d) );\n"
+"}\n"
 "\n"
 "void main()\n"
 "{\n"
 "   compute_motion_vectors();\n"
 "\n"
 "   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"   vec4 vsamplemain = texture( uTexMain, aUv );\n"
 "   vec3 qnorm = aNorm.xyz;\n"
 "\n"
-"   vfrag = vsamplemain.rgb;\n"
+"   //vec4 vsamplemain = texture( uTexMain, aUv );\n"
+"   //vfrag = vsamplemain.rgb;\n"
 "\n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
+"   vec4 spread0 = uTime*0.0002*vec4(  17.3,-19.6, 23.2,-47.7 );\n"
+"   vec4 spread1 = uTime*0.0002*vec4( -13.3, 12.6,-28.2, 14.7 );\n"
+"\n"
+"   vec2 p = aCo.xy + vec2(0.3);\n"
+"   float a = atan( p.y/p.x );\n"
+"   vec4 v0 = step( vec4(0.5), fract(vec4(a) + spread0) );\n"
+"   vec4 v1 = step( vec4(0.5), fract(vec4(a) + spread1) );\n"
+"\n"
+"   float d = ( v0.x+v0.y+v0.z+v0.w +\n"
+"               v1.x+v1.y+v1.z+v1.w ) * 0.0625;\n"
+"   \n"
+"   float dither = fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0);\n"
+"   const float STEPS = 8.;\n"
+"   float x = d*0.8+length(p)*0.2;\n"
+"   x = (floor(x * STEPS) + step(dither, fract(x * STEPS))) / STEPS;\n"
+"\n"
+"   if( x + (uOpacity*2.0-1.0) < 0.5 ) \n"
+"      discard;\n"
+"\n"
+"   vfrag = mix( vec3(x), pal( x ), uColourize );\n"
+"\n"
+"   if( g_light_preview == 1 ){\n"
 "      vfrag = vec3(0.5);\n"
 "   }\n"
 "\n"
-"   vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-"   oColour = vec4( vfrag, 1.0 );\n"
+"   vec3 litfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
+"   oColour = vec4( litfrag, 1.0 );\n"
 "}\n"
 ""},
 };
@@ -456,7 +486,9 @@ static GLuint _uniform_scene_font_uOffset;
 static GLuint _uniform_scene_font_uTexGarbage;
 static GLuint _uniform_scene_font_uTexMain;
 static GLuint _uniform_scene_font_uCamera;
-static GLuint _uniform_scene_font_uPlane;
+static GLuint _uniform_scene_font_uTime;
+static GLuint _uniform_scene_font_uOpacity;
+static GLuint _uniform_scene_font_uColourize;
 static GLuint _uniform_scene_font_g_world_depth;
 static GLuint _uniform_scene_font_uLightsArray;
 static GLuint _uniform_scene_font_uLightsIndex;
@@ -481,8 +513,14 @@ static void shader_scene_font_uTexMain(int i){
 static void shader_scene_font_uCamera(v3f v){
    glUniform3fv(_uniform_scene_font_uCamera,1,v);
 }
-static void shader_scene_font_uPlane(v4f v){
-   glUniform4fv(_uniform_scene_font_uPlane,1,v);
+static void shader_scene_font_uTime(float f){
+   glUniform1f(_uniform_scene_font_uTime,f);
+}
+static void shader_scene_font_uOpacity(float f){
+   glUniform1f(_uniform_scene_font_uOpacity,f);
+}
+static void shader_scene_font_uColourize(float f){
+   glUniform1f(_uniform_scene_font_uColourize,f);
 }
 static void shader_scene_font_g_world_depth(int i){
    glUniform1i(_uniform_scene_font_g_world_depth,i);
@@ -499,7 +537,9 @@ static void shader_scene_font_link(void){
    _uniform_scene_font_uTexGarbage = glGetUniformLocation( _shader_scene_font.id, "uTexGarbage" );
    _uniform_scene_font_uTexMain = glGetUniformLocation( _shader_scene_font.id, "uTexMain" );
    _uniform_scene_font_uCamera = glGetUniformLocation( _shader_scene_font.id, "uCamera" );
-   _uniform_scene_font_uPlane = glGetUniformLocation( _shader_scene_font.id, "uPlane" );
+   _uniform_scene_font_uTime = glGetUniformLocation( _shader_scene_font.id, "uTime" );
+   _uniform_scene_font_uOpacity = glGetUniformLocation( _shader_scene_font.id, "uOpacity" );
+   _uniform_scene_font_uColourize = glGetUniformLocation( _shader_scene_font.id, "uColourize" );
    _uniform_scene_font_g_world_depth = glGetUniformLocation( _shader_scene_font.id, "g_world_depth" );
    _uniform_scene_font_uLightsArray = glGetUniformLocation( _shader_scene_font.id, "uLightsArray" );
    _uniform_scene_font_uLightsIndex = glGetUniformLocation( _shader_scene_font.id, "uLightsIndex" );
index 5ec52f774dd8b983c25a23a0148bea53407e2d01..4a8670d085447d41868e89d0e4c8c8317f554b98 100644 (file)
@@ -340,6 +340,18 @@ entity_bh_expand_bound( void *user, boxf bound, u32 item_index ){
       m4x3_expand_aabb_aabb( volume->to_world, bound,
                               (boxf){{-1.0f,-1.0f,-1.0f},{ 1.0f, 1.0f, 1.0f}} );
    }
+   else if( type == k_ent_unlock ){
+      ent_unlock *unlock = mdl_arritm( &world->ent_unlock, index );
+
+      boxf box = {{-1.2f*0.5f,-0.72f*0.5f,-0.01f*0.5f},
+                  { 1.2f*0.5f, 0.72f*0.5f, 0.01f*0.5f}};
+      m4x3f transform;
+      mdl_transform_m4x3( &unlock->transform, transform );
+      m4x3_expand_aabb_aabb( transform, bound, box );
+   }
+   else{
+      vg_fatal_error( "Programming error\n" );
+   }
 }
 
 VG_STATIC float entity_bh_centroid( void *user, u32 item_index, int axis ){
@@ -415,6 +427,15 @@ VG_STATIC void entity_bh_debug( void *user, u32 item_index ){
                                 (boxf){{-1.0f,-1.0f,-1.0f},{ 1.0f, 1.0f, 1.0f}},
                                 0xf000ff00 );
    }
+   else if( type == k_ent_unlock ){
+      ent_unlock *unlock = mdl_arritm( &world->ent_unlock, index );
+
+      boxf box = {{-1.2f*0.5f,-0.72f*0.5f,-0.01f*0.5f},
+                  { 1.2f*0.5f, 0.72f*0.5f, 0.01f*0.5f}};
+      m4x3f transform;
+      mdl_transform_m4x3( &unlock->transform, transform );
+      vg_line_boxf_transformed( transform, box, 0xf0ff0000 );
+   }
    else{
       vg_fatal_error( "Programming error\n" );
    }
@@ -440,6 +461,10 @@ VG_STATIC void entity_bh_closest( void *user, u32 item_index, v3f point,
       ent_volume *volume = mdl_arritm( &world->ent_volume, index );
       v3_copy( volume->to_world[3], closest );
    }
+   else if( type == k_ent_unlock ){
+      ent_unlock *unlock = mdl_arritm( &world->ent_unlock, index );
+      v3_copy( unlock->transform.co, closest );
+   }
    else{
       vg_fatal_error( "Programming error\n" );
    }
index fc2d34f3f895f56ef92828c799dec45d887cccdb..55d13d447a07b067da5042d3d260e8b2e7a9fb29 100644 (file)
@@ -418,7 +418,7 @@ void world_render_challenges( world_instance *world, struct world_pass *pass,
    /* sort lists */
    const f32 radius = 40.0f;
    bh_iter it;
-   bh_iter_init_range( 0, &it, pos, radius );
+   bh_iter_init_range( 0, &it, pos, radius+10.0f );
    i32 idx;
 
    u32 challenge_list[ 32 ],
@@ -452,7 +452,7 @@ void world_render_challenges( world_instance *world, struct world_pass *pass,
       if( challenge->flags & k_ent_challenge_hidden ) continue;
 
       f32 dist = v3_dist( challenge->transform.co, pos ) * (1.0f/radius),
-          scale = vg_smoothstepf( vg_clampf( 10.0f-dist*10.0f, 0.0f,1.0f ) );
+          scale = vg_smoothstepf( vg_clampf( 5.0f-dist*5.0f, 0.0f,1.0f ) );
 
       v3_fill( challenge->transform.s, scale );
 
@@ -479,6 +479,7 @@ void world_render_challenges( world_instance *world, struct world_pass *pass,
    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 );
@@ -498,11 +499,44 @@ void world_render_challenges( world_instance *world, struct world_pass *pass,
 
    mesh_bind( &gui.font.mesh );
 
+   char buf[32];
+   u32 count = 0;
+
+   for( u32 i=0; i<mdl_arrcount(&world->ent_unlock); i++ ){
+      ent_unlock *unlock = mdl_arritm( &world->ent_unlock, i );
+      vg_line_point( unlock->transform.co, 0.2f, VG__GREEN );
+      if( unlock->status ) count ++;
+   }
+
+   int c=0;
+   c+=highscore_intl( buf+c, count, 3 );
+   buf[c++] = '/';
+   c+=highscore_intl( buf+c, mdl_arrcount(&world->ent_unlock), 3 );
+   buf[c++] = '\0';
+
+   f32 w = font3d_string_width( &gui.font, 1, buf );
+   m4x3f mlocal;
+   m3x3_identity( mlocal );
+   mlocal[3][0] = -w*0.5f;
+
    for( u32 i=0; i<unlock_count; i++ ){
       u32 index = unlock_list[ i ];
       ent_unlock *unlock = mdl_arritm( &world->ent_unlock, index );
       m4x3f mmdl;
       mdl_transform_m4x3( &unlock->transform, mmdl );
+      m4x3_mul( mmdl, mlocal, mmdl );
+
+      vg_line_point( unlock->transform.co, 0.25f, VG__RED );
+
+      f32 dist = v3_dist( unlock->transform.co, pos ) * (1.0f/radius),
+          scale = vg_smoothstepf( vg_clampf( 10.0f-dist*10.0f, 0.0f,1.0f ) ),
+          colour = 0.0f;
+
+      if( unlock->status )
+         colour = 1.0f;
+
+      shader_scene_font_uOpacity( scale );
+      shader_scene_font_uColourize( colour );
 
       struct font3d_render render = {
          .font = &gui.font,
@@ -510,7 +544,7 @@ void world_render_challenges( world_instance *world, struct world_pass *pass,
          .shader = k_font_shader_world
       };
 
-      font3d_begin( "Test!", &skaterift.cam, mmdl, &render );
+      font3d_begin( buf, &skaterift.cam, mmdl, &render );
       font3d_draw( &render );
    }
 }