fuckin hell
authorhgn <hgodden00@gmail.com>
Thu, 23 Feb 2023 02:29:58 +0000 (02:29 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 23 Feb 2023 02:29:58 +0000 (02:29 +0000)
110 files changed:
blender_export.py
build.c
maps_src/mp_arizona.mdl [new file with mode: 0644]
maps_src/mp_gridmap.mdl
maps_src/mp_mtzero.mdl
model.h
player.c
player_model.h
render.h
scene.h
shaders.sh
shaders/alphatest.h [deleted file]
shaders/character.fs [deleted file]
shaders/character.h [deleted file]
shaders/character.vs [deleted file]
shaders/common_scene.glsl [new file with mode: 0644]
shaders/common_world.glsl
shaders/fscolour.h [deleted file]
shaders/gate.fs [deleted file]
shaders/gate.h [deleted file]
shaders/gate.vs [deleted file]
shaders/gate_lq.fs [deleted file]
shaders/gatelq.h [deleted file]
shaders/gpos.fs [deleted file]
shaders/gpos.h [deleted file]
shaders/menu.fs [deleted file]
shaders/menu.h [deleted file]
shaders/model.vs [new file with mode: 0644]
shaders/model_character_view.fs [new file with mode: 0644]
shaders/model_character_view.h [new file with mode: 0644]
shaders/model_gate.fs [new file with mode: 0644]
shaders/model_gate.h [new file with mode: 0644]
shaders/model_gate.vs [new file with mode: 0644]
shaders/model_gate_lq.fs [new file with mode: 0644]
shaders/model_menu.fs [new file with mode: 0644]
shaders/model_menu.h [new file with mode: 0644]
shaders/model_skinned.vs [new file with mode: 0644]
shaders/model_sky.fs [new file with mode: 0644]
shaders/model_sky.h [new file with mode: 0644]
shaders/model_water.fs [new file with mode: 0644]
shaders/model_water.h [new file with mode: 0644]
shaders/model_water_fast.fs [new file with mode: 0644]
shaders/model_water_fast.h [new file with mode: 0644]
shaders/noise.glsl [deleted file]
shaders/planeinf.fs [deleted file]
shaders/planeinf.h [deleted file]
shaders/route.fs [deleted file]
shaders/route.h [deleted file]
shaders/scene.vs [new file with mode: 0644]
shaders/scene_depth.fs [new file with mode: 0644]
shaders/scene_depth.h [new file with mode: 0644]
shaders/scene_route.fs [new file with mode: 0644]
shaders/scene_route.h [new file with mode: 0644]
shaders/scene_standard.fs [new file with mode: 0644]
shaders/scene_standard.h [new file with mode: 0644]
shaders/scene_standard_alphatest.fs [new file with mode: 0644]
shaders/scene_standard_alphatest.h [new file with mode: 0644]
shaders/scene_terrain.fs [new file with mode: 0644]
shaders/scene_terrain.h [new file with mode: 0644]
shaders/scene_vertex_blend.fs [new file with mode: 0644]
shaders/scene_vertex_blend.h [new file with mode: 0644]
shaders/scoretext.h [deleted file]
shaders/scoretext.vs [deleted file]
shaders/sky.fs [deleted file]
shaders/sky.h [deleted file]
shaders/standard.fs [deleted file]
shaders/standard.h [deleted file]
shaders/standard.vs [deleted file]
shaders/standard_skinned.vs [deleted file]
shaders/std_alphatest.fs [deleted file]
shaders/sway.glsl [deleted file]
shaders/terrain.fs [deleted file]
shaders/terrain.h [deleted file]
shaders/terrain.vs [deleted file]
shaders/terrain_fast.fs [deleted file]
shaders/unlit.fs [deleted file]
shaders/unlit.h [deleted file]
shaders/vblend.fs [deleted file]
shaders/vblend.h [deleted file]
shaders/vertex_standard.glsl [deleted file]
shaders/vg/blit.fs.glsl [deleted file]
shaders/vg/blit.vs.glsl [deleted file]
shaders/vg/character.fs.glsl [deleted file]
shaders/vg/character.vs.glsl [deleted file]
shaders/vg/gate.fs.glsl [deleted file]
shaders/vg/gate.vs.glsl [deleted file]
shaders/vg/standard.fs.glsl [deleted file]
shaders/vg/standard.vs.glsl [deleted file]
shaders/vg/terrain.fs.glsl [deleted file]
shaders/vg/terrain.vs.glsl [deleted file]
shaders/vg/unlit.fs.glsl [deleted file]
shaders/vg/water.fs.glsl [deleted file]
shaders/vg/water.vs.glsl [deleted file]
shaders/viewchar.fs [deleted file]
shaders/viewchar.h [deleted file]
shaders/water.fs [deleted file]
shaders/water.h [deleted file]
shaders/water.vs [deleted file]
shaders/water_fast.fs [deleted file]
shaders/water_fast.h [deleted file]
shaders/water_old.fs [deleted file]
shaders/water_ref.glsl [deleted file]
skaterift.c
world.h
world_gate.h
world_gen.h
world_render.h
world_routes.h
world_sfd.h
world_water.h

index 538ed6cdd69168bf32316d683daa90cfbd57deca..06d90a4b11d4cb69654c547958f28e6d134a695d 100644 (file)
@@ -2,7 +2,7 @@
 # =============================================================================
 # 
 # Copyright  .        . .       -----, ,----- ,---.   .---.
-# 2021-2022  |\      /| |           /  |      |    | |    /|
+# 2021-2023  |\      /| |           /  |      |    | |    /|
 #            | \    / | +--        /   +----- +---'  |   / |
 #            |  \  /  | |         /    |      |   \  |  /  |
 #            |   \/   | |        /     |      |    \ | /   |
@@ -771,6 +771,33 @@ class classtype_audio(Structure):
    #}
 #}
 
+# Classtype 200
+# 
+#  Purpose: point light
+#
+class classtype_point_light(Structure):
+#{
+   _pack_ = 1
+   _fields_ = [("colour",c_float*4)]
+
+   def encode_obj(_, node, node_def):
+   #{
+      node.classtype = 200
+
+      data = node_def['obj'].data
+      _.colour[0] = data.color[0]
+      _.colour[1] = data.color[1]
+      _.colour[2] = data.color[2]
+      _.colour[3] = data.energy
+   #}
+
+   @staticmethod
+   def editor_interface( layout, obj ):
+   #{
+      pass
+   #}
+#}
+
 class classtype_spawn_link(Structure):
 #{
    _pack_ = 1
@@ -1816,6 +1843,11 @@ def encoder_process_definition( node_def ):
 
       if obj_type == 'ARMATURE':
          obj_classtype = 'classtype_skeleton'
+      elif obj_type == 'LIGHT':
+      #{
+         if obj.data.type == 'POINT':
+            obj_classtype = 'classtype_point_light'
+      #}
       else:
       #{
          obj_classtype = obj.cv_data.classtype
diff --git a/build.c b/build.c
index c0a79b654a6d36fe94deb373207fbd542ce2ec09..5f050df75c92181d50ca5933a268bb6e92a7774c 100644 (file)
--- a/build.c
+++ b/build.c
@@ -109,37 +109,37 @@ int main( int argc, char *argv[] )
    }
 }
 
-void _shader( char *name, char *vs, char *fs )
-{
-   vg_build_shader( vs, fs, NULL, "shaders", name );
-}
+#define _S( NAME, VS, FS ) \
+   vg_build_shader( "shaders/" VS, "shaders/" FS, NULL, "shaders", NAME )
 
 void build_shaders(void)
 {
    vg_shader_set_include_dir( "shaders" );
 
-   // 2D
-   _shader( "blit",      "shaders/blit.vs",      "shaders/blit.fs" );
-   _shader( "blitblur",  "shaders/blit.vs",      "shaders/blitblur.fs" );
-   _shader( "blitcolour","shaders/blit.vs",      "shaders/colour.fs" );
-   _shader( "routeui",   "shaders/routeui.vs",   "shaders/routeui.fs" );
+   /* Scene */
+   _S( "scene_standard",            "scene.vs", "scene_standard.fs" );
+   _S( "scene_standard_alphatest",  "scene.vs", "scene_standard_alphatest.fs" );
+   _S( "scene_vertex_blend",        "scene.vs", "scene_vertex_blend.fs" );
+   _S( "scene_terrain",             "scene.vs", "scene_terrain.fs" );
+   _S( "scene_route",               "scene.vs", "scene_route.fs" );
+   _S( "scene_depth",               "scene.vs", "scene_depth.fs" );
+
+   /* Models */
+   _S( "model_sky",            "model.vs",         "model_sky.fs" );
+   _S( "model_water",          "model.vs",         "model_water.fs" );
+   _S( "model_water_fast",     "model.vs",         "model_water_fast.fs" );
+   _S( "model_menu",           "model.vs",         "model_menu.fs" );
+   _S( "model_character_view", "model_skinned.vs", "model_character_view.fs" );
+   _S( "model_gate",           "model_gate.vs",    "model_gate_lq.fs" );
+
+   /* 2D */
+   _S( "blit",      "blit.vs",      "blit.fs" );
+   _S( "blitblur",  "blit.vs",      "blitblur.fs" );
+   _S( "blitcolour","blit.vs",      "colour.fs" );
+   _S( "routeui",   "routeui.vs",   "routeui.fs" );
    
+#if 0
    // 3D Standard
-   _shader( "standard",  "shaders/standard.vs",  "shaders/standard.fs" );
-   _shader( "vblend",    "shaders/standard.vs",  "shaders/vblend.fs" );
-   _shader( "scoretext", "shaders/scoretext.vs", "shaders/vblend.fs" );
-   _shader( "terrain",   "shaders/standard.vs",  "shaders/terrain.fs" );
-   _shader( "alphatest", "shaders/standard.vs",  "shaders/std_alphatest.fs" );
-   _shader( "route",     "shaders/standard.vs",  "shaders/route.fs" );
-   _shader( "menu",      "shaders/standard.vs",  "shaders/menu.fs" );
-   
-   // 3D Skinned
-   _shader( "viewchar",  "shaders/standard_skinned.vs", "shaders/viewchar.fs" );
-
-   // 3D extra/effects
-   _shader( "gpos",      "shaders/standard.vs",  "shaders/gpos.fs" );
-   _shader( "sky",       "shaders/standard.vs",  "shaders/sky.fs" );
-   _shader( "water",     "shaders/standard.vs",  "shaders/water.fs" );
-   _shader( "water_fast","shaders/standard.vs",  "shaders/water_fast.fs" );
-   _shader( "gatelq",    "shaders/gate.vs",      "shaders/gate_lq.fs" );
+   _S( "scoretext", "shaders/scoretext.vs", "shaders/vblend.fs" );
+#endif
 }
diff --git a/maps_src/mp_arizona.mdl b/maps_src/mp_arizona.mdl
new file mode 100644 (file)
index 0000000..9d1ce85
Binary files /dev/null and b/maps_src/mp_arizona.mdl differ
index 465de6c8a6cfdbe150c078a6af6a0691d464c252..cb5211b434b91c4b03bc99086158344809de8f4c 100644 (file)
Binary files a/maps_src/mp_gridmap.mdl and b/maps_src/mp_gridmap.mdl differ
index 219be463775cdf0ebcfd6757569d4a46ee0a1694..96165c9dd9419b24ee463a7c74388a7e965ec874 100644 (file)
Binary files a/maps_src/mp_mtzero.mdl and b/maps_src/mp_mtzero.mdl differ
diff --git a/model.h b/model.h
index 12a05b1678b36a64e350a79c3de9843f8afc4d4d..54987233a1f3cd8200468f5e1dcbee3640b6b407 100644 (file)
--- a/model.h
+++ b/model.h
@@ -41,7 +41,8 @@ enum classtype
    k_classtype_audio                = 14,
    k_classtype_trigger              = 100,
    k_classtype_logic_achievement    = 101,
-   k_classtype_logic_relay          = 102
+   k_classtype_logic_relay          = 102,
+   k_classtype_point_light          = 200
 };
 
 enum mdl_shader
@@ -269,6 +270,11 @@ struct classtype_audio
    float volume;
 };
 
+struct classtype_point_light
+{
+   v4f colour; /* RGB, Energy */
+};
+
 #pragma pack(pop)
 
 
index 10f5cc5d3d99e9659461ba2af1239f8b74d5752d..4c8f76a755bc2e2f9f31d374085a7f8b199dafc9 100644 (file)
--- a/player.c
+++ b/player.c
@@ -263,13 +263,13 @@ VG_STATIC void player__pre_render( player_instance *player )
 
 PLAYER_API void player__render( camera *cam, player_instance *player )
 {
-   shader_viewchar_use();
+   shader_model_character_view_use();
    vg_tex2d_bind( player->playertex, 0 );
-   shader_viewchar_uTexMain( 0 );
-   shader_viewchar_uCamera( cam->transform[3] );
-   shader_viewchar_uPv( cam->mtx.pv );
-   shader_link_standard_ub( _shader_viewchar.id, 2 );
-   glUniformMatrix4x3fv( _uniform_viewchar_uTransforms, 
+   shader_model_character_view_uTexMain( 0 );
+   shader_model_character_view_uCamera( cam->transform[3] );
+   shader_model_character_view_uPv( cam->mtx.pv );
+   shader_link_standard_ub( _shader_model_character_view.id, 2 );
+   glUniformMatrix4x3fv( _uniform_model_character_view_uTransforms,
                          player->playeravatar->sk.bone_count,
                          0,
                          (float *)player->playeravatar->sk.final_mtx );
index e7114cf6e71ab912746033919939ab9726f85425..5982eaeb8f21c8abfdde34c064d7c80cd760ad13 100644 (file)
@@ -13,7 +13,7 @@
 #include "player_ragdoll.h"
 #include "rigidbody.h"
 
-#include "shaders/viewchar.h"
+#include "shaders/model_character_view.h"
 
 struct player_avatar
 {
index cd41ec33e836d65ef02d690fc824d4505efee3a1..7b5b473739f7ec6c6b01083bd3448f6e73d43697 100644 (file)
--- a/render.h
+++ b/render.h
@@ -8,8 +8,12 @@
 
 #include "shaders/blit.h"
 #include "shaders/blitblur.h"
+#include "shaders/blitcolour.h"
+
+#if 0
 #include "shaders/standard.h"
 #include "shaders/vblend.h"
+#endif
 
 VG_STATIC void render_water_texture( camera *cam );
 VG_STATIC void render_water_surface( camera *cam );
@@ -50,6 +54,9 @@ VG_STATIC struct pipeline
       int g_light_count;
       int g_light_preview;
       int g_shadow_samples;
+
+      v4f g_point_light_positions[32];
+      v4f g_point_light_colours[32];
    }
    ub_world_lighting;
 
@@ -668,8 +675,7 @@ VG_STATIC void render_init(void)
 {
    shader_blit_register();
    shader_blitblur_register();
-   shader_standard_register();
-   shader_vblend_register();
+   shader_blitcolour_register();
 
    vg_acquire_thread_sync();
    {
diff --git a/scene.h b/scene.h
index d0615d52688a36b18d3656a5c64a8551f58fb1b9..902aedbff9924a8e4f2b7301d3e85bf6014dff4b 100644 (file)
--- a/scene.h
+++ b/scene.h
@@ -10,13 +10,14 @@ typedef struct scene_vert scene_vert;
 
 #pragma pack(push,1)
 
-/* 24 byte vertexs, we don't care about the normals too much,
+/* 28 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 */
 };
 
 #pragma pack(pop)
@@ -259,6 +260,11 @@ VG_STATIC void scene_upload( scene *pscene, glmesh *mesh )
          stride, (void *)offsetof(scene_vert, uv) );
    glEnableVertexAttribArray( 2 );
 
+   /* 3: light cluster */
+   glVertexAttribIPointer( 3, 4, GL_UNSIGNED_BYTE,
+         stride, (void *)offsetof(scene_vert, lights) );
+   glEnableVertexAttribArray( 3 );
+
    VG_CHECK_GL_ERR();
 
    mesh->indice_count = pscene->indice_count;
index 79604a6d66a7a8e6ad80c79ad100b98c4cd2a8e1..e7a6f61a9ebdc612d0af03c5bb9a981f4cc6d2b8 100755 (executable)
@@ -10,24 +10,32 @@ shader(){
    target_shaders="$target_shaders $1 $2 $3"
 }
 
-shader blit blit.vs blit.fs
-shader standard standard.vs standard.fs
-shader vblend standard.vs vblend.fs
-shader terrain standard.vs terrain.fs
-shader sky standard.vs sky.fs
-shader planeinf standard.vs planeinf.fs
-shader gpos standard.vs gpos.fs
-shader fscolour blit.vs colour.fs
-shader alphatest standard.vs std_alphatest.fs
-shader scoretext scoretext.vs vblend.fs
-shader water standard.vs water.fs
-shader water_fast standard.vs water_fast.fs
-shader gate gate.vs gate.fs
-shader gatelq gate.vs gate_lq.fs
-shader route standard.vs route.fs
-shader routeui routeui.vs routeui.fs
-shader viewchar standard_skinned.vs viewchar.fs
-shader menu standard.vs menu.fs
+# uses scene
+shader scene_standard            scene.vs    scene_standard.fs
+shader scene_standard_alphatest  scene.vs    scene_standard_alphatest.fs
+shader scene_vertex_blend        scene.vs    scene_vertex_blend.fs
+shader scene_terrain             scene.vs    scene_terrain.fs
+shader scene_route               scene.vs    scene_route.fs
+shader scene_depth               scene.vs    scene_depth.fs
+
+# model shaders
+shader model_sky                 model.vs          model_sky.fs
+shader model_water               model.vs          model_water.fs
+shader model_water_fast          model.vs          model_water_fast.fs
+shader model_menu                model.vs          model_menu.fs
+shader model_character_view      model_skinned.vs  model_character_view.fs
+shader model_gate                model_gate.vs     model_gate.fs
+shader model_gatelq              model_gate.vs     model_gate_lq.fs
+
+# fullscreen
+shader blit                      blit.vs blit.fs
+shader fscolour                  blit.vs colour.fs
+
+#shader planeinf standard.vs planeinf.fs
+#shader scoretext scoretext.vs vblend.fs
+# Special
+
+shader routeui                   routeui.vs routeui.fs
 
 cd shaders
 ../bin/linux/tools/shader $target_shaders
diff --git a/shaders/alphatest.h b/shaders/alphatest.h
deleted file mode 100644 (file)
index 9847894..0000000
+++ /dev/null
@@ -1,314 +0,0 @@
-#ifndef SHADER_alphatest_H
-#define SHADER_alphatest_H
-static void shader_alphatest_link(void);
-static void shader_alphatest_register(void);
-static struct vg_shader _shader_alphatest = {
-   .name = "alphatest",
-   .link = shader_alphatest_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     15        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     16        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"   vec4 vsamplemain = texture( uTexMain, aUv );\n"
-"   vec3 qnorm = normalize(aNorm);\n"
-"\n"
-"   if( vsamplemain.a < 0.15 )\n"
-"     discard;\n"
-"\n"
-"   vfrag = vsamplemain.rgb;\n"
-"\n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
-"      vfrag = vec3(0.5);\n"
-"   }\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   vfrag = do_light_diffuse( vfrag, qnorm );\n"
-"   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   oColour = vec4(vfrag, 1.0);\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_alphatest_uMdl;
-static GLuint _uniform_alphatest_uPv;
-static GLuint _uniform_alphatest_uPvmPrev;
-static GLuint _uniform_alphatest_uTexGarbage;
-static GLuint _uniform_alphatest_uTexMain;
-static GLuint _uniform_alphatest_uBoard0;
-static GLuint _uniform_alphatest_uBoard1;
-static GLuint _uniform_alphatest_uCamera;
-static GLuint _uniform_alphatest_uPlane;
-static GLuint _uniform_alphatest_g_world_depth;
-static void shader_alphatest_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_alphatest_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_alphatest_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_alphatest_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_alphatest_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_alphatest_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_alphatest_uTexGarbage(int i){
-   glUniform1i(_uniform_alphatest_uTexGarbage,i);
-}
-static void shader_alphatest_uTexMain(int i){
-   glUniform1i(_uniform_alphatest_uTexMain,i);
-}
-static void shader_alphatest_uBoard0(v3f v){
-   glUniform3fv(_uniform_alphatest_uBoard0,1,v);
-}
-static void shader_alphatest_uBoard1(v3f v){
-   glUniform3fv(_uniform_alphatest_uBoard1,1,v);
-}
-static void shader_alphatest_uCamera(v3f v){
-   glUniform3fv(_uniform_alphatest_uCamera,1,v);
-}
-static void shader_alphatest_uPlane(v4f v){
-   glUniform4fv(_uniform_alphatest_uPlane,1,v);
-}
-static void shader_alphatest_g_world_depth(int i){
-   glUniform1i(_uniform_alphatest_g_world_depth,i);
-}
-static void shader_alphatest_register(void){
-   vg_shader_register( &_shader_alphatest );
-}
-static void shader_alphatest_use(void){ glUseProgram(_shader_alphatest.id); }
-static void shader_alphatest_link(void){
-   _uniform_alphatest_uMdl = glGetUniformLocation( _shader_alphatest.id, "uMdl" );
-   _uniform_alphatest_uPv = glGetUniformLocation( _shader_alphatest.id, "uPv" );
-   _uniform_alphatest_uPvmPrev = glGetUniformLocation( _shader_alphatest.id, "uPvmPrev" );
-   _uniform_alphatest_uTexGarbage = glGetUniformLocation( _shader_alphatest.id, "uTexGarbage" );
-   _uniform_alphatest_uTexMain = glGetUniformLocation( _shader_alphatest.id, "uTexMain" );
-   _uniform_alphatest_uBoard0 = glGetUniformLocation( _shader_alphatest.id, "uBoard0" );
-   _uniform_alphatest_uBoard1 = glGetUniformLocation( _shader_alphatest.id, "uBoard1" );
-   _uniform_alphatest_uCamera = glGetUniformLocation( _shader_alphatest.id, "uCamera" );
-   _uniform_alphatest_uPlane = glGetUniformLocation( _shader_alphatest.id, "uPlane" );
-   _uniform_alphatest_g_world_depth = glGetUniformLocation( _shader_alphatest.id, "g_world_depth" );
-}
-#endif /* SHADER_alphatest_H */
diff --git a/shaders/character.fs b/shaders/character.fs
deleted file mode 100644 (file)
index 2b13d76..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform vec4 uColour;
-uniform vec3 uCamera;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-in float aOpacity;
-
-#include "common_world.glsl"
-
-void main()
-{
-   vec3 vfrag = texture( uTexMain, aUv ).rgb;
-
-   // Lighting
-   vec3 halfview = uCamera - aWorldCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   //vfrag = do_light_diffuse( vfrag, aNorm );
-   vfrag = do_light_spec( vfrag, aNorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   //vfrag = apply_fog( vfrag, fdist );
-
-   FragColor = vec4(vfrag,aOpacity);
-}
diff --git a/shaders/character.h b/shaders/character.h
deleted file mode 100644 (file)
index 8265c37..0000000
+++ /dev/null
@@ -1,223 +0,0 @@
-#ifndef SHADER_character_H
-#define SHADER_character_H
-static void shader_character_link(void);
-static void shader_character_register(void);
-static struct vg_shader _shader_character = {
-   .name = "character",
-   .link = shader_character_link,
-   .vs = 
-{
-.orig_file = "../../shaders/character.vs",
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"uniform mat4 uPv;\n"
-"uniform mat4x3 uMdl;\n"
-"uniform float uOpacity;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"out float aOpacity;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos = uMdl * vec4(a_co,1.0);\n"
-"   vec4 clip_pos = uPv * vec4(world_pos,1.0);\n"
-"   gl_Position = clip_pos;\n"
-"\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aWorldCo = world_pos;\n"
-"   aCo = a_co;\n"
-"   aOpacity = max(clip_pos.w*3.0,0.1);//  1.0-(gl_Position.y+0.5)*uOpacity;\n"
-"}\n"
-""},
-   .fs = 
-{
-.orig_file = "../../shaders/character.fs",
-.static_src = 
-"out vec4 FragColor;\n"
-"\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec4 uColour;\n"
-"uniform vec3 uCamera;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"in float aOpacity;\n"
-"\n"
-"#line       1        1 \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"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\n"
-"}\n"
-"\n"
-"vec3 do_light_shadowing( vec3 vfrag )\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"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     15        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 vfrag = texture( uTexMain, aUv ).rgb;\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   //vfrag = do_light_diffuse( vfrag, aNorm );\n"
-"   vfrag = do_light_spec( vfrag, aNorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   //vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   FragColor = vec4(vfrag,aOpacity);\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_character_uPv;
-static GLuint _uniform_character_uMdl;
-static GLuint _uniform_character_uOpacity;
-static GLuint _uniform_character_uTexMain;
-static GLuint _uniform_character_uColour;
-static GLuint _uniform_character_uCamera;
-static GLuint _uniform_character_g_world_depth;
-static void shader_character_uPv(m4x4f m){
-   glUniformMatrix4fv( _uniform_character_uPv, 1, GL_FALSE, (float *)m );
-}
-static void shader_character_uMdl(m4x3f m){
-   glUniformMatrix4x3fv( _uniform_character_uMdl, 1, GL_FALSE, (float *)m );
-}
-static void shader_character_uOpacity(float f){
-   glUniform1f( _uniform_character_uOpacity, f );
-}
-static void shader_character_uTexMain(int i){
-   glUniform1i( _uniform_character_uTexMain, i );
-}
-static void shader_character_uColour(v4f v){
-   glUniform4fv( _uniform_character_uColour, 1, v );
-}
-static void shader_character_uCamera(v3f v){
-   glUniform3fv( _uniform_character_uCamera, 1, v );
-}
-static void shader_character_g_world_depth(int i){
-   glUniform1i( _uniform_character_g_world_depth, i );
-}
-static void shader_character_register(void){
-   vg_shader_register( &_shader_character );
-}
-static void shader_character_use(void){ glUseProgram(_shader_character.id); }
-static void shader_character_link(void){
-   _uniform_character_uPv = glGetUniformLocation( _shader_character.id, "uPv" );
-   _uniform_character_uMdl = glGetUniformLocation( _shader_character.id, "uMdl" );
-   _uniform_character_uOpacity = glGetUniformLocation( _shader_character.id, "uOpacity" );
-   _uniform_character_uTexMain = glGetUniformLocation( _shader_character.id, "uTexMain" );
-   _uniform_character_uColour = glGetUniformLocation( _shader_character.id, "uColour" );
-   _uniform_character_uCamera = glGetUniformLocation( _shader_character.id, "uCamera" );
-   _uniform_character_g_world_depth = glGetUniformLocation( _shader_character.id, "g_world_depth" );
-}
-#endif /* SHADER_character_H */
diff --git a/shaders/character.vs b/shaders/character.vs
deleted file mode 100644 (file)
index 6d90ce6..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "vertex_standard.glsl"
-
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-uniform float uOpacity;
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-out vec3 aWorldCo;
-out float aOpacity;
-
-void main()
-{
-   vec3 world_pos = uMdl * vec4(a_co,1.0);
-   vec4 clip_pos = uPv * vec4(world_pos,1.0);
-   gl_Position = clip_pos;
-
-   aColour = a_colour;
-   aUv = a_uv;
-   aNorm = mat3(uMdl) * a_norm;
-   aWorldCo = world_pos;
-   aCo = a_co;
-   aOpacity = max(clip_pos.w*3.0,0.1);//  1.0-(gl_Position.y+0.5)*uOpacity;
-}
diff --git a/shaders/common_scene.glsl b/shaders/common_scene.glsl
new file mode 100644 (file)
index 0000000..4a78fbc
--- /dev/null
@@ -0,0 +1,46 @@
+// :D
+
+#include "common_world.glsl"
+
+vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )
+{
+   // Lighting
+   vec3 halfview = uCamera - aWorldCo;
+   float fdist = length(halfview);
+   halfview /= fdist;
+
+   vec3 total_light = newlight_compute_ambient();
+   
+   // Compute world lighting contribution and apply it according to the
+   // shadow map
+   //
+   vec3 world_light = newlight_compute_world_diffuse( wnormal );
+   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );
+
+   float world_shadow = newlight_compute_sun_shadow();
+
+   total_light += world_light * 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 
+                  );
+   total_light += newlight_compute_quadratic
+                  ( 
+                     wnormal, halfview,
+                     g_point_light_positions[ aLights.y ].xyz,
+                     g_point_light_colours[ aLights.y ].rgb 
+                  );
+   total_light += newlight_compute_quadratic
+                  ( 
+                     wnormal, halfview,
+                     g_point_light_positions[ aLights.z ].xyz,
+                     g_point_light_colours[ aLights.z ].rgb 
+                  );
+
+   return apply_fog( diffuse * total_light, fdist );
+}
index baffd66001af0c7dbd5b680f5dc1408b022b3223..b5c79dfac683779b4ddfe6977f7c20c823b929f5 100644 (file)
@@ -12,39 +12,13 @@ layout (std140) uniform ub_world_lighting
    int g_light_count;
    int g_light_preview;
    int g_shadow_samples;
+
+   vec4 g_point_light_positions[32];
+   vec4 g_point_light_colours[32];
 };
 
 uniform sampler2D g_world_depth;
 
-// Standard diffuse + spec models
-// ==============================
-
-vec3 do_light_diffuse( vec3 vfrag, vec3 wnormal )
-{
-   vec3 vtotal = g_ambient_colour.rgb;
-
-   for( int i=0; i<g_light_count; i++ )
-   {
-      vec3 vcolour = g_light_colours[i].rgb;
-      vec3 vdir = g_light_directions[i].xyz;
-
-      float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);
-      vtotal += vcolour*flight;
-   }
-
-   return vfrag * vtotal;
-}
-
-vec3 do_light_spec( vec3 vfrag, vec3 wnormal, vec3 halfview, float fintensity )
-{
-   vec3 vcolour = g_light_colours[0].rgb;
-   vec3 vdir = g_light_directions[0].xyz;
-
-   vec3 specdir = reflect( -vdir, wnormal );
-   float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0);
-   return vfrag + vcolour*spec*fintensity;
-}
-
 float world_depth_sample( vec3 pos )
 {
    vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; 
@@ -60,20 +34,6 @@ float shadow_sample( vec3 vdir )
    return clamp( fdelta, 0.1, 0.2 )-0.1;
 }
 
-vec3 do_light_shadowing_old( vec3 vfrag )
-{
-   float faccum = 0.0;
-   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));
-   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));
-   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));
-   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));
-   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);
-   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);
-   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);
-   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);
-   return mix( vfrag, g_ambient_colour.rgb, faccum );
-}
-
 float sdLine( vec3 p, vec3 a, vec3 b )
 {
   vec3 pa = p - a;
@@ -83,11 +43,25 @@ float sdLine( vec3 p, vec3 a, vec3 b )
   return length( pa - ba*h );
 }
 
-vec3 do_light_shadowing( vec3 vfrag )
+vec3 apply_fog( vec3 vfrag, float fdist )
+{
+   float dist = pow(fdist*0.0008,1.2);
+   return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );
+}
+
+
+// New lighting model
+
+vec3 newlight_compute_ambient()
+{
+   return g_ambient_colour.rgb;
+}
+
+float newlight_compute_sun_shadow()
 {
    if( g_shadow_samples == 0 )
    {
-      return vfrag;
+      return 1.0;
    }
 
    float fspread = g_light_colours[0].w;
@@ -109,12 +83,43 @@ vec3 do_light_shadowing( vec3 vfrag )
    float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );
    player_shadow *= player_shadow*player_shadow*player_shadow;
 
-   famt = max( player_shadow*0.8, famt );
-   return mix( vfrag, g_ambient_colour.rgb, famt );
+   return 1.0 - max( player_shadow*0.8, famt );
 }
 
-vec3 apply_fog( vec3 vfrag, float fdist )
+vec3 newlight_compute_world_diffuse( vec3 wnormal )
 {
-   float dist = pow(fdist*0.0008,1.2);
-   return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );
+   vec3 vtotal = g_ambient_colour.rgb;
+
+   for( int i=0; i<g_light_count; i++ )
+   {
+      vec3 vcolour = g_light_colours[i].rgb;
+      vec3 vdir = g_light_directions[i].xyz;
+
+      float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);
+      vtotal += vcolour*flight;
+   }
+
+   return vtotal;
+}
+
+vec3 newlight_compute_sun_spec( vec3 wnormal, vec3 halfview, float fintensity )
+{
+   vec3 vcolour = g_light_colours[0].rgb;
+   vec3 vdir = g_light_directions[0].xyz;
+
+   vec3 specdir = reflect( -vdir, wnormal );
+   float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0);
+   return vcolour*spec*fintensity;
+}
+
+vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, 
+                                 vec3 light_pos, vec3 light_colour )
+{
+   vec3 light_delta = (light_pos-aWorldCo) * 10.0;
+
+   float quadratic = dot(light_delta,light_delta);
+   float attenuation = 1.0f/( 1.0f + quadratic );
+   attenuation *= max( 0.0, dot( normalize(light_delta), wnormal ) );
+
+   return light_colour*attenuation;
 }
diff --git a/shaders/fscolour.h b/shaders/fscolour.h
deleted file mode 100644 (file)
index 08fe21e..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef SHADER_fscolour_H
-#define SHADER_fscolour_H
-static void shader_fscolour_link(void);
-static void shader_fscolour_register(void);
-static struct vg_shader _shader_fscolour = {
-   .name = "fscolour",
-   .link = shader_fscolour_link,
-   .vs = 
-{
-.orig_file = "../../shaders/blit.vs",
-.static_src = 
-"layout (location=0) in vec2 a_co;\n"
-"out vec2 aUv;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
-"   aUv = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.orig_file = "../../shaders/colour.fs",
-.static_src = 
-"out vec4 FragColor;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"in vec2 aUv;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   FragColor = uColour;\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_fscolour_uColour;
-static void shader_fscolour_uColour(v4f v){
-   glUniform4fv( _uniform_fscolour_uColour, 1, v );
-}
-static void shader_fscolour_register(void){
-   vg_shader_register( &_shader_fscolour );
-}
-static void shader_fscolour_use(void){ glUseProgram(_shader_fscolour.id); }
-static void shader_fscolour_link(void){
-   _uniform_fscolour_uColour = glGetUniformLocation( _shader_fscolour.id, "uColour" );
-}
-#endif /* SHADER_fscolour_H */
diff --git a/shaders/gate.fs b/shaders/gate.fs
deleted file mode 100644 (file)
index ba48f1e..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform sampler2D uTexWater;
-uniform vec2 uInvRes;
-uniform float uTime;
-uniform vec3 uCam;
-
-in vec3 aNorm;
-in vec2 aUv;
-in vec3 aCo;
-
-void main()
-{
-   vec2 ssuv = gl_FragCoord.xy*uInvRes;
-   vec4 mapwater = texture( uTexWater, vec2(aUv.x,aUv.y-uTime));
-
-   float undistort = smoothstep(0.1,0.6,distance( uCam, aCo )*0.1);
-   vec2 trimedge = smoothstep(0.0,0.2,1.0-abs(ssuv-0.5)*2.0);
-   undistort *= trimedge.x * trimedge.y;
-
-   vec2 warpamt = (mapwater.rg-0.5)*0.05*aUv.y*undistort;
-   vec4 mapbackbuffer = texture( uTexMain, ssuv + warpamt );
-
-   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);
-   FragColor = vec4( mapbackbuffer.rgb, opacity );
-}
diff --git a/shaders/gate.h b/shaders/gate.h
deleted file mode 100644 (file)
index 51eb312..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-#ifndef SHADER_gate_H
-#define SHADER_gate_H
-static void shader_gate_link(void);
-static void shader_gate_register(void);
-static struct vg_shader _shader_gate = {
-   .name = "gate",
-   .link = shader_gate_link,
-   .vs = 
-{
-.orig_file = "../../shaders/gate.vs",
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"uniform mat4 uPv;\n"
-"uniform mat4x3 uMdl;\n"
-"\n"
-"out vec3 aNorm;\n"
-"out vec2 aUv;\n"
-"out vec3 aCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos = uMdl * vec4( a_co, 1.0 );\n"
-"   gl_Position = uPv * vec4(world_pos,1.0);\n"
-"\n"
-"   aNorm = a_norm;\n"
-"   aCo = world_pos;\n"
-"   aUv = a_uv;\n"
-"}\n"
-""},
-   .fs = 
-{
-.orig_file = "../../shaders/gate.fs",
-.static_src = 
-"out vec4 FragColor;\n"
-"\n"
-"uniform sampler2D uTexMain;\n"
-"uniform sampler2D uTexWater;\n"
-"uniform vec2 uInvRes;\n"
-"uniform float uTime;\n"
-"uniform vec3 uCam;\n"
-"\n"
-"in vec3 aNorm;\n"
-"in vec2 aUv;\n"
-"in vec3 aCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
-"   vec4 mapwater = texture( uTexWater, vec2(aUv.x,aUv.y-uTime));\n"
-"\n"
-"   float undistort = smoothstep(0.1,0.6,distance( uCam, aCo )*0.1);\n"
-"   vec2 trimedge = smoothstep(0.0,0.2,1.0-abs(ssuv-0.5)*2.0);\n"
-"   undistort *= trimedge.x * trimedge.y;\n"
-"\n"
-"   vec2 warpamt = (mapwater.rg-0.5)*0.05*aUv.y*undistort;\n"
-"   vec4 mapbackbuffer = texture( uTexMain, ssuv + warpamt );\n"
-"\n"
-"   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);\n"
-"   FragColor = vec4( mapbackbuffer.rgb, opacity );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_gate_uPv;
-static GLuint _uniform_gate_uMdl;
-static GLuint _uniform_gate_uTexMain;
-static GLuint _uniform_gate_uTexWater;
-static GLuint _uniform_gate_uInvRes;
-static GLuint _uniform_gate_uTime;
-static GLuint _uniform_gate_uCam;
-static void shader_gate_uPv(m4x4f m){
-   glUniformMatrix4fv( _uniform_gate_uPv, 1, GL_FALSE, (float *)m );
-}
-static void shader_gate_uMdl(m4x3f m){
-   glUniformMatrix4x3fv( _uniform_gate_uMdl, 1, GL_FALSE, (float *)m );
-}
-static void shader_gate_uTexMain(int i){
-   glUniform1i( _uniform_gate_uTexMain, i );
-}
-static void shader_gate_uTexWater(int i){
-   glUniform1i( _uniform_gate_uTexWater, i );
-}
-static void shader_gate_uInvRes(v2f v){
-   glUniform2fv( _uniform_gate_uInvRes, 1, v );
-}
-static void shader_gate_uTime(float f){
-   glUniform1f( _uniform_gate_uTime, f );
-}
-static void shader_gate_uCam(v3f v){
-   glUniform3fv( _uniform_gate_uCam, 1, v );
-}
-static void shader_gate_register(void){
-   vg_shader_register( &_shader_gate );
-}
-static void shader_gate_use(void){ glUseProgram(_shader_gate.id); }
-static void shader_gate_link(void){
-   _uniform_gate_uPv = glGetUniformLocation( _shader_gate.id, "uPv" );
-   _uniform_gate_uMdl = glGetUniformLocation( _shader_gate.id, "uMdl" );
-   _uniform_gate_uTexMain = glGetUniformLocation( _shader_gate.id, "uTexMain" );
-   _uniform_gate_uTexWater = glGetUniformLocation( _shader_gate.id, "uTexWater" );
-   _uniform_gate_uInvRes = glGetUniformLocation( _shader_gate.id, "uInvRes" );
-   _uniform_gate_uTime = glGetUniformLocation( _shader_gate.id, "uTime" );
-   _uniform_gate_uCam = glGetUniformLocation( _shader_gate.id, "uCam" );
-}
-#endif /* SHADER_gate_H */
diff --git a/shaders/gate.vs b/shaders/gate.vs
deleted file mode 100644 (file)
index 9d5853c..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "vertex_standard.glsl"
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-
-out vec3 aNorm;
-out vec2 aUv;
-out vec3 aCo;
-
-void main()
-{
-   vec3 world_pos = uMdl * vec4( a_co, 1.0 );
-   gl_Position = uPv * vec4(world_pos,1.0);
-
-   aNorm = a_norm;
-   aCo = world_pos;
-   aUv = a_uv;
-}
diff --git a/shaders/gate_lq.fs b/shaders/gate_lq.fs
deleted file mode 100644 (file)
index c455126..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-out vec4 FragColor;
-
-uniform float uTime;
-uniform vec3 uCam;
-uniform vec2 uInvRes;
-
-in vec3 aNorm;
-in vec2 aUv;
-in vec3 aCo;
-
-void main()
-{
-   vec2 ssuv = gl_FragCoord.xy;
-   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);
-   
-   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
-   float dither = fract( vDither.g / 71.0 ) - 0.5;
-
-   if( opacity+dither<0.5 )
-      discard;
-
-   FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );
-}
diff --git a/shaders/gatelq.h b/shaders/gatelq.h
deleted file mode 100644 (file)
index b717aa9..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#ifndef SHADER_gatelq_H
-#define SHADER_gatelq_H
-static void shader_gatelq_link(void);
-static void shader_gatelq_register(void);
-static struct vg_shader _shader_gatelq = {
-   .name = "gatelq",
-   .link = shader_gatelq_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"uniform mat4 uPv;\n"
-"uniform mat4x3 uMdl;\n"
-"\n"
-"out vec3 aNorm;\n"
-"out vec2 aUv;\n"
-"out vec3 aCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos = uMdl * vec4( a_co, 1.0 );\n"
-"   gl_Position = uPv * vec4(world_pos,1.0);\n"
-"\n"
-"   aNorm = a_norm;\n"
-"   aCo = world_pos;\n"
-"   aUv = a_uv;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"out vec4 FragColor;\n"
-"\n"
-"uniform float uTime;\n"
-"uniform vec3 uCam;\n"
-"uniform vec2 uInvRes;\n"
-"\n"
-"in vec3 aNorm;\n"
-"in vec2 aUv;\n"
-"in vec3 aCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec2 ssuv = gl_FragCoord.xy;\n"
-"   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);\n"
-"   \n"
-"   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-"   float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-"   if( opacity+dither<0.5 )\n"
-"      discard;\n"
-"\n"
-"   FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_gatelq_uPv;
-static GLuint _uniform_gatelq_uMdl;
-static GLuint _uniform_gatelq_uTime;
-static GLuint _uniform_gatelq_uCam;
-static GLuint _uniform_gatelq_uInvRes;
-static void shader_gatelq_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_gatelq_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_gatelq_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_gatelq_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_gatelq_uTime(float f){
-   glUniform1f(_uniform_gatelq_uTime,f);
-}
-static void shader_gatelq_uCam(v3f v){
-   glUniform3fv(_uniform_gatelq_uCam,1,v);
-}
-static void shader_gatelq_uInvRes(v2f v){
-   glUniform2fv(_uniform_gatelq_uInvRes,1,v);
-}
-static void shader_gatelq_register(void){
-   vg_shader_register( &_shader_gatelq );
-}
-static void shader_gatelq_use(void){ glUseProgram(_shader_gatelq.id); }
-static void shader_gatelq_link(void){
-   _uniform_gatelq_uPv = glGetUniformLocation( _shader_gatelq.id, "uPv" );
-   _uniform_gatelq_uMdl = glGetUniformLocation( _shader_gatelq.id, "uMdl" );
-   _uniform_gatelq_uTime = glGetUniformLocation( _shader_gatelq.id, "uTime" );
-   _uniform_gatelq_uCam = glGetUniformLocation( _shader_gatelq.id, "uCam" );
-   _uniform_gatelq_uInvRes = glGetUniformLocation( _shader_gatelq.id, "uInvRes" );
-}
-#endif /* SHADER_gatelq_H */
diff --git a/shaders/gpos.fs b/shaders/gpos.fs
deleted file mode 100644 (file)
index d76f6e4..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-out vec4 FragColor;
-
-uniform vec3 uCamera;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-
-#include "common_world.glsl"
-
-// Water blending
-// ==============
-
-float water_depth( vec3 pos, vec3 halfview )
-{
-   vec3 pnorm = g_water_plane.xyz;
-   float pdist = g_water_plane.w;
-
-   float d = dot( pnorm, halfview );
-   float t = dot((pnorm*pdist - pos), pnorm) / d;
-   return t * g_water_fog;
-}
-
-void main()
-{
-   vec3 halfview = normalize( uCamera - aCo );
-   vec3 world_pos = vec3( aCo.y, aCo.x, aCo.z );
-   FragColor = vec4( world_pos, water_depth( aCo, halfview ) );
-}
diff --git a/shaders/gpos.h b/shaders/gpos.h
deleted file mode 100644 (file)
index f2ac393..0000000
+++ /dev/null
@@ -1,267 +0,0 @@
-#ifndef SHADER_gpos_H
-#define SHADER_gpos_H
-static void shader_gpos_link(void);
-static void shader_gpos_register(void);
-static struct vg_shader _shader_gpos = {
-   .name = "gpos",
-   .link = shader_gpos_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"out vec4 FragColor;\n"
-"\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     14        0 \n"
-"\n"
-"// Water blending\n"
-"// ==============\n"
-"\n"
-"float water_depth( vec3 pos, vec3 halfview )\n"
-"{\n"
-"   vec3 pnorm = g_water_plane.xyz;\n"
-"   float pdist = g_water_plane.w;\n"
-"\n"
-"   float d = dot( pnorm, halfview );\n"
-"   float t = dot((pnorm*pdist - pos), pnorm) / d;\n"
-"   return t * g_water_fog;\n"
-"}\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 halfview = normalize( uCamera - aCo );\n"
-"   vec3 world_pos = vec3( aCo.y, aCo.x, aCo.z );\n"
-"   FragColor = vec4( world_pos, water_depth( aCo, halfview ) );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_gpos_uMdl;
-static GLuint _uniform_gpos_uPv;
-static GLuint _uniform_gpos_uPvmPrev;
-static GLuint _uniform_gpos_uCamera;
-static GLuint _uniform_gpos_uBoard0;
-static GLuint _uniform_gpos_uBoard1;
-static GLuint _uniform_gpos_g_world_depth;
-static void shader_gpos_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_gpos_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_gpos_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_gpos_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_gpos_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_gpos_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_gpos_uCamera(v3f v){
-   glUniform3fv(_uniform_gpos_uCamera,1,v);
-}
-static void shader_gpos_uBoard0(v3f v){
-   glUniform3fv(_uniform_gpos_uBoard0,1,v);
-}
-static void shader_gpos_uBoard1(v3f v){
-   glUniform3fv(_uniform_gpos_uBoard1,1,v);
-}
-static void shader_gpos_g_world_depth(int i){
-   glUniform1i(_uniform_gpos_g_world_depth,i);
-}
-static void shader_gpos_register(void){
-   vg_shader_register( &_shader_gpos );
-}
-static void shader_gpos_use(void){ glUseProgram(_shader_gpos.id); }
-static void shader_gpos_link(void){
-   _uniform_gpos_uMdl = glGetUniformLocation( _shader_gpos.id, "uMdl" );
-   _uniform_gpos_uPv = glGetUniformLocation( _shader_gpos.id, "uPv" );
-   _uniform_gpos_uPvmPrev = glGetUniformLocation( _shader_gpos.id, "uPvmPrev" );
-   _uniform_gpos_uCamera = glGetUniformLocation( _shader_gpos.id, "uCamera" );
-   _uniform_gpos_uBoard0 = glGetUniformLocation( _shader_gpos.id, "uBoard0" );
-   _uniform_gpos_uBoard1 = glGetUniformLocation( _shader_gpos.id, "uBoard1" );
-   _uniform_gpos_g_world_depth = glGetUniformLocation( _shader_gpos.id, "g_world_depth" );
-}
-#endif /* SHADER_gpos_H */
diff --git a/shaders/menu.fs b/shaders/menu.fs
deleted file mode 100644 (file)
index e957ddf..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform vec4 uColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-
-void main()
-{
-   vec4 diffuse = texture( uTexMain, aUv );
-
-   if( diffuse.a < 0.5 )
-      discard;
-
-   FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;
-}
diff --git a/shaders/menu.h b/shaders/menu.h
deleted file mode 100644 (file)
index 3bf0d1f..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-#ifndef SHADER_menu_H
-#define SHADER_menu_H
-static void shader_menu_link(void);
-static void shader_menu_register(void);
-static struct vg_shader _shader_menu = {
-   .name = "menu",
-   .link = shader_menu_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"out vec4 FragColor;\n"
-"\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec4 diffuse = texture( uTexMain, aUv );\n"
-"\n"
-"   if( diffuse.a < 0.5 )\n"
-"      discard;\n"
-"\n"
-"   FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_menu_uMdl;
-static GLuint _uniform_menu_uPv;
-static GLuint _uniform_menu_uPvmPrev;
-static GLuint _uniform_menu_uTexMain;
-static GLuint _uniform_menu_uColour;
-static void shader_menu_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_menu_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_menu_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_menu_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_menu_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_menu_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_menu_uTexMain(int i){
-   glUniform1i(_uniform_menu_uTexMain,i);
-}
-static void shader_menu_uColour(v4f v){
-   glUniform4fv(_uniform_menu_uColour,1,v);
-}
-static void shader_menu_register(void){
-   vg_shader_register( &_shader_menu );
-}
-static void shader_menu_use(void){ glUseProgram(_shader_menu.id); }
-static void shader_menu_link(void){
-   _uniform_menu_uMdl = glGetUniformLocation( _shader_menu.id, "uMdl" );
-   _uniform_menu_uPv = glGetUniformLocation( _shader_menu.id, "uPv" );
-   _uniform_menu_uPvmPrev = glGetUniformLocation( _shader_menu.id, "uPvmPrev" );
-   _uniform_menu_uTexMain = glGetUniformLocation( _shader_menu.id, "uTexMain" );
-   _uniform_menu_uColour = glGetUniformLocation( _shader_menu.id, "uColour" );
-}
-#endif /* SHADER_menu_H */
diff --git a/shaders/model.vs b/shaders/model.vs
new file mode 100644 (file)
index 0000000..350a821
--- /dev/null
@@ -0,0 +1,34 @@
+layout (location=0) in vec3 a_co;
+layout (location=1) in vec3 a_norm;
+layout (location=2) in vec2 a_uv;
+layout (location=3) in vec4 a_colour;
+layout (location=4) in vec4 a_weights;
+layout (location=5) in ivec4 a_groups;
+
+#include "motion_vectors_vs.glsl"
+
+uniform mat4x3 uMdl;
+uniform mat4 uPv;
+uniform mat4 uPvmPrev;
+
+out vec4 aColour;
+out vec2 aUv;
+out vec3 aNorm;
+out vec3 aCo;
+out vec3 aWorldCo;
+
+void main()
+{
+   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );
+   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );
+   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );
+
+   vs_motion_out( vproj0, vproj1 );
+
+   gl_Position = vproj0;
+   aWorldCo = world_pos0;
+   aColour = a_colour;
+   aUv = a_uv;
+   aNorm = mat3(uMdl) * a_norm;
+   aCo = a_co;
+}
diff --git a/shaders/model_character_view.fs b/shaders/model_character_view.fs
new file mode 100644 (file)
index 0000000..8bf29bc
--- /dev/null
@@ -0,0 +1,39 @@
+uniform sampler2D uTexMain;
+uniform vec3 uCamera;
+uniform vec3 uBoard0;
+uniform vec3 uBoard1;
+
+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();
+
+   vec3 vfrag = texture( uTexMain, aUv ).rgb;
+
+   // Lighting
+   vec3 halfview = uCamera - aWorldCo;
+   float fdist = length( halfview );
+   halfview /= fdist;
+   fdist -= 0.08;
+
+   vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);
+
+   vec3 total_light = newlight_compute_ambient();
+   vec3 world_light = newlight_compute_world_diffuse( qnorm );
+
+   float world_shadow = newlight_compute_sun_shadow();
+   total_light += world_light * world_shadow;
+
+   vfrag = apply_fog( vfrag * total_light, fdist );
+
+   float opacity = clamp( fdist*fdist, 0.0, 1.0 );
+   oColour = vec4(vfrag,opacity);
+}
diff --git a/shaders/model_character_view.h b/shaders/model_character_view.h
new file mode 100644 (file)
index 0000000..d1c8efd
--- /dev/null
@@ -0,0 +1,301 @@
+#ifndef SHADER_model_character_view_H
+#define SHADER_model_character_view_H
+static void shader_model_character_view_link(void);
+static void shader_model_character_view_register(void);
+static struct vg_shader _shader_model_character_view = {
+   .name = "model_character_view",
+   .link = shader_model_character_view_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec2 a_uv;\n"
+"layout (location=3) in vec4 a_colour;\n"
+"layout (location=4) in vec4 a_weights;\n"
+"layout (location=5) in ivec4 a_groups;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      9        0 \n"
+"\n"
+"uniform mat4 uPv;\n"
+"uniform mat4x3 uTransforms[32];\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec4 co_local = vec4( a_co, 1.0 );\n"
+"   vec3 co0 = uTransforms[ a_groups[0] ] * co_local;\n"
+"   vec3 co1 = uTransforms[ a_groups[1] ] * co_local;\n"
+"   vec3 co2 = uTransforms[ a_groups[2] ] * co_local;\n"
+"   vec3 n0  = mat3(uTransforms[ a_groups[0] ]) * a_norm;\n"
+"   vec3 n1  = mat3(uTransforms[ a_groups[1] ]) * a_norm;\n"
+"   vec3 n2  = mat3(uTransforms[ a_groups[2] ]) * a_norm;\n"
+"\n"
+"   vec3 world_pos    = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];\n"
+"   vec3 world_normal = n0*a_weights[0]  + n1*a_weights[1]  + n2*a_weights[2];\n"
+"   \n"
+"   gl_Position = uPv * vec4( world_pos, 1.0 );\n"
+"   aColour = a_colour;\n"
+"   aUv = a_uv;\n"
+"   aNorm = world_normal;\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos;\n"
+"\n"
+"   // TODO:\n"
+"   aMotionVec0 = vec3(1.0);\n"
+"   aMotionVec1 = vec3(1.0);\n"
+"}\n"
+""},
+   .fs = 
+{
+.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"
+"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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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     13        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     14        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   vec3 vfrag = texture( uTexMain, aUv ).rgb;\n"
+"\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - aWorldCo;\n"
+"   float fdist = length( halfview );\n"
+"   halfview /= fdist;\n"
+"   fdist -= 0.08;\n"
+"\n"
+"   vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n"
+"\n"
+"   vec3 total_light = newlight_compute_ambient();\n"
+"   vec3 world_light = newlight_compute_world_diffuse( qnorm );\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow();\n"
+"   total_light += world_light * world_shadow;\n"
+"\n"
+"   vfrag = apply_fog( vfrag * total_light, fdist );\n"
+"\n"
+"   float opacity = clamp( fdist*fdist, 0.0, 1.0 );\n"
+"   oColour = vec4(vfrag,opacity);\n"
+"}\n"
+""},
+};
+
+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);
+}
+static void shader_model_character_view_uTexMain(int i){
+   glUniform1i(_uniform_model_character_view_uTexMain,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);
+}
+static void shader_model_character_view_register(void){
+   vg_shader_register( &_shader_model_character_view );
+}
+static void shader_model_character_view_use(void){ glUseProgram(_shader_model_character_view.id); }
+static void shader_model_character_view_link(void){
+   _uniform_model_character_view_uPv = glGetUniformLocation( _shader_model_character_view.id, "uPv" );
+   _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 */
diff --git a/shaders/model_gate.fs b/shaders/model_gate.fs
new file mode 100644 (file)
index 0000000..ba48f1e
--- /dev/null
@@ -0,0 +1,27 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexMain;
+uniform sampler2D uTexWater;
+uniform vec2 uInvRes;
+uniform float uTime;
+uniform vec3 uCam;
+
+in vec3 aNorm;
+in vec2 aUv;
+in vec3 aCo;
+
+void main()
+{
+   vec2 ssuv = gl_FragCoord.xy*uInvRes;
+   vec4 mapwater = texture( uTexWater, vec2(aUv.x,aUv.y-uTime));
+
+   float undistort = smoothstep(0.1,0.6,distance( uCam, aCo )*0.1);
+   vec2 trimedge = smoothstep(0.0,0.2,1.0-abs(ssuv-0.5)*2.0);
+   undistort *= trimedge.x * trimedge.y;
+
+   vec2 warpamt = (mapwater.rg-0.5)*0.05*aUv.y*undistort;
+   vec4 mapbackbuffer = texture( uTexMain, ssuv + warpamt );
+
+   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);
+   FragColor = vec4( mapbackbuffer.rgb, opacity );
+}
diff --git a/shaders/model_gate.h b/shaders/model_gate.h
new file mode 100644 (file)
index 0000000..e89929d
--- /dev/null
@@ -0,0 +1,95 @@
+#ifndef SHADER_model_gate_H
+#define SHADER_model_gate_H
+static void shader_model_gate_link(void);
+static void shader_model_gate_register(void);
+static struct vg_shader _shader_model_gate = {
+   .name = "model_gate",
+   .link = shader_model_gate_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec2 a_uv;\n"
+"layout (location=3) in vec4 a_colour;\n"
+"layout (location=4) in vec4 a_weights;\n"
+"layout (location=5) in ivec4 a_groups;\n"
+"\n"
+"uniform mat4 uPv;\n"
+"uniform mat4x3 uMdl;\n"
+"\n"
+"out vec3 aNorm;\n"
+"out vec2 aUv;\n"
+"out vec3 aCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos = uMdl * vec4( a_co, 1.0 );\n"
+"   gl_Position = uPv * vec4(world_pos,1.0);\n"
+"\n"
+"   aNorm = a_norm;\n"
+"   aCo = world_pos;\n"
+"   aUv = a_uv;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"out vec4 FragColor;\n"
+"\n"
+"uniform float uTime;\n"
+"uniform vec3 uCam;\n"
+"uniform vec2 uInvRes;\n"
+"\n"
+"in vec3 aNorm;\n"
+"in vec2 aUv;\n"
+"in vec3 aCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec2 ssuv = gl_FragCoord.xy;\n"
+"   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);\n"
+"   \n"
+"   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
+"   float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
+"\n"
+"   if( opacity+dither<0.5 )\n"
+"      discard;\n"
+"\n"
+"   FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_model_gate_uPv;
+static GLuint _uniform_model_gate_uMdl;
+static GLuint _uniform_model_gate_uTime;
+static GLuint _uniform_model_gate_uCam;
+static GLuint _uniform_model_gate_uInvRes;
+static void shader_model_gate_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_gate_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_model_gate_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_model_gate_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_model_gate_uTime(float f){
+   glUniform1f(_uniform_model_gate_uTime,f);
+}
+static void shader_model_gate_uCam(v3f v){
+   glUniform3fv(_uniform_model_gate_uCam,1,v);
+}
+static void shader_model_gate_uInvRes(v2f v){
+   glUniform2fv(_uniform_model_gate_uInvRes,1,v);
+}
+static void shader_model_gate_register(void){
+   vg_shader_register( &_shader_model_gate );
+}
+static void shader_model_gate_use(void){ glUseProgram(_shader_model_gate.id); }
+static void shader_model_gate_link(void){
+   _uniform_model_gate_uPv = glGetUniformLocation( _shader_model_gate.id, "uPv" );
+   _uniform_model_gate_uMdl = glGetUniformLocation( _shader_model_gate.id, "uMdl" );
+   _uniform_model_gate_uTime = glGetUniformLocation( _shader_model_gate.id, "uTime" );
+   _uniform_model_gate_uCam = glGetUniformLocation( _shader_model_gate.id, "uCam" );
+   _uniform_model_gate_uInvRes = glGetUniformLocation( _shader_model_gate.id, "uInvRes" );
+}
+#endif /* SHADER_model_gate_H */
diff --git a/shaders/model_gate.vs b/shaders/model_gate.vs
new file mode 100644 (file)
index 0000000..edea94d
--- /dev/null
@@ -0,0 +1,23 @@
+layout (location=0) in vec3 a_co;
+layout (location=1) in vec3 a_norm;
+layout (location=2) in vec2 a_uv;
+layout (location=3) in vec4 a_colour;
+layout (location=4) in vec4 a_weights;
+layout (location=5) in ivec4 a_groups;
+
+uniform mat4 uPv;
+uniform mat4x3 uMdl;
+
+out vec3 aNorm;
+out vec2 aUv;
+out vec3 aCo;
+
+void main()
+{
+   vec3 world_pos = uMdl * vec4( a_co, 1.0 );
+   gl_Position = uPv * vec4(world_pos,1.0);
+
+   aNorm = a_norm;
+   aCo = world_pos;
+   aUv = a_uv;
+}
diff --git a/shaders/model_gate_lq.fs b/shaders/model_gate_lq.fs
new file mode 100644 (file)
index 0000000..c455126
--- /dev/null
@@ -0,0 +1,23 @@
+out vec4 FragColor;
+
+uniform float uTime;
+uniform vec3 uCam;
+uniform vec2 uInvRes;
+
+in vec3 aNorm;
+in vec2 aUv;
+in vec3 aCo;
+
+void main()
+{
+   vec2 ssuv = gl_FragCoord.xy;
+   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);
+   
+   vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );
+   float dither = fract( vDither.g / 71.0 ) - 0.5;
+
+   if( opacity+dither<0.5 )
+      discard;
+
+   FragColor = vec4( 0.0, 1.0, 0.0, 1.0 );
+}
diff --git a/shaders/model_menu.fs b/shaders/model_menu.fs
new file mode 100644 (file)
index 0000000..e957ddf
--- /dev/null
@@ -0,0 +1,19 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexMain;
+uniform vec4 uColour;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
+
+void main()
+{
+   vec4 diffuse = texture( uTexMain, aUv );
+
+   if( diffuse.a < 0.5 )
+      discard;
+
+   FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;
+}
diff --git a/shaders/model_menu.h b/shaders/model_menu.h
new file mode 100644 (file)
index 0000000..1762390
--- /dev/null
@@ -0,0 +1,120 @@
+#ifndef SHADER_model_menu_H
+#define SHADER_model_menu_H
+static void shader_model_menu_link(void);
+static void shader_model_menu_register(void);
+static struct vg_shader _shader_model_menu = {
+   .name = "model_menu",
+   .link = shader_model_menu_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec2 a_uv;\n"
+"layout (location=3) in vec4 a_colour;\n"
+"layout (location=4) in vec4 a_weights;\n"
+"layout (location=5) in ivec4 a_groups;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      9        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4 uPv;\n"
+"uniform mat4 uPvmPrev;\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"   aWorldCo = world_pos0;\n"
+"   aColour = a_colour;\n"
+"   aUv = a_uv;\n"
+"   aNorm = mat3(uMdl) * a_norm;\n"
+"   aCo = a_co;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"out vec4 FragColor;\n"
+"\n"
+"uniform sampler2D uTexMain;\n"
+"uniform vec4 uColour;\n"
+"\n"
+"in vec4 aColour;\n"
+"in vec2 aUv;\n"
+"in vec3 aNorm;\n"
+"in vec3 aCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec4 diffuse = texture( uTexMain, aUv );\n"
+"\n"
+"   if( diffuse.a < 0.5 )\n"
+"      discard;\n"
+"\n"
+"   FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_model_menu_uMdl;
+static GLuint _uniform_model_menu_uPv;
+static GLuint _uniform_model_menu_uPvmPrev;
+static GLuint _uniform_model_menu_uTexMain;
+static GLuint _uniform_model_menu_uColour;
+static void shader_model_menu_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_model_menu_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_model_menu_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_menu_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_model_menu_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_menu_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_model_menu_uTexMain(int i){
+   glUniform1i(_uniform_model_menu_uTexMain,i);
+}
+static void shader_model_menu_uColour(v4f v){
+   glUniform4fv(_uniform_model_menu_uColour,1,v);
+}
+static void shader_model_menu_register(void){
+   vg_shader_register( &_shader_model_menu );
+}
+static void shader_model_menu_use(void){ glUseProgram(_shader_model_menu.id); }
+static void shader_model_menu_link(void){
+   _uniform_model_menu_uMdl = glGetUniformLocation( _shader_model_menu.id, "uMdl" );
+   _uniform_model_menu_uPv = glGetUniformLocation( _shader_model_menu.id, "uPv" );
+   _uniform_model_menu_uPvmPrev = glGetUniformLocation( _shader_model_menu.id, "uPvmPrev" );
+   _uniform_model_menu_uTexMain = glGetUniformLocation( _shader_model_menu.id, "uTexMain" );
+   _uniform_model_menu_uColour = glGetUniformLocation( _shader_model_menu.id, "uColour" );
+}
+#endif /* SHADER_model_menu_H */
diff --git a/shaders/model_skinned.vs b/shaders/model_skinned.vs
new file mode 100644 (file)
index 0000000..78255e1
--- /dev/null
@@ -0,0 +1,42 @@
+layout (location=0) in vec3 a_co;
+layout (location=1) in vec3 a_norm;
+layout (location=2) in vec2 a_uv;
+layout (location=3) in vec4 a_colour;
+layout (location=4) in vec4 a_weights;
+layout (location=5) in ivec4 a_groups;
+
+#include "motion_vectors_vs.glsl"
+
+uniform mat4 uPv;
+uniform mat4x3 uTransforms[32];
+
+out vec4 aColour;
+out vec2 aUv;
+out vec3 aNorm;
+out vec3 aCo;
+out vec3 aWorldCo;
+
+void main()
+{
+   vec4 co_local = vec4( a_co, 1.0 );
+   vec3 co0 = uTransforms[ a_groups[0] ] * co_local;
+   vec3 co1 = uTransforms[ a_groups[1] ] * co_local;
+   vec3 co2 = uTransforms[ a_groups[2] ] * co_local;
+   vec3 n0  = mat3(uTransforms[ a_groups[0] ]) * a_norm;
+   vec3 n1  = mat3(uTransforms[ a_groups[1] ]) * a_norm;
+   vec3 n2  = mat3(uTransforms[ a_groups[2] ]) * a_norm;
+
+   vec3 world_pos    = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];
+   vec3 world_normal = n0*a_weights[0]  + n1*a_weights[1]  + n2*a_weights[2];
+   
+   gl_Position = uPv * vec4( world_pos, 1.0 );
+   aColour = a_colour;
+   aUv = a_uv;
+   aNorm = world_normal;
+   aCo = a_co;
+   aWorldCo = world_pos;
+
+   // TODO:
+   aMotionVec0 = vec3(1.0);
+   aMotionVec1 = vec3(1.0);
+}
diff --git a/shaders/model_sky.fs b/shaders/model_sky.fs
new file mode 100644 (file)
index 0000000..036f244
--- /dev/null
@@ -0,0 +1,37 @@
+layout (location = 0) out vec4 oColour;
+
+uniform vec4 uColour;
+uniform sampler2D uTexGarbage;
+uniform float uTime;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
+
+#include "motion_vectors_fs.glsl"
+
+void main()
+{
+   compute_motion_vectors();
+
+   float fintensity = 1.0-(abs(aNorm.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 diffuse = mix( skycolour, horizon, fblend );
+
+   float fmove = uTime * 0.004;
+   vec2 cloudplane = (aNorm.xz / (aNorm.y*sign(aNorm.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 );
+
+   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;
+
+   vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );
+   float fhorizon = step( aNorm.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);
+}
diff --git a/shaders/model_sky.h b/shaders/model_sky.h
new file mode 100644 (file)
index 0000000..1559bcf
--- /dev/null
@@ -0,0 +1,162 @@
+#ifndef SHADER_model_sky_H
+#define SHADER_model_sky_H
+static void shader_model_sky_link(void);
+static void shader_model_sky_register(void);
+static struct vg_shader _shader_model_sky = {
+   .name = "model_sky",
+   .link = shader_model_sky_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec2 a_uv;\n"
+"layout (location=3) in vec4 a_colour;\n"
+"layout (location=4) in vec4 a_weights;\n"
+"layout (location=5) in ivec4 a_groups;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      9        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4 uPv;\n"
+"uniform mat4 uPvmPrev;\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"   aWorldCo = world_pos0;\n"
+"   aColour = a_colour;\n"
+"   aUv = a_uv;\n"
+"   aNorm = mat3(uMdl) * a_norm;\n"
+"   aCo = a_co;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"layout (location = 0) out vec4 oColour;\n"
+"\n"
+"uniform vec4 uColour;\n"
+"uniform sampler2D uTexGarbage;\n"
+"uniform float uTime;\n"
+"\n"
+"in vec4 aColour;\n"
+"in vec2 aUv;\n"
+"in vec3 aNorm;\n"
+"in vec3 aCo;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     13        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   float fintensity = 1.0-(abs(aNorm.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 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"
+"   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"
+"\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"
+"\n"
+"   vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );\n"
+"   float fhorizon = step( aNorm.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"
+""},
+};
+
+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 void shader_model_sky_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_model_sky_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_model_sky_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_sky_uPv,1,GL_FALSE,(float*)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_register(void){
+   vg_shader_register( &_shader_model_sky );
+}
+static void shader_model_sky_use(void){ glUseProgram(_shader_model_sky.id); }
+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" );
+}
+#endif /* SHADER_model_sky_H */
diff --git a/shaders/model_water.fs b/shaders/model_water.fs
new file mode 100644 (file)
index 0000000..68fc66d
--- /dev/null
@@ -0,0 +1,81 @@
+uniform sampler2D uTexMain;
+uniform sampler2D uTexDudv;
+uniform sampler2D uTexBack;
+
+uniform vec2 uInvRes;
+uniform float uTime;
+uniform vec3 uCamera;
+uniform float uSurfaceY;
+uniform vec3 uBoard0;
+uniform vec3 uBoard1;
+
+uniform vec3 uShoreColour;
+uniform vec3 uOceanColour;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+
+#include "common_world.glsl"
+#include "motion_vectors_fs.glsl"
+
+vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, 
+      vec4 beneath, vec4 above )
+{
+   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
+
+   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);
+
+   vec3 lightdir = vec3(0.95,0.0,-0.3);
+   vec3 specdir = reflect( -lightdir, vnorm );
+   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
+   
+   // Depth 
+   float depthblend = pow( beneath.a,0.8 );
+
+   // Composite
+   vec3 vsurface = mix(surface_tint, above.rgb, ffresnel );
+   //vsurface += spec;
+
+   return vec4( vsurface,depthblend );
+}
+
+void main()
+{
+   compute_motion_vectors();
+
+   // Create texture coords
+   vec2 ssuv = gl_FragCoord.xy*uInvRes;
+   
+   // Surface colour composite
+   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );
+
+   vec2 world_coord = aCo.xz * 0.008;
+   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );
+   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;
+   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;
+
+   vec3 surfnorm = dudva.rgb + dudvb.rgb;
+   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);
+   
+   // Foam
+   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );
+   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);
+
+   // Lighting
+   vec3 halfview = -normalize( aCo-uCamera );
+
+   // Sample textures
+   vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );
+   vec4 beneath = texture( uTexBack, ssuv );
+
+   // Fog
+   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
+
+   // Composite
+   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above );
+   vsurface.a -= fdist;
+   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
+}
diff --git a/shaders/model_water.h b/shaders/model_water.h
new file mode 100644 (file)
index 0000000..2b4f093
--- /dev/null
@@ -0,0 +1,378 @@
+#ifndef SHADER_model_water_H
+#define SHADER_model_water_H
+static void shader_model_water_link(void);
+static void shader_model_water_register(void);
+static struct vg_shader _shader_model_water = {
+   .name = "model_water",
+   .link = shader_model_water_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec2 a_uv;\n"
+"layout (location=3) in vec4 a_colour;\n"
+"layout (location=4) in vec4 a_weights;\n"
+"layout (location=5) in ivec4 a_groups;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      9        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4 uPv;\n"
+"uniform mat4 uPvmPrev;\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"   aWorldCo = world_pos0;\n"
+"   aColour = a_colour;\n"
+"   aUv = a_uv;\n"
+"   aNorm = mat3(uMdl) * a_norm;\n"
+"   aCo = a_co;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexMain;\n"
+"uniform sampler2D uTexDudv;\n"
+"uniform sampler2D uTexBack;\n"
+"\n"
+"uniform vec2 uInvRes;\n"
+"uniform float uTime;\n"
+"uniform vec3 uCamera;\n"
+"uniform float uSurfaceY;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\n"
+"\n"
+"uniform vec3 uShoreColour;\n"
+"uniform vec3 uOceanColour;\n"
+"\n"
+"in vec4 aColour;\n"
+"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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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     22        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     23        0 \n"
+"\n"
+"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
+"      vec4 beneath, vec4 above )\n"
+"{\n"
+"   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
+"\n"
+"   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
+"\n"
+"   vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
+"   vec3 specdir = reflect( -lightdir, vnorm );\n"
+"   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
+"   \n"
+"   // Depth \n"
+"   float depthblend = pow( beneath.a,0.8 );\n"
+"\n"
+"   // Composite\n"
+"   vec3 vsurface = mix(surface_tint, above.rgb, ffresnel );\n"
+"   //vsurface += spec;\n"
+"\n"
+"   return vec4( vsurface,depthblend );\n"
+"}\n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   // Create texture coords\n"
+"   vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
+"   \n"
+"   // Surface colour composite\n"
+"   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
+"\n"
+"   vec2 world_coord = aCo.xz * 0.008;\n"
+"   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
+"   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
+"   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
+"\n"
+"   vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
+"   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
+"   \n"
+"   // Foam\n"
+"   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
+"   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
+"\n"
+"   // Lighting\n"
+"   vec3 halfview = -normalize( aCo-uCamera );\n"
+"\n"
+"   // Sample textures\n"
+"   vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );\n"
+"   vec4 beneath = texture( uTexBack, ssuv );\n"
+"\n"
+"   // Fog\n"
+"   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
+"\n"
+"   // Composite\n"
+"   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above );\n"
+"   vsurface.a -= fdist;\n"
+"   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_model_water_uMdl;
+static GLuint _uniform_model_water_uPv;
+static GLuint _uniform_model_water_uPvmPrev;
+static GLuint _uniform_model_water_uTexMain;
+static GLuint _uniform_model_water_uTexDudv;
+static GLuint _uniform_model_water_uTexBack;
+static GLuint _uniform_model_water_uInvRes;
+static GLuint _uniform_model_water_uTime;
+static GLuint _uniform_model_water_uCamera;
+static GLuint _uniform_model_water_uSurfaceY;
+static GLuint _uniform_model_water_uBoard0;
+static GLuint _uniform_model_water_uBoard1;
+static GLuint _uniform_model_water_uShoreColour;
+static GLuint _uniform_model_water_uOceanColour;
+static GLuint _uniform_model_water_g_world_depth;
+static void shader_model_water_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_model_water_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_model_water_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_water_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_model_water_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_water_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_model_water_uTexMain(int i){
+   glUniform1i(_uniform_model_water_uTexMain,i);
+}
+static void shader_model_water_uTexDudv(int i){
+   glUniform1i(_uniform_model_water_uTexDudv,i);
+}
+static void shader_model_water_uTexBack(int i){
+   glUniform1i(_uniform_model_water_uTexBack,i);
+}
+static void shader_model_water_uInvRes(v2f v){
+   glUniform2fv(_uniform_model_water_uInvRes,1,v);
+}
+static void shader_model_water_uTime(float f){
+   glUniform1f(_uniform_model_water_uTime,f);
+}
+static void shader_model_water_uCamera(v3f v){
+   glUniform3fv(_uniform_model_water_uCamera,1,v);
+}
+static void shader_model_water_uSurfaceY(float f){
+   glUniform1f(_uniform_model_water_uSurfaceY,f);
+}
+static void shader_model_water_uBoard0(v3f v){
+   glUniform3fv(_uniform_model_water_uBoard0,1,v);
+}
+static void shader_model_water_uBoard1(v3f v){
+   glUniform3fv(_uniform_model_water_uBoard1,1,v);
+}
+static void shader_model_water_uShoreColour(v3f v){
+   glUniform3fv(_uniform_model_water_uShoreColour,1,v);
+}
+static void shader_model_water_uOceanColour(v3f v){
+   glUniform3fv(_uniform_model_water_uOceanColour,1,v);
+}
+static void shader_model_water_g_world_depth(int i){
+   glUniform1i(_uniform_model_water_g_world_depth,i);
+}
+static void shader_model_water_register(void){
+   vg_shader_register( &_shader_model_water );
+}
+static void shader_model_water_use(void){ glUseProgram(_shader_model_water.id); }
+static void shader_model_water_link(void){
+   _uniform_model_water_uMdl = glGetUniformLocation( _shader_model_water.id, "uMdl" );
+   _uniform_model_water_uPv = glGetUniformLocation( _shader_model_water.id, "uPv" );
+   _uniform_model_water_uPvmPrev = glGetUniformLocation( _shader_model_water.id, "uPvmPrev" );
+   _uniform_model_water_uTexMain = glGetUniformLocation( _shader_model_water.id, "uTexMain" );
+   _uniform_model_water_uTexDudv = glGetUniformLocation( _shader_model_water.id, "uTexDudv" );
+   _uniform_model_water_uTexBack = glGetUniformLocation( _shader_model_water.id, "uTexBack" );
+   _uniform_model_water_uInvRes = glGetUniformLocation( _shader_model_water.id, "uInvRes" );
+   _uniform_model_water_uTime = glGetUniformLocation( _shader_model_water.id, "uTime" );
+   _uniform_model_water_uCamera = glGetUniformLocation( _shader_model_water.id, "uCamera" );
+   _uniform_model_water_uSurfaceY = glGetUniformLocation( _shader_model_water.id, "uSurfaceY" );
+   _uniform_model_water_uBoard0 = glGetUniformLocation( _shader_model_water.id, "uBoard0" );
+   _uniform_model_water_uBoard1 = glGetUniformLocation( _shader_model_water.id, "uBoard1" );
+   _uniform_model_water_uShoreColour = glGetUniformLocation( _shader_model_water.id, "uShoreColour" );
+   _uniform_model_water_uOceanColour = glGetUniformLocation( _shader_model_water.id, "uOceanColour" );
+   _uniform_model_water_g_world_depth = glGetUniformLocation( _shader_model_water.id, "g_world_depth" );
+}
+#endif /* SHADER_model_water_H */
diff --git a/shaders/model_water_fast.fs b/shaders/model_water_fast.fs
new file mode 100644 (file)
index 0000000..5f68c45
--- /dev/null
@@ -0,0 +1,63 @@
+uniform sampler2D uTexDudv;
+
+uniform float uTime;
+uniform vec3 uCamera;
+uniform float uSurfaceY;
+uniform vec3 uBoard0;
+uniform vec3 uBoard1;
+
+uniform vec3 uShoreColour;
+uniform vec3 uOceanColour;
+
+in vec4 aColour;
+in vec2 aUv;
+in vec3 aNorm;
+in vec3 aCo;
+in vec3 aWorldCo;
+
+#include "common_world.glsl"
+#include "motion_vectors_fs.glsl"
+
+vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )
+{
+   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
+
+   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);
+
+   vec3 lightdir = vec3(0.95,0.0,-0.3);
+   vec3 specdir = reflect( -lightdir, vnorm );
+   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
+   
+   return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );
+}
+
+void main()
+{
+   compute_motion_vectors();
+
+   // Surface colour composite
+   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );
+
+   vec2 world_coord = aCo.xz * 0.008;
+   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );
+   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;
+   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;
+
+   vec3 surfnorm = dudva.rgb + dudvb.rgb;
+   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);
+   
+   // Foam
+   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );
+   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);
+
+   // Lighting
+   vec3 halfview = -normalize( aCo-uCamera );
+
+   // Fog
+   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
+
+   // Composite
+   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );
+   vsurface.a -= fdist;
+   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
+}
diff --git a/shaders/model_water_fast.h b/shaders/model_water_fast.h
new file mode 100644 (file)
index 0000000..32785f3
--- /dev/null
@@ -0,0 +1,345 @@
+#ifndef SHADER_model_water_fast_H
+#define SHADER_model_water_fast_H
+static void shader_model_water_fast_link(void);
+static void shader_model_water_fast_register(void);
+static struct vg_shader _shader_model_water_fast = {
+   .name = "model_water_fast",
+   .link = shader_model_water_fast_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3 a_co;\n"
+"layout (location=1) in vec3 a_norm;\n"
+"layout (location=2) in vec2 a_uv;\n"
+"layout (location=3) in vec4 a_colour;\n"
+"layout (location=4) in vec4 a_weights;\n"
+"layout (location=5) in ivec4 a_groups;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      9        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4 uPv;\n"
+"uniform mat4 uPvmPrev;\n"
+"\n"
+"out vec4 aColour;\n"
+"out vec2 aUv;\n"
+"out vec3 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"   aWorldCo = world_pos0;\n"
+"   aColour = a_colour;\n"
+"   aUv = a_uv;\n"
+"   aNorm = mat3(uMdl) * a_norm;\n"
+"   aCo = a_co;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexDudv;\n"
+"\n"
+"uniform float uTime;\n"
+"uniform vec3 uCamera;\n"
+"uniform float uSurfaceY;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\n"
+"\n"
+"uniform vec3 uShoreColour;\n"
+"uniform vec3 uOceanColour;\n"
+"\n"
+"in vec4 aColour;\n"
+"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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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     19        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     20        0 \n"
+"\n"
+"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )\n"
+"{\n"
+"   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
+"\n"
+"   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
+"\n"
+"   vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
+"   vec3 specdir = reflect( -lightdir, vnorm );\n"
+"   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
+"   \n"
+"   return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );\n"
+"}\n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   // Surface colour composite\n"
+"   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
+"\n"
+"   vec2 world_coord = aCo.xz * 0.008;\n"
+"   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
+"   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
+"   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
+"\n"
+"   vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
+"   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
+"   \n"
+"   // Foam\n"
+"   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
+"   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
+"\n"
+"   // Lighting\n"
+"   vec3 halfview = -normalize( aCo-uCamera );\n"
+"\n"
+"   // Fog\n"
+"   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
+"\n"
+"   // Composite\n"
+"   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );\n"
+"   vsurface.a -= fdist;\n"
+"   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_model_water_fast_uMdl;
+static GLuint _uniform_model_water_fast_uPv;
+static GLuint _uniform_model_water_fast_uPvmPrev;
+static GLuint _uniform_model_water_fast_uTexDudv;
+static GLuint _uniform_model_water_fast_uTime;
+static GLuint _uniform_model_water_fast_uCamera;
+static GLuint _uniform_model_water_fast_uSurfaceY;
+static GLuint _uniform_model_water_fast_uBoard0;
+static GLuint _uniform_model_water_fast_uBoard1;
+static GLuint _uniform_model_water_fast_uShoreColour;
+static GLuint _uniform_model_water_fast_uOceanColour;
+static GLuint _uniform_model_water_fast_g_world_depth;
+static void shader_model_water_fast_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_model_water_fast_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_model_water_fast_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_water_fast_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_model_water_fast_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_model_water_fast_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_model_water_fast_uTexDudv(int i){
+   glUniform1i(_uniform_model_water_fast_uTexDudv,i);
+}
+static void shader_model_water_fast_uTime(float f){
+   glUniform1f(_uniform_model_water_fast_uTime,f);
+}
+static void shader_model_water_fast_uCamera(v3f v){
+   glUniform3fv(_uniform_model_water_fast_uCamera,1,v);
+}
+static void shader_model_water_fast_uSurfaceY(float f){
+   glUniform1f(_uniform_model_water_fast_uSurfaceY,f);
+}
+static void shader_model_water_fast_uBoard0(v3f v){
+   glUniform3fv(_uniform_model_water_fast_uBoard0,1,v);
+}
+static void shader_model_water_fast_uBoard1(v3f v){
+   glUniform3fv(_uniform_model_water_fast_uBoard1,1,v);
+}
+static void shader_model_water_fast_uShoreColour(v3f v){
+   glUniform3fv(_uniform_model_water_fast_uShoreColour,1,v);
+}
+static void shader_model_water_fast_uOceanColour(v3f v){
+   glUniform3fv(_uniform_model_water_fast_uOceanColour,1,v);
+}
+static void shader_model_water_fast_g_world_depth(int i){
+   glUniform1i(_uniform_model_water_fast_g_world_depth,i);
+}
+static void shader_model_water_fast_register(void){
+   vg_shader_register( &_shader_model_water_fast );
+}
+static void shader_model_water_fast_use(void){ glUseProgram(_shader_model_water_fast.id); }
+static void shader_model_water_fast_link(void){
+   _uniform_model_water_fast_uMdl = glGetUniformLocation( _shader_model_water_fast.id, "uMdl" );
+   _uniform_model_water_fast_uPv = glGetUniformLocation( _shader_model_water_fast.id, "uPv" );
+   _uniform_model_water_fast_uPvmPrev = glGetUniformLocation( _shader_model_water_fast.id, "uPvmPrev" );
+   _uniform_model_water_fast_uTexDudv = glGetUniformLocation( _shader_model_water_fast.id, "uTexDudv" );
+   _uniform_model_water_fast_uTime = glGetUniformLocation( _shader_model_water_fast.id, "uTime" );
+   _uniform_model_water_fast_uCamera = glGetUniformLocation( _shader_model_water_fast.id, "uCamera" );
+   _uniform_model_water_fast_uSurfaceY = glGetUniformLocation( _shader_model_water_fast.id, "uSurfaceY" );
+   _uniform_model_water_fast_uBoard0 = glGetUniformLocation( _shader_model_water_fast.id, "uBoard0" );
+   _uniform_model_water_fast_uBoard1 = glGetUniformLocation( _shader_model_water_fast.id, "uBoard1" );
+   _uniform_model_water_fast_uShoreColour = glGetUniformLocation( _shader_model_water_fast.id, "uShoreColour" );
+   _uniform_model_water_fast_uOceanColour = glGetUniformLocation( _shader_model_water_fast.id, "uOceanColour" );
+   _uniform_model_water_fast_g_world_depth = glGetUniformLocation( _shader_model_water_fast.id, "g_world_depth" );
+}
+#endif /* SHADER_model_water_fast_H */
diff --git a/shaders/noise.glsl b/shaders/noise.glsl
deleted file mode 100644 (file)
index 6736e35..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-uniform sampler2D uTexNoise;
-
-float noise( vec3 x )
-{
-  vec3 i = floor(x);
-  vec3 f = fract(x);
-  f = f*f*(3.0-2.0*f);
-  vec2 uv = (i.xy+vec2(37.0,17.0)*i.z) + f.xy;
-  vec2 rg = texture( uTexNoise, (uv+0.5)/256.0).yx;
-  return mix( rg.x, rg.y, f.z );
-}
-
-const mat3 m = mat3( 0.00,  0.80,  0.60,
-                    -0.80,  0.36, -0.48,
-                    -0.60, -0.48,  0.64 );
-
-float fractalNoise( vec3 x )
-{
-  vec3 q = 8.0*x;
-  float f;
-  f  = 0.5000*noise( q ); q = m*q*2.01;
-  f += 0.2500*noise( q ); q = m*q*2.02;
-  f += 0.1250*noise( q ); q = m*q*2.03;
-  f += 0.0625*noise( q ); q = m*q*2.01;
-  return f;
-}
diff --git a/shaders/planeinf.fs b/shaders/planeinf.fs
deleted file mode 100644 (file)
index 926c79d..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "water_ref.glsl"
-
-out vec4 FragColor;
-
-uniform vec3 uCamera;
-uniform vec4 uPlane;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-
-float ray_plane( vec3 pos, vec3 dir, vec4 plane )
-{
-   float d = dot( plane.xyz, dir );
-   float t = dot((plane.xyz*plane.w - pos),plane.xyz) / d;
-   return t;
-}
-
-void main()
-{
-   float fdist = ray_plane( uCamera, -aNorm, uPlane );
-   vec3 world_pos = uCamera - aNorm*fdist;
-
-   FragColor = vec4(fract(world_pos*0.1),1.0);
-}
diff --git a/shaders/planeinf.h b/shaders/planeinf.h
deleted file mode 100644 (file)
index 4bd7e86..0000000
+++ /dev/null
@@ -1,131 +0,0 @@
-#ifndef SHADER_planeinf_H
-#define SHADER_planeinf_H
-static void shader_planeinf_link(void);
-static void shader_planeinf_register(void);
-static struct vg_shader _shader_planeinf = {
-   .name = "planeinf",
-   .link = shader_planeinf_link,
-   .vs = 
-{
-.orig_file = "../../shaders/standard.vs",
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.orig_file = "../../shaders/planeinf.fs",
-.static_src = 
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec4 FragColor;\n"
-"\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"\n"
-"float ray_plane( vec3 pos, vec3 dir, vec4 plane )\n"
-"{\n"
-"   float d = dot( plane.xyz, dir );\n"
-"   float t = dot((plane.xyz*plane.w - pos),plane.xyz) / d;\n"
-"   return t;\n"
-"}\n"
-"\n"
-"void main()\n"
-"{\n"
-"   float fdist = ray_plane( uCamera, -aNorm, uPlane );\n"
-"   vec3 world_pos = uCamera - aNorm*fdist;\n"
-"\n"
-"   FragColor = vec4(fract(world_pos*0.1),1.0);\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_planeinf_uMdl;
-static GLuint _uniform_planeinf_uPv;
-static GLuint _uniform_planeinf_uPvmPrev;
-static GLuint _uniform_planeinf_uCamera;
-static GLuint _uniform_planeinf_uPlane;
-static void shader_planeinf_uMdl(m4x3f m){
-   glUniformMatrix4x3fv( _uniform_planeinf_uMdl, 1, GL_FALSE, (float *)m );
-}
-static void shader_planeinf_uPv(m4x4f m){
-   glUniformMatrix4fv( _uniform_planeinf_uPv, 1, GL_FALSE, (float *)m );
-}
-static void shader_planeinf_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv( _uniform_planeinf_uPvmPrev, 1, GL_FALSE, (float *)m );
-}
-static void shader_planeinf_uCamera(v3f v){
-   glUniform3fv( _uniform_planeinf_uCamera, 1, v );
-}
-static void shader_planeinf_uPlane(v4f v){
-   glUniform4fv( _uniform_planeinf_uPlane, 1, v );
-}
-static void shader_planeinf_register(void){
-   vg_shader_register( &_shader_planeinf );
-}
-static void shader_planeinf_use(void){ glUseProgram(_shader_planeinf.id); }
-static void shader_planeinf_link(void){
-   _uniform_planeinf_uMdl = glGetUniformLocation( _shader_planeinf.id, "uMdl" );
-   _uniform_planeinf_uPv = glGetUniformLocation( _shader_planeinf.id, "uPv" );
-   _uniform_planeinf_uPvmPrev = glGetUniformLocation( _shader_planeinf.id, "uPvmPrev" );
-   _uniform_planeinf_uCamera = glGetUniformLocation( _shader_planeinf.id, "uCamera" );
-   _uniform_planeinf_uPlane = glGetUniformLocation( _shader_planeinf.id, "uPlane" );
-}
-#endif /* SHADER_planeinf_H */
diff --git a/shaders/route.fs b/shaders/route.fs
deleted file mode 100644 (file)
index 2e7db2e..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-uniform sampler2D uTexGarbage;
-uniform sampler2D uTexGradients;
-uniform vec3 uCamera;
-uniform vec4 uColour;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-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();
-
-   vec3 vfrag = vec3(0.5,0.5,0.5);
-
-   // ws modulation
-   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
-
-   // Creating normal patches
-   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
-   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);
-
-   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
-   vec3 tangent1 = cross(qnorm,tangent0);
-   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;
-   
-   // Patch local noise
-   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
-
-   vfrag = pow(uColour.rgb,vec3(1.0/2.2));
-   vfrag -= rgarbage.a*0.1;
-
-   if( wgarbage.g < 0.3 )
-      discard;
-
-   if( g_light_preview == 1 )
-   {
-      vfrag = vec3(0.5);
-   }
-
-   // Lighting
-   vec3 halfview = uCamera - aWorldCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   vfrag = do_light_diffuse( vfrag, qnorm );
-   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   oColour = vec4(vfrag, 1.0 );
-}
diff --git a/shaders/route.h b/shaders/route.h
deleted file mode 100644 (file)
index 752b60c..0000000
+++ /dev/null
@@ -1,327 +0,0 @@
-#ifndef SHADER_route_H
-#define SHADER_route_H
-static void shader_route_link(void);
-static void shader_route_register(void);
-static struct vg_shader _shader_route = {
-   .name = "route",
-   .link = shader_route_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uColour;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     15        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     16        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"\n"
-"   // ws modulation\n"
-"   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
-"\n"
-"   // Creating normal patches\n"
-"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
-"   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);\n"
-"\n"
-"   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
-"   vec3 tangent1 = cross(qnorm,tangent0);\n"
-"   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;\n"
-"   \n"
-"   // Patch local noise\n"
-"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
-"\n"
-"   vfrag = pow(uColour.rgb,vec3(1.0/2.2));\n"
-"   vfrag -= rgarbage.a*0.1;\n"
-"\n"
-"   if( wgarbage.g < 0.3 )\n"
-"      discard;\n"
-"\n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
-"      vfrag = vec3(0.5);\n"
-"   }\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   vfrag = do_light_diffuse( vfrag, qnorm );\n"
-"   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   oColour = vec4(vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_route_uMdl;
-static GLuint _uniform_route_uPv;
-static GLuint _uniform_route_uPvmPrev;
-static GLuint _uniform_route_uTexGarbage;
-static GLuint _uniform_route_uTexGradients;
-static GLuint _uniform_route_uCamera;
-static GLuint _uniform_route_uColour;
-static GLuint _uniform_route_uBoard0;
-static GLuint _uniform_route_uBoard1;
-static GLuint _uniform_route_g_world_depth;
-static void shader_route_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_route_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_route_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_route_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_route_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_route_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_route_uTexGarbage(int i){
-   glUniform1i(_uniform_route_uTexGarbage,i);
-}
-static void shader_route_uTexGradients(int i){
-   glUniform1i(_uniform_route_uTexGradients,i);
-}
-static void shader_route_uCamera(v3f v){
-   glUniform3fv(_uniform_route_uCamera,1,v);
-}
-static void shader_route_uColour(v4f v){
-   glUniform4fv(_uniform_route_uColour,1,v);
-}
-static void shader_route_uBoard0(v3f v){
-   glUniform3fv(_uniform_route_uBoard0,1,v);
-}
-static void shader_route_uBoard1(v3f v){
-   glUniform3fv(_uniform_route_uBoard1,1,v);
-}
-static void shader_route_g_world_depth(int i){
-   glUniform1i(_uniform_route_g_world_depth,i);
-}
-static void shader_route_register(void){
-   vg_shader_register( &_shader_route );
-}
-static void shader_route_use(void){ glUseProgram(_shader_route.id); }
-static void shader_route_link(void){
-   _uniform_route_uMdl = glGetUniformLocation( _shader_route.id, "uMdl" );
-   _uniform_route_uPv = glGetUniformLocation( _shader_route.id, "uPv" );
-   _uniform_route_uPvmPrev = glGetUniformLocation( _shader_route.id, "uPvmPrev" );
-   _uniform_route_uTexGarbage = glGetUniformLocation( _shader_route.id, "uTexGarbage" );
-   _uniform_route_uTexGradients = glGetUniformLocation( _shader_route.id, "uTexGradients" );
-   _uniform_route_uCamera = glGetUniformLocation( _shader_route.id, "uCamera" );
-   _uniform_route_uColour = glGetUniformLocation( _shader_route.id, "uColour" );
-   _uniform_route_uBoard0 = glGetUniformLocation( _shader_route.id, "uBoard0" );
-   _uniform_route_uBoard1 = glGetUniformLocation( _shader_route.id, "uBoard1" );
-   _uniform_route_g_world_depth = glGetUniformLocation( _shader_route.id, "g_world_depth" );
-}
-#endif /* SHADER_route_H */
diff --git a/shaders/scene.vs b/shaders/scene.vs
new file mode 100644 (file)
index 0000000..9c8e4eb
--- /dev/null
@@ -0,0 +1,33 @@
+layout (location=0) in vec3  a_co;
+layout (location=1) in vec4  a_norm;
+layout (location=2) in vec2  a_uv;
+layout (location=3) in ivec4 a_lights;
+
+#include "motion_vectors_vs.glsl"
+
+uniform mat4x3 uMdl;
+uniform mat4   uPv;
+uniform mat4   uPvmPrev;
+
+out vec2 aUv;
+out vec4 aNorm;
+out vec3 aCo;
+out vec3 aWorldCo;
+flat out ivec4 aLights;
+
+void main()
+{
+   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );
+   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );
+   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );
+
+   vs_motion_out( vproj0, vproj1 );
+
+   gl_Position = vproj0;
+
+   aUv = a_uv;
+   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );
+   aCo = a_co;
+   aWorldCo = world_pos0;
+   aLights = a_lights;
+}
diff --git a/shaders/scene_depth.fs b/shaders/scene_depth.fs
new file mode 100644 (file)
index 0000000..05d886b
--- /dev/null
@@ -0,0 +1,33 @@
+out vec4 FragColor;
+
+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_world.glsl"
+
+// Water blending
+// ==============
+
+float water_depth( vec3 pos, vec3 halfview )
+{
+   vec3 pnorm = g_water_plane.xyz;
+   float pdist = g_water_plane.w;
+
+   float d = dot( pnorm, halfview );
+   float t = dot((pnorm*pdist - pos), pnorm) / d;
+   return t * g_water_fog;
+}
+
+void main()
+{
+   vec3 halfview = normalize( uCamera - aCo );
+   vec3 world_pos = vec3( aCo.y, aCo.x, aCo.z );
+   FragColor = vec4( world_pos, water_depth( aCo, halfview ) );
+}
diff --git a/shaders/scene_depth.h b/shaders/scene_depth.h
new file mode 100644 (file)
index 0000000..53b2bfa
--- /dev/null
@@ -0,0 +1,270 @@
+#ifndef SHADER_scene_depth_H
+#define SHADER_scene_depth_H
+static void shader_scene_depth_link(void);
+static void shader_scene_depth_register(void);
+static struct vg_shader _shader_scene_depth = {
+   .name = "scene_depth",
+   .link = shader_scene_depth_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"layout (location=3) in ivec4 a_lights;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      7        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"flat out ivec4 aLights;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"   aLights = a_lights;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"out vec4 FragColor;\n"
+"\n"
+"uniform vec3 uCamera;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\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"
+"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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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     14        0 \n"
+"\n"
+"// Water blending\n"
+"// ==============\n"
+"\n"
+"float water_depth( vec3 pos, vec3 halfview )\n"
+"{\n"
+"   vec3 pnorm = g_water_plane.xyz;\n"
+"   float pdist = g_water_plane.w;\n"
+"\n"
+"   float d = dot( pnorm, halfview );\n"
+"   float t = dot((pnorm*pdist - pos), pnorm) / d;\n"
+"   return t * g_water_fog;\n"
+"}\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 halfview = normalize( uCamera - aCo );\n"
+"   vec3 world_pos = vec3( aCo.y, aCo.x, aCo.z );\n"
+"   FragColor = vec4( world_pos, water_depth( aCo, halfview ) );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_scene_depth_uMdl;
+static GLuint _uniform_scene_depth_uPv;
+static GLuint _uniform_scene_depth_uPvmPrev;
+static GLuint _uniform_scene_depth_uCamera;
+static GLuint _uniform_scene_depth_uBoard0;
+static GLuint _uniform_scene_depth_uBoard1;
+static GLuint _uniform_scene_depth_g_world_depth;
+static void shader_scene_depth_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_depth_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_depth_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_depth_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_depth_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_depth_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_depth_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_depth_uCamera,1,v);
+}
+static void shader_scene_depth_uBoard0(v3f v){
+   glUniform3fv(_uniform_scene_depth_uBoard0,1,v);
+}
+static void shader_scene_depth_uBoard1(v3f v){
+   glUniform3fv(_uniform_scene_depth_uBoard1,1,v);
+}
+static void shader_scene_depth_g_world_depth(int i){
+   glUniform1i(_uniform_scene_depth_g_world_depth,i);
+}
+static void shader_scene_depth_register(void){
+   vg_shader_register( &_shader_scene_depth );
+}
+static void shader_scene_depth_use(void){ glUseProgram(_shader_scene_depth.id); }
+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_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" );
+   _uniform_scene_depth_g_world_depth = glGetUniformLocation( _shader_scene_depth.id, "g_world_depth" );
+}
+#endif /* SHADER_scene_depth_H */
diff --git a/shaders/scene_route.fs b/shaders/scene_route.fs
new file mode 100644 (file)
index 0000000..5bb973d
--- /dev/null
@@ -0,0 +1,53 @@
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexGradients;
+uniform vec3 uCamera;
+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"
+
+void main()
+{
+   compute_motion_vectors();
+
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+
+   // ws modulation
+   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
+
+   // Creating normal patches
+   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
+   vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);
+   qnorm += vec3(0.001,0.0,0.0);
+
+   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
+   vec3 tangent1 = cross(qnorm,tangent0);
+   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;
+   
+   // Patch local noise
+   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
+
+   vfrag = pow(uColour.rgb,vec3(1.0/2.2));
+   vfrag -= rgarbage.a*0.1;
+
+   if( wgarbage.g < 0.3 )
+      discard;
+
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
+
+   // Lighting
+
+   vfrag = scene_do_lighting( vfrag, qnorm );
+   oColour = vec4(vfrag, 1.0);
+}
diff --git a/shaders/scene_route.h b/shaders/scene_route.h
new file mode 100644 (file)
index 0000000..dd36bb2
--- /dev/null
@@ -0,0 +1,372 @@
+#ifndef SHADER_scene_route_H
+#define SHADER_scene_route_H
+static void shader_scene_route_link(void);
+static void shader_scene_route_register(void);
+static struct vg_shader _shader_scene_route = {
+   .name = "scene_route",
+   .link = shader_scene_route_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"layout (location=3) in ivec4 a_lights;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      7        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"flat out ivec4 aLights;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"   aLights = a_lights;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexGradients;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec4 uColour;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\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"
+"\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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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      4        0 \n"
+"\n"
+"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
+"{\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - aWorldCo;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   vec3 total_light = newlight_compute_ambient();\n"
+"   \n"
+"   // Compute world lighting contribution and apply it according to the\n"
+"   // shadow map\n"
+"   //\n"
+"   vec3 world_light = newlight_compute_world_diffuse( wnormal );\n"
+"   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow();\n"
+"\n"
+"   total_light += world_light * world_shadow;\n"
+"\n"
+"   // Compute the other lights that exist in the map, not effected by the sun\n"
+"   // shadow\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"
+"   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"
+"   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"
+"\n"
+"   return apply_fog( diffuse * total_light, fdist );\n"
+"}\n"
+"\n"
+"#line     15        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     16        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"\n"
+"   // ws modulation\n"
+"   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
+"\n"
+"   // Creating normal patches\n"
+"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
+"   vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
+"   qnorm += vec3(0.001,0.0,0.0);\n"
+"\n"
+"   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
+"   vec3 tangent1 = cross(qnorm,tangent0);\n"
+"   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;\n"
+"   \n"
+"   // Patch local noise\n"
+"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
+"\n"
+"   vfrag = pow(uColour.rgb,vec3(1.0/2.2));\n"
+"   vfrag -= rgarbage.a*0.1;\n"
+"\n"
+"   if( wgarbage.g < 0.3 )\n"
+"      discard;\n"
+"\n"
+"   if( g_light_preview == 1 )\n"
+"   {\n"
+"      vfrag = vec3(0.5);\n"
+"   }\n"
+"\n"
+"   // Lighting\n"
+"\n"
+"   vfrag = scene_do_lighting( vfrag, qnorm );\n"
+"   oColour = vec4(vfrag, 1.0);\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_scene_route_uMdl;
+static GLuint _uniform_scene_route_uPv;
+static GLuint _uniform_scene_route_uPvmPrev;
+static GLuint _uniform_scene_route_uTexGarbage;
+static GLuint _uniform_scene_route_uTexGradients;
+static GLuint _uniform_scene_route_uCamera;
+static GLuint _uniform_scene_route_uColour;
+static GLuint _uniform_scene_route_uBoard0;
+static GLuint _uniform_scene_route_uBoard1;
+static GLuint _uniform_scene_route_g_world_depth;
+static void shader_scene_route_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_route_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_route_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_route_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_route_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_route_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_route_uTexGarbage(int i){
+   glUniform1i(_uniform_scene_route_uTexGarbage,i);
+}
+static void shader_scene_route_uTexGradients(int i){
+   glUniform1i(_uniform_scene_route_uTexGradients,i);
+}
+static void shader_scene_route_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_route_uCamera,1,v);
+}
+static void shader_scene_route_uColour(v4f v){
+   glUniform4fv(_uniform_scene_route_uColour,1,v);
+}
+static void shader_scene_route_uBoard0(v3f v){
+   glUniform3fv(_uniform_scene_route_uBoard0,1,v);
+}
+static void shader_scene_route_uBoard1(v3f v){
+   glUniform3fv(_uniform_scene_route_uBoard1,1,v);
+}
+static void shader_scene_route_g_world_depth(int i){
+   glUniform1i(_uniform_scene_route_g_world_depth,i);
+}
+static void shader_scene_route_register(void){
+   vg_shader_register( &_shader_scene_route );
+}
+static void shader_scene_route_use(void){ glUseProgram(_shader_scene_route.id); }
+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_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" );
+   _uniform_scene_route_uColour = glGetUniformLocation( _shader_scene_route.id, "uColour" );
+   _uniform_scene_route_uBoard0 = glGetUniformLocation( _shader_scene_route.id, "uBoard0" );
+   _uniform_scene_route_uBoard1 = glGetUniformLocation( _shader_scene_route.id, "uBoard1" );
+   _uniform_scene_route_g_world_depth = glGetUniformLocation( _shader_scene_route.id, "g_world_depth" );
+}
+#endif /* SHADER_scene_route_H */
diff --git a/shaders/scene_standard.fs b/shaders/scene_standard.fs
new file mode 100644 (file)
index 0000000..0675bff
--- /dev/null
@@ -0,0 +1,34 @@
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexMain;
+uniform vec3 uCamera;
+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"
+
+void main()
+{
+   compute_motion_vectors();
+
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+   vec4 vsamplemain = texture( uTexMain, aUv );
+   vec3 qnorm = aNorm.xyz;
+
+   vfrag = vsamplemain.rgb;
+
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
+
+   vfrag = scene_do_lighting( vfrag, qnorm );
+   oColour = vec4( vfrag, 1.0 );
+}
diff --git a/shaders/scene_standard.h b/shaders/scene_standard.h
new file mode 100644 (file)
index 0000000..ccd31a6
--- /dev/null
@@ -0,0 +1,353 @@
+#ifndef SHADER_scene_standard_H
+#define SHADER_scene_standard_H
+static void shader_scene_standard_link(void);
+static void shader_scene_standard_register(void);
+static struct vg_shader _shader_scene_standard = {
+   .name = "scene_standard",
+   .link = shader_scene_standard_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"layout (location=3) in ivec4 a_lights;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      7        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"flat out ivec4 aLights;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"   aLights = a_lights;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexMain;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec4 uPlane;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\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"
+"\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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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      4        0 \n"
+"\n"
+"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
+"{\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - aWorldCo;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   vec3 total_light = newlight_compute_ambient();\n"
+"   \n"
+"   // Compute world lighting contribution and apply it according to the\n"
+"   // shadow map\n"
+"   //\n"
+"   vec3 world_light = newlight_compute_world_diffuse( wnormal );\n"
+"   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow();\n"
+"\n"
+"   total_light += world_light * world_shadow;\n"
+"\n"
+"   // Compute the other lights that exist in the map, not effected by the sun\n"
+"   // shadow\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"
+"   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"
+"   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"
+"\n"
+"   return apply_fog( diffuse * total_light, fdist );\n"
+"}\n"
+"\n"
+"#line     15        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     16        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"   vec4 vsamplemain = texture( uTexMain, aUv );\n"
+"   vec3 qnorm = aNorm.xyz;\n"
+"\n"
+"   vfrag = vsamplemain.rgb;\n"
+"\n"
+"   if( g_light_preview == 1 )\n"
+"   {\n"
+"      vfrag = vec3(0.5);\n"
+"   }\n"
+"\n"
+"   vfrag = scene_do_lighting( vfrag, qnorm );\n"
+"   oColour = vec4( vfrag, 1.0 );\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_scene_standard_uMdl;
+static GLuint _uniform_scene_standard_uPv;
+static GLuint _uniform_scene_standard_uPvmPrev;
+static GLuint _uniform_scene_standard_uTexGarbage;
+static GLuint _uniform_scene_standard_uTexMain;
+static GLuint _uniform_scene_standard_uCamera;
+static GLuint _uniform_scene_standard_uPlane;
+static GLuint _uniform_scene_standard_uBoard0;
+static GLuint _uniform_scene_standard_uBoard1;
+static GLuint _uniform_scene_standard_g_world_depth;
+static void shader_scene_standard_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_standard_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_standard_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_standard_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_standard_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_standard_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_standard_uTexGarbage(int i){
+   glUniform1i(_uniform_scene_standard_uTexGarbage,i);
+}
+static void shader_scene_standard_uTexMain(int i){
+   glUniform1i(_uniform_scene_standard_uTexMain,i);
+}
+static void shader_scene_standard_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_standard_uCamera,1,v);
+}
+static void shader_scene_standard_uPlane(v4f v){
+   glUniform4fv(_uniform_scene_standard_uPlane,1,v);
+}
+static void shader_scene_standard_uBoard0(v3f v){
+   glUniform3fv(_uniform_scene_standard_uBoard0,1,v);
+}
+static void shader_scene_standard_uBoard1(v3f v){
+   glUniform3fv(_uniform_scene_standard_uBoard1,1,v);
+}
+static void shader_scene_standard_g_world_depth(int i){
+   glUniform1i(_uniform_scene_standard_g_world_depth,i);
+}
+static void shader_scene_standard_register(void){
+   vg_shader_register( &_shader_scene_standard );
+}
+static void shader_scene_standard_use(void){ glUseProgram(_shader_scene_standard.id); }
+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_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" );
+   _uniform_scene_standard_uPlane = glGetUniformLocation( _shader_scene_standard.id, "uPlane" );
+   _uniform_scene_standard_uBoard0 = glGetUniformLocation( _shader_scene_standard.id, "uBoard0" );
+   _uniform_scene_standard_uBoard1 = glGetUniformLocation( _shader_scene_standard.id, "uBoard1" );
+   _uniform_scene_standard_g_world_depth = glGetUniformLocation( _shader_scene_standard.id, "g_world_depth" );
+}
+#endif /* SHADER_scene_standard_H */
diff --git a/shaders/scene_standard_alphatest.fs b/shaders/scene_standard_alphatest.fs
new file mode 100644 (file)
index 0000000..ea5eafe
--- /dev/null
@@ -0,0 +1,37 @@
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexMain;
+uniform vec3 uBoard0;
+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"
+
+void main()
+{
+   compute_motion_vectors();
+
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+   vec4 vsamplemain = texture( uTexMain, aUv );
+   vec3 qnorm = aNorm.xyz;
+
+   if( vsamplemain.a < 0.15 )
+     discard;
+
+   vfrag = vsamplemain.rgb;
+
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
+
+   vfrag = scene_do_lighting( vfrag, qnorm );
+   oColour = vec4(vfrag, 1.0);
+}
diff --git a/shaders/scene_standard_alphatest.h b/shaders/scene_standard_alphatest.h
new file mode 100644 (file)
index 0000000..f9aa650
--- /dev/null
@@ -0,0 +1,356 @@
+#ifndef SHADER_scene_standard_alphatest_H
+#define SHADER_scene_standard_alphatest_H
+static void shader_scene_standard_alphatest_link(void);
+static void shader_scene_standard_alphatest_register(void);
+static struct vg_shader _shader_scene_standard_alphatest = {
+   .name = "scene_standard_alphatest",
+   .link = shader_scene_standard_alphatest_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"layout (location=3) in ivec4 a_lights;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      7        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"flat out ivec4 aLights;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"   aLights = a_lights;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexMain;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec4 uPlane;\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"
+"\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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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      4        0 \n"
+"\n"
+"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
+"{\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - aWorldCo;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   vec3 total_light = newlight_compute_ambient();\n"
+"   \n"
+"   // Compute world lighting contribution and apply it according to the\n"
+"   // shadow map\n"
+"   //\n"
+"   vec3 world_light = newlight_compute_world_diffuse( wnormal );\n"
+"   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow();\n"
+"\n"
+"   total_light += world_light * world_shadow;\n"
+"\n"
+"   // Compute the other lights that exist in the map, not effected by the sun\n"
+"   // shadow\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"
+"   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"
+"   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"
+"\n"
+"   return apply_fog( diffuse * total_light, fdist );\n"
+"}\n"
+"\n"
+"#line     15        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     16        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"   vec4 vsamplemain = texture( uTexMain, aUv );\n"
+"   vec3 qnorm = aNorm.xyz;\n"
+"\n"
+"   if( vsamplemain.a < 0.15 )\n"
+"     discard;\n"
+"\n"
+"   vfrag = vsamplemain.rgb;\n"
+"\n"
+"   if( g_light_preview == 1 )\n"
+"   {\n"
+"      vfrag = vec3(0.5);\n"
+"   }\n"
+"\n"
+"   vfrag = scene_do_lighting( vfrag, qnorm );\n"
+"   oColour = vec4(vfrag, 1.0);\n"
+"}\n"
+""},
+};
+
+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_uTexGarbage;
+static GLuint _uniform_scene_standard_alphatest_uTexMain;
+static GLuint _uniform_scene_standard_alphatest_uBoard0;
+static GLuint _uniform_scene_standard_alphatest_uBoard1;
+static GLuint _uniform_scene_standard_alphatest_uCamera;
+static GLuint _uniform_scene_standard_alphatest_uPlane;
+static GLuint _uniform_scene_standard_alphatest_g_world_depth;
+static void shader_scene_standard_alphatest_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_standard_alphatest_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_standard_alphatest_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_standard_alphatest_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_standard_alphatest_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_standard_alphatest_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_standard_alphatest_uTexGarbage(int i){
+   glUniform1i(_uniform_scene_standard_alphatest_uTexGarbage,i);
+}
+static void shader_scene_standard_alphatest_uTexMain(int i){
+   glUniform1i(_uniform_scene_standard_alphatest_uTexMain,i);
+}
+static void shader_scene_standard_alphatest_uBoard0(v3f v){
+   glUniform3fv(_uniform_scene_standard_alphatest_uBoard0,1,v);
+}
+static void shader_scene_standard_alphatest_uBoard1(v3f v){
+   glUniform3fv(_uniform_scene_standard_alphatest_uBoard1,1,v);
+}
+static void shader_scene_standard_alphatest_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_standard_alphatest_uCamera,1,v);
+}
+static void shader_scene_standard_alphatest_uPlane(v4f v){
+   glUniform4fv(_uniform_scene_standard_alphatest_uPlane,1,v);
+}
+static void shader_scene_standard_alphatest_g_world_depth(int i){
+   glUniform1i(_uniform_scene_standard_alphatest_g_world_depth,i);
+}
+static void shader_scene_standard_alphatest_register(void){
+   vg_shader_register( &_shader_scene_standard_alphatest );
+}
+static void shader_scene_standard_alphatest_use(void){ glUseProgram(_shader_scene_standard_alphatest.id); }
+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_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" );
+   _uniform_scene_standard_alphatest_uBoard1 = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uBoard1" );
+   _uniform_scene_standard_alphatest_uCamera = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uCamera" );
+   _uniform_scene_standard_alphatest_uPlane = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPlane" );
+   _uniform_scene_standard_alphatest_g_world_depth = glGetUniformLocation( _shader_scene_standard_alphatest.id, "g_world_depth" );
+}
+#endif /* SHADER_scene_standard_alphatest_H */
diff --git a/shaders/scene_terrain.fs b/shaders/scene_terrain.fs
new file mode 100644 (file)
index 0000000..7f7648a
--- /dev/null
@@ -0,0 +1,57 @@
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexGradients;
+uniform vec3 uCamera;
+uniform vec3 uSandColour;
+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"
+
+void main()
+{
+   compute_motion_vectors();
+
+   // Colour
+   // ------
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+
+   // ws modulation
+   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
+   
+   // Creating normal patches
+   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
+   vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);
+   qnorm += vec3(0.001,0.0,0.0);
+
+   vec2 dir = normalize(qnorm.xz);
+   vec2 uvdiffuse = aCo.xz * 0.02;
+   uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;
+   
+   // Patch local noise
+   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
+
+   // Colour blending
+   float amtgrass = step(qnorm.y,0.6);
+   float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*qnorm.y,1.0);
+   vec2 uvgradients = aUv + vec2( amtgrass + rgarbage.a*0.8 )*uBlendOffset;
+   vfrag = texture( uTexGradients, uvgradients ).rgb;
+   vfrag = mix( vfrag, uSandColour, amtsand );
+
+   qnorm = mix( qnorm, aNorm.xyz, amtsand );
+   
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
+
+   vfrag = scene_do_lighting( vfrag, qnorm );
+   oColour = vec4(vfrag, 1.0);
+}
diff --git a/shaders/scene_terrain.h b/shaders/scene_terrain.h
new file mode 100644 (file)
index 0000000..467cd91
--- /dev/null
@@ -0,0 +1,381 @@
+#ifndef SHADER_scene_terrain_H
+#define SHADER_scene_terrain_H
+static void shader_scene_terrain_link(void);
+static void shader_scene_terrain_register(void);
+static struct vg_shader _shader_scene_terrain = {
+   .name = "scene_terrain",
+   .link = shader_scene_terrain_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"layout (location=3) in ivec4 a_lights;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      7        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"flat out ivec4 aLights;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"   aLights = a_lights;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexGradients;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec3 uSandColour;\n"
+"uniform vec2 uBlendOffset;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\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"
+"\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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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      4        0 \n"
+"\n"
+"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
+"{\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - aWorldCo;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   vec3 total_light = newlight_compute_ambient();\n"
+"   \n"
+"   // Compute world lighting contribution and apply it according to the\n"
+"   // shadow map\n"
+"   //\n"
+"   vec3 world_light = newlight_compute_world_diffuse( wnormal );\n"
+"   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow();\n"
+"\n"
+"   total_light += world_light * world_shadow;\n"
+"\n"
+"   // Compute the other lights that exist in the map, not effected by the sun\n"
+"   // shadow\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"
+"   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"
+"   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"
+"\n"
+"   return apply_fog( diffuse * total_light, fdist );\n"
+"}\n"
+"\n"
+"#line     16        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     17        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   // Colour\n"
+"   // ------\n"
+"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"\n"
+"   // ws modulation\n"
+"   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
+"   \n"
+"   // Creating normal patches\n"
+"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
+"   vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
+"   qnorm += vec3(0.001,0.0,0.0);\n"
+"\n"
+"   vec2 dir = normalize(qnorm.xz);\n"
+"   vec2 uvdiffuse = aCo.xz * 0.02;\n"
+"   uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;\n"
+"   \n"
+"   // Patch local noise\n"
+"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
+"\n"
+"   // Colour blending\n"
+"   float amtgrass = step(qnorm.y,0.6);\n"
+"   float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*qnorm.y,1.0);\n"
+"   vec2 uvgradients = aUv + vec2( amtgrass + rgarbage.a*0.8 )*uBlendOffset;\n"
+"   vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
+"   vfrag = mix( vfrag, uSandColour, amtsand );\n"
+"\n"
+"   qnorm = mix( qnorm, aNorm.xyz, amtsand );\n"
+"   \n"
+"   if( g_light_preview == 1 )\n"
+"   {\n"
+"      vfrag = vec3(0.5);\n"
+"   }\n"
+"\n"
+"   vfrag = scene_do_lighting( vfrag, qnorm );\n"
+"   oColour = vec4(vfrag, 1.0);\n"
+"}\n"
+""},
+};
+
+static GLuint _uniform_scene_terrain_uMdl;
+static GLuint _uniform_scene_terrain_uPv;
+static GLuint _uniform_scene_terrain_uPvmPrev;
+static GLuint _uniform_scene_terrain_uTexGarbage;
+static GLuint _uniform_scene_terrain_uTexGradients;
+static GLuint _uniform_scene_terrain_uCamera;
+static GLuint _uniform_scene_terrain_uSandColour;
+static GLuint _uniform_scene_terrain_uBlendOffset;
+static GLuint _uniform_scene_terrain_uBoard0;
+static GLuint _uniform_scene_terrain_uBoard1;
+static GLuint _uniform_scene_terrain_g_world_depth;
+static void shader_scene_terrain_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_terrain_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_terrain_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_terrain_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_terrain_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_terrain_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_terrain_uTexGarbage(int i){
+   glUniform1i(_uniform_scene_terrain_uTexGarbage,i);
+}
+static void shader_scene_terrain_uTexGradients(int i){
+   glUniform1i(_uniform_scene_terrain_uTexGradients,i);
+}
+static void shader_scene_terrain_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_terrain_uCamera,1,v);
+}
+static void shader_scene_terrain_uSandColour(v3f v){
+   glUniform3fv(_uniform_scene_terrain_uSandColour,1,v);
+}
+static void shader_scene_terrain_uBlendOffset(v2f v){
+   glUniform2fv(_uniform_scene_terrain_uBlendOffset,1,v);
+}
+static void shader_scene_terrain_uBoard0(v3f v){
+   glUniform3fv(_uniform_scene_terrain_uBoard0,1,v);
+}
+static void shader_scene_terrain_uBoard1(v3f v){
+   glUniform3fv(_uniform_scene_terrain_uBoard1,1,v);
+}
+static void shader_scene_terrain_g_world_depth(int i){
+   glUniform1i(_uniform_scene_terrain_g_world_depth,i);
+}
+static void shader_scene_terrain_register(void){
+   vg_shader_register( &_shader_scene_terrain );
+}
+static void shader_scene_terrain_use(void){ glUseProgram(_shader_scene_terrain.id); }
+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_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" );
+   _uniform_scene_terrain_uSandColour = glGetUniformLocation( _shader_scene_terrain.id, "uSandColour" );
+   _uniform_scene_terrain_uBlendOffset = glGetUniformLocation( _shader_scene_terrain.id, "uBlendOffset" );
+   _uniform_scene_terrain_uBoard0 = glGetUniformLocation( _shader_scene_terrain.id, "uBoard0" );
+   _uniform_scene_terrain_uBoard1 = glGetUniformLocation( _shader_scene_terrain.id, "uBoard1" );
+   _uniform_scene_terrain_g_world_depth = glGetUniformLocation( _shader_scene_terrain.id, "g_world_depth" );
+}
+#endif /* SHADER_scene_terrain_H */
diff --git a/shaders/scene_vertex_blend.fs b/shaders/scene_vertex_blend.fs
new file mode 100644 (file)
index 0000000..86466d0
--- /dev/null
@@ -0,0 +1,51 @@
+uniform sampler2D uTexGarbage;
+uniform sampler2D uTexGradients;
+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"
+
+void main()
+{
+   compute_motion_vectors();
+
+   vec3 vfrag = vec3(0.5,0.5,0.5);
+
+   // ws modulation
+   vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);
+   
+   // Creating normal patches
+   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
+   vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);
+   qnorm += vec3(0.001,0.0,0.0);
+
+   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
+   vec3 tangent1 = cross(qnorm,tangent0);
+   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;
+   
+   // Patch local noise
+   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
+
+   // Colour blending
+   float fblendclip = step(0.380,aNorm.w + (rgarbage.r-0.5)*-1.740)*0.320;
+   vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );
+
+   vfrag = texture( uTexGradients, uvgradients ).rgb;
+   vfrag -= rgarbage.a*0.04;
+
+   if( g_light_preview == 1 )
+   {
+      vfrag = vec3(0.5);
+   }
+
+   vfrag = scene_do_lighting( vfrag, qnorm );
+   oColour = vec4(vfrag, 1.0);
+}
diff --git a/shaders/scene_vertex_blend.h b/shaders/scene_vertex_blend.h
new file mode 100644 (file)
index 0000000..1f3946f
--- /dev/null
@@ -0,0 +1,365 @@
+#ifndef SHADER_scene_vertex_blend_H
+#define SHADER_scene_vertex_blend_H
+static void shader_scene_vertex_blend_link(void);
+static void shader_scene_vertex_blend_register(void);
+static struct vg_shader _shader_scene_vertex_blend = {
+   .name = "scene_vertex_blend",
+   .link = shader_scene_vertex_blend_link,
+   .vs = 
+{
+.static_src = 
+"layout (location=0) in vec3  a_co;\n"
+"layout (location=1) in vec4  a_norm;\n"
+"layout (location=2) in vec2  a_uv;\n"
+"layout (location=3) in ivec4 a_lights;\n"
+"\n"
+"#line       1        1 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"out vec3 aMotionVec0;\n"
+"out vec3 aMotionVec1;\n"
+"\n"
+"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
+"{\n"
+"   // This magically solves some artifacting errors!\n"
+"   //\n"
+"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
+"\n"
+"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
+"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
+"}\n"
+"\n"
+"#line      7        0 \n"
+"\n"
+"uniform mat4x3 uMdl;\n"
+"uniform mat4   uPv;\n"
+"uniform mat4   uPvmPrev;\n"
+"\n"
+"out vec2 aUv;\n"
+"out vec4 aNorm;\n"
+"out vec3 aCo;\n"
+"out vec3 aWorldCo;\n"
+"flat out ivec4 aLights;\n"
+"\n"
+"void main()\n"
+"{\n"
+"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
+"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
+"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
+"\n"
+"   vs_motion_out( vproj0, vproj1 );\n"
+"\n"
+"   gl_Position = vproj0;\n"
+"\n"
+"   aUv = a_uv;\n"
+"   aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
+"   aCo = a_co;\n"
+"   aWorldCo = world_pos0;\n"
+"   aLights = a_lights;\n"
+"}\n"
+""},
+   .fs = 
+{
+.static_src = 
+"uniform sampler2D uTexGarbage;\n"
+"uniform sampler2D uTexGradients;\n"
+"uniform vec3 uCamera;\n"
+"uniform vec3 uBoard0;\n"
+"uniform vec3 uBoard1;\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"
+"\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"
+"   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 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"
+"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"
+"   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"
+"   // 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"
+"}\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      4        0 \n"
+"\n"
+"vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
+"{\n"
+"   // Lighting\n"
+"   vec3 halfview = uCamera - aWorldCo;\n"
+"   float fdist = length(halfview);\n"
+"   halfview /= fdist;\n"
+"\n"
+"   vec3 total_light = newlight_compute_ambient();\n"
+"   \n"
+"   // Compute world lighting contribution and apply it according to the\n"
+"   // shadow map\n"
+"   //\n"
+"   vec3 world_light = newlight_compute_world_diffuse( wnormal );\n"
+"   world_light += newlight_compute_sun_spec( wnormal, halfview, 0.1 );\n"
+"\n"
+"   float world_shadow = newlight_compute_sun_shadow();\n"
+"\n"
+"   total_light += world_light * world_shadow;\n"
+"\n"
+"   // Compute the other lights that exist in the map, not effected by the sun\n"
+"   // shadow\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"
+"   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"
+"   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"
+"\n"
+"   return apply_fog( diffuse * total_light, fdist );\n"
+"}\n"
+"\n"
+"#line     14        0 \n"
+"#line       1        2 \n"
+"const float k_motion_lerp_amount = 0.01;\n"
+"\n"
+"#line      2        0 \n"
+"\n"
+"layout (location = 1) out vec2 oMotionVec;\n"
+"\n"
+"in vec3 aMotionVec0;\n"
+"in vec3 aMotionVec1;\n"
+"\n"
+"void compute_motion_vectors()\n"
+"{\n"
+"   // Write motion vectors\n"
+"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
+"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
+"\n"
+"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
+"}\n"
+"\n"
+"#line     15        0 \n"
+"\n"
+"void main()\n"
+"{\n"
+"   compute_motion_vectors();\n"
+"\n"
+"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
+"\n"
+"   // ws modulation\n"
+"   vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);\n"
+"   \n"
+"   // Creating normal patches\n"
+"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
+"   vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
+"   qnorm += vec3(0.001,0.0,0.0);\n"
+"\n"
+"   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
+"   vec3 tangent1 = cross(qnorm,tangent0);\n"
+"   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;\n"
+"   \n"
+"   // Patch local noise\n"
+"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
+"\n"
+"   // Colour blending\n"
+"   float fblendclip = step(0.380,aNorm.w + (rgarbage.r-0.5)*-1.740)*0.320;\n"
+"   vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );\n"
+"\n"
+"   vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
+"   vfrag -= rgarbage.a*0.04;\n"
+"\n"
+"   if( g_light_preview == 1 )\n"
+"   {\n"
+"      vfrag = vec3(0.5);\n"
+"   }\n"
+"\n"
+"   vfrag = scene_do_lighting( vfrag, qnorm );\n"
+"   oColour = vec4(vfrag, 1.0);\n"
+"}\n"
+""},
+};
+
+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_uTexGarbage;
+static GLuint _uniform_scene_vertex_blend_uTexGradients;
+static GLuint _uniform_scene_vertex_blend_uCamera;
+static GLuint _uniform_scene_vertex_blend_uBoard0;
+static GLuint _uniform_scene_vertex_blend_uBoard1;
+static GLuint _uniform_scene_vertex_blend_g_world_depth;
+static void shader_scene_vertex_blend_uMdl(m4x3f m){
+   glUniformMatrix4x3fv(_uniform_scene_vertex_blend_uMdl,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_vertex_blend_uPv(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_vertex_blend_uPv,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_vertex_blend_uPvmPrev(m4x4f m){
+   glUniformMatrix4fv(_uniform_scene_vertex_blend_uPvmPrev,1,GL_FALSE,(float*)m);
+}
+static void shader_scene_vertex_blend_uTexGarbage(int i){
+   glUniform1i(_uniform_scene_vertex_blend_uTexGarbage,i);
+}
+static void shader_scene_vertex_blend_uTexGradients(int i){
+   glUniform1i(_uniform_scene_vertex_blend_uTexGradients,i);
+}
+static void shader_scene_vertex_blend_uCamera(v3f v){
+   glUniform3fv(_uniform_scene_vertex_blend_uCamera,1,v);
+}
+static void shader_scene_vertex_blend_uBoard0(v3f v){
+   glUniform3fv(_uniform_scene_vertex_blend_uBoard0,1,v);
+}
+static void shader_scene_vertex_blend_uBoard1(v3f v){
+   glUniform3fv(_uniform_scene_vertex_blend_uBoard1,1,v);
+}
+static void shader_scene_vertex_blend_g_world_depth(int i){
+   glUniform1i(_uniform_scene_vertex_blend_g_world_depth,i);
+}
+static void shader_scene_vertex_blend_register(void){
+   vg_shader_register( &_shader_scene_vertex_blend );
+}
+static void shader_scene_vertex_blend_use(void){ glUseProgram(_shader_scene_vertex_blend.id); }
+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_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" );
+   _uniform_scene_vertex_blend_uBoard0 = glGetUniformLocation( _shader_scene_vertex_blend.id, "uBoard0" );
+   _uniform_scene_vertex_blend_uBoard1 = glGetUniformLocation( _shader_scene_vertex_blend.id, "uBoard1" );
+   _uniform_scene_vertex_blend_g_world_depth = glGetUniformLocation( _shader_scene_vertex_blend.id, "g_world_depth" );
+}
+#endif /* SHADER_scene_vertex_blend_H */
diff --git a/shaders/scoretext.h b/shaders/scoretext.h
deleted file mode 100644 (file)
index 7a9bf3a..0000000
+++ /dev/null
@@ -1,349 +0,0 @@
-#ifndef SHADER_scoretext_H
-#define SHADER_scoretext_H
-static void shader_scoretext_link(void);
-static void shader_scoretext_register(void);
-static struct vg_shader _shader_scoretext = {
-   .name = "scoretext",
-   .link = shader_scoretext_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"uniform vec3 uInfo;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   float w = (a_colour.g * 8.0)-5.5 + fract(uInfo.z+0.5);\n"
-"   float c = -cos(w*0.2);\n"
-"   float s = -sin(w*0.2);\n"
-"   float r = 0.2;\n"
-"\n"
-"   float w1 = clamp( w*4.0 - a_co.y*10.0, -1.0, 1.0 ) * (3.14159265*0.5);\n"
-"   float c1 = cos(w1);\n"
-"   float s1 = sin(w1);\n"
-"\n"
-"   float yoff = step(0.01,fract(uInfo.z))*-0.5;\n"
-"\n"
-"   mat4x3 mlocal;\n"
-"   mlocal[0] = vec3(c1, s1,0.0);\n"
-"   mlocal[1] = vec3(-s1,c1,0.0);\n"
-"   mlocal[2] = vec3(0.0,0.0,1.0);\n"
-"   mlocal[3] = vec3(c*r,uInfo.y*0.875 + s*r,uInfo.x*0.5);\n"
-"\n"
-"   vec3 local_pos = mlocal * vec4( a_co, 1.0 );\n"
-"   vec3 world_pos = uMdl * vec4( local_pos, 1.0 );\n"
-"\n"
-"   vec4 vproj0 = uPv      * vec4( world_pos, 1.0 );\n"
-"   vec4 vproj1 = uPvmPrev * vec4( local_pos, 1.0 );\n"
-"\n"
-"   // Output\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv + vec2( floor(uInfo.z+0.5)*(1.0/64.0), yoff );\n"
-"   aNorm = mat3(uMdl) * mat3(mlocal) * a_norm;\n"
-"   aCo = a_co;\n"
-"   aWorldCo = world_pos;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     14        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     15        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"\n"
-"   // ws modulation\n"
-"   vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);//texture( uTexGarbage, aCo.xz * 0.160 );\n"
-"   \n"
-"   // Creating normal patches\n"
-"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
-"   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);\n"
-"\n"
-"   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
-"   vec3 tangent1 = cross(qnorm,tangent0);\n"
-"   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;\n"
-"   \n"
-"   // Patch local noise\n"
-"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
-"\n"
-"   // Colour blending\n"
-"   float fblendclip = step(0.380,aColour.r + (rgarbage.r-0.5)*-1.740)*0.320;\n"
-"   vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );\n"
-"\n"
-"   vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
-"   vfrag -= rgarbage.a*0.04;\n"
-"\n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
-"      vfrag = vec3(0.5);\n"
-"   }\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   vfrag = do_light_diffuse( vfrag, qnorm );\n"
-"   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   oColour = vec4(vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_scoretext_uMdl;
-static GLuint _uniform_scoretext_uPv;
-static GLuint _uniform_scoretext_uPvmPrev;
-static GLuint _uniform_scoretext_uInfo;
-static GLuint _uniform_scoretext_uTexGarbage;
-static GLuint _uniform_scoretext_uTexGradients;
-static GLuint _uniform_scoretext_uCamera;
-static GLuint _uniform_scoretext_uBoard0;
-static GLuint _uniform_scoretext_uBoard1;
-static GLuint _uniform_scoretext_g_world_depth;
-static void shader_scoretext_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_scoretext_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_scoretext_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_scoretext_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_scoretext_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_scoretext_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_scoretext_uInfo(v3f v){
-   glUniform3fv(_uniform_scoretext_uInfo,1,v);
-}
-static void shader_scoretext_uTexGarbage(int i){
-   glUniform1i(_uniform_scoretext_uTexGarbage,i);
-}
-static void shader_scoretext_uTexGradients(int i){
-   glUniform1i(_uniform_scoretext_uTexGradients,i);
-}
-static void shader_scoretext_uCamera(v3f v){
-   glUniform3fv(_uniform_scoretext_uCamera,1,v);
-}
-static void shader_scoretext_uBoard0(v3f v){
-   glUniform3fv(_uniform_scoretext_uBoard0,1,v);
-}
-static void shader_scoretext_uBoard1(v3f v){
-   glUniform3fv(_uniform_scoretext_uBoard1,1,v);
-}
-static void shader_scoretext_g_world_depth(int i){
-   glUniform1i(_uniform_scoretext_g_world_depth,i);
-}
-static void shader_scoretext_register(void){
-   vg_shader_register( &_shader_scoretext );
-}
-static void shader_scoretext_use(void){ glUseProgram(_shader_scoretext.id); }
-static void shader_scoretext_link(void){
-   _uniform_scoretext_uMdl = glGetUniformLocation( _shader_scoretext.id, "uMdl" );
-   _uniform_scoretext_uPv = glGetUniformLocation( _shader_scoretext.id, "uPv" );
-   _uniform_scoretext_uPvmPrev = glGetUniformLocation( _shader_scoretext.id, "uPvmPrev" );
-   _uniform_scoretext_uInfo = glGetUniformLocation( _shader_scoretext.id, "uInfo" );
-   _uniform_scoretext_uTexGarbage = glGetUniformLocation( _shader_scoretext.id, "uTexGarbage" );
-   _uniform_scoretext_uTexGradients = glGetUniformLocation( _shader_scoretext.id, "uTexGradients" );
-   _uniform_scoretext_uCamera = glGetUniformLocation( _shader_scoretext.id, "uCamera" );
-   _uniform_scoretext_uBoard0 = glGetUniformLocation( _shader_scoretext.id, "uBoard0" );
-   _uniform_scoretext_uBoard1 = glGetUniformLocation( _shader_scoretext.id, "uBoard1" );
-   _uniform_scoretext_g_world_depth = glGetUniformLocation( _shader_scoretext.id, "g_world_depth" );
-}
-#endif /* SHADER_scoretext_H */
diff --git a/shaders/scoretext.vs b/shaders/scoretext.vs
deleted file mode 100644 (file)
index ab714d6..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#include "vertex_standard.glsl"
-#include "motion_vectors_vs.glsl"
-
-uniform mat4x3 uMdl;
-uniform mat4 uPv;
-uniform mat4 uPvmPrev;
-
-uniform vec3 uInfo;
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-out vec3 aWorldCo;
-
-void main()
-{
-   float w = (a_colour.g * 8.0)-5.5 + fract(uInfo.z+0.5);
-   float c = -cos(w*0.2);
-   float s = -sin(w*0.2);
-   float r = 0.2;
-
-   float w1 = clamp( w*4.0 - a_co.y*10.0, -1.0, 1.0 ) * (3.14159265*0.5);
-   float c1 = cos(w1);
-   float s1 = sin(w1);
-
-   float yoff = step(0.01,fract(uInfo.z))*-0.5;
-
-   mat4x3 mlocal;
-   mlocal[0] = vec3(c1, s1,0.0);
-   mlocal[1] = vec3(-s1,c1,0.0);
-   mlocal[2] = vec3(0.0,0.0,1.0);
-   mlocal[3] = vec3(c*r,uInfo.y*0.875 + s*r,uInfo.x*0.5);
-
-   vec3 local_pos = mlocal * vec4( a_co, 1.0 );
-   vec3 world_pos = uMdl * vec4( local_pos, 1.0 );
-
-   vec4 vproj0 = uPv      * vec4( world_pos, 1.0 );
-   vec4 vproj1 = uPvmPrev * vec4( local_pos, 1.0 );
-
-   // Output
-   vs_motion_out( vproj0, vproj1 );
-
-   gl_Position = vproj0;
-   aColour = a_colour;
-   aUv = a_uv + vec2( floor(uInfo.z+0.5)*(1.0/64.0), yoff );
-   aNorm = mat3(uMdl) * mat3(mlocal) * a_norm;
-   aCo = a_co;
-   aWorldCo = world_pos;
-}
diff --git a/shaders/sky.fs b/shaders/sky.fs
deleted file mode 100644 (file)
index 036f244..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-layout (location = 0) out vec4 oColour;
-
-uniform vec4 uColour;
-uniform sampler2D uTexGarbage;
-uniform float uTime;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-
-#include "motion_vectors_fs.glsl"
-
-void main()
-{
-   compute_motion_vectors();
-
-   float fintensity = 1.0-(abs(aNorm.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 diffuse = mix( skycolour, horizon, fblend );
-
-   float fmove = uTime * 0.004;
-   vec2 cloudplane = (aNorm.xz / (aNorm.y*sign(aNorm.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 );
-
-   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;
-
-   vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );
-   float fhorizon = step( aNorm.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);
-}
diff --git a/shaders/sky.h b/shaders/sky.h
deleted file mode 100644 (file)
index b7b26ef..0000000
+++ /dev/null
@@ -1,163 +0,0 @@
-#ifndef SHADER_sky_H
-#define SHADER_sky_H
-static void shader_sky_link(void);
-static void shader_sky_register(void);
-static struct vg_shader _shader_sky = {
-   .name = "sky",
-   .link = shader_sky_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"uniform vec4 uColour;\n"
-"uniform sampler2D uTexGarbage;\n"
-"uniform float uTime;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"\n"
-"#line       1        1 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     13        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   float fintensity = 1.0-(abs(aNorm.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 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"
-"   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"
-"\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"
-"\n"
-"   vec3 colour_ocean = vec3( 0.61, 0.84, 0.9 );\n"
-"   float fhorizon = step( aNorm.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"
-""},
-};
-
-static GLuint _uniform_sky_uMdl;
-static GLuint _uniform_sky_uPv;
-static GLuint _uniform_sky_uPvmPrev;
-static GLuint _uniform_sky_uColour;
-static GLuint _uniform_sky_uTexGarbage;
-static GLuint _uniform_sky_uTime;
-static void shader_sky_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_sky_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_sky_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_sky_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_sky_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_sky_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_sky_uColour(v4f v){
-   glUniform4fv(_uniform_sky_uColour,1,v);
-}
-static void shader_sky_uTexGarbage(int i){
-   glUniform1i(_uniform_sky_uTexGarbage,i);
-}
-static void shader_sky_uTime(float f){
-   glUniform1f(_uniform_sky_uTime,f);
-}
-static void shader_sky_register(void){
-   vg_shader_register( &_shader_sky );
-}
-static void shader_sky_use(void){ glUseProgram(_shader_sky.id); }
-static void shader_sky_link(void){
-   _uniform_sky_uMdl = glGetUniformLocation( _shader_sky.id, "uMdl" );
-   _uniform_sky_uPv = glGetUniformLocation( _shader_sky.id, "uPv" );
-   _uniform_sky_uPvmPrev = glGetUniformLocation( _shader_sky.id, "uPvmPrev" );
-   _uniform_sky_uColour = glGetUniformLocation( _shader_sky.id, "uColour" );
-   _uniform_sky_uTexGarbage = glGetUniformLocation( _shader_sky.id, "uTexGarbage" );
-   _uniform_sky_uTime = glGetUniformLocation( _shader_sky.id, "uTime" );
-}
-#endif /* SHADER_sky_H */
diff --git a/shaders/standard.fs b/shaders/standard.fs
deleted file mode 100644 (file)
index 321d7ad..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-uniform sampler2D uTexGarbage;
-uniform sampler2D uTexMain;
-uniform vec3 uCamera;
-uniform vec4 uPlane;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-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();
-
-   vec3 vfrag = vec3(0.5,0.5,0.5);
-   vec4 vsamplemain = texture( uTexMain, aUv );
-   vec3 qnorm = normalize(aNorm);
-
-   vfrag = vsamplemain.rgb;
-
-   if( g_light_preview == 1 )
-   {
-      vfrag = vec3(0.5);
-   }
-
-   // Lighting
-   vec3 halfview = uCamera - aWorldCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   vfrag = do_light_diffuse( vfrag, qnorm );
-   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   oColour = vec4(vfrag, 1.0);
-}
diff --git a/shaders/standard.h b/shaders/standard.h
deleted file mode 100644 (file)
index 32976f5..0000000
+++ /dev/null
@@ -1,311 +0,0 @@
-#ifndef SHADER_standard_H
-#define SHADER_standard_H
-static void shader_standard_link(void);
-static void shader_standard_register(void);
-static struct vg_shader _shader_standard = {
-   .name = "standard",
-   .link = shader_standard_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     15        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     16        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"   vec4 vsamplemain = texture( uTexMain, aUv );\n"
-"   vec3 qnorm = normalize(aNorm);\n"
-"\n"
-"   vfrag = vsamplemain.rgb;\n"
-"\n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
-"      vfrag = vec3(0.5);\n"
-"   }\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   vfrag = do_light_diffuse( vfrag, qnorm );\n"
-"   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   oColour = vec4(vfrag, 1.0);\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_standard_uMdl;
-static GLuint _uniform_standard_uPv;
-static GLuint _uniform_standard_uPvmPrev;
-static GLuint _uniform_standard_uTexGarbage;
-static GLuint _uniform_standard_uTexMain;
-static GLuint _uniform_standard_uCamera;
-static GLuint _uniform_standard_uPlane;
-static GLuint _uniform_standard_uBoard0;
-static GLuint _uniform_standard_uBoard1;
-static GLuint _uniform_standard_g_world_depth;
-static void shader_standard_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_standard_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_standard_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_standard_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_standard_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_standard_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_standard_uTexGarbage(int i){
-   glUniform1i(_uniform_standard_uTexGarbage,i);
-}
-static void shader_standard_uTexMain(int i){
-   glUniform1i(_uniform_standard_uTexMain,i);
-}
-static void shader_standard_uCamera(v3f v){
-   glUniform3fv(_uniform_standard_uCamera,1,v);
-}
-static void shader_standard_uPlane(v4f v){
-   glUniform4fv(_uniform_standard_uPlane,1,v);
-}
-static void shader_standard_uBoard0(v3f v){
-   glUniform3fv(_uniform_standard_uBoard0,1,v);
-}
-static void shader_standard_uBoard1(v3f v){
-   glUniform3fv(_uniform_standard_uBoard1,1,v);
-}
-static void shader_standard_g_world_depth(int i){
-   glUniform1i(_uniform_standard_g_world_depth,i);
-}
-static void shader_standard_register(void){
-   vg_shader_register( &_shader_standard );
-}
-static void shader_standard_use(void){ glUseProgram(_shader_standard.id); }
-static void shader_standard_link(void){
-   _uniform_standard_uMdl = glGetUniformLocation( _shader_standard.id, "uMdl" );
-   _uniform_standard_uPv = glGetUniformLocation( _shader_standard.id, "uPv" );
-   _uniform_standard_uPvmPrev = glGetUniformLocation( _shader_standard.id, "uPvmPrev" );
-   _uniform_standard_uTexGarbage = glGetUniformLocation( _shader_standard.id, "uTexGarbage" );
-   _uniform_standard_uTexMain = glGetUniformLocation( _shader_standard.id, "uTexMain" );
-   _uniform_standard_uCamera = glGetUniformLocation( _shader_standard.id, "uCamera" );
-   _uniform_standard_uPlane = glGetUniformLocation( _shader_standard.id, "uPlane" );
-   _uniform_standard_uBoard0 = glGetUniformLocation( _shader_standard.id, "uBoard0" );
-   _uniform_standard_uBoard1 = glGetUniformLocation( _shader_standard.id, "uBoard1" );
-   _uniform_standard_g_world_depth = glGetUniformLocation( _shader_standard.id, "g_world_depth" );
-}
-#endif /* SHADER_standard_H */
diff --git a/shaders/standard.vs b/shaders/standard.vs
deleted file mode 100644 (file)
index 679eae8..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "vertex_standard.glsl"
-#include "motion_vectors_vs.glsl"
-
-uniform mat4x3 uMdl;
-uniform mat4 uPv;
-uniform mat4 uPvmPrev;
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-out vec3 aWorldCo;
-
-void main()
-{
-   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );
-   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );
-   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );
-
-   vs_motion_out( vproj0, vproj1 );
-
-   gl_Position = vproj0;
-   aWorldCo = world_pos0;
-   aColour = a_colour;
-   aUv = a_uv;
-   aNorm = mat3(uMdl) * a_norm;
-   aCo = a_co;
-}
diff --git a/shaders/standard_skinned.vs b/shaders/standard_skinned.vs
deleted file mode 100644 (file)
index 0893795..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "vertex_standard.glsl"
-#include "motion_vectors_vs.glsl"
-
-uniform mat4 uPv;
-
-// TODO: Send a previous transform matrix stack
-//
-uniform mat4x3 uTransforms[32];
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-out vec3 aWorldCo;
-
-void main()
-{
-   vec4 co_local = vec4( a_co, 1.0 );
-   vec3 co0 = uTransforms[ a_groups[0] ] * co_local;
-   vec3 co1 = uTransforms[ a_groups[1] ] * co_local;
-   vec3 co2 = uTransforms[ a_groups[2] ] * co_local;
-   vec3 n0  = mat3(uTransforms[ a_groups[0] ]) * a_norm;
-   vec3 n1  = mat3(uTransforms[ a_groups[1] ]) * a_norm;
-   vec3 n2  = mat3(uTransforms[ a_groups[2] ]) * a_norm;
-
-   vec3 world_pos = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];
-   vec3 world_normal = n0*a_weights[0] + n1*a_weights[1] + n2*a_weights[2];
-   
-   gl_Position = uPv * vec4( world_pos, 1.0 );
-   aColour = a_colour;
-   aUv = a_uv;
-   aNorm = world_normal;
-   aCo = a_co;
-   aWorldCo = world_pos;
-
-   // TODO:
-   aMotionVec0 = vec3(1.0);
-   aMotionVec1 = vec3(1.0);
-}
diff --git a/shaders/std_alphatest.fs b/shaders/std_alphatest.fs
deleted file mode 100644 (file)
index cd22275..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-uniform sampler2D uTexGarbage;
-uniform sampler2D uTexMain;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-uniform vec3 uCamera;
-uniform vec4 uPlane;
-
-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();
-
-   vec3 vfrag = vec3(0.5,0.5,0.5);
-   vec4 vsamplemain = texture( uTexMain, aUv );
-   vec3 qnorm = normalize(aNorm);
-
-   if( vsamplemain.a < 0.15 )
-     discard;
-
-   vfrag = vsamplemain.rgb;
-
-   if( g_light_preview == 1 )
-   {
-      vfrag = vec3(0.5);
-   }
-
-   // Lighting
-   vec3 halfview = uCamera - aWorldCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   vfrag = do_light_diffuse( vfrag, qnorm );
-   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   oColour = vec4(vfrag, 1.0);
-}
diff --git a/shaders/sway.glsl b/shaders/sway.glsl
deleted file mode 100644 (file)
index 6cd92d0..0000000
+++ /dev/null
@@ -1,112 +0,0 @@
-
-       "uniform mat4 uPv;"
-   "uniform mat4x3 uMdl;"
-   "uniform float uTime;"
-   "uniform float uSwayAmt;"
-   ""
-   "out vec4 aColour;"
-   "out vec2 aUv;"
-   "out vec3 aNorm;"
-   "out vec3 aCo;"
-   ""
-   "vec3 compute_sway( vec3 pos )"
-   "{"
-      "vec4 sines = vec4( sin(uTime + pos.x)*1.0," 
-                         "sin(uTime*1.2 + pos.z*2.0)*1.1,"
-                         "sin(uTime*2.33)*0.5,"
-                         "sin(uTime*0.6 + pos.x*0.3)*1.3 );"
-
-      "vec3 offset = vec3( sines.x+sines.y*sines.w, 0.0, sines.x+sines.z );"
-      "return pos + offset*a_colour.r*uSwayAmt;"
-   "}"
-       ""
-       "void main()"
-       "{"
-      "vec3 swaypos = compute_sway( a_co );"
-               "gl_Position = uPv * vec4(uMdl * vec4(swaypos,1.0), 1.0 );"
-      "aColour = a_colour;"
-      "aUv = a_uv;"
-      "aNorm = normalize(mat3(uMdl) * a_norm);"
-      "aCo = a_co;"
-       "}",
-   /* Fragment */
-       "out vec4 FragColor;"
-       ""
-   "uniform int uMode;"
-   "uniform sampler2D uTexMain;"
-   "uniform sampler2D uTexGradients;"
-   ""
-   /*Include*/ SHADER_VALUE_NOISE_3D
-   ""
-   "in vec4 aColour;"
-   "in vec2 aUv;"
-   "in vec3 aNorm;"
-   "in vec3 aCo;"
-   ""
-       "void main()"
-       "{"
-      "vec4 colour = vec4(1.0,0.0,0.5,1.0);"
-      "vec4 diffuse = texture( uTexMain, aUv );"
-
-      "if( uMode == 1 )"
-      "{"
-         "colour = vec4(aNorm * 0.5 + 0.5, 1.0);"
-      "}"
-      "if( uMode == 2 )"
-      "{"
-         "colour = aColour;"
-      "}"
-      "if( uMode == 3 )"
-      "{"
-         "float light = dot(aNorm, vec3(0.2,0.8,0.1));"
-         "vec3 grid3 = fract(aCo);"
-         
-         "colour = vec4(vec3(light)*(1.0-grid3*0.3),1.0);"
-      "}"
-      "if( uMode == 4 )"
-      "{"
-         "colour = vec4( aUv, 0.0, 1.0 );"
-      "}"
-      "if( uMode == 5 )"
-      "{"
-         "if( diffuse.a < 0.45 ) discard;"
-         "colour = diffuse;"
-      "}"
-      "if( uMode == 6 )"
-      "{"
-         "float r1 = fractalNoise(aCo);"
-         "colour = vec4( vec3(r1), 1.0 );"
-      "}"
-      "if( uMode == 7 )"
-      "{"
-         "if( diffuse.a < 0.2 ) discard;"
-         "float lighting = 1.0 - aColour.g*0.8;"
-   
-         "float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));"
-         "float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));"
-         "vec3 lt = vec3(0.2,0.2,0.2 ) + " 
-                   "vec3(1.0,1.0,0.9)*light1 + "
-                   "vec3(0.1,0.3,0.4 )*light2;"
-
-
-         "colour = vec4(vec3(pow(lighting,1.6)*(diffuse.r*0.7+0.5)),1.0);"
-         "colour = vec4(colour.rgb*lt,1.0);"
-
-         "vec2 gradUV = vec2(lighting*1.9,aColour.b*0.8);"
-         "vec4 gradient_sample = texture( uTexGradients, gradUV );"
-         "colour = colour*gradient_sample;"
-      "}"
-      "if( uMode == 8 )"
-      "{"
-         "if( diffuse.a < 0.45 ) discard;"
-         "float light = 1.0 - aColour.g;"
-         "light = pow(light,1.6)*(diffuse.r*0.7+0.5);"
-         "float r1 = fractalNoise(aCo*0.01);"
-         
-         "vec2 gradUV = vec2(light*1.9,r1+aColour.b);"
-         "vec4 gradient_sample = texture( uTexGradients, gradUV );"
-         "colour = gradient_sample*light;"
-      "}"
-
-               "FragColor = colour;"
-       "}"
diff --git a/shaders/terrain.fs b/shaders/terrain.fs
deleted file mode 100644 (file)
index 3f5cd3a..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-uniform sampler2D uTexGarbage;
-uniform sampler2D uTexGradients;
-uniform vec3 uCamera;
-uniform vec3 uSandColour;
-uniform vec2 uBlendOffset;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-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();
-
-   // Colour
-   // ------
-   vec3 vfrag = vec3(0.5,0.5,0.5);
-
-   // ws modulation
-   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );
-   
-   // Creating normal patches
-   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
-   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);
-   vec2 dir = normalize(qnorm.xz);
-   vec2 uvdiffuse = aCo.xz * 0.02;
-   uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;
-   
-   // Patch local noise
-   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
-
-   // Colour blending
-   float amtgrass = step(qnorm.y,0.6);
-   float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*qnorm.y,1.0);
-   vec2 uvgradients = aUv + vec2( amtgrass + rgarbage.a*0.8 )*uBlendOffset;
-   vfrag = texture( uTexGradients, uvgradients ).rgb;
-   vfrag = mix( vfrag, uSandColour, amtsand );
-
-   qnorm = mix( qnorm, aNorm, amtsand );
-   
-   if( g_light_preview == 1 )
-   {
-      vfrag = vec3(0.5);
-   }
-
-   // Lighting
-   vec3 halfview = uCamera - aCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   vfrag = do_light_diffuse( vfrag, qnorm );
-   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   oColour = vec4(vfrag, 1.0 );
-}
diff --git a/shaders/terrain.h b/shaders/terrain.h
deleted file mode 100644 (file)
index 08d8500..0000000
+++ /dev/null
@@ -1,337 +0,0 @@
-#ifndef SHADER_terrain_H
-#define SHADER_terrain_H
-static void shader_terrain_link(void);
-static void shader_terrain_register(void);
-static struct vg_shader _shader_terrain = {
-   .name = "terrain",
-   .link = shader_terrain_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uSandColour;\n"
-"uniform vec2 uBlendOffset;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     16        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     17        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   // Colour\n"
-"   // ------\n"
-"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"\n"
-"   // ws modulation\n"
-"   vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
-"   \n"
-"   // Creating normal patches\n"
-"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
-"   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);\n"
-"   vec2 dir = normalize(qnorm.xz);\n"
-"   vec2 uvdiffuse = aCo.xz * 0.02;\n"
-"   uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;\n"
-"   \n"
-"   // Patch local noise\n"
-"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
-"\n"
-"   // Colour blending\n"
-"   float amtgrass = step(qnorm.y,0.6);\n"
-"   float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*qnorm.y,1.0);\n"
-"   vec2 uvgradients = aUv + vec2( amtgrass + rgarbage.a*0.8 )*uBlendOffset;\n"
-"   vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
-"   vfrag = mix( vfrag, uSandColour, amtsand );\n"
-"\n"
-"   qnorm = mix( qnorm, aNorm, amtsand );\n"
-"   \n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
-"      vfrag = vec3(0.5);\n"
-"   }\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   vfrag = do_light_diffuse( vfrag, qnorm );\n"
-"   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   oColour = vec4(vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_terrain_uMdl;
-static GLuint _uniform_terrain_uPv;
-static GLuint _uniform_terrain_uPvmPrev;
-static GLuint _uniform_terrain_uTexGarbage;
-static GLuint _uniform_terrain_uTexGradients;
-static GLuint _uniform_terrain_uCamera;
-static GLuint _uniform_terrain_uSandColour;
-static GLuint _uniform_terrain_uBlendOffset;
-static GLuint _uniform_terrain_uBoard0;
-static GLuint _uniform_terrain_uBoard1;
-static GLuint _uniform_terrain_g_world_depth;
-static void shader_terrain_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_terrain_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_terrain_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_terrain_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_terrain_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_terrain_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_terrain_uTexGarbage(int i){
-   glUniform1i(_uniform_terrain_uTexGarbage,i);
-}
-static void shader_terrain_uTexGradients(int i){
-   glUniform1i(_uniform_terrain_uTexGradients,i);
-}
-static void shader_terrain_uCamera(v3f v){
-   glUniform3fv(_uniform_terrain_uCamera,1,v);
-}
-static void shader_terrain_uSandColour(v3f v){
-   glUniform3fv(_uniform_terrain_uSandColour,1,v);
-}
-static void shader_terrain_uBlendOffset(v2f v){
-   glUniform2fv(_uniform_terrain_uBlendOffset,1,v);
-}
-static void shader_terrain_uBoard0(v3f v){
-   glUniform3fv(_uniform_terrain_uBoard0,1,v);
-}
-static void shader_terrain_uBoard1(v3f v){
-   glUniform3fv(_uniform_terrain_uBoard1,1,v);
-}
-static void shader_terrain_g_world_depth(int i){
-   glUniform1i(_uniform_terrain_g_world_depth,i);
-}
-static void shader_terrain_register(void){
-   vg_shader_register( &_shader_terrain );
-}
-static void shader_terrain_use(void){ glUseProgram(_shader_terrain.id); }
-static void shader_terrain_link(void){
-   _uniform_terrain_uMdl = glGetUniformLocation( _shader_terrain.id, "uMdl" );
-   _uniform_terrain_uPv = glGetUniformLocation( _shader_terrain.id, "uPv" );
-   _uniform_terrain_uPvmPrev = glGetUniformLocation( _shader_terrain.id, "uPvmPrev" );
-   _uniform_terrain_uTexGarbage = glGetUniformLocation( _shader_terrain.id, "uTexGarbage" );
-   _uniform_terrain_uTexGradients = glGetUniformLocation( _shader_terrain.id, "uTexGradients" );
-   _uniform_terrain_uCamera = glGetUniformLocation( _shader_terrain.id, "uCamera" );
-   _uniform_terrain_uSandColour = glGetUniformLocation( _shader_terrain.id, "uSandColour" );
-   _uniform_terrain_uBlendOffset = glGetUniformLocation( _shader_terrain.id, "uBlendOffset" );
-   _uniform_terrain_uBoard0 = glGetUniformLocation( _shader_terrain.id, "uBoard0" );
-   _uniform_terrain_uBoard1 = glGetUniformLocation( _shader_terrain.id, "uBoard1" );
-   _uniform_terrain_g_world_depth = glGetUniformLocation( _shader_terrain.id, "g_world_depth" );
-}
-#endif /* SHADER_terrain_H */
diff --git a/shaders/terrain.vs b/shaders/terrain.vs
deleted file mode 100644 (file)
index db7f980..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "vertex_standard.glsl"
-
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-
-void main()
-{
-   gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );
-   aColour = a_colour;
-   aUv = a_uv;
-   aNorm = mat3(uMdl) * a_norm;
-   aCo = a_co;
-}
diff --git a/shaders/terrain_fast.fs b/shaders/terrain_fast.fs
deleted file mode 100644 (file)
index 4d61464..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-uniform sampler2D uTexGarbage;
-uniform sampler2D uTexGradients;
-uniform vec3 uCamera;
-uniform vec3 uSandColour;
-uniform vec2 uBlendOffset;
-
-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();
-
-   // Colour
-   // ------
-   vec3 vfrag = vec3(0.5,0.5,0.5);
-
-   // Colour blending
-   float amtgrass = step(aNorm.y,0.6);
-   float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*aNorm.y,1.0);
-   vec2 uvgradients = aUv + vec2( amtgrass )*uBlendOffset;
-   vfrag = texture( uTexGradients, uvgradients ).rgb;
-   vfrag = mix( vfrag, uSandColour, amtsand );
-   
-   if( g_light_preview == 1 )
-   {
-      vfrag = vec3(0.5);
-   }
-
-   // Lighting
-   vec3 halfview = uCamera - aCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   vfrag = do_light_diffuse( vfrag, aNorm );
-   vfrag = do_light_spec( vfrag, aNorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   oColour = vec4(vfrag, 1.0 );
-}
diff --git a/shaders/unlit.fs b/shaders/unlit.fs
deleted file mode 100644 (file)
index bc57d62..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform vec4 uColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-
-void main()
-{
-   vec3 diffuse = texture( uTexMain, aUv ).rgb;
-   FragColor = vec4( diffuse, 1.0 );
-}
diff --git a/shaders/unlit.h b/shaders/unlit.h
deleted file mode 100644 (file)
index 6f7466e..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-#ifndef SHADER_unlit_H
-#define SHADER_unlit_H
-static void shader_unlit_link(void);
-static void shader_unlit_register(void);
-static struct vg_shader _shader_unlit = {
-   .name = "unlit",
-   .link = shader_unlit_link,
-   .vs = 
-{
-.orig_file = "../../shaders/standard.vs",
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"uniform mat4 uPv;\n"
-"uniform mat4x3 uMdl;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos = uMdl * vec4(a_co,1.0);\n"
-"   gl_Position = uPv * vec4( world_pos, 1.0 );\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"   aWorldCo = world_pos;\n"
-"}\n"
-""},
-   .fs = 
-{
-.orig_file = "../../shaders/unlit.fs",
-.static_src = 
-"out vec4 FragColor;\n"
-"\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
-"   FragColor = vec4(pow(diffuse,vec3(1.0)),1.0);\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_unlit_uPv;
-static GLuint _uniform_unlit_uMdl;
-static GLuint _uniform_unlit_uTexMain;
-static GLuint _uniform_unlit_uColour;
-static void shader_unlit_uPv(m4x4f m){
-   glUniformMatrix4fv( _uniform_unlit_uPv, 1, GL_FALSE, (float *)m );
-}
-static void shader_unlit_uMdl(m4x3f m){
-   glUniformMatrix4x3fv( _uniform_unlit_uMdl, 1, GL_FALSE, (float *)m );
-}
-static void shader_unlit_uTexMain(int i){
-   glUniform1i( _uniform_unlit_uTexMain, i );
-}
-static void shader_unlit_uColour(v4f v){
-   glUniform4fv( _uniform_unlit_uColour, 1, v );
-}
-static void shader_unlit_register(void){
-   vg_shader_register( &_shader_unlit );
-}
-static void shader_unlit_use(void){ glUseProgram(_shader_unlit.id); }
-static void shader_unlit_link(void){
-   _uniform_unlit_uPv = glGetUniformLocation( _shader_unlit.id, "uPv" );
-   _uniform_unlit_uMdl = glGetUniformLocation( _shader_unlit.id, "uMdl" );
-   _uniform_unlit_uTexMain = glGetUniformLocation( _shader_unlit.id, "uTexMain" );
-   _uniform_unlit_uColour = glGetUniformLocation( _shader_unlit.id, "uColour" );
-}
-#endif /* SHADER_unlit_H */
diff --git a/shaders/vblend.fs b/shaders/vblend.fs
deleted file mode 100644 (file)
index b2e9928..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-uniform sampler2D uTexGarbage;
-uniform sampler2D uTexGradients;
-uniform vec3 uCamera;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-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();
-
-   vec3 vfrag = vec3(0.5,0.5,0.5);
-
-   // ws modulation
-   vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);//texture( uTexGarbage, aCo.xz * 0.160 );
-   
-   // Creating normal patches
-   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;
-   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);
-
-   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));
-   vec3 tangent1 = cross(qnorm,tangent0);
-   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;
-   
-   // Patch local noise
-   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );
-
-   // Colour blending
-   float fblendclip = step(0.380,aColour.r + (rgarbage.r-0.5)*-1.740)*0.320;
-   vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );
-
-   vfrag = texture( uTexGradients, uvgradients ).rgb;
-   vfrag -= rgarbage.a*0.04;
-
-   if( g_light_preview == 1 )
-   {
-      vfrag = vec3(0.5);
-   }
-
-   // Lighting
-   vec3 halfview = uCamera - aWorldCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-
-   vfrag = do_light_diffuse( vfrag, qnorm );
-   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   oColour = vec4(vfrag, 1.0 );
-}
diff --git a/shaders/vblend.h b/shaders/vblend.h
deleted file mode 100644 (file)
index fcdd836..0000000
+++ /dev/null
@@ -1,322 +0,0 @@
-#ifndef SHADER_vblend_H
-#define SHADER_vblend_H
-static void shader_vblend_link(void);
-static void shader_vblend_register(void);
-static struct vg_shader _shader_vblend = {
-   .name = "vblend",
-   .link = shader_vblend_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     14        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     15        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-"\n"
-"   // ws modulation\n"
-"   vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);//texture( uTexGarbage, aCo.xz * 0.160 );\n"
-"   \n"
-"   // Creating normal patches\n"
-"   vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
-"   vec3 qnorm = normalize(floor(aNorm*4.0+modnorm)*0.25) + vec3(0.001,0.0,0.0);\n"
-"\n"
-"   vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
-"   vec3 tangent1 = cross(qnorm,tangent0);\n"
-"   vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;\n"
-"   \n"
-"   // Patch local noise\n"
-"   vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
-"\n"
-"   // Colour blending\n"
-"   float fblendclip = step(0.380,aColour.r + (rgarbage.r-0.5)*-1.740)*0.320;\n"
-"   vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );\n"
-"\n"
-"   vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
-"   vfrag -= rgarbage.a*0.04;\n"
-"\n"
-"   if( g_light_preview == 1 )\n"
-"   {\n"
-"      vfrag = vec3(0.5);\n"
-"   }\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"\n"
-"   vfrag = do_light_diffuse( vfrag, qnorm );\n"
-"   vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   oColour = vec4(vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_vblend_uMdl;
-static GLuint _uniform_vblend_uPv;
-static GLuint _uniform_vblend_uPvmPrev;
-static GLuint _uniform_vblend_uTexGarbage;
-static GLuint _uniform_vblend_uTexGradients;
-static GLuint _uniform_vblend_uCamera;
-static GLuint _uniform_vblend_uBoard0;
-static GLuint _uniform_vblend_uBoard1;
-static GLuint _uniform_vblend_g_world_depth;
-static void shader_vblend_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_vblend_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_vblend_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_vblend_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_vblend_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_vblend_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_vblend_uTexGarbage(int i){
-   glUniform1i(_uniform_vblend_uTexGarbage,i);
-}
-static void shader_vblend_uTexGradients(int i){
-   glUniform1i(_uniform_vblend_uTexGradients,i);
-}
-static void shader_vblend_uCamera(v3f v){
-   glUniform3fv(_uniform_vblend_uCamera,1,v);
-}
-static void shader_vblend_uBoard0(v3f v){
-   glUniform3fv(_uniform_vblend_uBoard0,1,v);
-}
-static void shader_vblend_uBoard1(v3f v){
-   glUniform3fv(_uniform_vblend_uBoard1,1,v);
-}
-static void shader_vblend_g_world_depth(int i){
-   glUniform1i(_uniform_vblend_g_world_depth,i);
-}
-static void shader_vblend_register(void){
-   vg_shader_register( &_shader_vblend );
-}
-static void shader_vblend_use(void){ glUseProgram(_shader_vblend.id); }
-static void shader_vblend_link(void){
-   _uniform_vblend_uMdl = glGetUniformLocation( _shader_vblend.id, "uMdl" );
-   _uniform_vblend_uPv = glGetUniformLocation( _shader_vblend.id, "uPv" );
-   _uniform_vblend_uPvmPrev = glGetUniformLocation( _shader_vblend.id, "uPvmPrev" );
-   _uniform_vblend_uTexGarbage = glGetUniformLocation( _shader_vblend.id, "uTexGarbage" );
-   _uniform_vblend_uTexGradients = glGetUniformLocation( _shader_vblend.id, "uTexGradients" );
-   _uniform_vblend_uCamera = glGetUniformLocation( _shader_vblend.id, "uCamera" );
-   _uniform_vblend_uBoard0 = glGetUniformLocation( _shader_vblend.id, "uBoard0" );
-   _uniform_vblend_uBoard1 = glGetUniformLocation( _shader_vblend.id, "uBoard1" );
-   _uniform_vblend_g_world_depth = glGetUniformLocation( _shader_vblend.id, "g_world_depth" );
-}
-#endif /* SHADER_vblend_H */
diff --git a/shaders/vertex_standard.glsl b/shaders/vertex_standard.glsl
deleted file mode 100644 (file)
index a780cf7..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-layout (location=0) in vec3 a_co;
-layout (location=1) in vec3 a_norm;
-layout (location=2) in vec2 a_uv;
-layout (location=3) in vec4 a_colour;
-layout (location=4) in vec4 a_weights;
-layout (location=5) in ivec4 a_groups;
diff --git a/shaders/vg/blit.fs.glsl b/shaders/vg/blit.fs.glsl
deleted file mode 100644 (file)
index b98d5e8..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-out vec4 FragColor;
-uniform sampler2D uTexMain;
-
-in vec2 aUv;
-
-void main()
-{
-   FragColor = texture( uTexMain, aUv );
-}
diff --git a/shaders/vg/blit.vs.glsl b/shaders/vg/blit.vs.glsl
deleted file mode 100644 (file)
index 2593725..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-layout (location=0) in vec2 a_co;
-out vec2 aUv;
-
-void main()
-{
-   gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);
-   aUv = a_co;
-}
diff --git a/shaders/vg/character.fs.glsl b/shaders/vg/character.fs.glsl
deleted file mode 100644 (file)
index d3c2bea..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform vec4 uColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-in float aOpacity;
-
-void main()
-{
-   vec3 diffuse = texture( uTexMain, aUv ).rgb;
-   FragColor = vec4(pow(diffuse,vec3(1.0)),aOpacity);
-}
diff --git a/shaders/vg/character.vs.glsl b/shaders/vg/character.vs.glsl
deleted file mode 100644 (file)
index 7f79f4d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-layout (location=0) in vec3 a_co;
-layout (location=1) in vec3 a_norm;
-layout (location=2) in vec4 a_colour;
-layout (location=3) in vec2 a_uv;
-
-#line      2        0 
-
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-uniform float uOpacity;
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-out float aOpacity;
-
-void main()
-{
-   vec3 world_pos = uMdl * vec4(a_co,1.0);
-   gl_Position = uPv * vec4(world_pos,1.0);
-
-   aColour = a_colour;
-   aUv = a_uv;
-   aNorm = mat3(uMdl) * a_norm;
-   aCo = a_co;
-   aOpacity = 1.0-(gl_Position.y+0.5)*uOpacity;
-}
diff --git a/shaders/vg/gate.fs.glsl b/shaders/vg/gate.fs.glsl
deleted file mode 100644 (file)
index ba48f1e..0000000
+++ /dev/null
@@ -1,27 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform sampler2D uTexWater;
-uniform vec2 uInvRes;
-uniform float uTime;
-uniform vec3 uCam;
-
-in vec3 aNorm;
-in vec2 aUv;
-in vec3 aCo;
-
-void main()
-{
-   vec2 ssuv = gl_FragCoord.xy*uInvRes;
-   vec4 mapwater = texture( uTexWater, vec2(aUv.x,aUv.y-uTime));
-
-   float undistort = smoothstep(0.1,0.6,distance( uCam, aCo )*0.1);
-   vec2 trimedge = smoothstep(0.0,0.2,1.0-abs(ssuv-0.5)*2.0);
-   undistort *= trimedge.x * trimedge.y;
-
-   vec2 warpamt = (mapwater.rg-0.5)*0.05*aUv.y*undistort;
-   vec4 mapbackbuffer = texture( uTexMain, ssuv + warpamt );
-
-   float opacity = 1.0-smoothstep(0.4,1.0,aUv.y);
-   FragColor = vec4( mapbackbuffer.rgb, opacity );
-}
diff --git a/shaders/vg/gate.vs.glsl b/shaders/vg/gate.vs.glsl
deleted file mode 100644 (file)
index e33c754..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-layout (location=0) in vec3 a_co;
-layout (location=1) in vec3 a_norm;
-layout (location=2) in vec4 a_colour;
-layout (location=3) in vec2 a_uv;
-
-#line      2        0 
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-
-out vec3 aNorm;
-out vec2 aUv;
-out vec3 aCo;
-
-void main()
-{
-   vec3 world_pos = uMdl * vec4( a_co, 1.0 );
-   gl_Position = uPv * vec4(world_pos,1.0);
-
-   aNorm = a_norm;
-   aCo = world_pos;
-   aUv = a_uv;
-}
diff --git a/shaders/vg/standard.fs.glsl b/shaders/vg/standard.fs.glsl
deleted file mode 100644 (file)
index e3f05c8..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform vec4 uColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-
-void main()
-{
-   vec3 diffuse = texture( uTexMain, aUv ).rgb;
-   float light1 = max(0.0,dot(-vec3(0.5,-0.8,0.25), aNorm));
-   float light2 = max(0.0,dot(-vec3(-0.8,0.5,-0.25), aNorm));
-   diffuse += vec3(0.2,0.2,0.2) +
-             vec3(1.0,1.0,0.9)*light1 + 
-             vec3(0.1,0.3,0.4)*light2;
-   FragColor = vec4(diffuse*uColour.rgb, aColour.a*uColour.a);
-}
diff --git a/shaders/vg/standard.vs.glsl b/shaders/vg/standard.vs.glsl
deleted file mode 100644 (file)
index f755542..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-layout (location=0) in vec3 a_co;
-layout (location=1) in vec3 a_norm;
-layout (location=2) in vec4 a_colour;
-layout (location=3) in vec2 a_uv;
-
-#line      2        0 
-
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-
-out vec4 aColour;
-out vec2 aUv;
-out vec3 aNorm;
-out vec3 aCo;
-
-void main()
-{
-   gl_Position = uPv * vec4( uMdl * vec4(a_co,1.0), 1.0 );
-   aColour = a_colour;
-   aUv = a_uv;
-   aNorm = mat3(uMdl) * a_norm;
-   aCo = a_co;
-}
diff --git a/shaders/vg/terrain.fs.glsl b/shaders/vg/terrain.fs.glsl
deleted file mode 100644 (file)
index 7bcdab8..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-// Nothing
-
-#line      2        0 
-
-void main()
-{
-
-}
diff --git a/shaders/vg/terrain.vs.glsl b/shaders/vg/terrain.vs.glsl
deleted file mode 100644 (file)
index 5bb262b..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-uniform mat4x3 uMdl;
-
-void main()
-{
-
-}
diff --git a/shaders/vg/unlit.fs.glsl b/shaders/vg/unlit.fs.glsl
deleted file mode 100644 (file)
index ec4d7ae..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform vec4 uColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-
-void main()
-{
-   vec3 diffuse = texture( uTexMain, aUv ).rgb;
-   FragColor = vec4(pow(diffuse,vec3(1.0)),1.0);
-}
diff --git a/shaders/vg/water.fs.glsl b/shaders/vg/water.fs.glsl
deleted file mode 100644 (file)
index b352e39..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform sampler2D uTexDudv;
-uniform vec2 uInvRes;
-uniform float uTime;
-
-in vec2 aUv;
-
-void main()
-{
-   vec2 ssuv = gl_FragCoord.xy*uInvRes;
-   vec4 dudva = texture( uTexDudv, aUv + vec2(uTime*0.04f,uTime*0.03f) );
-   vec4 dudvb = texture( uTexDudv, aUv - vec2(uTime*0.1,uTime*0.054) );
-
-   vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 2.0;
-
-   vec4 reflected = texture( uTexMain, ssuv+distortamt );
-   FragColor = vec4(reflected.rgb*1.0,reflected.a);
-}
diff --git a/shaders/vg/water.vs.glsl b/shaders/vg/water.vs.glsl
deleted file mode 100644 (file)
index 7751336..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-layout (location=0) in vec3 a_co;
-layout (location=1) in vec3 a_norm;
-layout (location=2) in vec4 a_colour;
-layout (location=3) in vec2 a_uv;
-
-#line      2        0 
-
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-
-out vec2 aUv;
-
-void main()
-{
-   vec3 world_pos = uMdl * vec4( a_co, 1.0 );
-   gl_Position = uPv * vec4(world_pos,1.0);
-   aUv = vec2(world_pos[0],world_pos[2])*0.15;
-}
diff --git a/shaders/viewchar.fs b/shaders/viewchar.fs
deleted file mode 100644 (file)
index 3c29360..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-uniform sampler2D uTexMain;
-uniform vec3 uCamera;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-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();
-
-   vec3 vfrag = texture( uTexMain, aUv ).rgb;
-
-   // Lighting
-   vec3 halfview = uCamera - aWorldCo;
-   float fdist = length( halfview );
-   halfview /= fdist;
-   fdist -= 0.08;
-
-   vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);
-
-   vfrag = mix( vfrag, do_light_diffuse( vfrag, qnorm ), 0.5 );
-   //vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );
-   vfrag = do_light_shadowing( vfrag );
-   vfrag = apply_fog( vfrag, fdist );
-
-   float opacity = clamp( fdist*fdist, 0.0, 1.0 );
-   oColour = vec4(vfrag,opacity);
-}
diff --git a/shaders/viewchar.h b/shaders/viewchar.h
deleted file mode 100644 (file)
index 4240728..0000000
+++ /dev/null
@@ -1,297 +0,0 @@
-#ifndef SHADER_viewchar_H
-#define SHADER_viewchar_H
-static void shader_viewchar_link(void);
-static void shader_viewchar_register(void);
-static struct vg_shader _shader_viewchar = {
-   .name = "viewchar",
-   .link = shader_viewchar_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4 uPv;\n"
-"\n"
-"// TODO: Send a previous transform matrix stack\n"
-"//\n"
-"uniform mat4x3 uTransforms[32];\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec4 co_local = vec4( a_co, 1.0 );\n"
-"   vec3 co0 = uTransforms[ a_groups[0] ] * co_local;\n"
-"   vec3 co1 = uTransforms[ a_groups[1] ] * co_local;\n"
-"   vec3 co2 = uTransforms[ a_groups[2] ] * co_local;\n"
-"   vec3 n0  = mat3(uTransforms[ a_groups[0] ]) * a_norm;\n"
-"   vec3 n1  = mat3(uTransforms[ a_groups[1] ]) * a_norm;\n"
-"   vec3 n2  = mat3(uTransforms[ a_groups[2] ]) * a_norm;\n"
-"\n"
-"   vec3 world_pos = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];\n"
-"   vec3 world_normal = n0*a_weights[0] + n1*a_weights[1] + n2*a_weights[2];\n"
-"   \n"
-"   gl_Position = uPv * vec4( world_pos, 1.0 );\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = world_normal;\n"
-"   aCo = a_co;\n"
-"   aWorldCo = world_pos;\n"
-"\n"
-"   // TODO:\n"
-"   aMotionVec0 = vec3(1.0);\n"
-"   aMotionVec1 = vec3(1.0);\n"
-"}\n"
-""},
-   .fs = 
-{
-.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"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     13        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     14        0 \n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   vec3 vfrag = texture( uTexMain, aUv ).rgb;\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = uCamera - aWorldCo;\n"
-"   float fdist = length( halfview );\n"
-"   halfview /= fdist;\n"
-"   fdist -= 0.08;\n"
-"\n"
-"   vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n"
-"\n"
-"   vfrag = mix( vfrag, do_light_diffuse( vfrag, qnorm ), 0.5 );\n"
-"   //vfrag = do_light_spec( vfrag, qnorm, halfview, 0.1 );\n"
-"   vfrag = do_light_shadowing( vfrag );\n"
-"   vfrag = apply_fog( vfrag, fdist );\n"
-"\n"
-"   float opacity = clamp( fdist*fdist, 0.0, 1.0 );\n"
-"   oColour = vec4(vfrag,opacity);\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_viewchar_uPv;
-static GLuint _uniform_viewchar_uTransforms;
-static GLuint _uniform_viewchar_uTexMain;
-static GLuint _uniform_viewchar_uCamera;
-static GLuint _uniform_viewchar_uBoard0;
-static GLuint _uniform_viewchar_uBoard1;
-static GLuint _uniform_viewchar_g_world_depth;
-static void shader_viewchar_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_viewchar_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_viewchar_uTexMain(int i){
-   glUniform1i(_uniform_viewchar_uTexMain,i);
-}
-static void shader_viewchar_uCamera(v3f v){
-   glUniform3fv(_uniform_viewchar_uCamera,1,v);
-}
-static void shader_viewchar_uBoard0(v3f v){
-   glUniform3fv(_uniform_viewchar_uBoard0,1,v);
-}
-static void shader_viewchar_uBoard1(v3f v){
-   glUniform3fv(_uniform_viewchar_uBoard1,1,v);
-}
-static void shader_viewchar_g_world_depth(int i){
-   glUniform1i(_uniform_viewchar_g_world_depth,i);
-}
-static void shader_viewchar_register(void){
-   vg_shader_register( &_shader_viewchar );
-}
-static void shader_viewchar_use(void){ glUseProgram(_shader_viewchar.id); }
-static void shader_viewchar_link(void){
-   _uniform_viewchar_uPv = glGetUniformLocation( _shader_viewchar.id, "uPv" );
-   _uniform_viewchar_uTransforms = glGetUniformLocation( _shader_viewchar.id, "uTransforms" );
-   _uniform_viewchar_uTexMain = glGetUniformLocation( _shader_viewchar.id, "uTexMain" );
-   _uniform_viewchar_uCamera = glGetUniformLocation( _shader_viewchar.id, "uCamera" );
-   _uniform_viewchar_uBoard0 = glGetUniformLocation( _shader_viewchar.id, "uBoard0" );
-   _uniform_viewchar_uBoard1 = glGetUniformLocation( _shader_viewchar.id, "uBoard1" );
-   _uniform_viewchar_g_world_depth = glGetUniformLocation( _shader_viewchar.id, "g_world_depth" );
-}
-#endif /* SHADER_viewchar_H */
diff --git a/shaders/water.fs b/shaders/water.fs
deleted file mode 100644 (file)
index 68fc66d..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-uniform sampler2D uTexMain;
-uniform sampler2D uTexDudv;
-uniform sampler2D uTexBack;
-
-uniform vec2 uInvRes;
-uniform float uTime;
-uniform vec3 uCamera;
-uniform float uSurfaceY;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-uniform vec3 uShoreColour;
-uniform vec3 uOceanColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-
-#include "common_world.glsl"
-#include "motion_vectors_fs.glsl"
-
-vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, 
-      vec4 beneath, vec4 above )
-{
-   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
-
-   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);
-
-   vec3 lightdir = vec3(0.95,0.0,-0.3);
-   vec3 specdir = reflect( -lightdir, vnorm );
-   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
-   
-   // Depth 
-   float depthblend = pow( beneath.a,0.8 );
-
-   // Composite
-   vec3 vsurface = mix(surface_tint, above.rgb, ffresnel );
-   //vsurface += spec;
-
-   return vec4( vsurface,depthblend );
-}
-
-void main()
-{
-   compute_motion_vectors();
-
-   // Create texture coords
-   vec2 ssuv = gl_FragCoord.xy*uInvRes;
-   
-   // Surface colour composite
-   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );
-
-   vec2 world_coord = aCo.xz * 0.008;
-   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );
-   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;
-   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;
-
-   vec3 surfnorm = dudva.rgb + dudvb.rgb;
-   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);
-   
-   // Foam
-   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );
-   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);
-
-   // Lighting
-   vec3 halfview = -normalize( aCo-uCamera );
-
-   // Sample textures
-   vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );
-   vec4 beneath = texture( uTexBack, ssuv );
-
-   // Fog
-   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
-
-   // Composite
-   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above );
-   vsurface.a -= fdist;
-   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
-}
diff --git a/shaders/water.h b/shaders/water.h
deleted file mode 100644 (file)
index 518b6b4..0000000
+++ /dev/null
@@ -1,374 +0,0 @@
-#ifndef SHADER_water_H
-#define SHADER_water_H
-static void shader_water_link(void);
-static void shader_water_register(void);
-static struct vg_shader _shader_water = {
-   .name = "water",
-   .link = shader_water_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexMain;\n"
-"uniform sampler2D uTexDudv;\n"
-"uniform sampler2D uTexBack;\n"
-"\n"
-"uniform vec2 uInvRes;\n"
-"uniform float uTime;\n"
-"uniform vec3 uCamera;\n"
-"uniform float uSurfaceY;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"uniform vec3 uShoreColour;\n"
-"uniform vec3 uOceanColour;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     22        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     23        0 \n"
-"\n"
-"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
-"      vec4 beneath, vec4 above )\n"
-"{\n"
-"   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
-"\n"
-"   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
-"\n"
-"   vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
-"   vec3 specdir = reflect( -lightdir, vnorm );\n"
-"   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
-"   \n"
-"   // Depth \n"
-"   float depthblend = pow( beneath.a,0.8 );\n"
-"\n"
-"   // Composite\n"
-"   vec3 vsurface = mix(surface_tint, above.rgb, ffresnel );\n"
-"   //vsurface += spec;\n"
-"\n"
-"   return vec4( vsurface,depthblend );\n"
-"}\n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   // Create texture coords\n"
-"   vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
-"   \n"
-"   // Surface colour composite\n"
-"   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
-"\n"
-"   vec2 world_coord = aCo.xz * 0.008;\n"
-"   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
-"   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
-"   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
-"\n"
-"   vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
-"   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
-"   \n"
-"   // Foam\n"
-"   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
-"   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = -normalize( aCo-uCamera );\n"
-"\n"
-"   // Sample textures\n"
-"   vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );\n"
-"   vec4 beneath = texture( uTexBack, ssuv );\n"
-"\n"
-"   // Fog\n"
-"   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
-"\n"
-"   // Composite\n"
-"   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above );\n"
-"   vsurface.a -= fdist;\n"
-"   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_water_uMdl;
-static GLuint _uniform_water_uPv;
-static GLuint _uniform_water_uPvmPrev;
-static GLuint _uniform_water_uTexMain;
-static GLuint _uniform_water_uTexDudv;
-static GLuint _uniform_water_uTexBack;
-static GLuint _uniform_water_uInvRes;
-static GLuint _uniform_water_uTime;
-static GLuint _uniform_water_uCamera;
-static GLuint _uniform_water_uSurfaceY;
-static GLuint _uniform_water_uBoard0;
-static GLuint _uniform_water_uBoard1;
-static GLuint _uniform_water_uShoreColour;
-static GLuint _uniform_water_uOceanColour;
-static GLuint _uniform_water_g_world_depth;
-static void shader_water_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_water_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_water_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_water_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_water_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_water_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_water_uTexMain(int i){
-   glUniform1i(_uniform_water_uTexMain,i);
-}
-static void shader_water_uTexDudv(int i){
-   glUniform1i(_uniform_water_uTexDudv,i);
-}
-static void shader_water_uTexBack(int i){
-   glUniform1i(_uniform_water_uTexBack,i);
-}
-static void shader_water_uInvRes(v2f v){
-   glUniform2fv(_uniform_water_uInvRes,1,v);
-}
-static void shader_water_uTime(float f){
-   glUniform1f(_uniform_water_uTime,f);
-}
-static void shader_water_uCamera(v3f v){
-   glUniform3fv(_uniform_water_uCamera,1,v);
-}
-static void shader_water_uSurfaceY(float f){
-   glUniform1f(_uniform_water_uSurfaceY,f);
-}
-static void shader_water_uBoard0(v3f v){
-   glUniform3fv(_uniform_water_uBoard0,1,v);
-}
-static void shader_water_uBoard1(v3f v){
-   glUniform3fv(_uniform_water_uBoard1,1,v);
-}
-static void shader_water_uShoreColour(v3f v){
-   glUniform3fv(_uniform_water_uShoreColour,1,v);
-}
-static void shader_water_uOceanColour(v3f v){
-   glUniform3fv(_uniform_water_uOceanColour,1,v);
-}
-static void shader_water_g_world_depth(int i){
-   glUniform1i(_uniform_water_g_world_depth,i);
-}
-static void shader_water_register(void){
-   vg_shader_register( &_shader_water );
-}
-static void shader_water_use(void){ glUseProgram(_shader_water.id); }
-static void shader_water_link(void){
-   _uniform_water_uMdl = glGetUniformLocation( _shader_water.id, "uMdl" );
-   _uniform_water_uPv = glGetUniformLocation( _shader_water.id, "uPv" );
-   _uniform_water_uPvmPrev = glGetUniformLocation( _shader_water.id, "uPvmPrev" );
-   _uniform_water_uTexMain = glGetUniformLocation( _shader_water.id, "uTexMain" );
-   _uniform_water_uTexDudv = glGetUniformLocation( _shader_water.id, "uTexDudv" );
-   _uniform_water_uTexBack = glGetUniformLocation( _shader_water.id, "uTexBack" );
-   _uniform_water_uInvRes = glGetUniformLocation( _shader_water.id, "uInvRes" );
-   _uniform_water_uTime = glGetUniformLocation( _shader_water.id, "uTime" );
-   _uniform_water_uCamera = glGetUniformLocation( _shader_water.id, "uCamera" );
-   _uniform_water_uSurfaceY = glGetUniformLocation( _shader_water.id, "uSurfaceY" );
-   _uniform_water_uBoard0 = glGetUniformLocation( _shader_water.id, "uBoard0" );
-   _uniform_water_uBoard1 = glGetUniformLocation( _shader_water.id, "uBoard1" );
-   _uniform_water_uShoreColour = glGetUniformLocation( _shader_water.id, "uShoreColour" );
-   _uniform_water_uOceanColour = glGetUniformLocation( _shader_water.id, "uOceanColour" );
-   _uniform_water_g_world_depth = glGetUniformLocation( _shader_water.id, "g_world_depth" );
-}
-#endif /* SHADER_water_H */
diff --git a/shaders/water.vs b/shaders/water.vs
deleted file mode 100644 (file)
index 6fbee77..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "vertex_standard.glsl"
-
-uniform mat4 uPv;
-uniform mat4x3 uMdl;
-
-out vec4 aUv;
-out vec3 aCo;
-
-void main()
-{
-   vec3 world_pos = uMdl * vec4( a_co, 1.0 );
-   gl_Position = uPv * vec4(world_pos,1.0);
-
-   aUv = vec4(world_pos.xz*0.005,depth_coords);
-   aCo = world_pos;
-}
diff --git a/shaders/water_fast.fs b/shaders/water_fast.fs
deleted file mode 100644 (file)
index 5f68c45..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-uniform sampler2D uTexDudv;
-
-uniform float uTime;
-uniform vec3 uCamera;
-uniform float uSurfaceY;
-uniform vec3 uBoard0;
-uniform vec3 uBoard1;
-
-uniform vec3 uShoreColour;
-uniform vec3 uOceanColour;
-
-in vec4 aColour;
-in vec2 aUv;
-in vec3 aNorm;
-in vec3 aCo;
-in vec3 aWorldCo;
-
-#include "common_world.glsl"
-#include "motion_vectors_fs.glsl"
-
-vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )
-{
-   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);
-
-   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);
-
-   vec3 lightdir = vec3(0.95,0.0,-0.3);
-   vec3 specdir = reflect( -lightdir, vnorm );
-   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
-   
-   return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );
-}
-
-void main()
-{
-   compute_motion_vectors();
-
-   // Surface colour composite
-   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );
-
-   vec2 world_coord = aCo.xz * 0.008;
-   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );
-   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;
-   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;
-
-   vec3 surfnorm = dudva.rgb + dudvb.rgb;
-   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);
-   
-   // Foam
-   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );
-   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);
-
-   // Lighting
-   vec3 halfview = -normalize( aCo-uCamera );
-
-   // Fog
-   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);
-
-   // Composite
-   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );
-   vsurface.a -= fdist;
-   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );
-}
diff --git a/shaders/water_fast.h b/shaders/water_fast.h
deleted file mode 100644 (file)
index 0370cd6..0000000
+++ /dev/null
@@ -1,341 +0,0 @@
-#ifndef SHADER_water_fast_H
-#define SHADER_water_fast_H
-static void shader_water_fast_link(void);
-static void shader_water_fast_register(void);
-static struct vg_shader _shader_water_fast = {
-   .name = "water_fast",
-   .link = shader_water_fast_link,
-   .vs = 
-{
-.static_src = 
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec3 a_norm;\n"
-"layout (location=2) in vec2 a_uv;\n"
-"layout (location=3) in vec4 a_colour;\n"
-"layout (location=4) in vec4 a_weights;\n"
-"layout (location=5) in ivec4 a_groups;\n"
-"\n"
-"#line      2        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"out vec3 aMotionVec0;\n"
-"out vec3 aMotionVec1;\n"
-"\n"
-"void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
-"{\n"
-"   // This magically solves some artifacting errors!\n"
-"   //\n"
-"   vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
-"\n"
-"   aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
-"   aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
-"}\n"
-"\n"
-"#line      3        0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"out vec2 aUv;\n"
-"out vec3 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-"   vec3 world_pos0 = uMdl     * vec4( a_co, 1.0 );\n"
-"   vec4 vproj0     = uPv      * vec4( world_pos0, 1.0 );\n"
-"   vec4 vproj1     = uPvmPrev * vec4( a_co, 1.0 );\n"
-"\n"
-"   vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-"   gl_Position = vproj0;\n"
-"   aWorldCo = world_pos0;\n"
-"   aColour = a_colour;\n"
-"   aUv = a_uv;\n"
-"   aNorm = mat3(uMdl) * a_norm;\n"
-"   aCo = a_co;\n"
-"}\n"
-""},
-   .fs = 
-{
-.static_src = 
-"uniform sampler2D uTexDudv;\n"
-"\n"
-"uniform float uTime;\n"
-"uniform vec3 uCamera;\n"
-"uniform float uSurfaceY;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"uniform vec3 uShoreColour;\n"
-"uniform vec3 uOceanColour;\n"
-"\n"
-"in vec4 aColour;\n"
-"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"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"\n"
-"// Standard diffuse + spec models\n"
-"// ==============================\n"
-"\n"
-"vec3 do_light_diffuse( vec3 vfrag, 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 vfrag * vtotal;\n"
-"}\n"
-"\n"
-"vec3 do_light_spec( vec3 vfrag, 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 vfrag + vcolour*spec*fintensity;\n"
-"}\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 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 do_light_shadowing_old( vec3 vfrag )\n"
-"{\n"
-"   float faccum = 0.0;\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 ));\n"
-"   faccum += shadow_sample( vec3( 0.0, 0.5, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 2.0, 0.3, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 3.0, 1.0, 0.0 )*1.5);\n"
-"   faccum += shadow_sample( vec3( 5.0, 1.0, 0.0 )*1.5);\n"
-"   return mix( vfrag, g_ambient_colour.rgb, faccum );\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 do_light_shadowing( vec3 vfrag )\n"
-"{\n"
-"   if( g_shadow_samples == 0 )\n"
-"   {\n"
-"      return vfrag;\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"
-"   // 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"
-"   famt = max( player_shadow*0.8, famt );\n"
-"   return mix( vfrag, g_ambient_colour.rgb, famt );\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"
-"#line     19        0 \n"
-"#line       1        2 \n"
-"const float k_motion_lerp_amount = 0.01;\n"
-"\n"
-"#line      2        0 \n"
-"\n"
-"layout (location = 1) out vec2 oMotionVec;\n"
-"\n"
-"in vec3 aMotionVec0;\n"
-"in vec3 aMotionVec1;\n"
-"\n"
-"void compute_motion_vectors()\n"
-"{\n"
-"   // Write motion vectors\n"
-"   vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
-"   vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
-"\n"
-"   oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
-"}\n"
-"\n"
-"#line     20        0 \n"
-"\n"
-"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )\n"
-"{\n"
-"   vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
-"\n"
-"   float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
-"\n"
-"   vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
-"   vec3 specdir = reflect( -lightdir, vnorm );\n"
-"   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
-"   \n"
-"   return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );\n"
-"}\n"
-"\n"
-"void main()\n"
-"{\n"
-"   compute_motion_vectors();\n"
-"\n"
-"   // Surface colour composite\n"
-"   float depthvalue = clamp( -world_depth_sample( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
-"\n"
-"   vec2 world_coord = aCo.xz * 0.008;\n"
-"   vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
-"   vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
-"   vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
-"\n"
-"   vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
-"   surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
-"   \n"
-"   // Foam\n"
-"   float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
-"   fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
-"\n"
-"   // Lighting\n"
-"   vec3 halfview = -normalize( aCo-uCamera );\n"
-"\n"
-"   // Fog\n"
-"   float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
-"\n"
-"   // Composite\n"
-"   vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );\n"
-"   vsurface.a -= fdist;\n"
-"   oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );\n"
-"}\n"
-""},
-};
-
-static GLuint _uniform_water_fast_uMdl;
-static GLuint _uniform_water_fast_uPv;
-static GLuint _uniform_water_fast_uPvmPrev;
-static GLuint _uniform_water_fast_uTexDudv;
-static GLuint _uniform_water_fast_uTime;
-static GLuint _uniform_water_fast_uCamera;
-static GLuint _uniform_water_fast_uSurfaceY;
-static GLuint _uniform_water_fast_uBoard0;
-static GLuint _uniform_water_fast_uBoard1;
-static GLuint _uniform_water_fast_uShoreColour;
-static GLuint _uniform_water_fast_uOceanColour;
-static GLuint _uniform_water_fast_g_world_depth;
-static void shader_water_fast_uMdl(m4x3f m){
-   glUniformMatrix4x3fv(_uniform_water_fast_uMdl,1,GL_FALSE,(float*)m);
-}
-static void shader_water_fast_uPv(m4x4f m){
-   glUniformMatrix4fv(_uniform_water_fast_uPv,1,GL_FALSE,(float*)m);
-}
-static void shader_water_fast_uPvmPrev(m4x4f m){
-   glUniformMatrix4fv(_uniform_water_fast_uPvmPrev,1,GL_FALSE,(float*)m);
-}
-static void shader_water_fast_uTexDudv(int i){
-   glUniform1i(_uniform_water_fast_uTexDudv,i);
-}
-static void shader_water_fast_uTime(float f){
-   glUniform1f(_uniform_water_fast_uTime,f);
-}
-static void shader_water_fast_uCamera(v3f v){
-   glUniform3fv(_uniform_water_fast_uCamera,1,v);
-}
-static void shader_water_fast_uSurfaceY(float f){
-   glUniform1f(_uniform_water_fast_uSurfaceY,f);
-}
-static void shader_water_fast_uBoard0(v3f v){
-   glUniform3fv(_uniform_water_fast_uBoard0,1,v);
-}
-static void shader_water_fast_uBoard1(v3f v){
-   glUniform3fv(_uniform_water_fast_uBoard1,1,v);
-}
-static void shader_water_fast_uShoreColour(v3f v){
-   glUniform3fv(_uniform_water_fast_uShoreColour,1,v);
-}
-static void shader_water_fast_uOceanColour(v3f v){
-   glUniform3fv(_uniform_water_fast_uOceanColour,1,v);
-}
-static void shader_water_fast_g_world_depth(int i){
-   glUniform1i(_uniform_water_fast_g_world_depth,i);
-}
-static void shader_water_fast_register(void){
-   vg_shader_register( &_shader_water_fast );
-}
-static void shader_water_fast_use(void){ glUseProgram(_shader_water_fast.id); }
-static void shader_water_fast_link(void){
-   _uniform_water_fast_uMdl = glGetUniformLocation( _shader_water_fast.id, "uMdl" );
-   _uniform_water_fast_uPv = glGetUniformLocation( _shader_water_fast.id, "uPv" );
-   _uniform_water_fast_uPvmPrev = glGetUniformLocation( _shader_water_fast.id, "uPvmPrev" );
-   _uniform_water_fast_uTexDudv = glGetUniformLocation( _shader_water_fast.id, "uTexDudv" );
-   _uniform_water_fast_uTime = glGetUniformLocation( _shader_water_fast.id, "uTime" );
-   _uniform_water_fast_uCamera = glGetUniformLocation( _shader_water_fast.id, "uCamera" );
-   _uniform_water_fast_uSurfaceY = glGetUniformLocation( _shader_water_fast.id, "uSurfaceY" );
-   _uniform_water_fast_uBoard0 = glGetUniformLocation( _shader_water_fast.id, "uBoard0" );
-   _uniform_water_fast_uBoard1 = glGetUniformLocation( _shader_water_fast.id, "uBoard1" );
-   _uniform_water_fast_uShoreColour = glGetUniformLocation( _shader_water_fast.id, "uShoreColour" );
-   _uniform_water_fast_uOceanColour = glGetUniformLocation( _shader_water_fast.id, "uOceanColour" );
-   _uniform_water_fast_g_world_depth = glGetUniformLocation( _shader_water_fast.id, "g_world_depth" );
-}
-#endif /* SHADER_water_fast_H */
diff --git a/shaders/water_old.fs b/shaders/water_old.fs
deleted file mode 100644 (file)
index 7ffee31..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-#include "water_ref.glsl"
-
-out vec4 FragColor;
-
-uniform sampler2D uTexMain;
-uniform sampler2D uTexDudv;
-uniform sampler2D uTexDepth;
-uniform sampler2D uTexBack;
-
-uniform vec2 uInvRes;
-uniform float uTime;
-
-uniform vec3 uCamera;
-uniform float uSurfaceY;
-
-in vec4 aUv;
-in vec3 aCo;
-in float aDepth;
-
-void main()
-{
-   // Reflected and warped texture
-   vec2 ssuv = gl_FragCoord.xy*uInvRes;
-
-   vec4 dudva = texture( uTexDudv, aUv.xy - vec2(uTime*0.004f,uTime*0.003f) );
-   vec4 dudvb = texture( uTexDudv, aUv.xy*0.7 - vec2(uTime*0.01,uTime*0.0054) );
-   vec2 distortamt = (dudva.rg-0.5) * (dudvb.ba-0.5) * 0.6;
-
-   vec4 reflected = texture( uTexMain, ssuv+distortamt );
-   
-   // Surface colour composite
-   float depthvalue = texture( uTexDepth, aUv.zw ).r;
-
-   vec3 colour_shore = vec3( 0.21, 0.6, 0.8 );
-   vec3 colour_ocean = vec3( 0.01, 0.1, 0.2 );
-   vec3 surface_tint = mix(colour_shore, colour_ocean, pow(depthvalue,1.8))*1.5;
-   
-   // Foam
-   float fband = fract( aCo.z*0.1+uTime*0.1-depthvalue*10.0 );
-   fband = step( fband+dudvb.g*0.8, 0.5 ) * max((1.0-depthvalue*4.0),0.0);
-
-   // Lighting
-   vec3 surfnorm = vec3(distortamt.x,1.0,distortamt.y);
-   
-   vec3 halfview = -normalize( aCo-uCamera );
-   float ffresnel = pow(1.0-dot( surfnorm, halfview ),5.0);
-
-   vec3 lightdir = vec3(0.95,0.0,-0.3);
-   vec3 specdir = reflect( -lightdir, surfnorm );
-   float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;
-   
-   // Depth 
-   vec4 backsample = texture( uTexBack, ssuv+distortamt*0.1 );
-   float depthblend = pow(backsample.a,0.8);
-
-   // Composite
-   vec3 vsurface = mix(surface_tint*backsample.rgb, reflected.rgb, ffresnel );
-   vsurface += spec;
-   
-   FragColor = mix( vec4(vsurface,depthblend), vec4(1.0,1.0,1.0,0.8), fband );
-}
diff --git a/shaders/water_ref.glsl b/shaders/water_ref.glsl
deleted file mode 100644 (file)
index e69de29..0000000
index c724906a2a1ff5c88da28825fb169648c8520cc4..4c531a4736f66dee33740b3cb13905db8e9777c9 100644 (file)
@@ -232,7 +232,7 @@ VG_STATIC void load_playermodels(void)
    vg_release_thread_sync();
 
    /* FIXME: hack */
-   shader_viewchar_register();
+   shader_model_character_view_register();
    vg_acquire_thread_sync();
    {
       vg_tex2d_init( (vg_tex2d *[]){ &localplayer_texture }, 1 );
diff --git a/world.h b/world.h
index f70f9ee87efc680ff40da95cb1064b7466f2283b..4f2c5c3a383df91819f794380c64feaf8fa0ff84 100644 (file)
--- a/world.h
+++ b/world.h
@@ -19,13 +19,13 @@ VG_STATIC int ray_world( v3f pos, v3f dir, ray_hit *hit );
 #include "bvh.h"
 #include "model.h"
 
-#include "shaders/terrain.h"
-#include "shaders/sky.h"
-#include "shaders/standard.h"
-#include "shaders/vblend.h"
-#include "shaders/gpos.h"
-#include "shaders/blitcolour.h"
-#include "shaders/alphatest.h"
+#include "shaders/scene_standard.h"
+#include "shaders/scene_standard_alphatest.h"
+#include "shaders/scene_vertex_blend.h"
+#include "shaders/scene_terrain.h"
+#include "shaders/scene_depth.h"
+
+#include "shaders/model_sky.h"
 
 typedef struct teleport_gate teleport_gate;
 
@@ -226,6 +226,16 @@ VG_STATIC struct gworld
    * logic_achievements;
    u32 achievement_count;
 
+   /* 
+    * Lights
+    */
+   struct world_light
+   {
+      v3f co;
+      v4f colour;
+   }
+   * lights;
+   u32 light_count;
 
    /*
     * Routes (world_routes.h)
@@ -415,11 +425,13 @@ VG_STATIC void world_init(void)
    world.sky_rate = 1.0;
    world.sky_target_rate = 1.0;
 
-   shader_terrain_register();
-   shader_sky_register();
-   shader_gpos_register();
-   shader_blitcolour_register();
-   shader_alphatest_register();
+   shader_scene_standard_register();
+   shader_scene_standard_alphatest_register();
+   shader_scene_vertex_blend_register();
+   shader_scene_terrain_register();
+   shader_scene_depth_register();
+
+   shader_model_sky_register();
 
    vg_info( "Loading world resources\n" );
    
@@ -621,6 +633,22 @@ VG_STATIC void world_update( v3f pos )
                                                         0xff00ff00 );
    }
 
+   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;
+
+      colour |= r;
+      colour |= g << 8;
+      colour |= b << 16;
+
+      vg_line_pt3( light->co, 0.25f, colour );
+   }
+
    world.in_trigger = in_trigger;
    sfd_update();
 }
index 1bf8afef0c4584d294bbe044780fbbd4485759d3..d92537eb1566fada932ddb4c4dc121828f776eaf 100644 (file)
 #include "render.h"
 #include "camera.h"
 
-#include "shaders/gatelq.h"
+#include "shaders/model_gate.h"
 #include "world_water.h"
 
-
 VG_STATIC void gate_transform_update( teleport_gate *gate )
 {
    m4x3f to_local;
@@ -32,7 +31,7 @@ VG_STATIC void world_gates_init(void)
 {
    vg_info( "world_gates_init\n" );
 
-   shader_gatelq_register();
+   shader_model_gate_register();
 
    vg_linear_clear( vg_mem.scratch );
    mdl_context *mgate = mdl_load_full( vg_mem.scratch, "models/rs_gate.mdl" );
@@ -110,12 +109,12 @@ VG_STATIC int render_gate( teleport_gate *gate, camera *cam )
       m4x3_copy( gate->to_world, gate_xform );
       m4x3_scalev( gate_xform, (v3f){ gate->dims[0], gate->dims[1], 1.0f } );
    
-      shader_gatelq_use();
-      shader_gatelq_uPv( cam->mtx.pv );
-      shader_gatelq_uMdl( gate_xform );
-      shader_gatelq_uCam( cam->pos );
-      shader_gatelq_uTime( vg.time*0.25f );
-      shader_gatelq_uInvRes( (v2f){
+      shader_model_gate_use();
+      shader_model_gate_uPv( cam->mtx.pv );
+      shader_model_gate_uMdl( gate_xform );
+      shader_model_gate_uCam( cam->pos );
+      shader_model_gate_uTime( vg.time*0.25f );
+      shader_model_gate_uInvRes( (v2f){
             1.0f / (float)vg.window_x,
             1.0f / (float)vg.window_y });
 
index 89fea39c9f5068227257a806da896f1aad23db4a..f5e7599c7fe260f17439259f3ea1e0e49ac16e85 100644 (file)
@@ -182,6 +182,11 @@ VG_STATIC void world_ents_allocate(void)
          k_classtype_logic_achievement,
          (void*)&world.logic_achievements,
          sizeof(struct logic_achievement)
+      },
+      {
+         k_classtype_point_light,
+         (void*)&world.lights,
+         sizeof(struct world_light)
       }
    };
 
@@ -325,6 +330,16 @@ VG_STATIC void world_pct_achievement( mdl_node *pnode )
    world.achievement_count ++;
 }
 
+VG_STATIC void world_pct_point_light( mdl_node *pnode )
+{
+   struct world_light *light = &world.lights[ world.light_count ];
+   v3_copy( pnode->co, light->co );
+
+   struct classtype_point_light *inf = mdl_get_entdata( world.meta, pnode );
+   v4_copy( inf->colour, light->colour );
+
+   world.light_count ++;
+}
 
 VG_STATIC void world_entities_process(void)
 {
@@ -340,7 +355,8 @@ VG_STATIC void world_entities_process(void)
       { k_classtype_audio,    world_pct_audio },
       { k_classtype_trigger,  world_pct_trigger },
       { k_classtype_logic_relay, world_pct_relay },
-      { k_classtype_logic_achievement, world_pct_achievement }
+      { k_classtype_logic_achievement, world_pct_achievement },
+      { k_classtype_point_light, world_pct_point_light }
    };
 
    for( int i=0; i<world.meta->info.node_count; i++ )
@@ -360,6 +376,42 @@ VG_STATIC void world_entities_process(void)
    }
 }
 
+VG_STATIC void world_scene_compute_light_clusters( scene *sc )
+{
+   for( int i=0; i<sc->vertex_count; i++ )
+   {
+      scene_vert *vert = &sc->arrvertices[i];
+      vert->lights[0] = 255;
+      vert->lights[1] = 255;
+      vert->lights[2] = 255;
+      vert->lights[3] = 255;
+
+      float distances[4] = { INFINITY, INFINITY, INFINITY, INFINITY };
+
+      for( int j=0; j<world.light_count; j ++ )
+      {
+         float dist = v3_dist2( world.lights[j].co, vert->co );
+
+         int best_pos = 4;
+         for( int k=best_pos-1; k>=0; k -- )
+            if( dist < distances[k] )
+               best_pos = k;
+
+         if( best_pos < 4 )
+         {
+            for( int k=3; k>best_pos; k -- )
+            {
+               distances[k] = distances[k-1];
+               vert->lights[k] = vert->lights[k-1];
+            }
+
+            distances[best_pos] = dist;
+            vert->lights[best_pos] = j;
+         }
+      }
+   }
+}
+
 VG_STATIC void world_generate(void)
 {
    /* 
@@ -387,10 +439,8 @@ VG_STATIC void world_generate(void)
 
       scene_copy_slice( world.scene_geo, &mat->sm_geo );
    }
+   world_scene_compute_light_clusters( world.scene_geo );
 
-
-
-   
    /* compress that bad boy */
    world.scene_geo = scene_fix( world.dynamic_vgl, world.scene_geo );
 
@@ -434,6 +484,7 @@ VG_STATIC void world_generate(void)
 
       scene_copy_slice( world.scene_no_collide, &mat->sm_no_collide );
    }
+   world_scene_compute_light_clusters( world.scene_no_collide );
 
    /* upload and free that */
    vg_acquire_thread_sync();
@@ -531,6 +582,17 @@ VG_STATIC void world_post_process(void)
       v4_copy( info_vec, winfo->g_depth_bounds );
 
       winfo->g_water_fog = 0.04f;
+
+      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,
+                  gpipeline.ub_world_lighting.g_point_light_colours[i] );
+         v3_copy( light->co, 
+                  gpipeline.ub_world_lighting.g_point_light_positions[i] );
+      }
+
       render_update_lighting_ub();
    }
 
@@ -664,6 +726,9 @@ VG_STATIC void world_unload(void)
    world.triggers = NULL;
    world.trigger_count = 0;
 
+   world.lights = NULL;
+   world.light_count = 0;
+
    world.logic_relays = NULL;
    world.relay_count = 0;
 
index e1c17c828ee9824e4408b3869a470459bc8d36c0..e738d372dd59d019011595e32f80829f85ac7146 100644 (file)
@@ -84,20 +84,20 @@ VG_STATIC void render_world_vb( camera *cam )
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
-   shader_vblend_use();
-   shader_vblend_uTexGarbage(0);
-   shader_vblend_uTexGradients(1);
-   shader_link_standard_ub( _shader_vblend.id, 2 );
+   shader_scene_vertex_blend_use();
+   shader_scene_vertex_blend_uTexGarbage(0);
+   shader_scene_vertex_blend_uTexGradients(1);
+   shader_link_standard_ub( _shader_scene_vertex_blend.id, 2 );
    vg_tex2d_bind( &tex_terrain_noise, 0 );
 
-   shader_vblend_uPv( cam->mtx.pv );
-   shader_vblend_uPvmPrev( cam->mtx_prev.pv );
-   shader_vblend_uMdl( identity_matrix );
-   shader_vblend_uCamera( cam->transform[3] );
-   shader_vblend_uBoard0( TEMP_BOARD_0 );
-   shader_vblend_uBoard1( TEMP_BOARD_1 );
+   shader_scene_vertex_blend_uPv( cam->mtx.pv );
+   shader_scene_vertex_blend_uPvmPrev( cam->mtx_prev.pv );
+   shader_scene_vertex_blend_uMdl( identity_matrix );
+   shader_scene_vertex_blend_uCamera( cam->transform[3] );
+   shader_scene_vertex_blend_uBoard0( TEMP_BOARD_0 );
+   shader_scene_vertex_blend_uBoard1( TEMP_BOARD_1 );
 
-   world_render_both_stages( k_shader_standard_vertex_blend, 
+   world_render_both_stages( k_shader_standard_vertex_blend,
                              bindpoint_diffuse_texture1 );
 }
 
@@ -106,18 +106,18 @@ VG_STATIC void render_world_standard( camera *cam )
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
-   shader_standard_use();
-   shader_standard_uTexGarbage(0);
-   shader_standard_uTexMain(1);
-   shader_standard_uPv( cam->mtx.pv );
-   shader_standard_uPvmPrev( cam->mtx_prev.pv );
-   shader_link_standard_ub( _shader_standard.id, 2 );
+   shader_scene_standard_use();
+   shader_scene_standard_uTexGarbage(0);
+   shader_scene_standard_uTexMain(1);
+   shader_scene_standard_uPv( cam->mtx.pv );
+   shader_scene_standard_uPvmPrev( cam->mtx_prev.pv );
+   shader_link_standard_ub( _shader_scene_standard.id, 2 );
    bind_terrain_noise();
 
-   shader_standard_uMdl( identity_matrix );
-   shader_standard_uCamera( cam->transform[3] );
-   shader_standard_uBoard0( TEMP_BOARD_0 );
-   shader_standard_uBoard1( TEMP_BOARD_1 );
+   shader_scene_standard_uMdl( identity_matrix );
+   shader_scene_standard_uCamera( cam->transform[3] );
+   shader_scene_standard_uBoard0( TEMP_BOARD_0 );
+   shader_scene_standard_uBoard1( TEMP_BOARD_1 );
    
    world_render_both_stages( k_shader_standard,
                              bindpoint_diffuse_texture1 );
@@ -128,18 +128,18 @@ VG_STATIC void render_world_alphatest( camera *cam )
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
-   shader_alphatest_use();
-   shader_alphatest_uTexGarbage(0);
-   shader_alphatest_uTexMain(1);
-   shader_alphatest_uPv( cam->mtx.pv );
-   shader_alphatest_uPvmPrev( cam->mtx_prev.pv );
-   shader_link_standard_ub( _shader_alphatest.id, 2 );
+   shader_scene_standard_alphatest_use();
+   shader_scene_standard_alphatest_uTexGarbage(0);
+   shader_scene_standard_alphatest_uTexMain(1);
+   shader_scene_standard_alphatest_uPv( cam->mtx.pv );
+   shader_scene_standard_alphatest_uPvmPrev( cam->mtx_prev.pv );
+   shader_link_standard_ub( _shader_scene_standard_alphatest.id, 2 );
    bind_terrain_noise();
 
-   shader_alphatest_uMdl( identity_matrix );
-   shader_alphatest_uCamera( cam->transform[3] );
-   shader_alphatest_uBoard0( TEMP_BOARD_0 );
-   shader_alphatest_uBoard1( TEMP_BOARD_1 );
+   shader_scene_standard_alphatest_uMdl( identity_matrix );
+   shader_scene_standard_alphatest_uCamera( cam->transform[3] );
+   shader_scene_standard_alphatest_uBoard0( TEMP_BOARD_0 );
+   shader_scene_standard_alphatest_uBoard1( TEMP_BOARD_1 );
 
    glDisable(GL_CULL_FACE);
    
@@ -154,8 +154,8 @@ VG_STATIC void bindpoint_terrain( struct world_material *mat )
    glActiveTexture( GL_TEXTURE1 );
    glBindTexture( GL_TEXTURE_2D, world.textures[ mat->info.tex_diffuse ] );
 
-   shader_terrain_uSandColour( mat->info.colour );
-   shader_terrain_uBlendOffset( mat->info.colour1 );
+   shader_scene_terrain_uSandColour( mat->info.colour );
+   shader_scene_terrain_uBlendOffset( mat->info.colour1 );
 }
 
 VG_STATIC void render_terrain( camera *cam )
@@ -163,20 +163,20 @@ VG_STATIC void render_terrain( camera *cam )
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
-   shader_terrain_use();
-   shader_terrain_uTexGarbage(0);
-   shader_terrain_uTexGradients(1);
-   shader_link_standard_ub( _shader_terrain.id, 2 );
+   shader_scene_terrain_use();
+   shader_scene_terrain_uTexGarbage(0);
+   shader_scene_terrain_uTexGradients(1);
+   shader_link_standard_ub( _shader_scene_terrain.id, 2 );
 
    vg_tex2d_bind( &tex_terrain_noise, 0 );
 
-   shader_terrain_uPv( cam->mtx.pv );
-   shader_terrain_uPvmPrev( cam->mtx_prev.pv );
+   shader_scene_terrain_uPv( cam->mtx.pv );
+   shader_scene_terrain_uPvmPrev( cam->mtx_prev.pv );
 
-   shader_terrain_uMdl( identity_matrix );
-   shader_terrain_uCamera( cam->transform[3] );
-   shader_terrain_uBoard0( TEMP_BOARD_0 );
-   shader_terrain_uBoard1( TEMP_BOARD_1 );
+   shader_scene_terrain_uMdl( identity_matrix );
+   shader_scene_terrain_uCamera( cam->transform[3] );
+   shader_scene_terrain_uBoard0( TEMP_BOARD_0 );
+   shader_scene_terrain_uBoard1( TEMP_BOARD_1 );
 
    world_render_both_stages( k_shader_terrain_blend, bindpoint_terrain );
 }
@@ -210,12 +210,12 @@ VG_STATIC void render_sky( camera *cam )
    /*
     * Draw
     */
-   shader_sky_use();
-   shader_sky_uMdl( identity_matrix );
-   shader_sky_uPv( pv );
-   shader_sky_uPvmPrev( pv_prev );
-   shader_sky_uTexGarbage(0);
-   shader_sky_uTime( world.sky_time );
+   shader_model_sky_use();
+   shader_model_sky_uMdl( identity_matrix );
+   shader_model_sky_uPv( pv );
+   shader_model_sky_uPvmPrev( pv_prev );
+   shader_model_sky_uTexGarbage(0);
+   shader_model_sky_uTime( world.sky_time );
 
    vg_tex2d_bind( &tex_terrain_noise, 0 );
 
@@ -292,11 +292,11 @@ VG_STATIC void render_world_depth( camera *cam )
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
-   shader_gpos_use();
-   shader_gpos_uCamera( cam->transform[3] );
-   shader_gpos_uPv( cam->mtx.pv );
-   shader_gpos_uPvmPrev( cam->mtx_prev.pv );
-   shader_gpos_uMdl( identity_matrix );
+   shader_scene_depth_use();
+   shader_scene_depth_uCamera( cam->transform[3] );
+   shader_scene_depth_uPv( cam->mtx.pv );
+   shader_scene_depth_uPvmPrev( cam->mtx_prev.pv );
+   shader_scene_depth_uMdl( identity_matrix );
    
    mesh_bind( &world.mesh_geo );
    mesh_draw( &world.mesh_geo );
index 4e455d345b8f4728ae2cdc9c3c305aefb9a76203..35f38f0f04a094394f80ab15a6d6f5563abafa42 100644 (file)
@@ -9,8 +9,11 @@
 #include "world.h"
 #include "world_gate.h"
 
+#if 0
 #include "shaders/vblend.h"
-#include "shaders/route.h"
+#endif
+
+#include "shaders/scene_route.h"
 #include "shaders/routeui.h"
 
 
@@ -1079,7 +1082,7 @@ VG_STATIC void world_routes_init(void)
    world.time = RESET_MAX_TIME*2.0;
    world.last_use = 0.0;
 
-   shader_route_register();
+   shader_scene_route_register();
    shader_routeui_register();
 
    vg_acquire_thread_sync();
@@ -1138,17 +1141,17 @@ VG_STATIC void render_world_routes( camera *cam )
    m4x3f identity_matrix;
    m4x3_identity( identity_matrix );
 
-   shader_route_use();
-   shader_route_uTexGarbage(0);
-   shader_link_standard_ub( _shader_route.id, 2 );
+   shader_scene_route_use();
+   shader_scene_route_uTexGarbage(0);
+   shader_link_standard_ub( _shader_scene_route.id, 2 );
    bind_terrain_noise();
 
-   shader_route_uPv( cam->mtx.pv );
-   shader_route_uPvmPrev( cam->mtx_prev.pv );
-   shader_route_uMdl( identity_matrix );
-   shader_route_uCamera( cam->transform[3] );
-   shader_route_uBoard0( TEMP_BOARD_0 );
-   shader_route_uBoard1( TEMP_BOARD_1 );
+   shader_scene_route_uPv( cam->mtx.pv );
+   shader_scene_route_uPvmPrev( cam->mtx_prev.pv );
+   shader_scene_route_uMdl( identity_matrix );
+   shader_scene_route_uCamera( cam->transform[3] );
+   shader_scene_route_uBoard0( TEMP_BOARD_0 );
+   shader_scene_route_uBoard1( TEMP_BOARD_1 );
 
    mesh_bind( &world.mesh_route_lines );
 
@@ -1160,7 +1163,7 @@ VG_STATIC void render_world_routes( camera *cam )
       v3_lerp( (v3f){0.7f,0.7f,0.7f}, route->colour, route->factive, colour );
       colour[3] = 1.0f;
 
-      shader_route_uColour( colour );
+      shader_scene_route_uColour( colour );
       mdl_draw_submesh( &route->sm );
    }
 }
index d7aeb552fb55b585131a33ec3327007b09f63f2a..3fbbe949482a775ebba620a53b71e25b36f86c50 100644 (file)
@@ -7,8 +7,10 @@
 
 #include "world.h"
 
+#if 0
 #include "shaders/scoretext.h"
 #include "shaders/vblend.h"
+#endif
 
 vg_tex2d tex_scoretext = { .path = "textures/scoretext.qoi",
                            .flags = VG_TEXTURE_CLAMP|VG_TEXTURE_NEAREST };
@@ -104,8 +106,8 @@ VG_STATIC void sfd_update(void)
 VG_STATIC void bind_terrain_noise(void);
 VG_STATIC void sfd_render( camera *cam, m4x3f transform )
 {
+#if 0
    mesh_bind( &world.sfd.mesh_display );
-
    shader_scoretext_use();
    shader_scoretext_uTexGarbage(0);
    shader_scoretext_uTexGradients(1);
@@ -147,6 +149,7 @@ VG_STATIC void sfd_render( camera *cam, m4x3f transform )
    
    mesh_bind( &world.sfd.mesh_base );
    mesh_draw( &world.sfd.mesh_base );
+#endif
 }
 
 VG_STATIC int world_sfd_test( int argc, const char *argv[] )
@@ -163,7 +166,10 @@ VG_STATIC int world_sfd_test( int argc, const char *argv[] )
 VG_STATIC void world_sfd_init(void)
 {
    vg_info( "world_sfd_init\n" );
+
+#if 0
    shader_scoretext_register();
+#endif
 
        vg_function_push( (struct vg_cmd){
                .name = "sfd",
index cd4836a44cfefcdd550dc33aca5a687193745345..d2447b513e22be1e6cd1503084b989d4f7205ff0 100644 (file)
@@ -7,8 +7,8 @@
 
 #include "world.h"
 #include "render.h"
-#include "shaders/water.h"
-#include "shaders/water_fast.h"
+#include "shaders/model_water.h"
+#include "shaders/model_water_fast.h"
 #include "scene.h"
 
 vg_tex2d tex_water_surf = { .path = "textures/water_surf.qoi" };
@@ -16,8 +16,8 @@ vg_tex2d tex_water_surf = { .path = "textures/water_surf.qoi" };
 VG_STATIC void world_water_init(void)
 {
    vg_info( "world_water_init\n" );
-   shader_water_register();
-   shader_water_fast_register();
+   shader_model_water_register();
+   shader_model_water_fast_register();
 
    vg_acquire_thread_sync();
    {
@@ -115,31 +115,31 @@ VG_STATIC void render_water_surface( camera *cam )
    if( vg.quality_profile == k_quality_profile_high )
    {
       /* Draw surface */
-      shader_water_use();
+      shader_model_water_use();
       
       render_fb_bind_texture( gpipeline.fb_water_reflection, 0, 0 );
-      shader_water_uTexMain( 0 );
+      shader_model_water_uTexMain( 0 );
 
       vg_tex2d_bind( &tex_water_surf, 1 );
-      shader_water_uTexDudv( 1 );
-      shader_water_uInvRes( (v2f){
+      shader_model_water_uTexDudv( 1 );
+      shader_model_water_uInvRes( (v2f){
             1.0f / (float)vg.window_x,
             1.0f / (float)vg.window_y });
 
-      shader_link_standard_ub( _shader_water.id, 2 );
+      shader_link_standard_ub( _shader_model_water.id, 2 );
 
       render_fb_bind_texture( gpipeline.fb_water_beneath, 0, 3 );
-      shader_water_uTexBack( 3 );
-      shader_water_uTime( world.time );
-      shader_water_uCamera( cam->transform[3] );
-      shader_water_uSurfaceY( world.water.height );
+      shader_model_water_uTexBack( 3 );
+      shader_model_water_uTime( world.time );
+      shader_model_water_uCamera( cam->transform[3] );
+      shader_model_water_uSurfaceY( world.water.height );
 
-      shader_water_uPv( cam->mtx.pv );
-      shader_water_uPvmPrev( cam->mtx_prev.pv );
+      shader_model_water_uPv( cam->mtx.pv );
+      shader_model_water_uPvmPrev( cam->mtx_prev.pv );
 
       m4x3f full;
       m4x3_identity( full );
-      shader_water_uMdl( full );
+      shader_model_water_uMdl( full );
 
       glEnable(GL_BLEND);
       glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -153,8 +153,8 @@ VG_STATIC void render_water_surface( camera *cam )
 
          if( mat->info.shader == k_shader_water )
          {
-            shader_water_uShoreColour( mat->info.colour );
-            shader_water_uOceanColour( mat->info.colour1 );
+            shader_model_water_uShoreColour( mat->info.colour );
+            shader_model_water_uOceanColour( mat->info.colour1 );
 
             mdl_draw_submesh( &mat->sm_no_collide );
          }
@@ -164,20 +164,20 @@ VG_STATIC void render_water_surface( camera *cam )
    }
    else if( vg.quality_profile == k_quality_profile_low )
    {
-      shader_water_fast_use();
+      shader_model_water_fast_use();
 
       vg_tex2d_bind( &tex_water_surf, 1 );
-      shader_water_fast_uTexDudv( 1 );
-      shader_water_fast_uTime( world.time );
-      shader_water_fast_uCamera( cam->transform[3] );
-      shader_water_fast_uSurfaceY( world.water.height );
-      shader_link_standard_ub( _shader_water_fast.id, 2 );
+      shader_model_water_fast_uTexDudv( 1 );
+      shader_model_water_fast_uTime( world.time );
+      shader_model_water_fast_uCamera( cam->transform[3] );
+      shader_model_water_fast_uSurfaceY( world.water.height );
+      shader_link_standard_ub( _shader_model_water_fast.id, 2 );
 
       m4x3f full;
       m4x3_identity( full );
-      shader_water_fast_uMdl( full );
-      shader_water_fast_uPv( cam->mtx.pv );
-      shader_water_fast_uPvmPrev( cam->mtx_prev.pv );
+      shader_model_water_fast_uMdl( full );
+      shader_model_water_fast_uPv( cam->mtx.pv );
+      shader_model_water_fast_uPvmPrev( cam->mtx_prev.pv );
 
       glEnable(GL_BLEND);
       glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
@@ -191,8 +191,8 @@ VG_STATIC void render_water_surface( camera *cam )
 
          if( mat->info.shader == k_shader_water )
          {
-            shader_water_fast_uShoreColour( mat->info.colour );
-            shader_water_fast_uOceanColour( mat->info.colour1 );
+            shader_model_water_fast_uShoreColour( mat->info.colour );
+            shader_model_water_fast_uOceanColour( mat->info.colour1 );
 
             mdl_draw_submesh( &mat->sm_no_collide );
          }