fix wwater fog
authorhgn <hgodden00@gmail.com>
Thu, 29 Feb 2024 06:04:17 +0000 (06:04 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 29 Feb 2024 06:04:17 +0000 (06:04 +0000)
shaders/impl.c
shaders/scene_water.fs
steam_build_script.vdf

index 539bcb1b66743421e0d15fecca79267c583abc37..dbcebf8258ab0a0d9067d92a3a4153d8675f0161 100644 (file)
@@ -5960,6 +5960,59 @@ struct vg_shader _shader_scene_water = {
 "\n"
 "#line     18        0 \n"
 "\n"
+"// Pasted from common_world.glsl\n"
+"vec3 water_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
+"{\n"
+"   float light_mask = compute_board_shadow();\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 = 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"
+"   return diffuse * total_light;\n"
+"}\n"
+"\n"
 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
 "                 vec4 beneath, vec4 above, vec4 dudva )\n"
 "{\n"
@@ -5980,8 +6033,22 @@ struct vg_shader _shader_scene_water = {
 "\n"
 "   vec4 surf = mix( vec4(surface_tint,depthblend), \n"
 "                    vec4(1.0,1.0,1.0,0.5), fband );\n"
-"   surf.rgb = scene_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );\n"
+"   surf.rgb = water_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );\n"
 "   surf.rgb = mix(surf.rgb, above.rgb, ffresnel );\n"
+"\n"
+"   // Take a section of the sky function to give us a matching fog colour\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"
+"   surf.rgb = scene_apply_fog( surf.rgb, fog_colour,  \n"
+"                               distance(uCamera, aWorldCo) );\n"
+"\n"
 "   return surf;\n"
 "}\n"
 "\n"
index d4bee82d8eb609a3354a72ff1748d217a1aae889..dab1692f465fa3612213d9263c6d02e54fe891a7 100644 (file)
@@ -16,6 +16,59 @@ uniform vec3 uOceanColour;
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
+// Pasted from common_world.glsl
+vec3 water_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )
+{
+   float light_mask = compute_board_shadow();
+
+   if( g_light_preview == 1 )
+      diffuse = vec3(0.75);
+
+   // Lighting
+   vec3 halfview = uCamera - co;
+   float fdist = length(halfview);
+   halfview /= fdist;
+
+   float world_shadow = newlight_compute_sun_shadow( 
+               co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );
+
+   vec3 total_light = clearskies_lighting( 
+                           normal, min( light_mask, world_shadow ), halfview );
+
+   vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;
+        cube_coord = floor( cube_coord );
+
+   if( g_debug_indices == 1 )
+   {
+      return rand33(cube_coord);
+   }
+
+   if( g_debug_complexity == 1 )
+   {
+      ivec3 coord = ivec3( cube_coord );
+      uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );
+
+      uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);
+      return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );
+   }
+
+   // FIXME: this coord should absolutely must be clamped!
+   
+   ivec3 coord = ivec3( cube_coord );
+   uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );
+
+   total_light += 
+      scene_calculate_packed_light_patch( index_sample.x,
+                                          halfview, co, normal ) 
+                                          * light_mask;
+   total_light += 
+      scene_calculate_packed_light_patch( index_sample.y,
+                                          halfview, co, normal )
+                                          * light_mask;
+
+   return diffuse * total_light;
+}
+
 vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, 
                  vec4 beneath, vec4 above, vec4 dudva )
 {
@@ -36,8 +89,22 @@ vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue,
 
    vec4 surf = mix( vec4(surface_tint,depthblend), 
                     vec4(1.0,1.0,1.0,0.5), fband );
-   surf.rgb = scene_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );
+   surf.rgb = water_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );
    surf.rgb = mix(surf.rgb, above.rgb, ffresnel );
+
+   // Take a section of the sky function to give us a matching fog colour
+   vec3 fog_colour  = clearskies_ambient( -halfview );
+   float sun_theta  = dot( -halfview, g_sun_dir.xyz );
+   float sun_size   = max( 0.0, sun_theta * 0.5 + 0.5 );
+   float sun_shape  = sun_size * max(g_sun_dir.y,0.0) * 0.5;
+         
+   vec3 sun_colour  = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );
+        sun_colour *= sun_shape;
+
+   fog_colour += sun_colour;
+   surf.rgb = scene_apply_fog( surf.rgb, fog_colour,  
+                               distance(uCamera, aWorldCo) );
+
    return surf;
 }
 
index 0c6cf18863a5afc5f668a07b7e7d4a57e2c092c3..a0564c1094e0c8bae3aad2ace959921b21d95aec 100644 (file)
@@ -30,7 +30,7 @@
       {\r
          "FileMapping"\r
          {\r
-            "LocalPath" "bin/skaterift-anyplatform-anyarch-blob/*"\r
+            "LocalPath" "bin/skaterift-anyplatform-x86_64-zig-cc/*"\r
             "DepotPath" "."\r
             "recursive" "1"\r
          }\r