fallback board
authorhgn <hgodden00@gmail.com>
Fri, 24 Nov 2023 05:41:18 +0000 (05:41 +0000)
committerhgn <hgodden00@gmail.com>
Fri, 24 Nov 2023 05:41:18 +0000 (05:41 +0000)
models_src/board_none.mdl [new file with mode: 0644]
player.h
player_render.c
shaders/model_board_view.h
shaders/model_character_view.h
skaterift.c

diff --git a/models_src/board_none.mdl b/models_src/board_none.mdl
new file mode 100644 (file)
index 0000000..b644f1c
Binary files /dev/null and b/models_src/board_none.mdl differ
index ef78e31645475117a4573609d16ed7a33dd1757b..a5ae8e89ddd55b819adffb39a2e0856e8e89ce4e 100644 (file)
--- a/player.h
+++ b/player.h
@@ -117,6 +117,7 @@ struct {
 
    struct player_ragdoll  ragdoll;
    struct player_model    fallback_model;
+   struct player_board    fallback_board;
 
    u16 board_view_slot, playermodel_view_slot;
 
index 13e4ada179505ce5f72ef8b35c267e9be6a8408a..b0f35e1d81151f0bb7e50bb9a09eb82bc06898c9 100644 (file)
@@ -299,7 +299,8 @@ static void render_board( camera *cam, world_instance *world,
                           struct player_board_pose *pose,
                           enum board_shader shader )
 {
-   if( !board ) return;
+   if( !board ) 
+      board = &localplayer.fallback_board;
 
    /* TODO: 
     *  adding depth compare to this shader
index 2d40352589aa899ac6d19b8ac61eb878490194e4..e976fe2f70c102fb0c877640ce7e642b7c3a6fcd 100644 (file)
@@ -460,13 +460,94 @@ static struct vg_shader _shader_model_board_view = {
 "\n"
 "#line     13        0 \n"
 "\n"
+"vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
+"{\n"
+"   float fresnel = step(0.5,1.0 - abs(dot(normal,halfview)));\n"
+"\n"
+"   vec3  reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
+"                               g_sunset_phase );\n"
+"\n"
+"\n"
+"   vec3  sky_reflection = 0.5 * fresnel * reflect_colour;\n"
+"   vec3  light_sun      = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
+"                           * g_sun_colour.rgb * g_day_phase;\n"
+"\n"
+"   float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
+"   vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
+"                       g_sunset_phase );\n"
+"\n"
+"   return ambient + (light_sun + sky_reflection) * shadow;\n"
+"}\n"
+"\n"
+"vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
+"                                 float light_mask )\n"
+"{\n"
+"   if( g_light_preview == 1 )\n"
+"      diffuse = vec3(0.75);\n"
+"\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - co;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow( \n"
+"               co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
+"\n"
+"   vec3 total_light = character_clearskies_lighting( \n"
+"                           normal, min( light_mask, world_shadow ), halfview );\n"
+"\n"
+"   vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
+"        cube_coord = floor( cube_coord );\n"
+"\n"
+"   if( g_debug_indices == 1 )\n"
+"   {\n"
+"      return rand33(cube_coord);\n"
+"   }\n"
+"\n"
+"   if( g_debug_complexity == 1 )\n"
+"   {\n"
+"      ivec3 coord = ivec3( cube_coord );\n"
+"      uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+"      uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
+"      return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
+"   }\n"
+"\n"
+"   // FIXME: this coord should absolutely must be clamped!\n"
+"   \n"
+"   ivec3 coord = ivec3( cube_coord );\n"
+"   uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+"   total_light += \n"
+"      scene_calculate_packed_light_patch( index_sample.x,\n"
+"                                          halfview, co, normal ) \n"
+"                                          * light_mask;\n"
+"   total_light += \n"
+"      scene_calculate_packed_light_patch( index_sample.y,\n"
+"                                          halfview, co, normal )\n"
+"                                          * light_mask;\n"
+"\n"
+"   // Take a section of the sky function to give us a matching fog colour\n"
+"\n"
+"   vec3 fog_colour  = clearskies_ambient( -halfview );\n"
+"   float sun_theta  = dot( -halfview, g_sun_dir.xyz );\n"
+"   float sun_size   = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
+"   float sun_shape  = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
+"         \n"
+"   vec3 sun_colour  = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
+"        sun_colour *= sun_shape;\n"
+"\n"
+"   fog_colour += sun_colour;\n"
+"   return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
+"}\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"
+"   vec3 composite = character_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"
index 51e06db12b3bbe5e72b62687bd38b2dcceef2f5c..7be4184a5bfce8d7d4d9db01ac9f25ecf667e6ca 100644 (file)
@@ -468,13 +468,94 @@ static struct vg_shader _shader_model_character_view = {
 "\n"
 "#line     13        0 \n"
 "\n"
+"vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
+"{\n"
+"   float fresnel = step(0.5,1.0 - abs(dot(normal,halfview)));\n"
+"\n"
+"   vec3  reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
+"                               g_sunset_phase );\n"
+"\n"
+"\n"
+"   vec3  sky_reflection = 0.5 * fresnel * reflect_colour;\n"
+"   vec3  light_sun      = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
+"                           * g_sun_colour.rgb * g_day_phase;\n"
+"\n"
+"   float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
+"   vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
+"                       g_sunset_phase );\n"
+"\n"
+"   return ambient + (light_sun + sky_reflection) * shadow;\n"
+"}\n"
+"\n"
+"vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
+"                                 float light_mask )\n"
+"{\n"
+"   if( g_light_preview == 1 )\n"
+"      diffuse = vec3(0.75);\n"
+"\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - co;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow( \n"
+"               co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
+"\n"
+"   vec3 total_light = character_clearskies_lighting( \n"
+"                           normal, min( light_mask, world_shadow ), halfview );\n"
+"\n"
+"   vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
+"        cube_coord = floor( cube_coord );\n"
+"\n"
+"   if( g_debug_indices == 1 )\n"
+"   {\n"
+"      return rand33(cube_coord);\n"
+"   }\n"
+"\n"
+"   if( g_debug_complexity == 1 )\n"
+"   {\n"
+"      ivec3 coord = ivec3( cube_coord );\n"
+"      uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+"      uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
+"      return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
+"   }\n"
+"\n"
+"   // FIXME: this coord should absolutely must be clamped!\n"
+"   \n"
+"   ivec3 coord = ivec3( cube_coord );\n"
+"   uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
+"\n"
+"   total_light += \n"
+"      scene_calculate_packed_light_patch( index_sample.x,\n"
+"                                          halfview, co, normal ) \n"
+"                                          * light_mask;\n"
+"   total_light += \n"
+"      scene_calculate_packed_light_patch( index_sample.y,\n"
+"                                          halfview, co, normal )\n"
+"                                          * light_mask;\n"
+"\n"
+"   // Take a section of the sky function to give us a matching fog colour\n"
+"\n"
+"   vec3 fog_colour  = clearskies_ambient( -halfview );\n"
+"   float sun_theta  = dot( -halfview, g_sun_dir.xyz );\n"
+"   float sun_size   = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
+"   float sun_shape  = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
+"         \n"
+"   vec3 sun_colour  = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
+"        sun_colour *= sun_shape;\n"
+"\n"
+"   fog_colour += sun_colour;\n"
+"   return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
+"}\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"
+"   vec3 composite = character_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"
index 14af6a7ca585f6d44d5a4f32f442880dcb47660c..eb51c9054da51df3aec74bfe6cad8fa3ea868efc 100644 (file)
@@ -194,10 +194,11 @@ static void vg_load(void){
    replay_clear( &skaterift.replay );
 
    player_load_animation_reference( "models/ch_none.mdl" );
-
    player_model_load( &localplayer.fallback_model, "models/ch_none.mdl" );
    player__bind();
 
+   player_board_load( &localplayer.fallback_board, "models/board_none.mdl" );
+
    /* --------------------- */
 
    vg_bake_shaders();