change shader properties to be vg_msg based
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / impl.c
index 539bcb1b66743421e0d15fecca79267c583abc37..eeebab19d159bfc980dd3fab9445588456fd68ef 100644 (file)
@@ -4507,7 +4507,9 @@ struct vg_shader _shader_scene_depth = {
 "\n"
 "   float d = dot( pnorm, halfview );\n"
 "   float t = dot((pnorm*pdist - pos), pnorm) / d;\n"
-"   return t * g_water_fog;\n"
+"\n"
+"   // TODO: Make g_water_fog a material param\n"
+"   return t * 0.3;//g_water_fog;\n"
 "}\n"
 "\n"
 "void main()\n"
@@ -5564,12 +5566,15 @@ struct vg_shader _shader_scene_water = {
 "\n"
 "uniform vec3 uShoreColour;\n"
 "uniform vec3 uOceanColour;\n"
+"uniform float uFresnel;\n"
+"uniform float uWaterScale;\n"
+"uniform vec4 uWaveSpeed;\n"
 "\n"
 "#line       1        1 \n"
 "// :D\n"
 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
 "\n"
-"#line     16        0 \n"
+"#line     19        0 \n"
 "#line       1        2 \n"
 "// :D\n"
 "\n"
@@ -5938,7 +5943,7 @@ struct vg_shader _shader_scene_water = {
 "   return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
 "}\n"
 "\n"
-"#line     17        0 \n"
+"#line     20        0 \n"
 "#line       1        3 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -5958,14 +5963,67 @@ struct vg_shader _shader_scene_water = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     18        0 \n"
+"#line     21        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"
 "   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
 "\n"
-"   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
+"   float ffresnel = pow(1.0-dot( vnorm, halfview ),uFresnel);\n"
 "\n"
 "   vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
 "   vec3 specdir = reflect( -lightdir, vnorm );\n"
@@ -5980,8 +6038,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"
@@ -5995,8 +6067,9 @@ struct vg_shader _shader_scene_water = {
 "   // Surface colour composite\n"
 "   float depthvalue = clamp( -world_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );\n"
 "\n"
-"   vec2 world_coord = aCo.xz * 0.008;\n"
-"   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
+"   vec2 world_coord = aCo.xz * uWaterScale;\n"
+"   //TODO: Material param ( 0.008, 0.006, 0.003, 0.03 );\n"
+"   vec4 time_offsets = vec4( uTime ) * vec4( 0.08, -0.08, -0.03, -0.01 );\n"
 "   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
 "   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
 "\n"
@@ -6036,6 +6109,9 @@ GLuint _uniform_scene_water_uBoard0;
 GLuint _uniform_scene_water_uBoard1;
 GLuint _uniform_scene_water_uShoreColour;
 GLuint _uniform_scene_water_uOceanColour;
+GLuint _uniform_scene_water_uFresnel;
+GLuint _uniform_scene_water_uWaterScale;
+GLuint _uniform_scene_water_uWaveSpeed;
 GLuint _uniform_scene_water_g_world_depth;
 GLuint _uniform_scene_water_uLightsArray;
 GLuint _uniform_scene_water_uLightsIndex;
@@ -11227,6 +11303,9 @@ void vg_auto_shader_link(void)
    _uniform_scene_water_uBoard1 = glGetUniformLocation( _shader_scene_water.id, "uBoard1" );
    _uniform_scene_water_uShoreColour = glGetUniformLocation( _shader_scene_water.id, "uShoreColour" );
    _uniform_scene_water_uOceanColour = glGetUniformLocation( _shader_scene_water.id, "uOceanColour" );
+   _uniform_scene_water_uFresnel = glGetUniformLocation( _shader_scene_water.id, "uFresnel" );
+   _uniform_scene_water_uWaterScale = glGetUniformLocation( _shader_scene_water.id, "uWaterScale" );
+   _uniform_scene_water_uWaveSpeed = glGetUniformLocation( _shader_scene_water.id, "uWaveSpeed" );
    _uniform_scene_water_g_world_depth = glGetUniformLocation( _shader_scene_water.id, "g_world_depth" );
    _uniform_scene_water_uLightsArray = glGetUniformLocation( _shader_scene_water.id, "uLightsArray" );
    _uniform_scene_water_uLightsIndex = glGetUniformLocation( _shader_scene_water.id, "uLightsIndex" );