-#include "shaders/scene_standard.h"
-struct vg_shader _shader_scene_standard = {
- .name = "scene_standard",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_standard.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 7 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 3 \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 9 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_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4( vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_standard_uMdl;
-GLuint _uniform_scene_standard_uPv;
-GLuint _uniform_scene_standard_uPvmPrev;
-GLuint _uniform_scene_standard_uTexGarbage;
-GLuint _uniform_scene_standard_uTexMain;
-GLuint _uniform_scene_standard_uCamera;
-GLuint _uniform_scene_standard_uPlane;
-GLuint _uniform_scene_standard_g_world_depth;
-GLuint _uniform_scene_standard_uLightsArray;
-GLuint _uniform_scene_standard_uLightsIndex;
-#include "shaders/scene_standard_alphatest.h"
-struct vg_shader _shader_scene_standard_alphatest = {
- .name = "scene_standard_alphatest",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_standard_alphatest.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 7 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 3 \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 9 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_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4(vfrag, 1.0);\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_standard_alphatest_uMdl;
-GLuint _uniform_scene_standard_alphatest_uPv;
-GLuint _uniform_scene_standard_alphatest_uPvmPrev;
-GLuint _uniform_scene_standard_alphatest_uTexGarbage;
-GLuint _uniform_scene_standard_alphatest_uTexMain;
-GLuint _uniform_scene_standard_alphatest_uCamera;
-GLuint _uniform_scene_standard_alphatest_uPlane;
-GLuint _uniform_scene_standard_alphatest_g_world_depth;
-GLuint _uniform_scene_standard_alphatest_uLightsArray;
-GLuint _uniform_scene_standard_alphatest_uLightsIndex;
-#include "shaders/scene_foliage.h"
-struct vg_shader _shader_scene_foliage = {
- .name = "scene_foliage",
- .vs =
-{
-.orig_file = "shaders/scene_foliage.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform float uTime;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main(){\n"
-" vec4 vsine = sin(vec4(uTime + a_co.x, uTime*0.7 + a_co.z,uTime,uTime*1.3));\n"
-" vec3 co = a_co + vsine.xyz * a_norm.w * 0.5;\n"
-" \n"
-" vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
-" vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
-" vec4 vproj1 = uPvmPrev * vec4( 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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_foliage.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.4;\n"
-"#line 1 1 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 8 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 9 0 \n"
-"\n"
-"void main(){\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"
-" vfrag = vec3(0.5);\n"
-" }\n"
-"\n"
-" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4(vfrag, 1.0);\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_foliage_uMdl;
-GLuint _uniform_scene_foliage_uPv;
-GLuint _uniform_scene_foliage_uPvmPrev;
-GLuint _uniform_scene_foliage_uTime;
-GLuint _uniform_scene_foliage_uTexGarbage;
-GLuint _uniform_scene_foliage_uTexMain;
-GLuint _uniform_scene_foliage_uCamera;
-GLuint _uniform_scene_foliage_uPlane;
-GLuint _uniform_scene_foliage_g_world_depth;
-GLuint _uniform_scene_foliage_uLightsArray;
-GLuint _uniform_scene_foliage_uLightsIndex;
-#include "shaders/scene_override.h"
-struct vg_shader _shader_scene_override = {
- .name = "scene_override",
- .vs =
-{
-.orig_file = "shaders/scene_override.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform mat3 uNormalMtx;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 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"
-"\n"
-" aUv = a_uv;\n"
-" aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
-" aCo = a_co;\n"
-" aWorldCo = world_pos0;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_override.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"uniform vec4 uPlayerPos; /* w: distance to uSpawnPos */\n"
-"uniform vec4 uSpawnPos; /* w: inverse distance to uPlayerPos */\n"
-"uniform bool uAlphatest;\n"
-"uniform vec4 uMapInfo; /* x: min, y: max, z: iso line amount */\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 12 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 13 0 \n"
-"#line 1 3 \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"
-"vec2 smin( float a, float b, float k ){\n"
-" float h = max( k-abs(a-b), 0.0 )/k;\n"
-" float m = h*h*0.5;\n"
-" float s = m*k*(1.0/2.0);\n"
-"\n"
-" if( a < b )\n"
-" return vec2(a-s,m);\n"
-" else\n"
-" return vec2(b-s,1.0-m);\n"
-"}\n"
-"\n"
-"void main(){\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" float dcam = (-8.0+distance( aCo, uCamera ))/4.0;\n"
-" float dy0 = aCo.y - uMapInfo.x;\n"
-" float dy1 = uMapInfo.y - aCo.y;\n"
-"\n"
-" if( min(min(dy0,dy1)*0.5, dcam) + dither < 0.51 ) \n"
-" discard;\n"
-"\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec3 vfrag = vec3(0.898,0.811,0.716);\n"
-" vec3 qnorm = aNorm.xyz;\n"
-"\n"
-" qnorm = normalize(floor(aNorm.xyz*4.0)*0.25);\n"
-" qnorm += vec3(0.001,0.0,0.0);\n"
-"\n"
-" if( uAlphatest ){\n"
-" vec4 vSample = texture( uTexMain, aUv );\n"
-" if( vSample.a < 0.5 )\n"
-" discard;\n"
-" }\n"
-" else{\n"
-" }\n"
-"\n"
-" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" \n"
-" // dots\n"
-" float d0 = distance( aCo, uPlayerPos.xyz )*2.0;\n"
-" float d1 = distance( aCo, uSpawnPos.xyz );\n"
-"\n"
-" vec2 dm = smin( d0, d1, 10.0 );\n"
-" float dd = fract(dm.x*0.2-g_realtime*0.5) * \n"
-" max(0.0,1.0-dm.x*0.04) * \n"
-" max(0.0,qnorm.y);\n"
-" vec3 emit = mix(vec3(1.0,0.0,0.0),vec3(0.0,1.0,0.0),dm.y)*dd;\n"
-"\n"
-" // line\n"
-" vec3 v0 = (uSpawnPos.xyz-uPlayerPos.xyz)*uSpawnPos.w;\n"
-" float t = clamp( dot(aCo-uPlayerPos.xyz,v0), 0.0, uPlayerPos.w );\n"
-" vec3 p0 = uPlayerPos.xyz + v0*t;\n"
-" float d3 = distance(p0,aCo);\n"
-" emit += vec3(fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2));\n"
-"\n"
-" vfrag += emit;\n"
-"\n"
-" if( uMapInfo.z > 0.0 ){\n"
-" float height = fract( aCo.y * 0.1 );\n"
-" float lg = 2.0*length(vec2(dFdx(height), dFdy(height)));\n"
-" vfrag *= 1.0f+(lg*0.2*uMapInfo.z);\n"
-" }\n"
-"\n"
-" oColour = vec4( vfrag, 1.0 );\n"
-" //oColour = vec4( vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_override_uMdl;
-GLuint _uniform_scene_override_uPv;
-GLuint _uniform_scene_override_uPvmPrev;
-GLuint _uniform_scene_override_uNormalMtx;
-GLuint _uniform_scene_override_uTexGarbage;
-GLuint _uniform_scene_override_uTexMain;
-GLuint _uniform_scene_override_uCamera;
-GLuint _uniform_scene_override_uPlane;
-GLuint _uniform_scene_override_uPlayerPos;
-GLuint _uniform_scene_override_uSpawnPos;
-GLuint _uniform_scene_override_uAlphatest;
-GLuint _uniform_scene_override_uMapInfo;
-GLuint _uniform_scene_override_g_world_depth;
-GLuint _uniform_scene_override_uLightsArray;
-GLuint _uniform_scene_override_uLightsIndex;
-#include "shaders/scene_fxglow.h"
-struct vg_shader _shader_scene_fxglow = {
- .name = "scene_fxglow",
- .vs =
-{
-.orig_file = "shaders/scene_fxglow.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform vec2 uUvOffset;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 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"
-"\n"
-" aUv = a_uv + uUvOffset;\n"
-" aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
-" aCo = a_co;\n"
-" aWorldCo = world_pos0;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_fxglow.fs",
-.static_src =
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 5 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 6 0 \n"
-"#line 1 3 \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 7 0 \n"
-"\n"
-"void main(){\n"
-" oMotionVec = vec2(0.0);\n"
-"\n"
-" vec4 vsamplemain = texture( uTexMain, aUv );\n"
-"\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" if( vsamplemain.a+dither<0.5 )\n"
-" discard;\n"
-"\n"
-" oColour = vec4( vsamplemain.rgb, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_fxglow_uMdl;
-GLuint _uniform_scene_fxglow_uPv;
-GLuint _uniform_scene_fxglow_uPvmPrev;
-GLuint _uniform_scene_fxglow_uUvOffset;
-GLuint _uniform_scene_fxglow_uTexMain;
-GLuint _uniform_scene_fxglow_uCamera;
-GLuint _uniform_scene_fxglow_g_world_depth;
-GLuint _uniform_scene_fxglow_uLightsArray;
-GLuint _uniform_scene_fxglow_uLightsIndex;
-#include "shaders/scene_vertex_blend.h"
-struct vg_shader _shader_scene_vertex_blend = {
- .name = "scene_vertex_blend",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_vertex_blend.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 6 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 7 0 \n"
-"#line 1 3 \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 8 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_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4(vfrag, 1.0);\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_vertex_blend_uMdl;
-GLuint _uniform_scene_vertex_blend_uPv;
-GLuint _uniform_scene_vertex_blend_uPvmPrev;
-GLuint _uniform_scene_vertex_blend_uTexGarbage;
-GLuint _uniform_scene_vertex_blend_uTexGradients;
-GLuint _uniform_scene_vertex_blend_uCamera;
-GLuint _uniform_scene_vertex_blend_g_world_depth;
-GLuint _uniform_scene_vertex_blend_uLightsArray;
-GLuint _uniform_scene_vertex_blend_uLightsIndex;
-#include "shaders/scene_terrain.h"
-struct vg_shader _shader_scene_terrain = {
- .name = "scene_terrain",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_terrain.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uSandColour;\n"
-"uniform vec2 uBlendOffset;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"#line 1 3 \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 10 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_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4(vfrag, 1.0);\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_terrain_uMdl;
-GLuint _uniform_scene_terrain_uPv;
-GLuint _uniform_scene_terrain_uPvmPrev;
-GLuint _uniform_scene_terrain_uTexGarbage;
-GLuint _uniform_scene_terrain_uTexGradients;
-GLuint _uniform_scene_terrain_uCamera;
-GLuint _uniform_scene_terrain_uSandColour;
-GLuint _uniform_scene_terrain_uBlendOffset;
-GLuint _uniform_scene_terrain_g_world_depth;
-GLuint _uniform_scene_terrain_uLightsArray;
-GLuint _uniform_scene_terrain_uLightsIndex;
-#include "shaders/scene_route.h"
-struct vg_shader _shader_scene_route = {
- .name = "scene_route",
- .vs =
-{
-.orig_file = "shaders/scene_override.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform mat3 uNormalMtx;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 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"
-"\n"
-" aUv = a_uv;\n"
-" aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
-" aCo = a_co;\n"
-" aWorldCo = world_pos0;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_route.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexGradients;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 7 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 3 \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 9 0 \n"
-"\n"
-"float filtered_stripe( in float p, in float ddx, in float ddy )\n"
-"{\n"
-" float w = max(abs(ddx), abs(ddy)) + 0.02;\n"
-" float i = (abs(fract((p-0.5*w)/2.0)-0.5)-abs(fract((p+0.5*w)/2.0)-0.5))/w;\n"
-" return 0.5 - i;\n"
-"}\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.1 )\n"
-" discard;\n"
-"\n"
-" float movep = (aUv.x + abs(aUv.y-0.5)*0.4 - g_realtime)*2.0;\n"
-" float stripe = filtered_stripe( movep, dFdx(movep), dFdy(movep) );\n"
-" vfrag *= 0.9+stripe*uColour.a; \n"
-"\n"
-" if( g_light_preview == 1 )\n"
-" {\n"
-" vfrag = vec3(0.5);\n"
-" }\n"
-"\n"
-" // Lighting\n"
-" oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_route_uMdl;
-GLuint _uniform_scene_route_uPv;
-GLuint _uniform_scene_route_uPvmPrev;
-GLuint _uniform_scene_route_uNormalMtx;
-GLuint _uniform_scene_route_uTexGarbage;
-GLuint _uniform_scene_route_uTexGradients;
-GLuint _uniform_scene_route_uCamera;
-GLuint _uniform_scene_route_uColour;
-GLuint _uniform_scene_route_g_world_depth;
-GLuint _uniform_scene_route_uLightsArray;
-GLuint _uniform_scene_route_uLightsIndex;
-#include "shaders/scene_depth.h"
-struct vg_shader _shader_scene_depth = {
- .name = "scene_depth",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_depth.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 9 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"
-"\n"
-" // TODO: Make g_water_fog a material param\n"
-" return t * 0.3;//g_water_fog;\n"
-"}\n"
-"\n"
-"void main()\n"
-"{\n"
-" vec3 halfview = normalize( uCamera - aWorldCo );\n"
-" float depth = water_depth( aWorldCo, halfview );\n"
-" FragColor = vec4( depth, 0.0, 0.0, 0.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_depth_uMdl;
-GLuint _uniform_scene_depth_uPv;
-GLuint _uniform_scene_depth_uPvmPrev;
-GLuint _uniform_scene_depth_uCamera;
-GLuint _uniform_scene_depth_uBoard0;
-GLuint _uniform_scene_depth_uBoard1;
-GLuint _uniform_scene_depth_g_world_depth;
-GLuint _uniform_scene_depth_uLightsArray;
-GLuint _uniform_scene_depth_uLightsIndex;
-#include "shaders/scene_position.h"
-struct vg_shader _shader_scene_position = {
- .name = "scene_position",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_position.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"\n"
-"uniform vec3 uCamera;\n"
-"uniform vec3 uBoard0;\n"
-"uniform vec3 uBoard1;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"void main()\n"
-"{\n"
-" float height_full = aWorldCo.y;\n"
-" float height_water = height_full;\n"
-"\n"
-" if( height_water > (g_water_plane.y * g_water_plane.w) + 2.0 )\n"
-" height_water = -99999.9;\n"
-"\n"
-" FragColor = vec4( height_full, height_water, 0.0, 0.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_position_uMdl;
-GLuint _uniform_scene_position_uPv;
-GLuint _uniform_scene_position_uPvmPrev;
-GLuint _uniform_scene_position_uCamera;
-GLuint _uniform_scene_position_uBoard0;
-GLuint _uniform_scene_position_uBoard1;
-GLuint _uniform_scene_position_g_world_depth;
-GLuint _uniform_scene_position_uLightsArray;
-GLuint _uniform_scene_position_uLightsIndex;
-#include "shaders/scene_cubemapped.h"
-struct vg_shader _shader_scene_cubemapped = {
- .name = "scene_cubemapped",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_cubemapped.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform samplerCube uTexCubemap;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 9 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 10 0 \n"
-"#line 1 3 \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 11 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"
-" vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.0015 + aCo.yx*0.002 );\n"
-" vec3 qnorm = aNorm.xyz;\n"
-" vfrag = vsamplemain.rgb;\n"
-"\n"
-" if( g_light_preview == 1 ){\n"
-" vfrag = vec3(0.5);\n"
-" }\n"
-"\n"
-" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4( vfrag, 1.0 );\n"
-"\n"
-" vec3 halfdir = normalize( aWorldCo - uCamera );\n"
-" vec3 reflectdir = reflect( halfdir, qnorm );\n"
-" oColour = mix( oColour, \n"
-" vec4(texture(uTexCubemap,reflectdir).rgb * uColour.rgb, 1.0),\n"
-" uColour.a*wgarbage.b );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_cubemapped_uMdl;
-GLuint _uniform_scene_cubemapped_uPv;
-GLuint _uniform_scene_cubemapped_uPvmPrev;
-GLuint _uniform_scene_cubemapped_uTexGarbage;
-GLuint _uniform_scene_cubemapped_uTexMain;
-GLuint _uniform_scene_cubemapped_uTexCubemap;
-GLuint _uniform_scene_cubemapped_uCamera;
-GLuint _uniform_scene_cubemapped_uPlane;
-GLuint _uniform_scene_cubemapped_uColour;
-GLuint _uniform_scene_cubemapped_g_world_depth;
-GLuint _uniform_scene_cubemapped_uLightsArray;
-GLuint _uniform_scene_cubemapped_uLightsIndex;
-#include "shaders/scene_water.h"
-struct vg_shader _shader_scene_water = {
- .name = "scene_water",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_water.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"
-"uniform float uFresnel;\n"
-"uniform float uWaterScale;\n"
-"uniform vec4 uWaveSpeed;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 19 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 20 0 \n"
-"#line 1 3 \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 21 0 \n"
-"\n"
-"// Pasted from common_world.glsl\n"
-"vec3 water_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" float light_mask = compute_board_shadow();\n"
-"\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" return diffuse * total_light;\n"
-"}\n"
-"\n"
-"vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
-" vec4 beneath, vec4 above, vec4 dudva )\n"
-"{\n"
-" vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
-"\n"
-" float ffresnel = pow(1.0-dot( vnorm, halfview ),uFresnel);\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.r, 0.8 );\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"
-" vec4 surf = mix( vec4(surface_tint,depthblend), \n"
-" vec4(1.0,1.0,1.0,0.5), fband );\n"
-" surf.rgb = water_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );\n"
-" surf.rgb = mix(surf.rgb, above.rgb, ffresnel );\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" surf.rgb = scene_apply_fog( surf.rgb, fog_colour, \n"
-" distance(uCamera, aWorldCo) );\n"
-"\n"
-" return surf;\n"
-"}\n"
-"\n"
-"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_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );\n"
-"\n"
-" vec2 world_coord = aCo.xz * uWaterScale;\n"
-" //TODO: Material param ( 0.008, 0.006, 0.003, 0.03 );\n"
-" vec4 time_offsets = vec4( uTime ) * vec4( 0.08, -0.08, -0.03, -0.01 );\n"
-" vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
-" vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
-"\n"
-" 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"
-" // 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, dudva );\n"
-" vsurface.a -= fdist;\n"
-"\n"
-" oColour = vsurface;\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_water_uMdl;
-GLuint _uniform_scene_water_uPv;
-GLuint _uniform_scene_water_uPvmPrev;
-GLuint _uniform_scene_water_uTexMain;
-GLuint _uniform_scene_water_uTexDudv;
-GLuint _uniform_scene_water_uTexBack;
-GLuint _uniform_scene_water_uInvRes;
-GLuint _uniform_scene_water_uTime;
-GLuint _uniform_scene_water_uCamera;
-GLuint _uniform_scene_water_uSurfaceY;
-GLuint _uniform_scene_water_uBoard0;
-GLuint _uniform_scene_water_uBoard1;
-GLuint _uniform_scene_water_uShoreColour;
-GLuint _uniform_scene_water_uOceanColour;
-GLuint _uniform_scene_water_uFresnel;
-GLuint _uniform_scene_water_uWaterScale;
-GLuint _uniform_scene_water_uWaveSpeed;
-GLuint _uniform_scene_water_g_world_depth;
-GLuint _uniform_scene_water_uLightsArray;
-GLuint _uniform_scene_water_uLightsIndex;
-#include "shaders/scene_water_fast.h"
-struct vg_shader _shader_scene_water_fast = {
- .name = "scene_water_fast",
- .vs =
-{
-.orig_file = "shaders/scene.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"
-"\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 6 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"
-"\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"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_water_fast.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"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 13 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 14 0 \n"
-"#line 1 3 \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"
-"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_water_depth( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
-"\n"
-" vec2 world_coord = aCo.xz * 0.008;\n"
-" vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
-" 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"
-" oColour.rgb = scene_compute_lighting( oColour.rgb, aNorm.xyz, aWorldCo );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_water_fast_uMdl;
-GLuint _uniform_scene_water_fast_uPv;
-GLuint _uniform_scene_water_fast_uPvmPrev;
-GLuint _uniform_scene_water_fast_uTexDudv;
-GLuint _uniform_scene_water_fast_uTime;
-GLuint _uniform_scene_water_fast_uCamera;
-GLuint _uniform_scene_water_fast_uSurfaceY;
-GLuint _uniform_scene_water_fast_uBoard0;
-GLuint _uniform_scene_water_fast_uBoard1;
-GLuint _uniform_scene_water_fast_uShoreColour;
-GLuint _uniform_scene_water_fast_uOceanColour;
-GLuint _uniform_scene_water_fast_g_world_depth;
-GLuint _uniform_scene_water_fast_uLightsArray;
-GLuint _uniform_scene_water_fast_uLightsIndex;
-#include "shaders/scene_scoretext.h"
-struct vg_shader _shader_scene_scoretext = {
- .name = "scene_scoretext",
- .vs =
-{
-.orig_file = "shaders/scene_sfd.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform vec3 uInfo;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-" float w = ((a_norm.w)-0.5)*2.0 + fract(uInfo.z) - 0.0;\n"
-" float c = -cos(w*0.6);\n"
-" float s = -sin(w*0.6);\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_pos0 = mlocal * vec4( a_co, 1.0 );\n"
-" vec3 world_pos0 = uMdl * vec4( local_pos0, 1.0 );\n"
-"\n"
-" vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
-" vec4 vproj1 = uPvmPrev * vec4( local_pos0, 1.0 );\n"
-"\n"
-" vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-" gl_Position = vproj0;\n"
-"\n"
-" aUv = a_uv + vec2( floor(uInfo.z+0.5)*(1.0/64.0), yoff );\n"
-" aNorm = vec4( mat3(uMdl) * mat3(mlocal) * a_norm.xyz, a_norm.w );\n"
-" aCo = a_co;\n"
-" aWorldCo = world_pos0;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_standard.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec3 uCamera;\n"
-"uniform vec4 uPlane;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 7 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 8 0 \n"
-"#line 1 3 \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 9 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_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4( vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_scoretext_uMdl;
-GLuint _uniform_scene_scoretext_uPv;
-GLuint _uniform_scene_scoretext_uPvmPrev;
-GLuint _uniform_scene_scoretext_uInfo;
-GLuint _uniform_scene_scoretext_uTexGarbage;
-GLuint _uniform_scene_scoretext_uTexMain;
-GLuint _uniform_scene_scoretext_uCamera;
-GLuint _uniform_scene_scoretext_uPlane;
-GLuint _uniform_scene_scoretext_g_world_depth;
-GLuint _uniform_scene_scoretext_uLightsArray;
-GLuint _uniform_scene_scoretext_uLightsIndex;
-#include "shaders/scene_font.h"
-struct vg_shader _shader_scene_font = {
- .name = "scene_font",
- .vs =
-{
-.orig_file = "shaders/model_font.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform vec4 uOffset;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-" vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
-" vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
-" vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
-" vec4 vproj1 = uPvmPrev * vec4( 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, 0.0 );\n"
-" aCo = co;\n"
-" aWorldCo = world_pos0;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/scene_font.fs",
-.static_src =
-"uniform sampler2D uTexGarbage; // unused\n"
-"uniform sampler2D uTexMain; // unused\n"
-"uniform vec3 uCamera;\n"
-"uniform float uTime;\n"
-"uniform float uOpacity;\n"
-"uniform float uColourize;\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 9 0 \n"
-"#line 1 2 \n"
-"// :D\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"#line 1 1 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 9 0 \n"
-"\n"
-"float sdLine( vec3 p, vec3 a, vec3 b )\n"
-"{\n"
-" vec3 pa = p - a;\n"
-" vec3 ba = b - a;\n"
-"\n"
-" float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
-" return length( pa - ba*h );\n"
-"}\n"
-"\n"
-"float compute_board_shadow()\n"
-"{\n"
-" // player shadow\n"
-" float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
-" g_board_1.xyz )-0.1 );\n"
-" float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
-" player_shadow *= player_shadow*player_shadow*player_shadow;\n"
-"\n"
-" return 1.0 - player_shadow*0.8;\n"
-"}\n"
-"\n"
-"vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
-"{\n"
-" return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
-"}\n"
-"\n"
-"#line 10 0 \n"
-"#line 1 3 \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 11 0 \n"
-"\n"
-"vec3 pal( float t ){\n"
-" vec3 a = vec3(0.30,0.3,0.3);\n"
-" vec3 b = vec3(0.8);\n"
-" vec3 c = vec3(0.28,0.3,0.4);\n"
-" vec3 d = vec3(0.00,0.1,0.1);\n"
-" return a + b*cos( 6.28318*(c*t+d) );\n"
-"}\n"
-"\n"
-"void main(){\n"
-" compute_motion_vectors();\n"
-" vec3 vfrag = vec3(0.5,0.5,0.5);\n"
-" vec3 qnorm = aNorm.xyz;\n"
-"\n"
-" //vec4 vsamplemain = texture( uTexMain, aUv );\n"
-" //vfrag = vsamplemain.rgb;\n"
-"\n"
-" vec4 spread0 = uTime*0.0002*vec4( 17.3,-19.6, 23.2,-47.7 );\n"
-" vec4 spread1 = uTime*0.0002*vec4( -13.3, 12.6,-28.2, 14.7 );\n"
-"\n"
-" vec2 p = aCo.xy + vec2(0.3);\n"
-" float a = atan( p.y/p.x );\n"
-" vec4 v0 = step( vec4(0.5), fract(vec4(a) + spread0) );\n"
-" vec4 v1 = step( vec4(0.5), fract(vec4(a) + spread1) );\n"
-"\n"
-" float d = ( v0.x+v0.y+v0.z+v0.w +\n"
-" v1.x+v1.y+v1.z+v1.w ) * 0.125;\n"
-" \n"
-" float dither = fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0);\n"
-" float x = d*0.8+length(p)*0.3;\n"
-" x = (floor(x*8.0) + step(dither, fract(x * 8.0))) / 8.0;\n"
-"\n"
-" if( x + (uOpacity*2.0-1.0) < 0.5 ) \n"
-" discard;\n"
-"\n"
-" vfrag = mix( vec3(x), pal( x ), uColourize );\n"
-"\n"
-" if( g_light_preview == 1 ){\n"
-" vfrag = vec3(0.5);\n"
-" }\n"
-"\n"
-" vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
-" oColour = vec4( vfrag, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_scene_font_uMdl;
-GLuint _uniform_scene_font_uPv;
-GLuint _uniform_scene_font_uPvmPrev;
-GLuint _uniform_scene_font_uOffset;
-GLuint _uniform_scene_font_uTexGarbage;
-GLuint _uniform_scene_font_uTexMain;
-GLuint _uniform_scene_font_uCamera;
-GLuint _uniform_scene_font_uTime;
-GLuint _uniform_scene_font_uOpacity;
-GLuint _uniform_scene_font_uColourize;
-GLuint _uniform_scene_font_g_world_depth;
-GLuint _uniform_scene_font_uLightsArray;
-GLuint _uniform_scene_font_uLightsIndex;
-#include "shaders/model_sky.h"
-struct vg_shader _shader_model_sky = {
- .name = "model_sky",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_sky.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"// Spooky!\n"
-"const vec3 uCamera = vec3(0.0);\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 13 0 \n"
-"#line 1 2 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 14 0 \n"
-"#line 1 3 \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 rd = normalize(aNorm);\n"
-"\n"
-" float fmove = g_time * 5.0;\n"
-" vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.025;\n"
-" vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );\n"
-" vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );\n"
-"\n"
-" float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);\n"
-" float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;\n"
-"\n"
-" oColour = vec4( clearskies_sky( -rd ) ,1.0);\n"
-"\n"
-" vec3 cloud_colour = mix( mix(g_nightsky_colour.rgb,vec3(1.0),g_day_phase), \n"
-" g_sunset_colour.rgb, g_sunset_phase );\n"
-"\n"
-" oColour.rgb = mix( oColour.rgb, cloud_colour, cloud_e );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_sky_uMdl;
-GLuint _uniform_model_sky_uPv;
-GLuint _uniform_model_sky_uPvmPrev;
-GLuint _uniform_model_sky_uTexGarbage;
-GLuint _uniform_model_sky_g_world_depth;
-GLuint _uniform_model_sky_uLightsArray;
-GLuint _uniform_model_sky_uLightsIndex;
-#include "shaders/model_sky_space.h"
-struct vg_shader _shader_model_sky_space = {
- .name = "model_sky_space",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_sky_space.fs",
-.static_src =
-"uniform sampler2D uTexGarbage;\n"
-"\n"
-"in vec4 aColour;\n"
-"in vec2 aUv;\n"
-"in vec3 aNorm;\n"
-"in vec3 aCo;\n"
-"in vec3 aWorldCo;\n"
-"\n"
-"// Spooky!\n"
-"const vec3 uCamera = vec3(0.0);\n"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 13 0 \n"
-"#line 1 2 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 14 0 \n"
-"#line 1 3 \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"
-"float stars1( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"void main(){\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec3 rd = -normalize(aNorm);\n"
-"\n"
-" float star = 0.0;\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( rd, 1.94 * pow( 1.64, j ), m ) * (1.0 / pow(4.0, j));\n"
-" }\n"
-"\n"
-" oColour = vec4( vec3(star*20.0), 1.0);\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_sky_space_uMdl;
-GLuint _uniform_model_sky_space_uPv;
-GLuint _uniform_model_sky_space_uPvmPrev;
-GLuint _uniform_model_sky_space_uTexGarbage;
-GLuint _uniform_model_sky_space_g_world_depth;
-GLuint _uniform_model_sky_space_uLightsArray;
-GLuint _uniform_model_sky_space_uLightsIndex;
-#include "shaders/model_menu.h"
-struct vg_shader _shader_model_menu = {
- .name = "model_menu",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_menu.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"
-""},
-};
-
-GLuint _uniform_model_menu_uMdl;
-GLuint _uniform_model_menu_uPv;
-GLuint _uniform_model_menu_uPvmPrev;
-GLuint _uniform_model_menu_uTexMain;
-GLuint _uniform_model_menu_uColour;
-#include "shaders/model_character_view.h"
-struct vg_shader _shader_model_character_view = {
- .name = "model_character_view",
- .vs =
-{
-.orig_file = "shaders/model_skinned.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: motion vectors\n"
-" aMotionVec0 = vec3(1.0);\n"
-" aMotionVec1 = vec3(1.0);\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_character_view.fs",
-.static_src =
-"uniform sampler2D uTexMain;\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"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 11 0 \n"
-"#line 1 2 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 12 0 \n"
-"#line 1 3 \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"
-"#line 1 4 \n"
-"uniform sampler2D uTexSceneDepth;\n"
-"uniform vec3 uInverseRatioDepth;\n"
-"uniform vec3 uInverseRatioMain;\n"
-"uniform int uDepthMode;\n"
-"uniform float uDitherCutoff;\n"
-"\n"
-"float linear_depth( float depth, float near, float far ) {\n"
-" float z = depth * 2.0 - 1.0;\n"
-" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
-"}\n"
-"\n"
-"void depth_compare_dither()\n"
-"{\n"
-" if( uDepthMode == 1 )\n"
-" {\n"
-" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
-" * uInverseRatioDepth.xy;\n"
-" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
-" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
-"\n"
-" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
-" float diff = back_depth - front_depth;\n"
-"\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" if( step(0.0,diff)+dither<0.3 )\n"
-" discard;\n"
-" }\n"
-"\n"
-" if( uDepthMode == 2 )\n"
-" {\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 );\n"
-" if( dither<uDitherCutoff ) discard;\n"
-" }\n"
-"}\n"
-"\n"
-"#line 14 0 \n"
-"\n"
-"vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
-" * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = character_clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"void main(){\n"
-" depth_compare_dither();\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec3 qnorm = aNorm;\n"
-" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
-" vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
-"\n"
-" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
-" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
-"\n"
-" oColour = vec4( composite, opacity );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_character_view_uPv;
-GLuint _uniform_model_character_view_uTransforms;
-GLuint _uniform_model_character_view_uTexMain;
-GLuint _uniform_model_character_view_uCamera;
-GLuint _uniform_model_character_view_g_world_depth;
-GLuint _uniform_model_character_view_uLightsArray;
-GLuint _uniform_model_character_view_uLightsIndex;
-GLuint _uniform_model_character_view_uTexSceneDepth;
-GLuint _uniform_model_character_view_uInverseRatioDepth;
-GLuint _uniform_model_character_view_uInverseRatioMain;
-GLuint _uniform_model_character_view_uDepthMode;
-GLuint _uniform_model_character_view_uDitherCutoff;
-#include "shaders/model_board_view.h"
-struct vg_shader _shader_model_board_view = {
- .name = "model_board_view",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_character_view.fs",
-.static_src =
-"uniform sampler2D uTexMain;\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"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 11 0 \n"
-"#line 1 2 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 12 0 \n"
-"#line 1 3 \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"
-"#line 1 4 \n"
-"uniform sampler2D uTexSceneDepth;\n"
-"uniform vec3 uInverseRatioDepth;\n"
-"uniform vec3 uInverseRatioMain;\n"
-"uniform int uDepthMode;\n"
-"uniform float uDitherCutoff;\n"
-"\n"
-"float linear_depth( float depth, float near, float far ) {\n"
-" float z = depth * 2.0 - 1.0;\n"
-" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
-"}\n"
-"\n"
-"void depth_compare_dither()\n"
-"{\n"
-" if( uDepthMode == 1 )\n"
-" {\n"
-" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
-" * uInverseRatioDepth.xy;\n"
-" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
-" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
-"\n"
-" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
-" float diff = back_depth - front_depth;\n"
-"\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" if( step(0.0,diff)+dither<0.3 )\n"
-" discard;\n"
-" }\n"
-"\n"
-" if( uDepthMode == 2 )\n"
-" {\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 );\n"
-" if( dither<uDitherCutoff ) discard;\n"
-" }\n"
-"}\n"
-"\n"
-"#line 14 0 \n"
-"\n"
-"vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
-" * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = character_clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"void main(){\n"
-" depth_compare_dither();\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec3 qnorm = aNorm;\n"
-" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
-" vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
-"\n"
-" float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
-" float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
-"\n"
-" oColour = vec4( composite, opacity );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_board_view_uMdl;
-GLuint _uniform_model_board_view_uPv;
-GLuint _uniform_model_board_view_uPvmPrev;
-GLuint _uniform_model_board_view_uTexMain;
-GLuint _uniform_model_board_view_uCamera;
-GLuint _uniform_model_board_view_g_world_depth;
-GLuint _uniform_model_board_view_uLightsArray;
-GLuint _uniform_model_board_view_uLightsIndex;
-GLuint _uniform_model_board_view_uTexSceneDepth;
-GLuint _uniform_model_board_view_uInverseRatioDepth;
-GLuint _uniform_model_board_view_uInverseRatioMain;
-GLuint _uniform_model_board_view_uDepthMode;
-GLuint _uniform_model_board_view_uDitherCutoff;
-#include "shaders/model_entity.h"
-struct vg_shader _shader_model_entity = {
- .name = "model_entity",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_entity.fs",
-.static_src =
-"uniform sampler2D uTexMain;\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"
-"\n"
-"#line 1 1 \n"
-"// :D\n"
-"const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
-"\n"
-"#line 11 0 \n"
-"#line 1 2 \n"
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
-"layout (std140) uniform ub_world_lighting\n"
-"{\n"
-" vec4 g_cube_min;\n"
-" vec4 g_cube_inv_range;\n"
-"\n"
-" vec4 g_water_plane;\n"
-" vec4 g_depth_bounds;\n"
-"\n"
-" vec4 g_daysky_colour;\n"
-" vec4 g_nightsky_colour;\n"
-" vec4 g_sunset_colour;\n"
-" vec4 g_ambient_colour;\n"
-" vec4 g_sunset_ambient;\n"
-" vec4 g_sun_colour;\n"
-" vec4 g_sun_dir;\n"
-" vec4 g_board_0;\n"
-" vec4 g_board_1;\n"
-"\n"
-" float g_water_fog;\n"
-" float g_time;\n"
-" float g_realtime;\n"
-" float g_shadow_length;\n"
-" float g_shadow_spread;\n"
-"\n"
-" float g_time_of_day;\n"
-" float g_day_phase;\n"
-" float g_sunset_phase;\n"
-"\n"
-" int g_light_preview;\n"
-" int g_shadow_samples;\n"
-"\n"
-" int g_debug_indices;\n"
-" int g_debug_complexity;\n"
-"};\n"
-"\n"
-"uniform sampler2D g_world_depth;\n"
-"uniform samplerBuffer uLightsArray;\n"
-"uniform usampler3D uLightsIndex;\n"
-"\n"
-"#line 1 1 \n"
-"//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
-"//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
-"//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
-"//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
-"//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
-"//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
-"\n"
-"const float SUN_ANGLE = 0.0001;\n"
-"const float PI = 3.14159265358979323846264;\n"
-"\n"
-"//struct world_info\n"
-"//{\n"
-"// float time,\n"
-"// time_of_day,\n"
-"// day_phase,\n"
-"// sunset_phase;\n"
-"// \n"
-"// vec3 sun_dir;\n"
-"//};\n"
-"\n"
-"vec3 rand33(vec3 p3)\n"
-"{\n"
-" p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
-" p3 += dot(p3, p3.yxz+33.33);\n"
-" return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
-"}\n"
-"\n"
-"float stars( vec3 rd, float rr, float size ){\n"
-" vec3 co = rd * rr;\n"
-"\n"
-" float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
-"\n"
-" float spaces = 1.0 / rr;\n"
-" size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
-" a -= mod(a, spaces) - spaces * 0.5;\n"
-"\n"
-" float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
-" \n"
-" float plane = atan(co.z, co.x) + 4.0 * PI;\n"
-" plane = plane - mod(plane, PI / count);\n"
-"\n"
-" vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
-"\n"
-" float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
-" float ydist = sqrt(rr * rr - level * level);\n"
-" float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
-" vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
-" float star = smoothstep(size, 0.0, distance(center, co));\n"
-" return star;\n"
-"}\n"
-"\n"
-"float luminance( vec3 v )\n"
-"{\n"
-" return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
-"}\n"
-"\n"
-"vec3 clearskies_ambient( vec3 dir )\n"
-"{\n"
-" float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
-" float sky_gradient = dir.y;\n"
-" \n"
-" /* Blend phase colours */\n"
-" vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
-" ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
-" ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
-" \n"
-" /* Add gradient */\n"
-" ambient -= sky_gradient * luminance(ambient)*1.6;\n"
-" \n"
-" return ambient;\n"
-"}\n"
-"\n"
-"vec3 clearskies_sky( vec3 ray_dir )\n"
-"{\n"
-" ray_dir.y = abs( ray_dir.y );\n"
-" vec3 sky_colour = clearskies_ambient( ray_dir );\n"
-" \n"
-" /* Sun */\n"
-" float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
-" float sun_shape = pow( sun_size, 2000.0 );\n"
-" sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" \n"
-" float star = 0.0;\n"
-" float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
-"\n"
-" if( star_blend > 0.001 ){\n"
-" for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
-" float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
-" star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
-" }\n"
-" }\n"
-" \n"
-" vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
-" return composite;\n"
-"}\n"
-"\n"
-"vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
-"{\n"
-" float fresnel = 1.0 - abs(dot(normal,halfview));\n"
-"\n"
-" vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
-" vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
-" dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
-" ) * g_sun_colour.rgb * g_day_phase;\n"
-"\n"
-" float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
-" vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
-" g_sunset_phase );\n"
-"\n"
-" return ambient + (light_sun + sky_reflection) * shadow;\n"
-"}\n"
-"\n"
-"#line 44 0 \n"
-"\n"
-"float world_depth_sample( vec3 pos )\n"
-"{\n"
-" vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
-" return texture( g_world_depth, depth_coord ).r;\n"
-"}\n"
-"\n"
-"float world_water_depth( vec3 pos )\n"
-"{\n"
-" float ref_depth = g_water_plane.y*g_water_plane.w;\n"
-" return world_depth_sample( pos ) - ref_depth;\n"
-"}\n"
-"\n"
-"float shadow_sample( vec3 co ){\n"
-" float height_sample = world_depth_sample( co );\n"
-"\n"
-" float fdelta = height_sample - co.y;\n"
-" return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
-"}\n"
-"\n"
-"float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
-" if( g_shadow_samples == 0 ){\n"
-" return 1.0;\n"
-" }\n"
-"\n"
-" float fspread = g_shadow_spread;\n"
-" float flength = g_shadow_length;\n"
-"\n"
-" float famt = 0.0;\n"
-" famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
-" famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
-" famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
-"\n"
-" //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
-" //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
-"\n"
-" return 1.0 - famt;\n"
-"}\n"
-"\n"
-"float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
-"{\n"
-" vec3 specdir = reflect( -dir, wnormal );\n"
-" return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
-"}\n"
-"\n"
-"vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
-" float dist = pow(fdist*0.0010,0.78);\n"
-" return mix( vfrag, colour, min( 1.0, dist ) );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_light( int light_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
-" vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
-" vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
-"\n"
-" vec3 light_delta = light_co.xyz-co;\n"
-" float dist2 = dot(light_delta,light_delta);\n"
-"\n"
-" light_delta = normalize( light_delta );\n"
-"\n"
-" float quadratic = dist2*100.0;\n"
-" float attenuation = 1.0/( 1.0 + quadratic );\n"
-" attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
-"\n"
-" float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
-"\n"
-" if( light_dir.w < 0.999999 ){\n"
-" float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
-" falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
-" }\n"
-"\n"
-" return light_colour.rgb * attenuation * falloff \n"
-" * step( g_day_phase, light_colour.w );\n"
-"}\n"
-"\n"
-"vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
-" vec3 halfview, vec3 co, vec3 normal )\n"
-"{\n"
-" uint light_count = packed_index & 0x3u;\n"
-"\n"
-" vec3 l = vec3(0.0);\n"
-"\n"
-" if( light_count >= 1u ){\n"
-" int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
-" int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
-" int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
-"\n"
-" l += scene_calculate_light( index_0, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 2u ){\n"
-" l += scene_calculate_light( index_1, halfview, co, normal );\n"
-"\n"
-" if( light_count >= 3u ){\n"
-" l += scene_calculate_light( index_2, halfview, co, normal );\n"
-" }\n"
-" }\n"
-" }\n"
-"\n"
-" return l;\n"
-"}\n"
-"\n"
-"vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
-" float light_mask )\n"
-"{\n"
-" if( g_light_preview == 1 )\n"
-" diffuse = vec3(0.75);\n"
-"\n"
-" // Lighting\n"
-" vec3 halfview = uCamera - co;\n"
-" float fdist = length(halfview);\n"
-" halfview /= fdist;\n"
-"\n"
-" float world_shadow = newlight_compute_sun_shadow( \n"
-" co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
-"\n"
-" vec3 total_light = clearskies_lighting( \n"
-" normal, min( light_mask, world_shadow ), halfview );\n"
-"\n"
-" vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
-" cube_coord = floor( cube_coord );\n"
-"\n"
-" if( g_debug_indices == 1 )\n"
-" {\n"
-" return rand33(cube_coord);\n"
-" }\n"
-"\n"
-" if( g_debug_complexity == 1 )\n"
-" {\n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
-" return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
-" }\n"
-"\n"
-" // FIXME: this coord should absolutely must be clamped!\n"
-" \n"
-" ivec3 coord = ivec3( cube_coord );\n"
-" uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
-"\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.x,\n"
-" halfview, co, normal ) \n"
-" * light_mask;\n"
-" total_light += \n"
-" scene_calculate_packed_light_patch( index_sample.y,\n"
-" halfview, co, normal )\n"
-" * light_mask;\n"
-"\n"
-" // Take a section of the sky function to give us a matching fog colour\n"
-"\n"
-" vec3 fog_colour = clearskies_ambient( -halfview );\n"
-" float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
-" float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
-" float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
-" \n"
-" vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
-" sun_colour *= sun_shape;\n"
-"\n"
-" fog_colour += sun_colour;\n"
-" return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
-"}\n"
-"\n"
-"#line 12 0 \n"
-"#line 1 3 \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"
-" vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n"
-" vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
-" vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
-"\n"
-" oColour = vec4( composite, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_entity_uMdl;
-GLuint _uniform_model_entity_uPv;
-GLuint _uniform_model_entity_uPvmPrev;
-GLuint _uniform_model_entity_uTexMain;
-GLuint _uniform_model_entity_uCamera;
-GLuint _uniform_model_entity_g_world_depth;
-GLuint _uniform_model_entity_uLightsArray;
-GLuint _uniform_model_entity_uLightsIndex;
-#include "shaders/model_gate.h"
-struct vg_shader _shader_model_gate = {
- .name = "model_gate",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_gate_lq.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"\n"
-"uniform float uTime;\n"
-"uniform vec3 uCam;\n"
-"uniform vec2 uInvRes;\n"
-"uniform vec4 uColour;\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.0,1.0,aUv.y+uColour.a);\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 = uColour;\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_gate_uMdl;
-GLuint _uniform_model_gate_uPv;
-GLuint _uniform_model_gate_uPvmPrev;
-GLuint _uniform_model_gate_uTime;
-GLuint _uniform_model_gate_uCam;
-GLuint _uniform_model_gate_uInvRes;
-GLuint _uniform_model_gate_uColour;
-#include "shaders/model_gate_unlinked.h"
-struct vg_shader _shader_model_gate_unlinked = {
- .name = "model_gate_unlinked",
- .vs =
-{
-.orig_file = "shaders/model.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 = normalize( mat3(uMdl) * a_norm );\n"
-" aCo = a_co;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_gate_unlinked.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"\n"
-"uniform float uTime;\n"
-"uniform vec3 uCam;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"in vec3 aNorm;\n"
-"in vec2 aUv;\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 12 0 \n"
-"\n"
-"const int NOISE_LOOP = 3;\n"
-"vec3 digital_noise( uvec3 iuv ){\n"
-" iuv *=uvec3(8,2524,7552);\n"
-" for( int i=0; i<NOISE_LOOP; i++ )\n"
-" iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
-" return vec3(iuv)*(1.0/float(0xffffffffU));\n"
-"}\n"
-"\n"
-"vec2 rand_hash22( vec2 p ){\n"
-" vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
-" p3 += dot(p3, p3.yzx+19.19);\n"
-" return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
-"}\n"
-"\n"
-"void main(){\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" float grad = 1.0-aUv.y*0.1;\n"
-" float opacity = rand_hash22( vec2(floor(aUv.y*100.0),floor(aCo.z*10.0+uTime*40.0)) ).r*grad;\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<0.9 )\n"
-" discard;\n"
-"\n"
-" FragColor = vec4(0.7,0.5,0.5,1.0);\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_gate_unlinked_uMdl;
-GLuint _uniform_model_gate_unlinked_uPv;
-GLuint _uniform_model_gate_unlinked_uPvmPrev;
-GLuint _uniform_model_gate_unlinked_uTime;
-GLuint _uniform_model_gate_unlinked_uCam;
-GLuint _uniform_model_gate_unlinked_uColour;
-#include "shaders/model_font.h"
-struct vg_shader _shader_model_font = {
- .name = "model_font",
- .vs =
-{
-.orig_file = "shaders/model_font.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"
-"\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 6 0 \n"
-"\n"
-"uniform mat4x3 uMdl;\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvmPrev;\n"
-"uniform vec4 uOffset;\n"
-"\n"
-"out vec2 aUv;\n"
-"out vec4 aNorm;\n"
-"out vec3 aCo;\n"
-"out vec3 aWorldCo;\n"
-"\n"
-"void main()\n"
-"{\n"
-" vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
-" vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
-" vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
-" vec4 vproj1 = uPvmPrev * vec4( 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, 0.0 );\n"
-" aCo = co;\n"
-" aWorldCo = world_pos0;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/model_font.fs",
-.static_src =
-"layout (location = 0) out vec4 oColour;\n"
-"\n"
-"uniform sampler2D uTexMain;\n"
-"uniform vec4 uColour;\n"
-"\n"
-"in vec2 aUv;\n"
-"in vec4 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 11 0 \n"
-"#line 1 2 \n"
-"uniform sampler2D uTexSceneDepth;\n"
-"uniform vec3 uInverseRatioDepth;\n"
-"uniform vec3 uInverseRatioMain;\n"
-"uniform int uDepthMode;\n"
-"uniform float uDitherCutoff;\n"
-"\n"
-"float linear_depth( float depth, float near, float far ) {\n"
-" float z = depth * 2.0 - 1.0;\n"
-" return (2.0 * near * far) / (far + near - z * (far - near)); \n"
-"}\n"
-"\n"
-"void depth_compare_dither()\n"
-"{\n"
-" if( uDepthMode == 1 )\n"
-" {\n"
-" vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
-" * uInverseRatioDepth.xy;\n"
-" float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
-" float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
-"\n"
-" back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
-" float diff = back_depth - front_depth;\n"
-"\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" if( step(0.0,diff)+dither<0.3 )\n"
-" discard;\n"
-" }\n"
-"\n"
-" if( uDepthMode == 2 )\n"
-" {\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 );\n"
-" if( dither<uDitherCutoff ) discard;\n"
-" }\n"
-"}\n"
-"\n"
-"#line 12 0 \n"
-"\n"
-"void main(){\n"
-" depth_compare_dither();\n"
-" compute_motion_vectors();\n"
-" oColour = texture( uTexMain, aUv ) * uColour;\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_model_font_uMdl;
-GLuint _uniform_model_font_uPv;
-GLuint _uniform_model_font_uPvmPrev;
-GLuint _uniform_model_font_uOffset;
-GLuint _uniform_model_font_uTexMain;
-GLuint _uniform_model_font_uColour;
-GLuint _uniform_model_font_uTexSceneDepth;
-GLuint _uniform_model_font_uInverseRatioDepth;
-GLuint _uniform_model_font_uInverseRatioMain;
-GLuint _uniform_model_font_uDepthMode;
-GLuint _uniform_model_font_uDitherCutoff;
-#include "shaders/particle.h"
-struct vg_shader _shader_particle = {
- .name = "particle",
- .vs =
-{
-.orig_file = "shaders/particle.vs",
-.static_src =
-"layout (location=0) in vec3 a_co;\n"
-"layout (location=1) in vec4 a_colour;\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 5 0 \n"
-"\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvPrev;\n"
-"\n"
-"out vec4 aColour;\n"
-"\n"
-"void main(){\n"
-" vec4 vproj0 = uPv * vec4( a_co, 1.0 );\n"
-" vec4 vproj1 = uPvPrev * vec4( a_co, 1.0 );\n"
-" vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-" gl_Position = vproj0;\n"
-" aColour = a_colour;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/particle.fs",
-.static_src =
-"layout (location = 0) out vec4 oColour;\n"
-"in vec4 aColour;\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 5 0 \n"
-"\n"
-"void main(){\n"
-" compute_motion_vectors();\n"
-"\n"
-" //vec2 ssuv = gl_FragCoord.xy;\n"
-" //vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" //float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" //if( vsamplemain.a+dither<0.5 )\n"
-" // discard;\n"
-"\n"
-" oColour = aColour;\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_particle_uPv;
-GLuint _uniform_particle_uPvPrev;
-#include "shaders/trail.h"
-struct vg_shader _shader_trail = {
- .name = "trail",
- .vs =
-{
-.orig_file = "shaders/trail.vs",
-.static_src =
-"layout (location=0) in vec4 a_co;\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 4 0 \n"
-"\n"
-"uniform mat4 uPv;\n"
-"uniform mat4 uPvPrev;\n"
-"\n"
-"out float aAlpha;\n"
-"\n"
-"void main(){\n"
-" vec4 vproj0 = uPv * vec4( a_co.xyz, 1.0 );\n"
-" vec4 vproj1 = uPvPrev * vec4( a_co.xyz, 1.0 );\n"
-" vs_motion_out( vproj0, vproj1 );\n"
-"\n"
-" gl_Position = vproj0;\n"
-" aAlpha = a_co.w;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/trail.fs",
-.static_src =
-"layout (location = 0) out vec4 oColour;\n"
-"in float aAlpha;\n"
-"uniform vec4 uColour;\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 6 0 \n"
-"\n"
-"void main(){\n"
-" compute_motion_vectors();\n"
-"\n"
-" vec2 ssuv = gl_FragCoord.xy;\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" if( aAlpha+dither<0.5 )\n"
-" discard;\n"
-"\n"
-" oColour = vec4( uColour.rgb, uColour.a * aAlpha );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_trail_uPv;
-GLuint _uniform_trail_uPvPrev;
-GLuint _uniform_trail_uColour;
-#include "shaders/blit.h"
-struct vg_shader _shader_blit = {
- .name = "blit",
- .vs =
-{
-.orig_file = "shaders/blit.vs",
-.static_src =
-"layout (location=0) in vec2 a_co;\n"
-"out vec2 aUv;\n"
-"\n"
-"uniform vec2 uInverseRatio;\n"
-"\n"
-"void main()\n"
-"{\n"
-" gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
-" aUv = a_co * uInverseRatio;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/blit.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"uniform sampler2D uTexMain;\n"
-"\n"
-"in vec2 aUv;\n"
-"\n"
-"float kPi = 3.14159265358979;\n"
-"\n"
-"vec2 fisheye_distort(vec2 xy)\n"
-"{\n"
-" float aperture = 1350.0;\n"
-" float apertureHalf = 0.5 * aperture * (kPi / 180.0);\n"
-" float maxFactor = sin(apertureHalf);\n"
-"\n"
-" vec2 uv;\n"
-" float d = length(xy);\n"
-" if(d < (2.0-maxFactor))\n"
-" {\n"
-" d = length(xy * maxFactor);\n"
-" float z = sqrt(1.0 - d * d);\n"
-" float r = atan(d, z) / kPi;\n"
-" float phi = atan(xy.y, xy.x);\n"
-"\n"
-" uv.x = r * cos(phi) + 0.5;\n"
-" uv.y = r * sin(phi) + 0.5;\n"
-" }\n"
-" else\n"
-" {\n"
-" uv = 0.5*xy + 0.5;\n"
-" }\n"
-" \n"
-" return uv;\n"
-"}\n"
-"\n"
-"\n"
-"void main()\n"
-"{\n"
-" vec2 vwarp = 2.0*aUv - 1.0;\n"
-" vwarp = fisheye_distort( vwarp );\n"
-"\n"
-" FragColor = texture( uTexMain, aUv );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_blit_uInverseRatio;
-GLuint _uniform_blit_uTexMain;
-#include "shaders/blitblur.h"
-struct vg_shader _shader_blitblur = {
- .name = "blitblur",
- .vs =
-{
-.orig_file = "shaders/blit.vs",
-.static_src =
-"layout (location=0) in vec2 a_co;\n"
-"out vec2 aUv;\n"
-"\n"
-"uniform vec2 uInverseRatio;\n"
-"\n"
-"void main()\n"
-"{\n"
-" gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
-" aUv = a_co * uInverseRatio;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/blitblur.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"uniform sampler2D uTexMain;\n"
-"uniform sampler2D uTexMotion;\n"
-"uniform float uBlurStrength;\n"
-"uniform vec2 uOverrideDir;\n"
-"uniform float uTime;\n"
-"uniform float uGlitchStrength;\n"
-"uniform vec2 uClampUv;\n"
-"\n"
-"in vec2 aUv;\n"
-"\n"
-"vec2 rand_hash22( vec2 p ){\n"
-" vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
-" p3 += dot(p3, p3.yzx+19.19);\n"
-" return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
-"}\n"
-"\n"
-"const int NOISE_LOOP = 3;\n"
-"vec3 digital_noise( uvec3 iuv ){\n"
-" iuv *=uvec3(8,2524,7552);\n"
-" for( int i=0; i<NOISE_LOOP; i++ )\n"
-" iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
-" return vec3(iuv)*(1.0/float(0xffffffffU));\n"
-"}\n"
-"\n"
-"void main(){\n"
-" vec2 vuv = aUv; \n"
-"\n"
-" //if( uGlitchStrength > 0.0 ){\n"
-" // uvec3 p = uvec3( gl_FragCoord.xy, uint(uTime*30.0) );\n"
-" // vec2 g = digital_noise(p).xy;\n"
-" // vuv = aUv + g.xy*uGlitchStrength - uGlitchStrength*0.5;\n"
-" //}\n"
-"\n"
-" vec2 vrand = rand_hash22( vuv ) * 2.0 - vec2(1.0);\n"
-" vec2 vrand1 = rand_hash22( vrand ) * 2.0 - vec2(1.0);\n"
-" \n"
-" vec2 vdir = texture( uTexMotion, vuv ).xy * uBlurStrength + uOverrideDir;\n"
-"\n"
-" vec4 vcolour0 = texture( uTexMain, min(vuv + vdir*vrand.x,uClampUv) );\n"
-" vec4 vcolour1 = texture( uTexMain, min(vuv + vdir*vrand.y,uClampUv) );\n"
-" vec4 vcolour2 = texture( uTexMain, min(vuv + vdir*vrand1.x,uClampUv) );\n"
-" vec4 vcolour3 = texture( uTexMain, min(vuv + vdir*vrand1.y,uClampUv) );\n"
-"\n"
-" FragColor = ( vcolour0 + vcolour1 + vcolour2 + vcolour3 ) * 0.25;\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_blitblur_uInverseRatio;
-GLuint _uniform_blitblur_uTexMain;
-GLuint _uniform_blitblur_uTexMotion;
-GLuint _uniform_blitblur_uBlurStrength;
-GLuint _uniform_blitblur_uOverrideDir;
-GLuint _uniform_blitblur_uTime;
-GLuint _uniform_blitblur_uGlitchStrength;
-GLuint _uniform_blitblur_uClampUv;
-#include "shaders/blitcolour.h"
-struct vg_shader _shader_blitcolour = {
- .name = "blitcolour",
- .vs =
-{
-.orig_file = "shaders/blit.vs",
-.static_src =
-"layout (location=0) in vec2 a_co;\n"
-"out vec2 aUv;\n"
-"\n"
-"uniform vec2 uInverseRatio;\n"
-"\n"
-"void main()\n"
-"{\n"
-" gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
-" aUv = a_co * uInverseRatio;\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"
-""},
-};
-
-GLuint _uniform_blitcolour_uInverseRatio;
-GLuint _uniform_blitcolour_uColour;
-#include "shaders/blit_transition.h"
-struct vg_shader _shader_blit_transition = {
- .name = "blit_transition",
- .vs =
-{
-.orig_file = "shaders/blit.vs",
-.static_src =
-"layout (location=0) in vec2 a_co;\n"
-"out vec2 aUv;\n"
-"\n"
-"uniform vec2 uInverseRatio;\n"
-"\n"
-"void main()\n"
-"{\n"
-" gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
-" aUv = a_co * uInverseRatio;\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/blit_transition.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"in vec2 aUv;\n"
-"uniform float uT;\n"
-"\n"
-"void main(){\n"
-" float d = uT + distance( aUv, vec2(0.5,0.5) );\n"
-"\n"
-" vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), gl_FragCoord.xy) );\n"
-" float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
-"\n"
-" if( d+dither < -0.5 )\n"
-" discard;\n"
-"\n"
-" FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_blit_transition_uInverseRatio;
-GLuint _uniform_blit_transition_uT;
-#include "shaders/routeui.h"
-struct vg_shader _shader_routeui = {
- .name = "routeui",
- .vs =
-{
-.orig_file = "shaders/routeui.vs",
-.static_src =
-"layout (location=0) in vec2 a_co;\n"
-"\n"
-"uniform vec4 uOffset;\n"
-"\n"
-"void main()\n"
-"{\n"
-" vec2 vpos = a_co * uOffset.zw + uOffset.xy;\n"
-" gl_Position = vec4(vpos,0.0,1.0);\n"
-"}\n"
-""},
- .fs =
-{
-.orig_file = "shaders/routeui.fs",
-.static_src =
-"out vec4 FragColor;\n"
-"\n"
-"uniform vec4 uColour;\n"
-"\n"
-"void main()\n"
-"{\n"
-" FragColor = uColour;\n"
-"}\n"
-""},
-};
-
-GLuint _uniform_routeui_uOffset;
-GLuint _uniform_routeui_uColour;
-
-
-void vg_auto_shader_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_g_world_depth = glGetUniformLocation( _shader_scene_standard.id, "g_world_depth" );
- _uniform_scene_standard_uLightsArray = glGetUniformLocation( _shader_scene_standard.id, "uLightsArray" );
- _uniform_scene_standard_uLightsIndex = glGetUniformLocation( _shader_scene_standard.id, "uLightsIndex" );
- _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_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" );
- _uniform_scene_standard_alphatest_uLightsArray = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uLightsArray" );
- _uniform_scene_standard_alphatest_uLightsIndex = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uLightsIndex" );
- _uniform_scene_foliage_uMdl = glGetUniformLocation( _shader_scene_foliage.id, "uMdl" );
- _uniform_scene_foliage_uPv = glGetUniformLocation( _shader_scene_foliage.id, "uPv" );
- _uniform_scene_foliage_uPvmPrev = glGetUniformLocation( _shader_scene_foliage.id, "uPvmPrev" );
- _uniform_scene_foliage_uTime = glGetUniformLocation( _shader_scene_foliage.id, "uTime" );
- _uniform_scene_foliage_uTexGarbage = glGetUniformLocation( _shader_scene_foliage.id, "uTexGarbage" );
- _uniform_scene_foliage_uTexMain = glGetUniformLocation( _shader_scene_foliage.id, "uTexMain" );
- _uniform_scene_foliage_uCamera = glGetUniformLocation( _shader_scene_foliage.id, "uCamera" );
- _uniform_scene_foliage_uPlane = glGetUniformLocation( _shader_scene_foliage.id, "uPlane" );
- _uniform_scene_foliage_g_world_depth = glGetUniformLocation( _shader_scene_foliage.id, "g_world_depth" );
- _uniform_scene_foliage_uLightsArray = glGetUniformLocation( _shader_scene_foliage.id, "uLightsArray" );
- _uniform_scene_foliage_uLightsIndex = glGetUniformLocation( _shader_scene_foliage.id, "uLightsIndex" );
- _uniform_scene_override_uMdl = glGetUniformLocation( _shader_scene_override.id, "uMdl" );
- _uniform_scene_override_uPv = glGetUniformLocation( _shader_scene_override.id, "uPv" );
- _uniform_scene_override_uPvmPrev = glGetUniformLocation( _shader_scene_override.id, "uPvmPrev" );
- _uniform_scene_override_uNormalMtx = glGetUniformLocation( _shader_scene_override.id, "uNormalMtx" );
- _uniform_scene_override_uTexGarbage = glGetUniformLocation( _shader_scene_override.id, "uTexGarbage" );
- _uniform_scene_override_uTexMain = glGetUniformLocation( _shader_scene_override.id, "uTexMain" );
- _uniform_scene_override_uCamera = glGetUniformLocation( _shader_scene_override.id, "uCamera" );
- _uniform_scene_override_uPlane = glGetUniformLocation( _shader_scene_override.id, "uPlane" );
- _uniform_scene_override_uPlayerPos = glGetUniformLocation( _shader_scene_override.id, "uPlayerPos" );
- _uniform_scene_override_uSpawnPos = glGetUniformLocation( _shader_scene_override.id, "uSpawnPos" );
- _uniform_scene_override_uAlphatest = glGetUniformLocation( _shader_scene_override.id, "uAlphatest" );
- _uniform_scene_override_uMapInfo = glGetUniformLocation( _shader_scene_override.id, "uMapInfo" );
- _uniform_scene_override_g_world_depth = glGetUniformLocation( _shader_scene_override.id, "g_world_depth" );
- _uniform_scene_override_uLightsArray = glGetUniformLocation( _shader_scene_override.id, "uLightsArray" );
- _uniform_scene_override_uLightsIndex = glGetUniformLocation( _shader_scene_override.id, "uLightsIndex" );
- _uniform_scene_fxglow_uMdl = glGetUniformLocation( _shader_scene_fxglow.id, "uMdl" );
- _uniform_scene_fxglow_uPv = glGetUniformLocation( _shader_scene_fxglow.id, "uPv" );
- _uniform_scene_fxglow_uPvmPrev = glGetUniformLocation( _shader_scene_fxglow.id, "uPvmPrev" );
- _uniform_scene_fxglow_uUvOffset = glGetUniformLocation( _shader_scene_fxglow.id, "uUvOffset" );
- _uniform_scene_fxglow_uTexMain = glGetUniformLocation( _shader_scene_fxglow.id, "uTexMain" );
- _uniform_scene_fxglow_uCamera = glGetUniformLocation( _shader_scene_fxglow.id, "uCamera" );
- _uniform_scene_fxglow_g_world_depth = glGetUniformLocation( _shader_scene_fxglow.id, "g_world_depth" );
- _uniform_scene_fxglow_uLightsArray = glGetUniformLocation( _shader_scene_fxglow.id, "uLightsArray" );
- _uniform_scene_fxglow_uLightsIndex = glGetUniformLocation( _shader_scene_fxglow.id, "uLightsIndex" );
- _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_g_world_depth = glGetUniformLocation( _shader_scene_vertex_blend.id, "g_world_depth" );
- _uniform_scene_vertex_blend_uLightsArray = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsArray" );
- _uniform_scene_vertex_blend_uLightsIndex = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsIndex" );
- _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_g_world_depth = glGetUniformLocation( _shader_scene_terrain.id, "g_world_depth" );
- _uniform_scene_terrain_uLightsArray = glGetUniformLocation( _shader_scene_terrain.id, "uLightsArray" );
- _uniform_scene_terrain_uLightsIndex = glGetUniformLocation( _shader_scene_terrain.id, "uLightsIndex" );
- _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_uNormalMtx = glGetUniformLocation( _shader_scene_route.id, "uNormalMtx" );
- _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_g_world_depth = glGetUniformLocation( _shader_scene_route.id, "g_world_depth" );
- _uniform_scene_route_uLightsArray = glGetUniformLocation( _shader_scene_route.id, "uLightsArray" );
- _uniform_scene_route_uLightsIndex = glGetUniformLocation( _shader_scene_route.id, "uLightsIndex" );
- _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" );
- _uniform_scene_depth_uLightsArray = glGetUniformLocation( _shader_scene_depth.id, "uLightsArray" );
- _uniform_scene_depth_uLightsIndex = glGetUniformLocation( _shader_scene_depth.id, "uLightsIndex" );
- _uniform_scene_position_uMdl = glGetUniformLocation( _shader_scene_position.id, "uMdl" );
- _uniform_scene_position_uPv = glGetUniformLocation( _shader_scene_position.id, "uPv" );
- _uniform_scene_position_uPvmPrev = glGetUniformLocation( _shader_scene_position.id, "uPvmPrev" );
- _uniform_scene_position_uCamera = glGetUniformLocation( _shader_scene_position.id, "uCamera" );
- _uniform_scene_position_uBoard0 = glGetUniformLocation( _shader_scene_position.id, "uBoard0" );
- _uniform_scene_position_uBoard1 = glGetUniformLocation( _shader_scene_position.id, "uBoard1" );
- _uniform_scene_position_g_world_depth = glGetUniformLocation( _shader_scene_position.id, "g_world_depth" );
- _uniform_scene_position_uLightsArray = glGetUniformLocation( _shader_scene_position.id, "uLightsArray" );
- _uniform_scene_position_uLightsIndex = glGetUniformLocation( _shader_scene_position.id, "uLightsIndex" );
- _uniform_scene_cubemapped_uMdl = glGetUniformLocation( _shader_scene_cubemapped.id, "uMdl" );
- _uniform_scene_cubemapped_uPv = glGetUniformLocation( _shader_scene_cubemapped.id, "uPv" );
- _uniform_scene_cubemapped_uPvmPrev = glGetUniformLocation( _shader_scene_cubemapped.id, "uPvmPrev" );
- _uniform_scene_cubemapped_uTexGarbage = glGetUniformLocation( _shader_scene_cubemapped.id, "uTexGarbage" );
- _uniform_scene_cubemapped_uTexMain = glGetUniformLocation( _shader_scene_cubemapped.id, "uTexMain" );
- _uniform_scene_cubemapped_uTexCubemap = glGetUniformLocation( _shader_scene_cubemapped.id, "uTexCubemap" );
- _uniform_scene_cubemapped_uCamera = glGetUniformLocation( _shader_scene_cubemapped.id, "uCamera" );
- _uniform_scene_cubemapped_uPlane = glGetUniformLocation( _shader_scene_cubemapped.id, "uPlane" );
- _uniform_scene_cubemapped_uColour = glGetUniformLocation( _shader_scene_cubemapped.id, "uColour" );
- _uniform_scene_cubemapped_g_world_depth = glGetUniformLocation( _shader_scene_cubemapped.id, "g_world_depth" );
- _uniform_scene_cubemapped_uLightsArray = glGetUniformLocation( _shader_scene_cubemapped.id, "uLightsArray" );
- _uniform_scene_cubemapped_uLightsIndex = glGetUniformLocation( _shader_scene_cubemapped.id, "uLightsIndex" );
- _uniform_scene_water_uMdl = glGetUniformLocation( _shader_scene_water.id, "uMdl" );
- _uniform_scene_water_uPv = glGetUniformLocation( _shader_scene_water.id, "uPv" );
- _uniform_scene_water_uPvmPrev = glGetUniformLocation( _shader_scene_water.id, "uPvmPrev" );
- _uniform_scene_water_uTexMain = glGetUniformLocation( _shader_scene_water.id, "uTexMain" );
- _uniform_scene_water_uTexDudv = glGetUniformLocation( _shader_scene_water.id, "uTexDudv" );
- _uniform_scene_water_uTexBack = glGetUniformLocation( _shader_scene_water.id, "uTexBack" );
- _uniform_scene_water_uInvRes = glGetUniformLocation( _shader_scene_water.id, "uInvRes" );
- _uniform_scene_water_uTime = glGetUniformLocation( _shader_scene_water.id, "uTime" );
- _uniform_scene_water_uCamera = glGetUniformLocation( _shader_scene_water.id, "uCamera" );
- _uniform_scene_water_uSurfaceY = glGetUniformLocation( _shader_scene_water.id, "uSurfaceY" );
- _uniform_scene_water_uBoard0 = glGetUniformLocation( _shader_scene_water.id, "uBoard0" );
- _uniform_scene_water_uBoard1 = glGetUniformLocation( _shader_scene_water.id, "uBoard1" );
- _uniform_scene_water_uShoreColour = glGetUniformLocation( _shader_scene_water.id, "uShoreColour" );
- _uniform_scene_water_uOceanColour = glGetUniformLocation( _shader_scene_water.id, "uOceanColour" );
- _uniform_scene_water_uFresnel = glGetUniformLocation( _shader_scene_water.id, "uFresnel" );
- _uniform_scene_water_uWaterScale = glGetUniformLocation( _shader_scene_water.id, "uWaterScale" );
- _uniform_scene_water_uWaveSpeed = glGetUniformLocation( _shader_scene_water.id, "uWaveSpeed" );
- _uniform_scene_water_g_world_depth = glGetUniformLocation( _shader_scene_water.id, "g_world_depth" );
- _uniform_scene_water_uLightsArray = glGetUniformLocation( _shader_scene_water.id, "uLightsArray" );
- _uniform_scene_water_uLightsIndex = glGetUniformLocation( _shader_scene_water.id, "uLightsIndex" );
- _uniform_scene_water_fast_uMdl = glGetUniformLocation( _shader_scene_water_fast.id, "uMdl" );
- _uniform_scene_water_fast_uPv = glGetUniformLocation( _shader_scene_water_fast.id, "uPv" );
- _uniform_scene_water_fast_uPvmPrev = glGetUniformLocation( _shader_scene_water_fast.id, "uPvmPrev" );
- _uniform_scene_water_fast_uTexDudv = glGetUniformLocation( _shader_scene_water_fast.id, "uTexDudv" );
- _uniform_scene_water_fast_uTime = glGetUniformLocation( _shader_scene_water_fast.id, "uTime" );
- _uniform_scene_water_fast_uCamera = glGetUniformLocation( _shader_scene_water_fast.id, "uCamera" );
- _uniform_scene_water_fast_uSurfaceY = glGetUniformLocation( _shader_scene_water_fast.id, "uSurfaceY" );
- _uniform_scene_water_fast_uBoard0 = glGetUniformLocation( _shader_scene_water_fast.id, "uBoard0" );
- _uniform_scene_water_fast_uBoard1 = glGetUniformLocation( _shader_scene_water_fast.id, "uBoard1" );
- _uniform_scene_water_fast_uShoreColour = glGetUniformLocation( _shader_scene_water_fast.id, "uShoreColour" );
- _uniform_scene_water_fast_uOceanColour = glGetUniformLocation( _shader_scene_water_fast.id, "uOceanColour" );
- _uniform_scene_water_fast_g_world_depth = glGetUniformLocation( _shader_scene_water_fast.id, "g_world_depth" );
- _uniform_scene_water_fast_uLightsArray = glGetUniformLocation( _shader_scene_water_fast.id, "uLightsArray" );
- _uniform_scene_water_fast_uLightsIndex = glGetUniformLocation( _shader_scene_water_fast.id, "uLightsIndex" );
- _uniform_scene_scoretext_uMdl = glGetUniformLocation( _shader_scene_scoretext.id, "uMdl" );
- _uniform_scene_scoretext_uPv = glGetUniformLocation( _shader_scene_scoretext.id, "uPv" );
- _uniform_scene_scoretext_uPvmPrev = glGetUniformLocation( _shader_scene_scoretext.id, "uPvmPrev" );
- _uniform_scene_scoretext_uInfo = glGetUniformLocation( _shader_scene_scoretext.id, "uInfo" );
- _uniform_scene_scoretext_uTexGarbage = glGetUniformLocation( _shader_scene_scoretext.id, "uTexGarbage" );
- _uniform_scene_scoretext_uTexMain = glGetUniformLocation( _shader_scene_scoretext.id, "uTexMain" );
- _uniform_scene_scoretext_uCamera = glGetUniformLocation( _shader_scene_scoretext.id, "uCamera" );
- _uniform_scene_scoretext_uPlane = glGetUniformLocation( _shader_scene_scoretext.id, "uPlane" );
- _uniform_scene_scoretext_g_world_depth = glGetUniformLocation( _shader_scene_scoretext.id, "g_world_depth" );
- _uniform_scene_scoretext_uLightsArray = glGetUniformLocation( _shader_scene_scoretext.id, "uLightsArray" );
- _uniform_scene_scoretext_uLightsIndex = glGetUniformLocation( _shader_scene_scoretext.id, "uLightsIndex" );
- _uniform_scene_font_uMdl = glGetUniformLocation( _shader_scene_font.id, "uMdl" );
- _uniform_scene_font_uPv = glGetUniformLocation( _shader_scene_font.id, "uPv" );
- _uniform_scene_font_uPvmPrev = glGetUniformLocation( _shader_scene_font.id, "uPvmPrev" );
- _uniform_scene_font_uOffset = glGetUniformLocation( _shader_scene_font.id, "uOffset" );
- _uniform_scene_font_uTexGarbage = glGetUniformLocation( _shader_scene_font.id, "uTexGarbage" );
- _uniform_scene_font_uTexMain = glGetUniformLocation( _shader_scene_font.id, "uTexMain" );
- _uniform_scene_font_uCamera = glGetUniformLocation( _shader_scene_font.id, "uCamera" );
- _uniform_scene_font_uTime = glGetUniformLocation( _shader_scene_font.id, "uTime" );
- _uniform_scene_font_uOpacity = glGetUniformLocation( _shader_scene_font.id, "uOpacity" );
- _uniform_scene_font_uColourize = glGetUniformLocation( _shader_scene_font.id, "uColourize" );
- _uniform_scene_font_g_world_depth = glGetUniformLocation( _shader_scene_font.id, "g_world_depth" );
- _uniform_scene_font_uLightsArray = glGetUniformLocation( _shader_scene_font.id, "uLightsArray" );
- _uniform_scene_font_uLightsIndex = glGetUniformLocation( _shader_scene_font.id, "uLightsIndex" );
- _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_uTexGarbage = glGetUniformLocation( _shader_model_sky.id, "uTexGarbage" );
- _uniform_model_sky_g_world_depth = glGetUniformLocation( _shader_model_sky.id, "g_world_depth" );
- _uniform_model_sky_uLightsArray = glGetUniformLocation( _shader_model_sky.id, "uLightsArray" );
- _uniform_model_sky_uLightsIndex = glGetUniformLocation( _shader_model_sky.id, "uLightsIndex" );
- _uniform_model_sky_space_uMdl = glGetUniformLocation( _shader_model_sky_space.id, "uMdl" );
- _uniform_model_sky_space_uPv = glGetUniformLocation( _shader_model_sky_space.id, "uPv" );
- _uniform_model_sky_space_uPvmPrev = glGetUniformLocation( _shader_model_sky_space.id, "uPvmPrev" );
- _uniform_model_sky_space_uTexGarbage = glGetUniformLocation( _shader_model_sky_space.id, "uTexGarbage" );
- _uniform_model_sky_space_g_world_depth = glGetUniformLocation( _shader_model_sky_space.id, "g_world_depth" );
- _uniform_model_sky_space_uLightsArray = glGetUniformLocation( _shader_model_sky_space.id, "uLightsArray" );
- _uniform_model_sky_space_uLightsIndex = glGetUniformLocation( _shader_model_sky_space.id, "uLightsIndex" );
- _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" );
- _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_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" );
- _uniform_model_character_view_uLightsArray = glGetUniformLocation( _shader_model_character_view.id, "uLightsArray" );
- _uniform_model_character_view_uLightsIndex = glGetUniformLocation( _shader_model_character_view.id, "uLightsIndex" );
- _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" );
- _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" );
- _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" );
- _uniform_model_character_view_uDepthMode = glGetUniformLocation( _shader_model_character_view.id, "uDepthMode" );
- _uniform_model_character_view_uDitherCutoff = glGetUniformLocation( _shader_model_character_view.id, "uDitherCutoff" );
- _uniform_model_board_view_uMdl = glGetUniformLocation( _shader_model_board_view.id, "uMdl" );
- _uniform_model_board_view_uPv = glGetUniformLocation( _shader_model_board_view.id, "uPv" );
- _uniform_model_board_view_uPvmPrev = glGetUniformLocation( _shader_model_board_view.id, "uPvmPrev" );
- _uniform_model_board_view_uTexMain = glGetUniformLocation( _shader_model_board_view.id, "uTexMain" );
- _uniform_model_board_view_uCamera = glGetUniformLocation( _shader_model_board_view.id, "uCamera" );
- _uniform_model_board_view_g_world_depth = glGetUniformLocation( _shader_model_board_view.id, "g_world_depth" );
- _uniform_model_board_view_uLightsArray = glGetUniformLocation( _shader_model_board_view.id, "uLightsArray" );
- _uniform_model_board_view_uLightsIndex = glGetUniformLocation( _shader_model_board_view.id, "uLightsIndex" );
- _uniform_model_board_view_uTexSceneDepth = glGetUniformLocation( _shader_model_board_view.id, "uTexSceneDepth" );
- _uniform_model_board_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioDepth" );
- _uniform_model_board_view_uInverseRatioMain = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioMain" );
- _uniform_model_board_view_uDepthMode = glGetUniformLocation( _shader_model_board_view.id, "uDepthMode" );
- _uniform_model_board_view_uDitherCutoff = glGetUniformLocation( _shader_model_board_view.id, "uDitherCutoff" );
- _uniform_model_entity_uMdl = glGetUniformLocation( _shader_model_entity.id, "uMdl" );
- _uniform_model_entity_uPv = glGetUniformLocation( _shader_model_entity.id, "uPv" );
- _uniform_model_entity_uPvmPrev = glGetUniformLocation( _shader_model_entity.id, "uPvmPrev" );
- _uniform_model_entity_uTexMain = glGetUniformLocation( _shader_model_entity.id, "uTexMain" );
- _uniform_model_entity_uCamera = glGetUniformLocation( _shader_model_entity.id, "uCamera" );
- _uniform_model_entity_g_world_depth = glGetUniformLocation( _shader_model_entity.id, "g_world_depth" );
- _uniform_model_entity_uLightsArray = glGetUniformLocation( _shader_model_entity.id, "uLightsArray" );
- _uniform_model_entity_uLightsIndex = glGetUniformLocation( _shader_model_entity.id, "uLightsIndex" );
- _uniform_model_gate_uMdl = glGetUniformLocation( _shader_model_gate.id, "uMdl" );
- _uniform_model_gate_uPv = glGetUniformLocation( _shader_model_gate.id, "uPv" );
- _uniform_model_gate_uPvmPrev = glGetUniformLocation( _shader_model_gate.id, "uPvmPrev" );
- _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" );
- _uniform_model_gate_uColour = glGetUniformLocation( _shader_model_gate.id, "uColour" );
- _uniform_model_gate_unlinked_uMdl = glGetUniformLocation( _shader_model_gate_unlinked.id, "uMdl" );
- _uniform_model_gate_unlinked_uPv = glGetUniformLocation( _shader_model_gate_unlinked.id, "uPv" );
- _uniform_model_gate_unlinked_uPvmPrev = glGetUniformLocation( _shader_model_gate_unlinked.id, "uPvmPrev" );
- _uniform_model_gate_unlinked_uTime = glGetUniformLocation( _shader_model_gate_unlinked.id, "uTime" );
- _uniform_model_gate_unlinked_uCam = glGetUniformLocation( _shader_model_gate_unlinked.id, "uCam" );
- _uniform_model_gate_unlinked_uColour = glGetUniformLocation( _shader_model_gate_unlinked.id, "uColour" );
- _uniform_model_font_uMdl = glGetUniformLocation( _shader_model_font.id, "uMdl" );
- _uniform_model_font_uPv = glGetUniformLocation( _shader_model_font.id, "uPv" );
- _uniform_model_font_uPvmPrev = glGetUniformLocation( _shader_model_font.id, "uPvmPrev" );
- _uniform_model_font_uOffset = glGetUniformLocation( _shader_model_font.id, "uOffset" );
- _uniform_model_font_uTexMain = glGetUniformLocation( _shader_model_font.id, "uTexMain" );
- _uniform_model_font_uColour = glGetUniformLocation( _shader_model_font.id, "uColour" );
- _uniform_model_font_uTexSceneDepth = glGetUniformLocation( _shader_model_font.id, "uTexSceneDepth" );
- _uniform_model_font_uInverseRatioDepth = glGetUniformLocation( _shader_model_font.id, "uInverseRatioDepth" );
- _uniform_model_font_uInverseRatioMain = glGetUniformLocation( _shader_model_font.id, "uInverseRatioMain" );
- _uniform_model_font_uDepthMode = glGetUniformLocation( _shader_model_font.id, "uDepthMode" );
- _uniform_model_font_uDitherCutoff = glGetUniformLocation( _shader_model_font.id, "uDitherCutoff" );
- _uniform_particle_uPv = glGetUniformLocation( _shader_particle.id, "uPv" );
- _uniform_particle_uPvPrev = glGetUniformLocation( _shader_particle.id, "uPvPrev" );
- _uniform_trail_uPv = glGetUniformLocation( _shader_trail.id, "uPv" );
- _uniform_trail_uPvPrev = glGetUniformLocation( _shader_trail.id, "uPvPrev" );
- _uniform_trail_uColour = glGetUniformLocation( _shader_trail.id, "uColour" );
- _uniform_blit_uInverseRatio = glGetUniformLocation( _shader_blit.id, "uInverseRatio" );
- _uniform_blit_uTexMain = glGetUniformLocation( _shader_blit.id, "uTexMain" );
- _uniform_blitblur_uInverseRatio = glGetUniformLocation( _shader_blitblur.id, "uInverseRatio" );
- _uniform_blitblur_uTexMain = glGetUniformLocation( _shader_blitblur.id, "uTexMain" );
- _uniform_blitblur_uTexMotion = glGetUniformLocation( _shader_blitblur.id, "uTexMotion" );
- _uniform_blitblur_uBlurStrength = glGetUniformLocation( _shader_blitblur.id, "uBlurStrength" );
- _uniform_blitblur_uOverrideDir = glGetUniformLocation( _shader_blitblur.id, "uOverrideDir" );
- _uniform_blitblur_uTime = glGetUniformLocation( _shader_blitblur.id, "uTime" );
- _uniform_blitblur_uGlitchStrength = glGetUniformLocation( _shader_blitblur.id, "uGlitchStrength" );
- _uniform_blitblur_uClampUv = glGetUniformLocation( _shader_blitblur.id, "uClampUv" );
- _uniform_blitcolour_uInverseRatio = glGetUniformLocation( _shader_blitcolour.id, "uInverseRatio" );
- _uniform_blitcolour_uColour = glGetUniformLocation( _shader_blitcolour.id, "uColour" );
- _uniform_blit_transition_uInverseRatio = glGetUniformLocation( _shader_blit_transition.id, "uInverseRatio" );
- _uniform_blit_transition_uT = glGetUniformLocation( _shader_blit_transition.id, "uT" );
- _uniform_routeui_uOffset = glGetUniformLocation( _shader_routeui.id, "uOffset" );
- _uniform_routeui_uColour = glGetUniformLocation( _shader_routeui.id, "uColour" );
-}
-
-void vg_auto_shader_register(void)
-{
- vg_shader_register( &_shader_scene_standard );
- vg_shader_register( &_shader_scene_standard_alphatest );
- vg_shader_register( &_shader_scene_foliage );
- vg_shader_register( &_shader_scene_override );
- vg_shader_register( &_shader_scene_fxglow );
- vg_shader_register( &_shader_scene_vertex_blend );
- vg_shader_register( &_shader_scene_terrain );
- vg_shader_register( &_shader_scene_route );
- vg_shader_register( &_shader_scene_depth );
- vg_shader_register( &_shader_scene_position );
- vg_shader_register( &_shader_scene_cubemapped );
- vg_shader_register( &_shader_scene_water );
- vg_shader_register( &_shader_scene_water_fast );
- vg_shader_register( &_shader_scene_scoretext );
- vg_shader_register( &_shader_scene_font );
- vg_shader_register( &_shader_model_sky );
- vg_shader_register( &_shader_model_sky_space );
- vg_shader_register( &_shader_model_menu );
- vg_shader_register( &_shader_model_character_view );
- vg_shader_register( &_shader_model_board_view );
- vg_shader_register( &_shader_model_entity );
- vg_shader_register( &_shader_model_gate );
- vg_shader_register( &_shader_model_gate_unlinked );
- vg_shader_register( &_shader_model_font );
- vg_shader_register( &_shader_particle );
- vg_shader_register( &_shader_trail );
- vg_shader_register( &_shader_blit );
- vg_shader_register( &_shader_blitblur );
- vg_shader_register( &_shader_blitcolour );
- vg_shader_register( &_shader_blit_transition );
- vg_shader_register( &_shader_routeui );
-}
-