now we're doing a bunch of them
authorhgn <hgodden00@gmail.com>
Sat, 25 Feb 2023 07:00:26 +0000 (07:00 +0000)
committerhgn <hgodden00@gmail.com>
Sat, 25 Feb 2023 07:00:26 +0000 (07:00 +0000)
33 files changed:
maps_src/mp_mtzero.mdl
player.c
scene.h
shaders/common_scene.glsl
shaders/common_world.glsl
shaders/model_character_view.fs
shaders/model_character_view.h
shaders/model_sky.fs
shaders/model_sky.h
shaders/scene.vs
shaders/scene_depth.fs
shaders/scene_depth.h
shaders/scene_position.fs
shaders/scene_position.h
shaders/scene_route.fs
shaders/scene_route.h
shaders/scene_standard.fs
shaders/scene_standard.h
shaders/scene_standard_alphatest.fs
shaders/scene_standard_alphatest.h
shaders/scene_terrain.fs
shaders/scene_terrain.h
shaders/scene_vertex_blend.fs
shaders/scene_vertex_blend.h
shaders/scene_water.fs
shaders/scene_water.h
shaders/scene_water_fast.fs
shaders/scene_water_fast.h
world.h
world_gen.h
world_render.h
world_routes.h
world_water.h

index 4175d691890dfcadcab6c39c660520dc045a574d..f3a6aee96559aa9f4de948db4bdafbbe1d7b91fe 100644 (file)
Binary files a/maps_src/mp_mtzero.mdl and b/maps_src/mp_mtzero.mdl differ
index 115ecf2e361b3f420d3ff8a50329e76a9b6f294b..ef516a1a5bf9d92ec4bc6fc387c9c230e2f26d26 100644 (file)
--- a/player.c
+++ b/player.c
@@ -278,7 +278,9 @@ PLAYER_API void player__render( camera *cam, player_instance *player )
    shader_model_character_view_uPv( cam->mtx.pv );
 
    world_instance *world = get_active_world();
-   world_link_lighting_ub( world, _shader_model_character_view.id, 2 );
+   world_link_lighting_ub( world, _shader_model_character_view.id );
+   world_bind_position_texture( world, _shader_model_character_view.id,
+                              _uniform_model_character_view_g_world_depth, 2 );
 
    glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms,
                          player->playeravatar->sk.bone_count,
diff --git a/scene.h b/scene.h
index 63b351d3e320fd74b5527a0b5532b786a5231c0c..fa1ce4dbc8bc782a23953c22889aa20d7c27d384 100644 (file)
--- a/scene.h
+++ b/scene.h
@@ -10,14 +10,14 @@ typedef struct scene_vert scene_vert;
 
 #pragma pack(push,1)
 
-/* 28 byte vertexs, we don't care about the normals too much,
+/* 32 byte vertexs, we don't care about the normals too much,
  *    maybe possible to bring down uv to i16s too */
 struct scene_vert
 {
    v3f co;        /* 3*32 */
    v2f uv;        /* 2*32 */
    i8  norm[4];   /* 4*8 */
-   u8  lights[4]; /* 4*8 */
+   u16 lights[4]; /* 4*16 */
 };
 
 #pragma pack(pop)
@@ -260,7 +260,7 @@ VG_STATIC void scene_upload( scene *pscene, glmesh *mesh )
    glEnableVertexAttribArray( 2 );
 
    /* 3: light cluster */
-   glVertexAttribIPointer( 3, 4, GL_UNSIGNED_BYTE,
+   glVertexAttribIPointer( 3, 4, GL_UNSIGNED_SHORT,
          stride, (void *)offsetof(scene_vert, lights) );
    glEnableVertexAttribArray( 3 );
 
index 4a78fbcf01ca8a721a055dfb21a4b758b52dcb58..c71f5e2dbb4dbbd3359be1afa933eaaf5ba6f1c3 100644 (file)
@@ -1,7 +1,33 @@
 // :D
 
+in vec2 aUv;
+in vec4 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+flat in vec4 light_colours[3];
+flat in vec4 light_positions[3];
+
 #include "common_world.glsl"
 
+float sdLine( vec3 p, vec3 a, vec3 b )
+{
+  vec3 pa = p - a;
+  vec3 ba = b - a;
+
+  float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
+  return length( pa - ba*h );
+}
+
+float compute_board_shadow()
+{
+   // player shadow
+   float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
+   float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
+   player_shadow *= player_shadow*player_shadow*player_shadow;
+
+   return 1.0 - player_shadow*0.8;
+}
+
 vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
 {
    // Lighting
@@ -18,29 +44,31 @@ vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
    world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );
 
    float world_shadow = newlight_compute_sun_shadow();
+   float board_shadow = compute_board_shadow();
 
-   total_light += world_light * world_shadow;
+   total_light += world_light * min( board_shadow, world_shadow );
 
    // Compute the other lights that exist in the map, not effected by the sun
    // shadow
+
    total_light += newlight_compute_quadratic
                   ( 
                      wnormal, halfview,
-                     g_point_light_positions[ aLights.x ].xyz,
-                     g_point_light_colours[ aLights.x ].rgb 
-                  );
+                     light_positions[0].xyz,
+                     light_colours[0].rgb 
+                  ) * board_shadow;
    total_light += newlight_compute_quadratic
                   ( 
                      wnormal, halfview,
-                     g_point_light_positions[ aLights.y ].xyz,
-                     g_point_light_colours[ aLights.y ].rgb 
-                  );
+                     light_positions[1].xyz,
+                     light_colours[1].rgb 
+                  ) * board_shadow;
    total_light += newlight_compute_quadratic
                   ( 
                      wnormal, halfview,
-                     g_point_light_positions[ aLights.z ].xyz,
-                     g_point_light_colours[ aLights.z ].rgb 
-                  );
+                     light_positions[2].xyz,
+                     light_colours[2].rgb 
+                  ) * board_shadow;
 
    return apply_fog( diffuse * total_light, fdist );
 }
index 45e12dff48267ba71c814a07a3272ea3eb29c339..043cf26898971b270032a2b5ff5bd78c4bacd202 100644 (file)
@@ -13,8 +13,10 @@ layout (std140) uniform ub_world_lighting
    int g_light_preview;
    int g_shadow_samples;
 
-   vec4 g_point_light_positions[32];
-   vec4 g_point_light_colours[32];
+   // g_time ?
+
+   //vec4 g_point_light_positions[32];
+   //vec4 g_point_light_colours[32];
 };
 
 uniform sampler2D g_world_depth;
@@ -41,15 +43,6 @@ float shadow_sample( vec3 vdir )
    return clamp( fdelta, 0.1, 0.2 )-0.1;
 }
 
-float sdLine( vec3 p, vec3 a, vec3 b )
-{
-  vec3 pa = p - a;
-  vec3 ba = b - a;
-
-  float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );
-  return length( pa - ba*h );
-}
-
 vec3 apply_fog( vec3 vfrag, float fdist )
 {
    float dist = pow(fdist*0.0008,1.2);
@@ -85,12 +78,7 @@ float newlight_compute_sun_shadow()
    famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);
    famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);
 
-   // player shadow
-   float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );
-   float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
-   player_shadow *= player_shadow*player_shadow*player_shadow;
-
-   return 1.0 - max( player_shadow*0.8, famt );
+   return 1.0 - famt;
 }
 
 vec3 newlight_compute_world_diffuse( vec3 wnormal )
index 8bf29bcf899b9ba1700bc79750c269f7502b2fcc..a85e124d8a862947ce3b26f2da13a7f2551459fc 100644 (file)
@@ -1,7 +1,5 @@
 uniform sampler2D uTexMain;
 uniform vec3 uCamera;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
 
 in vec4 aColour;
 in vec2 aUv;
index c527d9032beacaead2bb5f08c399ca7f47e57ead..18d5c19062ec5d9afc1b92e55b68d3d1e19ec2e3 100644 (file)
@@ -74,8 +74,6 @@ static struct vg_shader _shader_model_character_view = {
 .static_src = 
 "uniform sampler2D uTexMain;\n"
 "uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
 "\n"
 "in vec4 aColour;\n"
 "in vec2 aUv;\n"
@@ -99,8 +97,10 @@ static struct vg_shader _shader_model_character_view = {
 "   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 +127,6 @@ static struct vg_shader _shader_model_character_view = {
 "   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 +162,7 @@ static struct vg_shader _shader_model_character_view = {
 "   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 +203,7 @@ static struct vg_shader _shader_model_character_view = {
 "   return light_colour*attenuation;\n"
 "}\n"
 "\n"
-"#line     13        0 \n"
+"#line     11        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -237,7 +223,7 @@ static struct vg_shader _shader_model_character_view = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     14        0 \n"
+"#line     12        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -271,8 +257,6 @@ static GLuint _uniform_model_character_view_uPv;
 static GLuint _uniform_model_character_view_uTransforms;
 static GLuint _uniform_model_character_view_uTexMain;
 static GLuint _uniform_model_character_view_uCamera;
-static GLuint _uniform_model_character_view_uBoard0;
-static GLuint _uniform_model_character_view_uBoard1;
 static GLuint _uniform_model_character_view_g_world_depth;
 static void shader_model_character_view_uPv(m4x4f m){
    glUniformMatrix4fv(_uniform_model_character_view_uPv,1,GL_FALSE,(float*)m);
@@ -283,12 +267,6 @@ static void shader_model_character_view_uTexMain(int i){
 static void shader_model_character_view_uCamera(v3f v){
    glUniform3fv(_uniform_model_character_view_uCamera,1,v);
 }
-static void shader_model_character_view_uBoard0(v3f v){
-   glUniform3fv(_uniform_model_character_view_uBoard0,1,v);
-}
-static void shader_model_character_view_uBoard1(v3f v){
-   glUniform3fv(_uniform_model_character_view_uBoard1,1,v);
-}
 static void shader_model_character_view_g_world_depth(int i){
    glUniform1i(_uniform_model_character_view_g_world_depth,i);
 }
@@ -301,8 +279,6 @@ static void shader_model_character_view_link(void){
    _uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" );
    _uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" );
    _uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" );
-   _uniform_model_character_view_uBoard0 = glGetUniformLocation( _shader_model_character_view.id, "uBoard0" );
-   _uniform_model_character_view_uBoard1 = glGetUniformLocation( _shader_model_character_view.id, "uBoard1" );
    _uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" );
 }
 #endif /* SHADER_model_character_view_H */
index 036f2445001ed8ccfddf0a2c9aee0cf165dda6da..e89379944e0c4135285ce8e2c2e1345516e0560f 100644 (file)
@@ -1,6 +1,3 @@
-layout (location = 0) out vec4 oColour;
-
-uniform vec4 uColour;
 uniform sampler2D uTexGarbage;
 uniform float uTime;
 
@@ -8,30 +5,42 @@ in vec4 aColour;
 in vec2 aUv;
 in vec3 aNorm;
 in vec3 aCo;
+in vec3 aWorldCo;
 
+#include "common_world.glsl"
 #include "motion_vectors_fs.glsl"
 
 void main()
 {
    compute_motion_vectors();
 
-   float fintensity = 1.0-(abs(aNorm.y)*0.7);
+   vec3 rd = normalize(aNorm);
+
+   float fintensity = 1.0-(abs(rd.y)*0.7);
    float fblend = pow(fintensity,4.0);
-   vec3 horizon = vec3( 0.8, 0.9, 0.9 );
-   vec3 skycolour = vec3( 0.5, 0.6, 0.9 );
+   vec3 horizon = vec3( 0.87, 0.93, 0.98 );
+   vec3 skycolour = vec3( 0.16, 0.58, 0.95 ) - rd.y*rd.y*0.5;
    vec3 diffuse = mix( skycolour, horizon, fblend );
 
    float fmove = uTime * 0.004;
-   vec2 cloudplane = (aNorm.xz / (aNorm.y*sign(aNorm.y))) * 0.05;
+   vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.05;
    vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );
-   vec4 clouds2 = texture( uTexGarbage, cloudplane + vec2(0.3,0.1)*fmove );
+   vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );
 
    float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);
-   float cloud_e = pow(cloud_d,1.5)*pow(abs(aNorm.y),0.3)*2.0;
+   float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;
 
    vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );
-   float fhorizon = step( aNorm.y * 0.5 + 0.5, 0.5 );
+   float fhorizon = step( rd.y * 0.5 + 0.5, 0.5 );
 
    vec3 skycomp = mix(diffuse, vec3(1.0,1.0,1.0), cloud_e);
-   oColour = vec4(pow(skycomp, vec3(1.5)),1.0);
+
+
+   float sundot = clamp(dot(rd, -g_light_directions[0].xyz), 0.0, 1.0);
+   vec3 sun = 0.25 * vec3(1.0,0.7,0.4) * pow( sundot,5.0 );
+   sun += 0.25 * vec3(1.0,0.8,0.6) * pow( sundot,64.0 );
+   sun += 0.2 * vec3(1.0,0.8,0.6) * pow( sundot,512.0 );
+   skycomp += sun * g_light_colours[0].rgb;
+
+   oColour = vec4(skycomp,1.0);
 }
index 1559bcf94b3011f20e41792d7a34fd35b7d4e5ec..2da4c32a4c8d62b429c153f4dec52336edcc45dc 100644 (file)
@@ -64,9 +64,6 @@ static struct vg_shader _shader_model_sky = {
    .fs = 
 {
 .static_src = 
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"uniform vec4 uColour;\n"
 "uniform sampler2D uTexGarbage;\n"
 "uniform float uTime;\n"
 "\n"
@@ -74,8 +71,132 @@ static struct vg_shader _shader_model_sky = {
 "in vec2 aUv;\n"
 "in vec3 aNorm;\n"
 "in vec3 aCo;\n"
+"in vec3 aWorldCo;\n"
 "\n"
 "#line       1        1 \n"
+"layout (location = 0) out vec4 oColour;\n"
+"\n"
+"layout (std140) uniform ub_world_lighting\n"
+"{\n"
+"   vec4 g_light_colours[3];\n"
+"   vec4 g_light_directions[3];\n"
+"   vec4 g_ambient_colour;\n"
+"\n"
+"   vec4 g_water_plane;\n"
+"   vec4 g_depth_bounds;\n"
+"   float g_water_fog;\n"
+"   int g_light_count;\n"
+"   int g_light_preview;\n"
+"   int g_shadow_samples;\n"
+"\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"
+"\n"
+"float world_depth_sample( vec3 pos )\n"
+"{\n"
+"   vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
+"   return texture( g_world_depth, depth_coord ).r;\n"
+"}\n"
+"\n"
+"float world_water_depth( vec3 pos )\n"
+"{\n"
+"   vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
+"   float ref_depth = g_water_plane.y*g_water_plane.w;\n"
+"   return texture( g_world_depth, depth_coord ).g - ref_depth;\n"
+"}\n"
+"\n"
+"float shadow_sample( vec3 vdir )\n"
+"{\n"
+"   vec3 sample_pos = aWorldCo + vdir;\n"
+"   float height_sample = world_depth_sample( sample_pos );\n"
+"\n"
+"   float fdelta = height_sample - sample_pos.y;\n"
+"   return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
+"}\n"
+"\n"
+"vec3 apply_fog( vec3 vfrag, float fdist )\n"
+"{\n"
+"   float dist = pow(fdist*0.0008,1.2);\n"
+"   return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );\n"
+"}\n"
+"\n"
+"\n"
+"// New lighting model\n"
+"\n"
+"vec3 newlight_compute_ambient()\n"
+"{\n"
+"   return g_ambient_colour.rgb;\n"
+"}\n"
+"\n"
+"float newlight_compute_sun_shadow()\n"
+"{\n"
+"   if( g_shadow_samples == 0 )\n"
+"   {\n"
+"      return 1.0;\n"
+"   }\n"
+"\n"
+"   float fspread = g_light_colours[0].w;\n"
+"   vec3  vdir = g_light_directions[0].xyz;\n"
+"   float flength = g_light_directions[0].w;\n"
+"\n"
+"   float famt = 0.0;\n"
+"   famt+=shadow_sample((vdir+vec3(-0.563, 0.550, 0.307)*fspread)*flength*0.1);\n"
+"   famt+=shadow_sample((vdir+vec3( 0.808, 0.686, 0.346)*fspread)*flength*0.2);\n"
+"   famt+=shadow_sample((vdir+vec3( 0.787, 0.074,-0.065)*fspread)*flength*0.3);\n"
+"   famt+=shadow_sample((vdir+vec3(-0.593, 0.071,-0.425)*fspread)*flength*0.4);\n"
+"   famt+=shadow_sample((vdir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
+"   famt+=shadow_sample((vdir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
+"   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"
+"   return 1.0 - famt;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
+"{\n"
+"   vec3 vtotal = g_ambient_colour.rgb;\n"
+"\n"
+"   for( int i=0; i<g_light_count; i++ )\n"
+"   {\n"
+"      vec3 vcolour = g_light_colours[i].rgb;\n"
+"      vec3 vdir = g_light_directions[i].xyz;\n"
+"\n"
+"      float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);\n"
+"      vtotal += vcolour*flight;\n"
+"   }\n"
+"\n"
+"   return vtotal;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_sun_spec( vec3 wnormal, vec3 halfview, float fintensity )\n"
+"{\n"
+"   vec3 vcolour = g_light_colours[0].rgb;\n"
+"   vec3 vdir = g_light_directions[0].xyz;\n"
+"\n"
+"   vec3 specdir = reflect( -vdir, wnormal );\n"
+"   float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0);\n"
+"   return vcolour*spec*fintensity;\n"
+"}\n"
+"\n"
+"vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, \n"
+"                                 vec3 light_pos, vec3 light_colour )\n"
+"{\n"
+"   vec3 light_delta = (light_pos-aWorldCo) * 10.0;\n"
+"\n"
+"   float quadratic = dot(light_delta,light_delta);\n"
+"   float attenuation = 1.0f/( 1.0f + quadratic );\n"
+"   attenuation *= max( 0.0, dot( normalize(light_delta), wnormal ) );\n"
+"\n"
+"   return light_colour*attenuation;\n"
+"}\n"
+"\n"
+"#line     11        0 \n"
+"#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
 "#line      2        0 \n"
@@ -94,31 +215,41 @@ static struct vg_shader _shader_model_sky = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     13        0 \n"
+"#line     12        0 \n"
 "\n"
 "void main()\n"
 "{\n"
 "   compute_motion_vectors();\n"
 "\n"
-"   float fintensity = 1.0-(abs(aNorm.y)*0.7);\n"
+"   vec3 rd = normalize(aNorm);\n"
+"\n"
+"   float fintensity = 1.0-(abs(rd.y)*0.7);\n"
 "   float fblend = pow(fintensity,4.0);\n"
-"   vec3 horizon = vec3( 0.8, 0.9, 0.9 );\n"
-"   vec3 skycolour = vec3( 0.5, 0.6, 0.9 );\n"
+"   vec3 horizon = vec3( 0.87, 0.93, 0.98 );\n"
+"   vec3 skycolour = vec3( 0.16, 0.58, 0.95 ) - rd.y*rd.y*0.5;\n"
 "   vec3 diffuse = mix( skycolour, horizon, fblend );\n"
 "\n"
 "   float fmove = uTime * 0.004;\n"
-"   vec2 cloudplane = (aNorm.xz / (aNorm.y*sign(aNorm.y))) * 0.05;\n"
+"   vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.05;\n"
 "   vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );\n"
-"   vec4 clouds2 = texture( uTexGarbage, cloudplane + vec2(0.3,0.1)*fmove );\n"
+"   vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );\n"
 "\n"
 "   float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);\n"
-"   float cloud_e = pow(cloud_d,1.5)*pow(abs(aNorm.y),0.3)*2.0;\n"
+"   float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;\n"
 "\n"
 "   vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );\n"
-"   float fhorizon = step( aNorm.y * 0.5 + 0.5, 0.5 );\n"
+"   float fhorizon = step( rd.y * 0.5 + 0.5, 0.5 );\n"
 "\n"
 "   vec3 skycomp = mix(diffuse, vec3(1.0,1.0,1.0), cloud_e);\n"
-"   oColour = vec4(pow(skycomp, vec3(1.5)),1.0);\n"
+"\n"
+"\n"
+"   float sundot = clamp(dot(rd, -g_light_directions[0].xyz), 0.0, 1.0);\n"
+"   vec3 sun = 0.25 * vec3(1.0,0.7,0.4) * pow( sundot,5.0 );\n"
+"   sun += 0.25 * vec3(1.0,0.8,0.6) * pow( sundot,64.0 );\n"
+"   sun += 0.2 * vec3(1.0,0.8,0.6) * pow( sundot,512.0 );\n"
+"   skycomp += sun * g_light_colours[0].rgb;\n"
+"\n"
+"   oColour = vec4(skycomp,1.0);\n"
 "}\n"
 ""},
 };
@@ -126,9 +257,9 @@ static struct vg_shader _shader_model_sky = {
 static GLuint _uniform_model_sky_uMdl;
 static GLuint _uniform_model_sky_uPv;
 static GLuint _uniform_model_sky_uPvmPrev;
-static GLuint _uniform_model_sky_uColour;
 static GLuint _uniform_model_sky_uTexGarbage;
 static GLuint _uniform_model_sky_uTime;
+static GLuint _uniform_model_sky_g_world_depth;
 static void shader_model_sky_uMdl(m4x3f m){
    glUniformMatrix4x3fv(_uniform_model_sky_uMdl,1,GL_FALSE,(float*)m);
 }
@@ -138,15 +269,15 @@ static void shader_model_sky_uPv(m4x4f m){
 static void shader_model_sky_uPvmPrev(m4x4f m){
    glUniformMatrix4fv(_uniform_model_sky_uPvmPrev,1,GL_FALSE,(float*)m);
 }
-static void shader_model_sky_uColour(v4f v){
-   glUniform4fv(_uniform_model_sky_uColour,1,v);
-}
 static void shader_model_sky_uTexGarbage(int i){
    glUniform1i(_uniform_model_sky_uTexGarbage,i);
 }
 static void shader_model_sky_uTime(float f){
    glUniform1f(_uniform_model_sky_uTime,f);
 }
+static void shader_model_sky_g_world_depth(int i){
+   glUniform1i(_uniform_model_sky_g_world_depth,i);
+}
 static void shader_model_sky_register(void){
    vg_shader_register( &_shader_model_sky );
 }
@@ -155,8 +286,8 @@ static void shader_model_sky_link(void){
    _uniform_model_sky_uMdl = glGetUniformLocation( _shader_model_sky.id, "uMdl" );
    _uniform_model_sky_uPv = glGetUniformLocation( _shader_model_sky.id, "uPv" );
    _uniform_model_sky_uPvmPrev = glGetUniformLocation( _shader_model_sky.id, "uPvmPrev" );
-   _uniform_model_sky_uColour = glGetUniformLocation( _shader_model_sky.id, "uColour" );
    _uniform_model_sky_uTexGarbage = glGetUniformLocation( _shader_model_sky.id, "uTexGarbage" );
    _uniform_model_sky_uTime = glGetUniformLocation( _shader_model_sky.id, "uTime" );
+   _uniform_model_sky_g_world_depth = glGetUniformLocation( _shader_model_sky.id, "g_world_depth" );
 }
 #endif /* SHADER_model_sky_H */
index 9c8e4ebdfb113df60b7faaa8457cf1ca63ae96f7..34ec16b235fd96d934ff6f39064b69b8a07edc3e 100644 (file)
@@ -8,12 +8,14 @@ layout (location=3) in ivec4 a_lights;
 uniform mat4x3 uMdl;
 uniform mat4   uPv;
 uniform mat4   uPvmPrev;
+uniform samplerBuffer uLightsArray;
 
 out vec2 aUv;
 out vec4 aNorm;
 out vec3 aCo;
 out vec3 aWorldCo;
-flat out ivec4 aLights;
+flat out vec4 light_colours[3];
+flat out vec4 light_positions[3];
 
 void main()
 {
@@ -29,5 +31,12 @@ void main()
    aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );
    aCo = a_co;
    aWorldCo = world_pos0;
-   aLights = a_lights;
+
+   // read lights
+   light_colours[0] = texelFetch( uLightsArray, a_lights.x*2+0 );
+   light_colours[1] = texelFetch( uLightsArray, a_lights.y*2+0 );
+   light_colours[2] = texelFetch( uLightsArray, a_lights.z*2+0 );
+   light_positions[0] = texelFetch( uLightsArray, a_lights.x*2+1 );
+   light_positions[1] = texelFetch( uLightsArray, a_lights.y*2+1 );
+   light_positions[2] = texelFetch( uLightsArray, a_lights.z*2+1 );
 }
index 2ac60135f18e5ab04e510120483b26aa12fe5836..053000ca1fa1bcbdef5e2960f2e8a0079b65b1c2 100644 (file)
@@ -4,12 +4,6 @@ uniform vec3 uCamera;
 uniform vec3 uBoard0;
 uniform vec3 uBoard1;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 
 // Water blending
index 59a3236c740a3bbcf8052c1ff28986c828329656..462833273f060fa21be4beefa20e4b7ab80f4472 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_depth = {
 "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_depth = {
 "   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 = 
@@ -69,14 +78,15 @@ static struct vg_shader _shader_scene_depth = {
 "uniform vec3 uBoard0;\n"
 "uniform vec3 uBoard1;\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"
@@ -94,8 +104,10 @@ static struct vg_shader _shader_scene_depth = {
 "   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"
@@ -122,15 +134,6 @@ static struct vg_shader _shader_scene_depth = {
 "   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"
@@ -166,12 +169,7 @@ static struct vg_shader _shader_scene_depth = {
 "   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"
@@ -212,7 +210,26 @@ static struct vg_shader _shader_scene_depth = {
 "   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"
@@ -230,34 +247,36 @@ static struct vg_shader _shader_scene_depth = {
 "   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     14        0 \n"
+"#line      8        0 \n"
 "\n"
 "// Water blending\n"
 "// ==============\n"
@@ -284,6 +303,7 @@ static struct vg_shader _shader_scene_depth = {
 static GLuint _uniform_scene_depth_uMdl;
 static GLuint _uniform_scene_depth_uPv;
 static GLuint _uniform_scene_depth_uPvmPrev;
+static GLuint _uniform_scene_depth_uLightsArray;
 static GLuint _uniform_scene_depth_uCamera;
 static GLuint _uniform_scene_depth_uBoard0;
 static GLuint _uniform_scene_depth_uBoard1;
@@ -317,6 +337,7 @@ static void shader_scene_depth_link(void){
    _uniform_scene_depth_uMdl = glGetUniformLocation( _shader_scene_depth.id, "uMdl" );
    _uniform_scene_depth_uPv = glGetUniformLocation( _shader_scene_depth.id, "uPv" );
    _uniform_scene_depth_uPvmPrev = glGetUniformLocation( _shader_scene_depth.id, "uPvmPrev" );
+   _uniform_scene_depth_uLightsArray = glGetUniformLocation( _shader_scene_depth.id, "uLightsArray" );
    _uniform_scene_depth_uCamera = glGetUniformLocation( _shader_scene_depth.id, "uCamera" );
    _uniform_scene_depth_uBoard0 = glGetUniformLocation( _shader_scene_depth.id, "uBoard0" );
    _uniform_scene_depth_uBoard1 = glGetUniformLocation( _shader_scene_depth.id, "uBoard1" );
index 57d1f06dbc615992b95400f87e3ee299d2add56c..2d959b0772c186c3d272c7eac584e39b0fb639fb 100644 (file)
@@ -4,12 +4,6 @@ uniform vec3 uCamera;
 uniform vec3 uBoard0;
 uniform vec3 uBoard1;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 
 void main()
index a748f487e5a82d94fc46b5b76e0af0046895759a..895b03bd97e6a4f914244691e2118898667a8f72 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_position = {
 "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_position = {
 "   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 = 
@@ -69,14 +78,15 @@ static struct vg_shader _shader_scene_position = {
 "uniform vec3 uBoard0;\n"
 "uniform vec3 uBoard1;\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"
@@ -94,8 +104,10 @@ static struct vg_shader _shader_scene_position = {
 "   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"
@@ -122,15 +134,6 @@ static struct vg_shader _shader_scene_position = {
 "   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"
@@ -166,12 +169,7 @@ static struct vg_shader _shader_scene_position = {
 "   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"
@@ -212,7 +210,26 @@ static struct vg_shader _shader_scene_position = {
 "   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"
@@ -230,34 +247,36 @@ static struct vg_shader _shader_scene_position = {
 "   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     14        0 \n"
+"#line      8        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -275,6 +294,7 @@ static struct vg_shader _shader_scene_position = {
 static GLuint _uniform_scene_position_uMdl;
 static GLuint _uniform_scene_position_uPv;
 static GLuint _uniform_scene_position_uPvmPrev;
+static GLuint _uniform_scene_position_uLightsArray;
 static GLuint _uniform_scene_position_uCamera;
 static GLuint _uniform_scene_position_uBoard0;
 static GLuint _uniform_scene_position_uBoard1;
@@ -308,6 +328,7 @@ static void shader_scene_position_link(void){
    _uniform_scene_position_uMdl = glGetUniformLocation( _shader_scene_position.id, "uMdl" );
    _uniform_scene_position_uPv = glGetUniformLocation( _shader_scene_position.id, "uPv" );
    _uniform_scene_position_uPvmPrev = glGetUniformLocation( _shader_scene_position.id, "uPvmPrev" );
+   _uniform_scene_position_uLightsArray = glGetUniformLocation( _shader_scene_position.id, "uLightsArray" );
    _uniform_scene_position_uCamera = glGetUniformLocation( _shader_scene_position.id, "uCamera" );
    _uniform_scene_position_uBoard0 = glGetUniformLocation( _shader_scene_position.id, "uBoard0" );
    _uniform_scene_position_uBoard1 = glGetUniformLocation( _shader_scene_position.id, "uBoard1" );
index 5bb973d380e81b753493e1d4a9682ad9e70a58a0..a2eeb99c810b50a17ce93eabf0b6a53b8250a90e 100644 (file)
@@ -5,12 +5,6 @@ uniform vec4 uColour;
 uniform vec3 uBoard0;
 uniform vec3 uBoard1;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
index 5bd8fd574623f83364071ea140c9013113a6336d..0de37fca94e8947db05ee060551a391619dc56b2 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_route = {
 "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_route = {
 "   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 = 
@@ -70,14 +79,15 @@ static struct vg_shader _shader_scene_route = {
 "uniform vec3 uBoard0;\n"
 "uniform vec3 uBoard1;\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"
@@ -95,8 +105,10 @@ static struct vg_shader _shader_scene_route = {
 "   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"
@@ -123,15 +135,6 @@ static struct vg_shader _shader_scene_route = {
 "   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"
@@ -167,12 +170,7 @@ static struct vg_shader _shader_scene_route = {
 "   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"
@@ -213,7 +211,26 @@ static struct vg_shader _shader_scene_route = {
 "   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"
@@ -231,34 +248,36 @@ static struct vg_shader _shader_scene_route = {
 "   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     15        0 \n"
+"#line      9        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -278,7 +297,7 @@ static struct vg_shader _shader_scene_route = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     16        0 \n"
+"#line     10        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -323,6 +342,7 @@ static struct vg_shader _shader_scene_route = {
 static GLuint _uniform_scene_route_uMdl;
 static GLuint _uniform_scene_route_uPv;
 static GLuint _uniform_scene_route_uPvmPrev;
+static GLuint _uniform_scene_route_uLightsArray;
 static GLuint _uniform_scene_route_uTexGarbage;
 static GLuint _uniform_scene_route_uTexGradients;
 static GLuint _uniform_scene_route_uCamera;
@@ -368,6 +388,7 @@ static void shader_scene_route_link(void){
    _uniform_scene_route_uMdl = glGetUniformLocation( _shader_scene_route.id, "uMdl" );
    _uniform_scene_route_uPv = glGetUniformLocation( _shader_scene_route.id, "uPv" );
    _uniform_scene_route_uPvmPrev = glGetUniformLocation( _shader_scene_route.id, "uPvmPrev" );
+   _uniform_scene_route_uLightsArray = glGetUniformLocation( _shader_scene_route.id, "uLightsArray" );
    _uniform_scene_route_uTexGarbage = glGetUniformLocation( _shader_scene_route.id, "uTexGarbage" );
    _uniform_scene_route_uTexGradients = glGetUniformLocation( _shader_scene_route.id, "uTexGradients" );
    _uniform_scene_route_uCamera = glGetUniformLocation( _shader_scene_route.id, "uCamera" );
index 0675bff71f2a85046e430cb7e1e9b3c3dcfcebb9..a45ee541193127e366081eea0f808707bbf24312 100644 (file)
@@ -5,12 +5,6 @@ uniform vec4 uPlane;
 uniform vec3 uBoard0;
 uniform vec3 uBoard1;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
index 232e67693bfbc4c0634cd6e9c508ba2dc411587f..d3051bc59610af1885908087534d12c429524336 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_standard = {
 "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_standard = {
 "   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 = 
@@ -70,14 +79,15 @@ static struct vg_shader _shader_scene_standard = {
 "uniform vec3 uBoard0;\n"
 "uniform vec3 uBoard1;\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"
@@ -95,8 +105,10 @@ static struct vg_shader _shader_scene_standard = {
 "   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"
@@ -123,15 +135,6 @@ static struct vg_shader _shader_scene_standard = {
 "   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"
@@ -167,12 +170,7 @@ static struct vg_shader _shader_scene_standard = {
 "   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"
@@ -213,7 +211,26 @@ static struct vg_shader _shader_scene_standard = {
 "   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"
@@ -231,34 +248,36 @@ static struct vg_shader _shader_scene_standard = {
 "   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     15        0 \n"
+"#line      9        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -278,7 +297,7 @@ static struct vg_shader _shader_scene_standard = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     16        0 \n"
+"#line     10        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -304,6 +323,7 @@ static struct vg_shader _shader_scene_standard = {
 static GLuint _uniform_scene_standard_uMdl;
 static GLuint _uniform_scene_standard_uPv;
 static GLuint _uniform_scene_standard_uPvmPrev;
+static GLuint _uniform_scene_standard_uLightsArray;
 static GLuint _uniform_scene_standard_uTexGarbage;
 static GLuint _uniform_scene_standard_uTexMain;
 static GLuint _uniform_scene_standard_uCamera;
@@ -349,6 +369,7 @@ static void shader_scene_standard_link(void){
    _uniform_scene_standard_uMdl = glGetUniformLocation( _shader_scene_standard.id, "uMdl" );
    _uniform_scene_standard_uPv = glGetUniformLocation( _shader_scene_standard.id, "uPv" );
    _uniform_scene_standard_uPvmPrev = glGetUniformLocation( _shader_scene_standard.id, "uPvmPrev" );
+   _uniform_scene_standard_uLightsArray = glGetUniformLocation( _shader_scene_standard.id, "uLightsArray" );
    _uniform_scene_standard_uTexGarbage = glGetUniformLocation( _shader_scene_standard.id, "uTexGarbage" );
    _uniform_scene_standard_uTexMain = glGetUniformLocation( _shader_scene_standard.id, "uTexMain" );
    _uniform_scene_standard_uCamera = glGetUniformLocation( _shader_scene_standard.id, "uCamera" );
index ea5eafe05921aa4961951208134b1dad47e11b53..c326ae8c14085be728fc34a1e99692868bf85a6b 100644 (file)
@@ -5,12 +5,6 @@ uniform vec3 uBoard1;
 uniform vec3 uCamera;
 uniform vec4 uPlane;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
index ed4417ba6350cb4cc63e653b79370e80e18802d3..8e7b1b016d0e3fe10b60ccde6bc24c8aebd70c59 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "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_standard_alphatest = {
 "   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 = 
@@ -70,14 +79,15 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "uniform vec3 uCamera;\n"
 "uniform vec4 uPlane;\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"
@@ -95,8 +105,10 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "   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"
@@ -123,15 +135,6 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "   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"
@@ -167,12 +170,7 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "   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"
@@ -213,7 +211,26 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "   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"
@@ -231,34 +248,36 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "   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     15        0 \n"
+"#line      9        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -278,7 +297,7 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     16        0 \n"
+"#line     10        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -307,6 +326,7 @@ static struct vg_shader _shader_scene_standard_alphatest = {
 static GLuint _uniform_scene_standard_alphatest_uMdl;
 static GLuint _uniform_scene_standard_alphatest_uPv;
 static GLuint _uniform_scene_standard_alphatest_uPvmPrev;
+static GLuint _uniform_scene_standard_alphatest_uLightsArray;
 static GLuint _uniform_scene_standard_alphatest_uTexGarbage;
 static GLuint _uniform_scene_standard_alphatest_uTexMain;
 static GLuint _uniform_scene_standard_alphatest_uBoard0;
@@ -352,6 +372,7 @@ static void shader_scene_standard_alphatest_link(void){
    _uniform_scene_standard_alphatest_uMdl = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uMdl" );
    _uniform_scene_standard_alphatest_uPv = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPv" );
    _uniform_scene_standard_alphatest_uPvmPrev = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPvmPrev" );
+   _uniform_scene_standard_alphatest_uLightsArray = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uLightsArray" );
    _uniform_scene_standard_alphatest_uTexGarbage = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uTexGarbage" );
    _uniform_scene_standard_alphatest_uTexMain = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uTexMain" );
    _uniform_scene_standard_alphatest_uBoard0 = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uBoard0" );
index 7f7648a045a5c8a90eb1a97207917039de294cce..2bc265f1b3b7b2726e628193e7438a22e84d0e5c 100644 (file)
@@ -6,12 +6,6 @@ uniform vec2 uBlendOffset;
 uniform vec3 uBoard0;
 uniform vec3 uBoard1;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
index 5913d2c0d30d7e992be7a282ee37d8a8e6ee03fc..a70ee32fdd1eae7cb2bf83cde805ccc7eab2ed00 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_terrain = {
 "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_terrain = {
 "   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 = 
@@ -71,14 +80,15 @@ static struct vg_shader _shader_scene_terrain = {
 "uniform vec3 uBoard0;\n"
 "uniform vec3 uBoard1;\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"
@@ -96,8 +106,10 @@ static struct vg_shader _shader_scene_terrain = {
 "   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"
@@ -124,15 +136,6 @@ static struct vg_shader _shader_scene_terrain = {
 "   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"
@@ -168,12 +171,7 @@ static struct vg_shader _shader_scene_terrain = {
 "   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"
@@ -214,7 +212,26 @@ static struct vg_shader _shader_scene_terrain = {
 "   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"
@@ -232,34 +249,36 @@ static struct vg_shader _shader_scene_terrain = {
 "   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     16        0 \n"
+"#line     10        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -279,7 +298,7 @@ static struct vg_shader _shader_scene_terrain = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     17        0 \n"
+"#line     11        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -327,6 +346,7 @@ static struct vg_shader _shader_scene_terrain = {
 static GLuint _uniform_scene_terrain_uMdl;
 static GLuint _uniform_scene_terrain_uPv;
 static GLuint _uniform_scene_terrain_uPvmPrev;
+static GLuint _uniform_scene_terrain_uLightsArray;
 static GLuint _uniform_scene_terrain_uTexGarbage;
 static GLuint _uniform_scene_terrain_uTexGradients;
 static GLuint _uniform_scene_terrain_uCamera;
@@ -376,6 +396,7 @@ static void shader_scene_terrain_link(void){
    _uniform_scene_terrain_uMdl = glGetUniformLocation( _shader_scene_terrain.id, "uMdl" );
    _uniform_scene_terrain_uPv = glGetUniformLocation( _shader_scene_terrain.id, "uPv" );
    _uniform_scene_terrain_uPvmPrev = glGetUniformLocation( _shader_scene_terrain.id, "uPvmPrev" );
+   _uniform_scene_terrain_uLightsArray = glGetUniformLocation( _shader_scene_terrain.id, "uLightsArray" );
    _uniform_scene_terrain_uTexGarbage = glGetUniformLocation( _shader_scene_terrain.id, "uTexGarbage" );
    _uniform_scene_terrain_uTexGradients = glGetUniformLocation( _shader_scene_terrain.id, "uTexGradients" );
    _uniform_scene_terrain_uCamera = glGetUniformLocation( _shader_scene_terrain.id, "uCamera" );
index 86466d0b5e410a280e919fe49b9aaaacc29936a4..7efd6800dc6084b2218f2fdf3598c99fdff89871 100644 (file)
@@ -4,12 +4,6 @@ uniform vec3 uCamera;
 uniform vec3 uBoard0;
 uniform vec3 uBoard1;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
index 1a9c7d2a7ae2768e74fe245a53b530a82cce684e..365cd044bd213b8edc89cd16b39116ad28001e6e 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "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_vertex_blend = {
 "   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 = 
@@ -69,14 +78,15 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "uniform vec3 uBoard0;\n"
 "uniform vec3 uBoard1;\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"
@@ -94,8 +104,10 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "   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"
@@ -122,15 +134,6 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "   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"
@@ -166,12 +169,7 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "   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"
@@ -212,7 +210,26 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "   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"
@@ -230,34 +247,36 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "   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     14        0 \n"
+"#line      8        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -277,7 +296,7 @@ static struct vg_shader _shader_scene_vertex_blend = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     15        0 \n"
+"#line      9        0 \n"
 "\n"
 "void main()\n"
 "{\n"
@@ -321,6 +340,7 @@ static struct vg_shader _shader_scene_vertex_blend = {
 static GLuint _uniform_scene_vertex_blend_uMdl;
 static GLuint _uniform_scene_vertex_blend_uPv;
 static GLuint _uniform_scene_vertex_blend_uPvmPrev;
+static GLuint _uniform_scene_vertex_blend_uLightsArray;
 static GLuint _uniform_scene_vertex_blend_uTexGarbage;
 static GLuint _uniform_scene_vertex_blend_uTexGradients;
 static GLuint _uniform_scene_vertex_blend_uCamera;
@@ -362,6 +382,7 @@ static void shader_scene_vertex_blend_link(void){
    _uniform_scene_vertex_blend_uMdl = glGetUniformLocation( _shader_scene_vertex_blend.id, "uMdl" );
    _uniform_scene_vertex_blend_uPv = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPv" );
    _uniform_scene_vertex_blend_uPvmPrev = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPvmPrev" );
+   _uniform_scene_vertex_blend_uLightsArray = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsArray" );
    _uniform_scene_vertex_blend_uTexGarbage = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGarbage" );
    _uniform_scene_vertex_blend_uTexGradients = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGradients" );
    _uniform_scene_vertex_blend_uCamera = glGetUniformLocation( _shader_scene_vertex_blend.id, "uCamera" );
index 329374f9dfb80cba7774c186847b909bd1104b6a..892f0db6132e6d6d53186fc4560ca2f602d7a7ef 100644 (file)
@@ -12,12 +12,6 @@ uniform vec3 uBoard1;
 uniform vec3 uShoreColour;
 uniform vec3 uOceanColour;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
index 1658e96af822cc9393738536d0271e4617af881b..dfba719da96e4dc9e4a59ac110c209f7808a3650 100644 (file)
@@ -36,12 +36,14 @@ static struct vg_shader _shader_scene_water = {
 "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 = {
 "   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 = 
@@ -77,14 +86,15 @@ static struct vg_shader _shader_scene_water = {
 "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"
@@ -102,8 +112,10 @@ static struct vg_shader _shader_scene_water = {
 "   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"
@@ -130,15 +142,6 @@ static struct vg_shader _shader_scene_water = {
 "   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"
@@ -174,12 +177,7 @@ static struct vg_shader _shader_scene_water = {
 "   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"
@@ -220,7 +218,26 @@ static struct vg_shader _shader_scene_water = {
 "   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"
@@ -238,34 +255,36 @@ static struct vg_shader _shader_scene_water = {
 "   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     22        0 \n"
+"#line     16        0 \n"
 "#line       1        2 \n"
 "const float k_motion_lerp_amount = 0.01;\n"
 "\n"
@@ -285,7 +304,7 @@ static struct vg_shader _shader_scene_water = {
 "   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
 "}\n"
 "\n"
-"#line     23        0 \n"
+"#line     17        0 \n"
 "\n"
 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
 "                 vec4 beneath, vec4 above )\n"
@@ -351,6 +370,7 @@ static struct vg_shader _shader_scene_water = {
 static GLuint _uniform_scene_water_uMdl;
 static GLuint _uniform_scene_water_uPv;
 static GLuint _uniform_scene_water_uPvmPrev;
+static GLuint _uniform_scene_water_uLightsArray;
 static GLuint _uniform_scene_water_uTexMain;
 static GLuint _uniform_scene_water_uTexDudv;
 static GLuint _uniform_scene_water_uTexBack;
@@ -416,6 +436,7 @@ static void shader_scene_water_link(void){
    _uniform_scene_water_uMdl = glGetUniformLocation( _shader_scene_water.id, "uMdl" );
    _uniform_scene_water_uPv = glGetUniformLocation( _shader_scene_water.id, "uPv" );
    _uniform_scene_water_uPvmPrev = glGetUniformLocation( _shader_scene_water.id, "uPvmPrev" );
+   _uniform_scene_water_uLightsArray = glGetUniformLocation( _shader_scene_water.id, "uLightsArray" );
    _uniform_scene_water_uTexMain = glGetUniformLocation( _shader_scene_water.id, "uTexMain" );
    _uniform_scene_water_uTexDudv = glGetUniformLocation( _shader_scene_water.id, "uTexDudv" );
    _uniform_scene_water_uTexBack = glGetUniformLocation( _shader_scene_water.id, "uTexBack" );
index e7cbc487565af8f85230e54ed9ca84d7afec2153..62672d468594e411a12a58cb275cd11920979f18 100644 (file)
@@ -9,12 +9,6 @@ uniform vec3 uBoard1;
 uniform vec3 uShoreColour;
 uniform vec3 uOceanColour;
 
-in vec2 aUv;
-in vec4 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-flat in ivec4 aLights;
-
 #include "common_scene.glsl"
 #include "motion_vectors_fs.glsl"
 
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" );
diff --git a/world.h b/world.h
index 9a45e3a6cdf862123be3042d6cdc841bfe1a7d3f..1b540d0d9d17176197003f04729b4f5ed4595803 100644 (file)
--- a/world.h
+++ b/world.h
@@ -92,13 +92,18 @@ struct world_instance
       int g_light_preview;
       int g_shadow_samples;
 
+#if 0
       v4f g_point_light_positions[32];
       v4f g_point_light_colours[32];
+#endif
    }
    ub_lighting;
    GLuint ubo_lighting;
    int    ubo_bind_point;
 
+   GLuint tbo_light_entities,
+          tex_light_entities;
+
    struct framebuffer heightmap;
 
    /*
@@ -638,10 +643,11 @@ VG_STATIC void world_update( world_instance *world, v3f pos )
       }
    }
 
-   world.sky_time += world.sky_rate * vg.time_delta;
-   world.sky_rate = vg_lerp( world.sky_rate, world.sky_target_rate, 
-                                 vg.time_delta * 5.0 );
 #endif
+   world_global.sky_time += world_global.sky_rate * vg.time_delta;
+   world_global.sky_rate = vg_lerp( world_global.sky_rate, 
+                                    world_global.sky_target_rate, 
+                                    vg.time_delta * 5.0 );
 
    world_routes_update( world );
 #if 0
@@ -712,20 +718,23 @@ VG_STATIC void world_update( world_instance *world, v3f pos )
                                                         0xff00ff00 );
    }
 
-   for( int i=0; i<world->light_count; i++ )
+   if( 0 )
    {
-      struct world_light *light = &world->lights[i];
+      for( int i=0; i<world->light_count; i++ )
+      {
+         struct world_light *light = &world->lights[i];
 
-      u32 colour = 0xff000000;
-      u8 r = light->colour[0] * 255.0f,
-         g = light->colour[1] * 255.0f,
-         b = light->colour[2] * 255.0f;
+         u32 colour = 0xff000000;
+         u8 r = light->colour[0] * 255.0f,
+            g = light->colour[1] * 255.0f,
+            b = light->colour[2] * 255.0f;
 
-      colour |= r;
-      colour |= g << 8;
-      colour |= b << 16;
+         colour |= r;
+         colour |= g << 8;
+         colour |= b << 16;
 
-      vg_line_pt3( light->co, 0.25f, colour );
+         vg_line_pt3( light->co, 0.25f, colour );
+      }
    }
 
    world_global.in_trigger = in_trigger;
index 5cfc9d102af3a94996e032ac177193ffc7ff4836..59bed34a282cfdd8ae05687b4c94d261168c76ef 100644 (file)
@@ -596,6 +596,29 @@ VG_STATIC void world_post_process( world_instance *world )
 
    vg_acquire_thread_sync();
    {
+      /* create scene lighting buffer */
+      glGenBuffers( 1, &world->tbo_light_entities );
+      glBindBuffer( GL_TEXTURE_BUFFER, world->tbo_light_entities );
+      glBufferData( GL_TEXTURE_BUFFER, world->light_count*sizeof(float)*8,
+                    NULL, GL_DYNAMIC_DRAW );
+
+      v4f *light_dst = glMapBuffer( GL_TEXTURE_BUFFER, GL_WRITE_ONLY );
+      
+      for( int i=0; i<world->light_count; i++ )
+      {
+         struct world_light *light = &world->lights[i];
+
+         v3_muls( light->colour, light->colour[3] * 2.0f, light_dst[i*2+0] );
+         v3_copy( light->co, light_dst[i*2+1] );
+      }
+
+      glUnmapBuffer( GL_TEXTURE_BUFFER );
+
+      glGenTextures( 1, &world->tex_light_entities );
+      glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities );
+      glTexBuffer( GL_TEXTURE_BUFFER, GL_RGBA32F, world->tbo_light_entities );
+
+
       /* Upload lighting uniform buffer */
       if( world->water.enabled )
          v4_copy( world->water.plane, world->ub_lighting.g_water_plane );
@@ -609,17 +632,6 @@ VG_STATIC void world_post_process( world_instance *world )
       info_vec[3] = 1.0f/ (bounds[1][2]-bounds[0][2]);
       v4_copy( info_vec, world->ub_lighting.g_depth_bounds );
 
-      /* add scene lights */
-      for( int i=0; i<world->light_count; i++ )
-      {
-         struct world_light *light = &world->lights[i];
-
-         v3_muls( light->colour, light->colour[3] * 2.0f,
-                  world->ub_lighting.g_point_light_colours[i] );
-         v3_copy( light->co, 
-                  world->ub_lighting.g_point_light_positions[i] );
-      }
-
       /* upload full buffer */
       glBindBuffer( GL_UNIFORM_BUFFER, world->ubo_lighting );
       glBufferSubData( GL_UNIFORM_BUFFER, 0, 
index 54c58a55d5796078fe1c07a00ebb02fb5cd8d455..1926364c6b437fa03ba206a82ae74af47a620af4 100644 (file)
@@ -69,14 +69,27 @@ VG_STATIC void world_render_init(void)
    vg_release_thread_sync();
 }
 
-VG_STATIC void world_link_lighting_ub( world_instance *world,
-                                       GLuint shader, int texture_id )
+VG_STATIC void world_link_lighting_ub( world_instance *world, GLuint shader )
 {
    GLuint idx = glGetUniformBlockIndex( shader, "ub_world_lighting" );   
    glUniformBlockBinding( shader, idx, world->ubo_bind_point );
+}
+
+VG_STATIC void world_bind_position_texture( world_instance *world, 
+                                            GLuint shader, GLuint location,
+                                            int slot )
+{
+   render_fb_bind_texture( &world->heightmap, 0, slot );
+   glUniform1i( location, slot );
+}
 
-   render_fb_bind_texture( &world->heightmap, 0, texture_id );
-   glUniform1i( glGetUniformLocation( shader, "g_world_depth" ), texture_id );
+VG_STATIC void world_bind_light_array( world_instance *world,
+                                       GLuint shader, GLuint location, 
+                                       int slot )
+{
+   glActiveTexture( GL_TEXTURE0 + slot );
+   glBindTexture( GL_TEXTURE_BUFFER, world->tex_light_entities );
+   glUniform1i( location, slot );
 }
 
 VG_STATIC void render_world_depth( world_instance *world, camera *cam );
@@ -150,7 +163,12 @@ VG_STATIC void render_world_vb( world_instance *world, camera *cam )
    shader_scene_vertex_blend_use();
    shader_scene_vertex_blend_uTexGarbage(0);
    shader_scene_vertex_blend_uTexGradients(1);
-   world_link_lighting_ub( world, _shader_scene_vertex_blend.id, 2 );
+   world_link_lighting_ub( world, _shader_scene_vertex_blend.id );
+   world_bind_position_texture( world, _shader_scene_vertex_blend.id, 
+                                _uniform_scene_vertex_blend_g_world_depth, 2 );
+   world_bind_light_array( world, _shader_scene_vertex_blend.id,
+                                _uniform_scene_vertex_blend_uLightsArray, 3 );
+
    vg_tex2d_bind( &tex_terrain_noise, 0 );
 
    shader_scene_vertex_blend_uPv( cam->mtx.pv );
@@ -174,7 +192,13 @@ VG_STATIC void render_world_standard( world_instance *world, camera *cam )
    shader_scene_standard_uTexMain(1);
    shader_scene_standard_uPv( cam->mtx.pv );
    shader_scene_standard_uPvmPrev( cam->mtx_prev.pv );
-   world_link_lighting_ub( world, _shader_scene_standard.id, 2 );
+
+   world_link_lighting_ub( world, _shader_scene_standard.id );
+   world_bind_position_texture( world, _shader_scene_standard.id, 
+                                _uniform_scene_standard_g_world_depth, 2 );
+   world_bind_light_array( world, _shader_scene_standard.id,
+                                _uniform_scene_standard_uLightsArray, 3 );
+
    bind_terrain_noise();
 
    shader_scene_standard_uMdl( identity_matrix );
@@ -196,7 +220,14 @@ VG_STATIC void render_world_alphatest( world_instance *world, camera *cam )
    shader_scene_standard_alphatest_uTexMain(1);
    shader_scene_standard_alphatest_uPv( cam->mtx.pv );
    shader_scene_standard_alphatest_uPvmPrev( cam->mtx_prev.pv );
-   world_link_lighting_ub( world, _shader_scene_standard_alphatest.id, 2 );
+
+   world_link_lighting_ub( world, _shader_scene_standard_alphatest.id );
+   world_bind_position_texture( world, _shader_scene_standard_alphatest.id, 
+                        _uniform_scene_standard_alphatest_g_world_depth, 2 );
+   world_bind_light_array( world, _shader_scene_standard_alphatest.id,
+                        _uniform_scene_standard_alphatest_uLightsArray, 3 );
+
+
    bind_terrain_noise();
 
    shader_scene_standard_alphatest_uMdl( identity_matrix );
@@ -230,7 +261,12 @@ VG_STATIC void render_terrain( world_instance *world, camera *cam )
    shader_scene_terrain_use();
    shader_scene_terrain_uTexGarbage(0);
    shader_scene_terrain_uTexGradients(1);
-   world_link_lighting_ub( world, _shader_scene_terrain.id, 2 );
+
+   world_link_lighting_ub( world, _shader_scene_terrain.id );
+   world_bind_position_texture( world, _shader_scene_terrain.id, 
+                        _uniform_scene_terrain_g_world_depth, 2 );
+   world_bind_light_array( world, _shader_scene_terrain.id,
+                        _uniform_scene_terrain_uLightsArray, 3 );
 
    vg_tex2d_bind( &tex_terrain_noise, 0 );
 
@@ -382,7 +418,7 @@ VG_STATIC void render_world_depth( world_instance *world, camera *cam )
    shader_scene_depth_uPv( cam->mtx.pv );
    shader_scene_depth_uPvmPrev( cam->mtx_prev.pv );
    shader_scene_depth_uMdl( identity_matrix );
-   world_link_lighting_ub( world, _shader_scene_depth.id, 2 );
+   world_link_lighting_ub( world, _shader_scene_depth.id );
 
    mesh_bind( &world->mesh_geo );
    mesh_draw( &world->mesh_geo );
@@ -398,7 +434,7 @@ VG_STATIC void render_world_position( world_instance *world, camera *cam )
    shader_scene_position_uPv( cam->mtx.pv );
    shader_scene_position_uPvmPrev( cam->mtx_prev.pv );
    shader_scene_position_uMdl( identity_matrix );
-   world_link_lighting_ub( world, _shader_scene_position.id, 2 );
+   world_link_lighting_ub( world, _shader_scene_position.id );
 
    mesh_bind( &world->mesh_geo );
    mesh_draw( &world->mesh_geo );
index 121f447fd5113d7536e55fdccec2530cabb473a7..bd4ce0cf803fa91ac97eec10acfa429e31b1233d 100644 (file)
@@ -1142,6 +1142,10 @@ VG_STATIC void world_routes_update( world_instance *world )
 }
 
 VG_STATIC void bind_terrain_noise(void);
+VG_STATIC void world_bind_light_array( world_instance *world,
+                                       GLuint shader, GLuint location, 
+                                       int slot );
+
 VG_STATIC void render_world_routes( world_instance *world, camera *cam )
 {
    m4x3f identity_matrix;
@@ -1149,7 +1153,11 @@ VG_STATIC void render_world_routes( world_instance *world, camera *cam )
 
    shader_scene_route_use();
    shader_scene_route_uTexGarbage(0);
-   world_link_lighting_ub( world, _shader_scene_route.id, 2 );
+   world_link_lighting_ub( world, _shader_scene_route.id );
+   world_bind_position_texture( world, _shader_scene_route.id, 
+                        _uniform_scene_route_g_world_depth, 2 );
+   world_bind_light_array( world, _shader_scene_route.id,
+                        _uniform_scene_route_uLightsArray, 3 );
    bind_terrain_noise();
 
    shader_scene_route_uPv( cam->mtx.pv );
index a86d4ee0d06cfee68c7a52525fbb2916c441c32f..c16e2c556f60caa9864826f46cc6396778998b7c 100644 (file)
@@ -34,8 +34,10 @@ VG_STATIC void water_set_surface( world_instance *world, float height )
    v4_copy( (v4f){ 0.0f, 1.0f, 0.0f, height }, world->water.plane );
 }
 
-VG_STATIC void world_link_lighting_ub( world_instance *world,
-                                       GLuint shader, int texture_id );
+VG_STATIC void world_link_lighting_ub( world_instance *world, GLuint shader );
+VG_STATIC void world_bind_position_texture( world_instance *world, 
+                                            GLuint shader, GLuint location,
+                                            int slot );
 
 /*
  * Does not write motion vectors
@@ -130,7 +132,9 @@ VG_STATIC void render_water_surface( world_instance *world, camera *cam )
             1.0f / (float)vg.window_x,
             1.0f / (float)vg.window_y });
 
-      world_link_lighting_ub( world, _shader_scene_water.id, 2 );
+      world_link_lighting_ub( world, _shader_scene_water.id );
+      world_bind_position_texture( world, _shader_scene_water.id, 
+                                    _uniform_scene_water_g_world_depth, 2 );
 
       render_fb_bind_texture( gpipeline.fb_water_beneath, 0, 3 );
       shader_scene_water_uTexBack( 3 );
@@ -175,7 +179,9 @@ VG_STATIC void render_water_surface( world_instance *world, camera *cam )
       shader_scene_water_fast_uTime( world_global.time );
       shader_scene_water_fast_uCamera( cam->transform[3] );
       shader_scene_water_fast_uSurfaceY( world->water.height );
-      world_link_lighting_ub( world, _shader_scene_water_fast.id, 2 );
+      world_link_lighting_ub( world, _shader_scene_water_fast.id );
+      world_bind_position_texture( world, _shader_scene_water_fast.id,
+                                   _uniform_scene_water_fast_g_world_depth, 2 );
 
       m4x3f full;
       m4x3_identity( full );