# =============================================================================
#
# Copyright . . . -----, ,----- ,---. .---.
-# 2021-2022 |\ /| | / | | | | /|
+# 2021-2023 |\ /| | / | | | | /|
# | \ / | +-- / +----- +---' | / |
# | \ / | | / | | \ | / |
# | \/ | | / | | \ | / |
#}
#}
+# 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
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
}
}
-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
}
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
float volume;
};
+struct classtype_point_light
+{
+ v4f colour; /* RGB, Energy */
+};
+
#pragma pack(pop)
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 );
#include "player_ragdoll.h"
#include "rigidbody.h"
-#include "shaders/viewchar.h"
+#include "shaders/model_character_view.h"
struct player_avatar
{
#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 );
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;
{
shader_blit_register();
shader_blitblur_register();
- shader_standard_register();
- shader_vblend_register();
+ shader_blitcolour_register();
vg_acquire_thread_sync();
{
#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)
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;
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
+++ /dev/null
-#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 */
+++ /dev/null
-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);
-}
+++ /dev/null
-#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 */
+++ /dev/null
-#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;
-}
--- /dev/null
+// :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 );
+}
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;
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;
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;
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;
}
+++ /dev/null
-#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 */
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-#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;
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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 ) );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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;
-}
+++ /dev/null
-#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 */
--- /dev/null
+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;
+}
--- /dev/null
+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);
+}
--- /dev/null
+#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 */
--- /dev/null
+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 );
+}
--- /dev/null
+#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 */
--- /dev/null
+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;
+}
--- /dev/null
+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 );
+}
--- /dev/null
+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;
+}
--- /dev/null
+#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 */
--- /dev/null
+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);
+}
--- /dev/null
+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);
+}
--- /dev/null
+#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 */
--- /dev/null
+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 );
+}
--- /dev/null
+#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 */
--- /dev/null
+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 );
+}
--- /dev/null
+#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 */
+++ /dev/null
-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;
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
--- /dev/null
+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;
+}
--- /dev/null
+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 ) );
+}
--- /dev/null
+#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 */
--- /dev/null
+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);
+}
--- /dev/null
+#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 */
--- /dev/null
+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 );
+}
--- /dev/null
+#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 */
--- /dev/null
+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);
+}
--- /dev/null
+#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 */
--- /dev/null
+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);
+}
--- /dev/null
+#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 */
--- /dev/null
+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);
+}
--- /dev/null
+#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 */
+++ /dev/null
-#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 */
+++ /dev/null
-#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;
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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);
-}
+++ /dev/null
-#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 */
+++ /dev/null
-#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;
-}
+++ /dev/null
-#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);
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-
- "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;"
- "}"
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-#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;
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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;
+++ /dev/null
-out vec4 FragColor;
-uniform sampler2D uTexMain;
-
-in vec2 aUv;
-
-void main()
-{
- FragColor = texture( uTexMain, aUv );
-}
+++ /dev/null
-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;
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-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;
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-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;
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-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;
-}
+++ /dev/null
-// Nothing
-
-#line 2 0
-
-void main()
-{
-
-}
+++ /dev/null
-uniform mat4x3 uMdl;
-
-void main()
-{
-
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-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;
-}
+++ /dev/null
-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);
-}
+++ /dev/null
-#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 */
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-#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;
-}
+++ /dev/null
-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 );
-}
+++ /dev/null
-#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 */
+++ /dev/null
-#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 );
-}
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 );
#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;
* logic_achievements;
u32 achievement_count;
+ /*
+ * Lights
+ */
+ struct world_light
+ {
+ v3f co;
+ v4f colour;
+ }
+ * lights;
+ u32 light_count;
/*
* Routes (world_routes.h)
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" );
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();
}
#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;
{
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" );
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 });
k_classtype_logic_achievement,
(void*)&world.logic_achievements,
sizeof(struct logic_achievement)
+ },
+ {
+ k_classtype_point_light,
+ (void*)&world.lights,
+ sizeof(struct world_light)
}
};
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)
{
{ 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++ )
}
}
+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)
{
/*
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 );
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();
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();
}
world.triggers = NULL;
world.trigger_count = 0;
+ world.lights = NULL;
+ world.light_count = 0;
+
world.logic_relays = NULL;
world.relay_count = 0;
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 );
}
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 );
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);
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 )
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 );
}
/*
* 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 );
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 );
#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"
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();
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 );
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 );
}
}
#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 };
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);
mesh_bind( &world.sfd.mesh_base );
mesh_draw( &world.sfd.mesh_base );
+#endif
}
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",
#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" };
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();
{
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);
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 );
}
}
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);
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 );
}