now we're doing a bunch of them
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_water_fast.h
index 6e19ac3424274471f5ff539891d59a42fb6500eb..576ee65880110a3c255abe0835a627cd167f3d97 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_water_fast = {
 "uniform mat4x3 uMdl;\n"
 "uniform mat4   uPv;\n"
 "uniform mat4   uPvmPrev;\n"
+"uniform samplerBuffer uLightsArray;\n"
 "\n"
 "out vec2 aUv;\n"
 "out vec4 aNorm;\n"
 "out vec3 aCo;\n"
 "out vec3 aWorldCo;\n"
-"flat out ivec4 aLights;\n"
+"flat out vec4 light_colours[3];\n"
+"flat out vec4 light_positions[3];\n"
 "\n"
 "void main()\n"
 "{\n"
@@ -57,7 +59,14 @@ static struct vg_shader _shader_scene_water_fast = {
 "   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
 "   aCo = a_co;\n"
 "   aWorldCo = world_pos0;\n"
-"   aLights = a_lights;\n"
+"\n"
+"   // read lights\n"
+"   light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );\n"
+"   light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );\n"
+"   light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );\n"
+"   light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );\n"
+"   light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );\n"
+"   light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );\n"
 "}\n"
 ""},
    .fs = 
@@ -74,14 +83,15 @@ static struct vg_shader _shader_scene_water_fast = {
 "uniform vec3 uShoreColour;\n"
 "uniform vec3 uOceanColour;\n"
 "\n"
+"#line       1        1 \n"
+"// :D\n"
+"\n"
 "in vec2 aUv;\n"
 "in vec4 aNorm;\n"
 "in vec3 aCo;\n"
 "in vec3 aWorldCo;\n"
-"flat in ivec4 aLights;\n"
-"\n"
-"#line       1        1 \n"
-"// :D\n"
+"flat in vec4 light_colours[3];\n"
+"flat in vec4 light_positions[3];\n"
 "\n"
 "#line       1        1 \n"
 "layout (location = 0) out vec4 oColour;\n"
@@ -99,8 +109,10 @@ static struct vg_shader _shader_scene_water_fast = {
 "   int g_light_preview;\n"
 "   int g_shadow_samples;\n"
 "\n"
-"   vec4 g_point_light_positions[32];\n"
-"   vec4 g_point_light_colours[32];\n"
+"   // g_time ?\n"
+"\n"
+"   //vec4 g_point_light_positions[32];\n"
+"   //vec4 g_point_light_colours[32];\n"
 "};\n"
 "\n"
 "uniform sampler2D g_world_depth;\n"
@@ -127,15 +139,6 @@ static struct vg_shader _shader_scene_water_fast = {
 "   return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
 "}\n"
 "\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-"  vec3 pa = p - a;\n"
-"  vec3 ba = b - a;\n"
-"\n"
-"  float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-"  return length( pa - ba*h );\n"
-"}\n"
-"\n"
 "vec3 apply_fog( vec3 vfrag, float fdist )\n"
 "{\n"
 "   float dist = pow(fdist*0.0008,1.2);\n"
@@ -171,12 +174,7 @@ static struct vg_shader _shader_scene_water_fast = {
 "   famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
 "   famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
 "\n"
-"   // player shadow\n"
-"   float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
-"   float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-"   player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-"   return 1.0 - max( player_shadow*0.8, famt );\n"
+"   return 1.0 - famt;\n"
 "}\n"
 "\n"
 "vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
@@ -217,7 +215,26 @@ static struct vg_shader _shader_scene_water_fast = {
 "   return light_colour*attenuation;\n"
 "}\n"
 "\n"
-"#line      4        0 \n"
+"#line     11        0 \n"
+"\n"
+"float sdLine( vec3 p, vec3 a, vec3 b )\n"
+"{\n"
+"  vec3 pa = p - a;\n"
+"  vec3 ba = b - a;\n"
+"\n"
+"  float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
+"  return length( pa - ba*h );\n"
+"}\n"
+"\n"
+"float compute_board_shadow()\n"
+"{\n"
+"   // player shadow\n"
+"   float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
+"   float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
+"   player_shadow *= player_shadow*player_shadow*player_shadow;\n"
+"\n"
+"   return 1.0 - player_shadow*0.8;\n"
+"}\n"
 "\n"
 "vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
 "{\n"
@@ -235,34 +252,36 @@ static struct vg_shader _shader_scene_water_fast = {
 "   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
 "\n"
 "   float world_shadow = newlight_compute_sun_shadow();\n"
+"   float board_shadow = compute_board_shadow();\n"
 "\n"
-"   total_light += world_light * world_shadow;\n"
+"   total_light += world_light * min( board_shadow, world_shadow );\n"
 "\n"
 "   // Compute the other lights that exist in the map, not effected by the sun\n"
 "   // shadow\n"
+"\n"
 "   total_light += newlight_compute_quadratic\n"
 "                  ( \n"
 "                     wnormal, halfview,\n"
-"                     g_point_light_positions[ aLights.x ].xyz,\n"
-"                     g_point_light_colours[ aLights.x ].rgb \n"
-"                  );\n"
+"                     light_positions[0].xyz,\n"
+"                     light_colours[0].rgb \n"
+"                  ) * board_shadow;\n"
 "   total_light += newlight_compute_quadratic\n"
 "                  ( \n"
 "                     wnormal, halfview,\n"
-"                     g_point_light_positions[ aLights.y ].xyz,\n"
-"                     g_point_light_colours[ aLights.y ].rgb \n"
-"                  );\n"
+"                     light_positions[1].xyz,\n"
+"                     light_colours[1].rgb \n"
+"                  ) * board_shadow;\n"
 "   total_light += newlight_compute_quadratic\n"
 "                  ( \n"
 "                     wnormal, halfview,\n"
-"                     g_point_light_positions[ aLights.z ].xyz,\n"
-"                     g_point_light_colours[ aLights.z ].rgb \n"
-"                  );\n"
+"                     light_positions[2].xyz,\n"
+"                     light_colours[2].rgb \n"
+"                  ) * board_shadow;\n"
 "\n"
 "   return apply_fog( diffuse * total_light, fdist );\n"
 "}\n"
 "\n"
-"#line     19        0 \n"
+"#line     13        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -282,7 +301,7 @@ static struct vg_shader _shader_scene_water_fast = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     20        0 \n"
+"#line     14        0 \n"
 "\n"
 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )\n"
 "{\n"
@@ -333,6 +352,7 @@ static struct vg_shader _shader_scene_water_fast = {
 static GLuint _uniform_scene_water_fast_uMdl;
 static GLuint _uniform_scene_water_fast_uPv;
 static GLuint _uniform_scene_water_fast_uPvmPrev;
+static GLuint _uniform_scene_water_fast_uLightsArray;
 static GLuint _uniform_scene_water_fast_uTexDudv;
 static GLuint _uniform_scene_water_fast_uTime;
 static GLuint _uniform_scene_water_fast_uCamera;
@@ -386,6 +406,7 @@ static void shader_scene_water_fast_link(void){
    _uniform_scene_water_fast_uMdl = glGetUniformLocation( _shader_scene_water_fast.id, "uMdl" );
    _uniform_scene_water_fast_uPv = glGetUniformLocation( _shader_scene_water_fast.id, "uPv" );
    _uniform_scene_water_fast_uPvmPrev = glGetUniformLocation( _shader_scene_water_fast.id, "uPvmPrev" );
+   _uniform_scene_water_fast_uLightsArray = glGetUniformLocation( _shader_scene_water_fast.id, "uLightsArray" );
    _uniform_scene_water_fast_uTexDudv = glGetUniformLocation( _shader_scene_water_fast.id, "uTexDudv" );
    _uniform_scene_water_fast_uTime = glGetUniformLocation( _shader_scene_water_fast.id, "uTime" );
    _uniform_scene_water_fast_uCamera = glGetUniformLocation( _shader_scene_water_fast.id, "uCamera" );