1 #include "shaders/scene_standard.h"
2 struct vg_shader _shader_scene_standard
= {
3 .name
= "scene_standard",
6 .orig_file
= "shaders/scene.vs",
8 "layout (location=0) in vec3 a_co;\n"
9 "layout (location=1) in vec4 a_norm;\n"
10 "layout (location=2) in vec2 a_uv;\n"
13 "const float k_motion_lerp_amount = 0.01;\n"
17 "out vec3 aMotionVec0;\n"
18 "out vec3 aMotionVec1;\n"
20 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
22 " // This magically solves some artifacting errors!\n"
24 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
26 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
27 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
32 "uniform mat4x3 uMdl;\n"
34 "uniform mat4 uPvmPrev;\n"
39 "out vec3 aWorldCo;\n"
43 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
44 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
45 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
47 " vs_motion_out( vproj0, vproj1 );\n"
49 " gl_Position = vproj0;\n"
52 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
54 " aWorldCo = world_pos0;\n"
59 .orig_file
= "shaders/scene_standard.fs",
61 "uniform sampler2D uTexGarbage;\n"
62 "uniform sampler2D uTexMain;\n"
63 "uniform vec3 uCamera;\n"
64 "uniform vec4 uPlane;\n"
68 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
80 "layout (location = 0) out vec4 oColour;\n"
82 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
83 "layout (std140) uniform ub_world_lighting\n"
86 " vec4 g_cube_inv_range;\n"
88 " vec4 g_water_plane;\n"
89 " vec4 g_depth_bounds;\n"
91 " vec4 g_daysky_colour;\n"
92 " vec4 g_nightsky_colour;\n"
93 " vec4 g_sunset_colour;\n"
94 " vec4 g_ambient_colour;\n"
95 " vec4 g_sunset_ambient;\n"
96 " vec4 g_sun_colour;\n"
101 " float g_water_fog;\n"
103 " float g_realtime;\n"
104 " float g_shadow_length;\n"
105 " float g_shadow_spread;\n"
107 " float g_time_of_day;\n"
108 " float g_day_phase;\n"
109 " float g_sunset_phase;\n"
111 " int g_light_preview;\n"
112 " int g_shadow_samples;\n"
114 " int g_debug_indices;\n"
115 " int g_debug_complexity;\n"
118 "uniform sampler2D g_world_depth;\n"
119 "uniform samplerBuffer uLightsArray;\n"
120 "uniform usampler3D uLightsIndex;\n"
123 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
124 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
125 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
126 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
127 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
128 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
130 "const float SUN_ANGLE = 0.0001;\n"
131 "const float PI = 3.14159265358979323846264;\n"
133 "//struct world_info\n"
143 "vec3 rand33(vec3 p3)\n"
145 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
146 " p3 += dot(p3, p3.yxz+33.33);\n"
147 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
150 "float stars( vec3 rd, float rr, float size ){\n"
151 " vec3 co = rd * rr;\n"
153 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
155 " float spaces = 1.0 / rr;\n"
156 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
157 " a -= mod(a, spaces) - spaces * 0.5;\n"
159 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
161 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
162 " plane = plane - mod(plane, PI / count);\n"
164 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
166 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
167 " float ydist = sqrt(rr * rr - level * level);\n"
168 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
169 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
170 " float star = smoothstep(size, 0.0, distance(center, co));\n"
174 "float luminance( vec3 v )\n"
176 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
179 "vec3 clearskies_ambient( vec3 dir )\n"
181 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
182 " float sky_gradient = dir.y;\n"
184 " /* Blend phase colours */\n"
185 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
186 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
187 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
189 " /* Add gradient */\n"
190 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
195 "vec3 clearskies_sky( vec3 ray_dir )\n"
197 " ray_dir.y = abs( ray_dir.y );\n"
198 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
201 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
202 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
203 " float sun_shape = pow( sun_size, 2000.0 );\n"
204 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
206 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
207 " sun_colour *= sun_shape;\n"
210 " float star = 0.0;\n"
211 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
213 " if( star_blend > 0.001 ){\n"
214 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
215 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
216 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
220 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
221 " return composite;\n"
224 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
226 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
228 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
229 " g_sunset_phase );\n"
231 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
232 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
233 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
234 " ) * g_sun_colour.rgb * g_day_phase;\n"
236 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
237 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
238 " g_sunset_phase );\n"
240 " return ambient + (light_sun + sky_reflection) * shadow;\n"
245 "float world_depth_sample( vec3 pos )\n"
247 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
248 " return texture( g_world_depth, depth_coord ).r;\n"
251 "float world_water_depth( vec3 pos )\n"
253 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
254 " return world_depth_sample( pos ) - ref_depth;\n"
257 "float shadow_sample( vec3 co ){\n"
258 " float height_sample = world_depth_sample( co );\n"
260 " float fdelta = height_sample - co.y;\n"
261 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
264 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
265 " if( g_shadow_samples == 0 ){\n"
269 " float fspread = g_shadow_spread;\n"
270 " float flength = g_shadow_length;\n"
272 " float famt = 0.0;\n"
273 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
274 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
275 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
276 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
278 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
279 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
280 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
281 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
283 " return 1.0 - famt;\n"
286 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
288 " vec3 specdir = reflect( -dir, wnormal );\n"
289 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
292 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
293 " float dist = pow(fdist*0.0010,0.78);\n"
294 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
297 "vec3 scene_calculate_light( int light_index, \n"
298 " vec3 halfview, vec3 co, vec3 normal )\n"
300 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
301 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
302 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
304 " vec3 light_delta = light_co.xyz-co;\n"
305 " float dist2 = dot(light_delta,light_delta);\n"
307 " light_delta = normalize( light_delta );\n"
309 " float quadratic = dist2*100.0;\n"
310 " float attenuation = 1.0/( 1.0 + quadratic );\n"
311 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
313 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
315 " if( light_dir.w < 0.999999 ){\n"
316 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
317 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
320 " return light_colour.rgb * attenuation * falloff \n"
321 " * step( g_day_phase, light_colour.w );\n"
324 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
325 " vec3 halfview, vec3 co, vec3 normal )\n"
327 " uint light_count = packed_index & 0x3u;\n"
329 " vec3 l = vec3(0.0);\n"
331 " if( light_count >= 1u ){\n"
332 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
333 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
334 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
336 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
338 " if( light_count >= 2u ){\n"
339 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
341 " if( light_count >= 3u ){\n"
342 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
350 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
351 " float light_mask )\n"
353 " if( g_light_preview == 1 )\n"
354 " diffuse = vec3(0.75);\n"
357 " vec3 halfview = uCamera - co;\n"
358 " float fdist = length(halfview);\n"
359 " halfview /= fdist;\n"
361 " float world_shadow = newlight_compute_sun_shadow( \n"
362 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
364 " vec3 total_light = clearskies_lighting( \n"
365 " normal, min( light_mask, world_shadow ), halfview );\n"
367 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
368 " cube_coord = floor( cube_coord );\n"
370 " if( g_debug_indices == 1 )\n"
372 " return rand33(cube_coord);\n"
375 " if( g_debug_complexity == 1 )\n"
377 " ivec3 coord = ivec3( cube_coord );\n"
378 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
380 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
381 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
384 " // FIXME: this coord should absolutely must be clamped!\n"
386 " ivec3 coord = ivec3( cube_coord );\n"
387 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
390 " scene_calculate_packed_light_patch( index_sample.x,\n"
391 " halfview, co, normal ) \n"
394 " scene_calculate_packed_light_patch( index_sample.y,\n"
395 " halfview, co, normal )\n"
398 " // Take a section of the sky function to give us a matching fog colour\n"
400 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
401 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
402 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
403 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
405 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
406 " sun_colour *= sun_shape;\n"
408 " fog_colour += sun_colour;\n"
409 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
414 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
416 " vec3 pa = p - a;\n"
417 " vec3 ba = b - a;\n"
419 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
420 " return length( pa - ba*h );\n"
423 "float compute_board_shadow()\n"
425 " // player shadow\n"
426 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
427 " g_board_1.xyz )-0.1 );\n"
428 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
429 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
431 " return 1.0 - player_shadow*0.8;\n"
434 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
436 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
441 "const float k_motion_lerp_amount = 0.01;\n"
445 "layout (location = 1) out vec2 oMotionVec;\n"
447 "in vec3 aMotionVec0;\n"
448 "in vec3 aMotionVec1;\n"
450 "void compute_motion_vectors()\n"
452 " // Write motion vectors\n"
453 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
454 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
456 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
463 " compute_motion_vectors();\n"
465 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
466 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
467 " vec3 qnorm = aNorm.xyz;\n"
469 " vfrag = vsamplemain.rgb;\n"
471 " if( g_light_preview == 1 )\n"
473 " vfrag = vec3(0.5);\n"
476 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
477 " oColour = vec4( vfrag, 1.0 );\n"
482 GLuint _uniform_scene_standard_uMdl
;
483 GLuint _uniform_scene_standard_uPv
;
484 GLuint _uniform_scene_standard_uPvmPrev
;
485 GLuint _uniform_scene_standard_uTexGarbage
;
486 GLuint _uniform_scene_standard_uTexMain
;
487 GLuint _uniform_scene_standard_uCamera
;
488 GLuint _uniform_scene_standard_uPlane
;
489 GLuint _uniform_scene_standard_g_world_depth
;
490 GLuint _uniform_scene_standard_uLightsArray
;
491 GLuint _uniform_scene_standard_uLightsIndex
;
492 #include "shaders/scene_standard_alphatest.h"
493 struct vg_shader _shader_scene_standard_alphatest
= {
494 .name
= "scene_standard_alphatest",
497 .orig_file
= "shaders/scene.vs",
499 "layout (location=0) in vec3 a_co;\n"
500 "layout (location=1) in vec4 a_norm;\n"
501 "layout (location=2) in vec2 a_uv;\n"
504 "const float k_motion_lerp_amount = 0.01;\n"
508 "out vec3 aMotionVec0;\n"
509 "out vec3 aMotionVec1;\n"
511 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
513 " // This magically solves some artifacting errors!\n"
515 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
517 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
518 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
523 "uniform mat4x3 uMdl;\n"
524 "uniform mat4 uPv;\n"
525 "uniform mat4 uPvmPrev;\n"
530 "out vec3 aWorldCo;\n"
534 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
535 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
536 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
538 " vs_motion_out( vproj0, vproj1 );\n"
540 " gl_Position = vproj0;\n"
543 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
545 " aWorldCo = world_pos0;\n"
550 .orig_file
= "shaders/scene_standard_alphatest.fs",
552 "uniform sampler2D uTexGarbage;\n"
553 "uniform sampler2D uTexMain;\n"
554 "uniform vec3 uCamera;\n"
555 "uniform vec4 uPlane;\n"
559 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
568 "in vec3 aWorldCo;\n"
571 "layout (location = 0) out vec4 oColour;\n"
573 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
574 "layout (std140) uniform ub_world_lighting\n"
576 " vec4 g_cube_min;\n"
577 " vec4 g_cube_inv_range;\n"
579 " vec4 g_water_plane;\n"
580 " vec4 g_depth_bounds;\n"
582 " vec4 g_daysky_colour;\n"
583 " vec4 g_nightsky_colour;\n"
584 " vec4 g_sunset_colour;\n"
585 " vec4 g_ambient_colour;\n"
586 " vec4 g_sunset_ambient;\n"
587 " vec4 g_sun_colour;\n"
592 " float g_water_fog;\n"
594 " float g_realtime;\n"
595 " float g_shadow_length;\n"
596 " float g_shadow_spread;\n"
598 " float g_time_of_day;\n"
599 " float g_day_phase;\n"
600 " float g_sunset_phase;\n"
602 " int g_light_preview;\n"
603 " int g_shadow_samples;\n"
605 " int g_debug_indices;\n"
606 " int g_debug_complexity;\n"
609 "uniform sampler2D g_world_depth;\n"
610 "uniform samplerBuffer uLightsArray;\n"
611 "uniform usampler3D uLightsIndex;\n"
614 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
615 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
616 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
617 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
618 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
619 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
621 "const float SUN_ANGLE = 0.0001;\n"
622 "const float PI = 3.14159265358979323846264;\n"
624 "//struct world_info\n"
634 "vec3 rand33(vec3 p3)\n"
636 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
637 " p3 += dot(p3, p3.yxz+33.33);\n"
638 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
641 "float stars( vec3 rd, float rr, float size ){\n"
642 " vec3 co = rd * rr;\n"
644 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
646 " float spaces = 1.0 / rr;\n"
647 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
648 " a -= mod(a, spaces) - spaces * 0.5;\n"
650 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
652 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
653 " plane = plane - mod(plane, PI / count);\n"
655 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
657 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
658 " float ydist = sqrt(rr * rr - level * level);\n"
659 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
660 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
661 " float star = smoothstep(size, 0.0, distance(center, co));\n"
665 "float luminance( vec3 v )\n"
667 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
670 "vec3 clearskies_ambient( vec3 dir )\n"
672 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
673 " float sky_gradient = dir.y;\n"
675 " /* Blend phase colours */\n"
676 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
677 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
678 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
680 " /* Add gradient */\n"
681 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
686 "vec3 clearskies_sky( vec3 ray_dir )\n"
688 " ray_dir.y = abs( ray_dir.y );\n"
689 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
692 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
693 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
694 " float sun_shape = pow( sun_size, 2000.0 );\n"
695 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
697 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
698 " sun_colour *= sun_shape;\n"
701 " float star = 0.0;\n"
702 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
704 " if( star_blend > 0.001 ){\n"
705 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
706 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
707 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
711 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
712 " return composite;\n"
715 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
717 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
719 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
720 " g_sunset_phase );\n"
722 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
723 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
724 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
725 " ) * g_sun_colour.rgb * g_day_phase;\n"
727 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
728 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
729 " g_sunset_phase );\n"
731 " return ambient + (light_sun + sky_reflection) * shadow;\n"
736 "float world_depth_sample( vec3 pos )\n"
738 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
739 " return texture( g_world_depth, depth_coord ).r;\n"
742 "float world_water_depth( vec3 pos )\n"
744 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
745 " return world_depth_sample( pos ) - ref_depth;\n"
748 "float shadow_sample( vec3 co ){\n"
749 " float height_sample = world_depth_sample( co );\n"
751 " float fdelta = height_sample - co.y;\n"
752 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
755 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
756 " if( g_shadow_samples == 0 ){\n"
760 " float fspread = g_shadow_spread;\n"
761 " float flength = g_shadow_length;\n"
763 " float famt = 0.0;\n"
764 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
765 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
766 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
767 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
769 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
770 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
771 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
772 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
774 " return 1.0 - famt;\n"
777 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
779 " vec3 specdir = reflect( -dir, wnormal );\n"
780 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
783 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
784 " float dist = pow(fdist*0.0010,0.78);\n"
785 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
788 "vec3 scene_calculate_light( int light_index, \n"
789 " vec3 halfview, vec3 co, vec3 normal )\n"
791 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
792 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
793 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
795 " vec3 light_delta = light_co.xyz-co;\n"
796 " float dist2 = dot(light_delta,light_delta);\n"
798 " light_delta = normalize( light_delta );\n"
800 " float quadratic = dist2*100.0;\n"
801 " float attenuation = 1.0/( 1.0 + quadratic );\n"
802 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
804 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
806 " if( light_dir.w < 0.999999 ){\n"
807 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
808 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
811 " return light_colour.rgb * attenuation * falloff \n"
812 " * step( g_day_phase, light_colour.w );\n"
815 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
816 " vec3 halfview, vec3 co, vec3 normal )\n"
818 " uint light_count = packed_index & 0x3u;\n"
820 " vec3 l = vec3(0.0);\n"
822 " if( light_count >= 1u ){\n"
823 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
824 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
825 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
827 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
829 " if( light_count >= 2u ){\n"
830 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
832 " if( light_count >= 3u ){\n"
833 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
841 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
842 " float light_mask )\n"
844 " if( g_light_preview == 1 )\n"
845 " diffuse = vec3(0.75);\n"
848 " vec3 halfview = uCamera - co;\n"
849 " float fdist = length(halfview);\n"
850 " halfview /= fdist;\n"
852 " float world_shadow = newlight_compute_sun_shadow( \n"
853 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
855 " vec3 total_light = clearskies_lighting( \n"
856 " normal, min( light_mask, world_shadow ), halfview );\n"
858 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
859 " cube_coord = floor( cube_coord );\n"
861 " if( g_debug_indices == 1 )\n"
863 " return rand33(cube_coord);\n"
866 " if( g_debug_complexity == 1 )\n"
868 " ivec3 coord = ivec3( cube_coord );\n"
869 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
871 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
872 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
875 " // FIXME: this coord should absolutely must be clamped!\n"
877 " ivec3 coord = ivec3( cube_coord );\n"
878 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
881 " scene_calculate_packed_light_patch( index_sample.x,\n"
882 " halfview, co, normal ) \n"
885 " scene_calculate_packed_light_patch( index_sample.y,\n"
886 " halfview, co, normal )\n"
889 " // Take a section of the sky function to give us a matching fog colour\n"
891 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
892 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
893 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
894 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
896 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
897 " sun_colour *= sun_shape;\n"
899 " fog_colour += sun_colour;\n"
900 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
905 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
907 " vec3 pa = p - a;\n"
908 " vec3 ba = b - a;\n"
910 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
911 " return length( pa - ba*h );\n"
914 "float compute_board_shadow()\n"
916 " // player shadow\n"
917 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
918 " g_board_1.xyz )-0.1 );\n"
919 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
920 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
922 " return 1.0 - player_shadow*0.8;\n"
925 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
927 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
932 "const float k_motion_lerp_amount = 0.01;\n"
936 "layout (location = 1) out vec2 oMotionVec;\n"
938 "in vec3 aMotionVec0;\n"
939 "in vec3 aMotionVec1;\n"
941 "void compute_motion_vectors()\n"
943 " // Write motion vectors\n"
944 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
945 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
947 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
954 " compute_motion_vectors();\n"
956 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
957 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
958 " vec3 qnorm = aNorm.xyz;\n"
960 " if( vsamplemain.a < 0.15 )\n"
963 " vfrag = vsamplemain.rgb;\n"
965 " if( g_light_preview == 1 )\n"
967 " vfrag = vec3(0.5);\n"
970 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
971 " oColour = vec4(vfrag, 1.0);\n"
976 GLuint _uniform_scene_standard_alphatest_uMdl
;
977 GLuint _uniform_scene_standard_alphatest_uPv
;
978 GLuint _uniform_scene_standard_alphatest_uPvmPrev
;
979 GLuint _uniform_scene_standard_alphatest_uTexGarbage
;
980 GLuint _uniform_scene_standard_alphatest_uTexMain
;
981 GLuint _uniform_scene_standard_alphatest_uCamera
;
982 GLuint _uniform_scene_standard_alphatest_uPlane
;
983 GLuint _uniform_scene_standard_alphatest_g_world_depth
;
984 GLuint _uniform_scene_standard_alphatest_uLightsArray
;
985 GLuint _uniform_scene_standard_alphatest_uLightsIndex
;
986 #include "shaders/scene_foliage.h"
987 struct vg_shader _shader_scene_foliage
= {
988 .name
= "scene_foliage",
991 .orig_file
= "shaders/scene_foliage.vs",
993 "layout (location=0) in vec3 a_co;\n"
994 "layout (location=1) in vec4 a_norm;\n"
995 "layout (location=2) in vec2 a_uv;\n"
998 "const float k_motion_lerp_amount = 0.01;\n"
1002 "out vec3 aMotionVec0;\n"
1003 "out vec3 aMotionVec1;\n"
1005 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
1007 " // This magically solves some artifacting errors!\n"
1009 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
1011 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
1012 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
1017 "uniform mat4x3 uMdl;\n"
1018 "uniform mat4 uPv;\n"
1019 "uniform mat4 uPvmPrev;\n"
1020 "uniform float uTime;\n"
1025 "out vec3 aWorldCo;\n"
1028 " vec4 vsine = sin(vec4(uTime + a_co.x, uTime*0.7 + a_co.z,uTime,uTime*1.3));\n"
1029 " vec3 co = a_co + vsine.xyz * a_norm.w * 0.5;\n"
1031 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
1032 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
1033 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
1035 " vs_motion_out( vproj0, vproj1 );\n"
1037 " gl_Position = vproj0;\n"
1040 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
1042 " aWorldCo = world_pos0;\n"
1047 .orig_file
= "shaders/scene_foliage.fs",
1049 "uniform sampler2D uTexGarbage;\n"
1050 "uniform sampler2D uTexMain;\n"
1051 "uniform vec3 uCamera;\n"
1052 "uniform vec4 uPlane;\n"
1054 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.4;\n"
1061 "in vec3 aWorldCo;\n"
1064 "layout (location = 0) out vec4 oColour;\n"
1066 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
1067 "layout (std140) uniform ub_world_lighting\n"
1069 " vec4 g_cube_min;\n"
1070 " vec4 g_cube_inv_range;\n"
1072 " vec4 g_water_plane;\n"
1073 " vec4 g_depth_bounds;\n"
1075 " vec4 g_daysky_colour;\n"
1076 " vec4 g_nightsky_colour;\n"
1077 " vec4 g_sunset_colour;\n"
1078 " vec4 g_ambient_colour;\n"
1079 " vec4 g_sunset_ambient;\n"
1080 " vec4 g_sun_colour;\n"
1081 " vec4 g_sun_dir;\n"
1082 " vec4 g_board_0;\n"
1083 " vec4 g_board_1;\n"
1085 " float g_water_fog;\n"
1087 " float g_realtime;\n"
1088 " float g_shadow_length;\n"
1089 " float g_shadow_spread;\n"
1091 " float g_time_of_day;\n"
1092 " float g_day_phase;\n"
1093 " float g_sunset_phase;\n"
1095 " int g_light_preview;\n"
1096 " int g_shadow_samples;\n"
1098 " int g_debug_indices;\n"
1099 " int g_debug_complexity;\n"
1102 "uniform sampler2D g_world_depth;\n"
1103 "uniform samplerBuffer uLightsArray;\n"
1104 "uniform usampler3D uLightsIndex;\n"
1107 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
1108 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
1109 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
1110 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
1111 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
1112 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
1114 "const float SUN_ANGLE = 0.0001;\n"
1115 "const float PI = 3.14159265358979323846264;\n"
1117 "//struct world_info\n"
1122 "// sunset_phase;\n"
1124 "// vec3 sun_dir;\n"
1127 "vec3 rand33(vec3 p3)\n"
1129 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
1130 " p3 += dot(p3, p3.yxz+33.33);\n"
1131 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
1134 "float stars( vec3 rd, float rr, float size ){\n"
1135 " vec3 co = rd * rr;\n"
1137 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
1139 " float spaces = 1.0 / rr;\n"
1140 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
1141 " a -= mod(a, spaces) - spaces * 0.5;\n"
1143 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
1145 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
1146 " plane = plane - mod(plane, PI / count);\n"
1148 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
1150 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
1151 " float ydist = sqrt(rr * rr - level * level);\n"
1152 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
1153 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
1154 " float star = smoothstep(size, 0.0, distance(center, co));\n"
1158 "float luminance( vec3 v )\n"
1160 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
1163 "vec3 clearskies_ambient( vec3 dir )\n"
1165 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
1166 " float sky_gradient = dir.y;\n"
1168 " /* Blend phase colours */\n"
1169 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
1170 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
1171 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
1173 " /* Add gradient */\n"
1174 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
1176 " return ambient;\n"
1179 "vec3 clearskies_sky( vec3 ray_dir )\n"
1181 " ray_dir.y = abs( ray_dir.y );\n"
1182 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
1185 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
1186 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
1187 " float sun_shape = pow( sun_size, 2000.0 );\n"
1188 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
1190 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
1191 " sun_colour *= sun_shape;\n"
1194 " float star = 0.0;\n"
1195 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
1197 " if( star_blend > 0.001 ){\n"
1198 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
1199 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
1200 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
1204 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
1205 " return composite;\n"
1208 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
1210 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
1212 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
1213 " g_sunset_phase );\n"
1215 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
1216 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
1217 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
1218 " ) * g_sun_colour.rgb * g_day_phase;\n"
1220 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
1221 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
1222 " g_sunset_phase );\n"
1224 " return ambient + (light_sun + sky_reflection) * shadow;\n"
1229 "float world_depth_sample( vec3 pos )\n"
1231 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
1232 " return texture( g_world_depth, depth_coord ).r;\n"
1235 "float world_water_depth( vec3 pos )\n"
1237 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
1238 " return world_depth_sample( pos ) - ref_depth;\n"
1241 "float shadow_sample( vec3 co ){\n"
1242 " float height_sample = world_depth_sample( co );\n"
1244 " float fdelta = height_sample - co.y;\n"
1245 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
1248 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
1249 " if( g_shadow_samples == 0 ){\n"
1253 " float fspread = g_shadow_spread;\n"
1254 " float flength = g_shadow_length;\n"
1256 " float famt = 0.0;\n"
1257 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
1258 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
1259 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
1260 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
1262 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
1263 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
1264 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
1265 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
1267 " return 1.0 - famt;\n"
1270 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
1272 " vec3 specdir = reflect( -dir, wnormal );\n"
1273 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
1276 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
1277 " float dist = pow(fdist*0.0010,0.78);\n"
1278 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
1281 "vec3 scene_calculate_light( int light_index, \n"
1282 " vec3 halfview, vec3 co, vec3 normal )\n"
1284 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
1285 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
1286 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
1288 " vec3 light_delta = light_co.xyz-co;\n"
1289 " float dist2 = dot(light_delta,light_delta);\n"
1291 " light_delta = normalize( light_delta );\n"
1293 " float quadratic = dist2*100.0;\n"
1294 " float attenuation = 1.0/( 1.0 + quadratic );\n"
1295 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
1297 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
1299 " if( light_dir.w < 0.999999 ){\n"
1300 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
1301 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
1304 " return light_colour.rgb * attenuation * falloff \n"
1305 " * step( g_day_phase, light_colour.w );\n"
1308 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
1309 " vec3 halfview, vec3 co, vec3 normal )\n"
1311 " uint light_count = packed_index & 0x3u;\n"
1313 " vec3 l = vec3(0.0);\n"
1315 " if( light_count >= 1u ){\n"
1316 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
1317 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
1318 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
1320 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
1322 " if( light_count >= 2u ){\n"
1323 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
1325 " if( light_count >= 3u ){\n"
1326 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
1334 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
1335 " float light_mask )\n"
1337 " if( g_light_preview == 1 )\n"
1338 " diffuse = vec3(0.75);\n"
1341 " vec3 halfview = uCamera - co;\n"
1342 " float fdist = length(halfview);\n"
1343 " halfview /= fdist;\n"
1345 " float world_shadow = newlight_compute_sun_shadow( \n"
1346 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
1348 " vec3 total_light = clearskies_lighting( \n"
1349 " normal, min( light_mask, world_shadow ), halfview );\n"
1351 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
1352 " cube_coord = floor( cube_coord );\n"
1354 " if( g_debug_indices == 1 )\n"
1356 " return rand33(cube_coord);\n"
1359 " if( g_debug_complexity == 1 )\n"
1361 " ivec3 coord = ivec3( cube_coord );\n"
1362 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1364 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
1365 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
1368 " // FIXME: this coord should absolutely must be clamped!\n"
1370 " ivec3 coord = ivec3( cube_coord );\n"
1371 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1373 " total_light += \n"
1374 " scene_calculate_packed_light_patch( index_sample.x,\n"
1375 " halfview, co, normal ) \n"
1377 " total_light += \n"
1378 " scene_calculate_packed_light_patch( index_sample.y,\n"
1379 " halfview, co, normal )\n"
1382 " // Take a section of the sky function to give us a matching fog colour\n"
1384 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
1385 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
1386 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
1387 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
1389 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
1390 " sun_colour *= sun_shape;\n"
1392 " fog_colour += sun_colour;\n"
1393 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
1398 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
1400 " vec3 pa = p - a;\n"
1401 " vec3 ba = b - a;\n"
1403 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
1404 " return length( pa - ba*h );\n"
1407 "float compute_board_shadow()\n"
1409 " // player shadow\n"
1410 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
1411 " g_board_1.xyz )-0.1 );\n"
1412 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
1413 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
1415 " return 1.0 - player_shadow*0.8;\n"
1418 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
1420 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
1425 "const float k_motion_lerp_amount = 0.01;\n"
1429 "layout (location = 1) out vec2 oMotionVec;\n"
1431 "in vec3 aMotionVec0;\n"
1432 "in vec3 aMotionVec1;\n"
1434 "void compute_motion_vectors()\n"
1436 " // Write motion vectors\n"
1437 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
1438 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
1440 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
1446 " compute_motion_vectors();\n"
1448 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
1449 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
1450 " vec3 qnorm = aNorm.xyz;\n"
1452 " if( vsamplemain.a < 0.15 )\n"
1455 " vfrag = vsamplemain.rgb;\n"
1457 " if( g_light_preview == 1 ){\n"
1458 " vfrag = vec3(0.5);\n"
1461 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
1462 " oColour = vec4(vfrag, 1.0);\n"
1467 GLuint _uniform_scene_foliage_uMdl
;
1468 GLuint _uniform_scene_foliage_uPv
;
1469 GLuint _uniform_scene_foliage_uPvmPrev
;
1470 GLuint _uniform_scene_foliage_uTime
;
1471 GLuint _uniform_scene_foliage_uTexGarbage
;
1472 GLuint _uniform_scene_foliage_uTexMain
;
1473 GLuint _uniform_scene_foliage_uCamera
;
1474 GLuint _uniform_scene_foliage_uPlane
;
1475 GLuint _uniform_scene_foliage_g_world_depth
;
1476 GLuint _uniform_scene_foliage_uLightsArray
;
1477 GLuint _uniform_scene_foliage_uLightsIndex
;
1478 #include "shaders/scene_override.h"
1479 struct vg_shader _shader_scene_override
= {
1480 .name
= "scene_override",
1483 .orig_file
= "shaders/scene_override.vs",
1485 "layout (location=0) in vec3 a_co;\n"
1486 "layout (location=1) in vec4 a_norm;\n"
1487 "layout (location=2) in vec2 a_uv;\n"
1490 "const float k_motion_lerp_amount = 0.01;\n"
1494 "out vec3 aMotionVec0;\n"
1495 "out vec3 aMotionVec1;\n"
1497 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
1499 " // This magically solves some artifacting errors!\n"
1501 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
1503 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
1504 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
1509 "uniform mat4x3 uMdl;\n"
1510 "uniform mat4 uPv;\n"
1511 "uniform mat4 uPvmPrev;\n"
1512 "uniform mat3 uNormalMtx;\n"
1517 "out vec3 aWorldCo;\n"
1521 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
1522 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
1523 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
1525 " vs_motion_out( vproj0, vproj1 );\n"
1527 " gl_Position = vproj0;\n"
1530 " aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
1532 " aWorldCo = world_pos0;\n"
1537 .orig_file
= "shaders/scene_override.fs",
1539 "uniform sampler2D uTexGarbage;\n"
1540 "uniform sampler2D uTexMain;\n"
1541 "uniform vec3 uCamera;\n"
1542 "uniform vec4 uPlane;\n"
1544 "uniform vec4 uPlayerPos; /* w: distance to uSpawnPos */\n"
1545 "uniform vec4 uSpawnPos; /* w: inverse distance to uPlayerPos */\n"
1546 "uniform bool uAlphatest;\n"
1547 "uniform vec4 uMapInfo; /* x: min, y: max, z: iso line amount */\n"
1551 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
1560 "in vec3 aWorldCo;\n"
1563 "layout (location = 0) out vec4 oColour;\n"
1565 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
1566 "layout (std140) uniform ub_world_lighting\n"
1568 " vec4 g_cube_min;\n"
1569 " vec4 g_cube_inv_range;\n"
1571 " vec4 g_water_plane;\n"
1572 " vec4 g_depth_bounds;\n"
1574 " vec4 g_daysky_colour;\n"
1575 " vec4 g_nightsky_colour;\n"
1576 " vec4 g_sunset_colour;\n"
1577 " vec4 g_ambient_colour;\n"
1578 " vec4 g_sunset_ambient;\n"
1579 " vec4 g_sun_colour;\n"
1580 " vec4 g_sun_dir;\n"
1581 " vec4 g_board_0;\n"
1582 " vec4 g_board_1;\n"
1584 " float g_water_fog;\n"
1586 " float g_realtime;\n"
1587 " float g_shadow_length;\n"
1588 " float g_shadow_spread;\n"
1590 " float g_time_of_day;\n"
1591 " float g_day_phase;\n"
1592 " float g_sunset_phase;\n"
1594 " int g_light_preview;\n"
1595 " int g_shadow_samples;\n"
1597 " int g_debug_indices;\n"
1598 " int g_debug_complexity;\n"
1601 "uniform sampler2D g_world_depth;\n"
1602 "uniform samplerBuffer uLightsArray;\n"
1603 "uniform usampler3D uLightsIndex;\n"
1606 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
1607 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
1608 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
1609 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
1610 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
1611 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
1613 "const float SUN_ANGLE = 0.0001;\n"
1614 "const float PI = 3.14159265358979323846264;\n"
1616 "//struct world_info\n"
1621 "// sunset_phase;\n"
1623 "// vec3 sun_dir;\n"
1626 "vec3 rand33(vec3 p3)\n"
1628 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
1629 " p3 += dot(p3, p3.yxz+33.33);\n"
1630 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
1633 "float stars( vec3 rd, float rr, float size ){\n"
1634 " vec3 co = rd * rr;\n"
1636 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
1638 " float spaces = 1.0 / rr;\n"
1639 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
1640 " a -= mod(a, spaces) - spaces * 0.5;\n"
1642 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
1644 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
1645 " plane = plane - mod(plane, PI / count);\n"
1647 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
1649 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
1650 " float ydist = sqrt(rr * rr - level * level);\n"
1651 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
1652 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
1653 " float star = smoothstep(size, 0.0, distance(center, co));\n"
1657 "float luminance( vec3 v )\n"
1659 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
1662 "vec3 clearskies_ambient( vec3 dir )\n"
1664 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
1665 " float sky_gradient = dir.y;\n"
1667 " /* Blend phase colours */\n"
1668 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
1669 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
1670 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
1672 " /* Add gradient */\n"
1673 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
1675 " return ambient;\n"
1678 "vec3 clearskies_sky( vec3 ray_dir )\n"
1680 " ray_dir.y = abs( ray_dir.y );\n"
1681 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
1684 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
1685 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
1686 " float sun_shape = pow( sun_size, 2000.0 );\n"
1687 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
1689 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
1690 " sun_colour *= sun_shape;\n"
1693 " float star = 0.0;\n"
1694 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
1696 " if( star_blend > 0.001 ){\n"
1697 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
1698 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
1699 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
1703 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
1704 " return composite;\n"
1707 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
1709 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
1711 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
1712 " g_sunset_phase );\n"
1714 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
1715 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
1716 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
1717 " ) * g_sun_colour.rgb * g_day_phase;\n"
1719 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
1720 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
1721 " g_sunset_phase );\n"
1723 " return ambient + (light_sun + sky_reflection) * shadow;\n"
1728 "float world_depth_sample( vec3 pos )\n"
1730 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
1731 " return texture( g_world_depth, depth_coord ).r;\n"
1734 "float world_water_depth( vec3 pos )\n"
1736 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
1737 " return world_depth_sample( pos ) - ref_depth;\n"
1740 "float shadow_sample( vec3 co ){\n"
1741 " float height_sample = world_depth_sample( co );\n"
1743 " float fdelta = height_sample - co.y;\n"
1744 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
1747 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
1748 " if( g_shadow_samples == 0 ){\n"
1752 " float fspread = g_shadow_spread;\n"
1753 " float flength = g_shadow_length;\n"
1755 " float famt = 0.0;\n"
1756 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
1757 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
1758 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
1759 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
1761 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
1762 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
1763 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
1764 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
1766 " return 1.0 - famt;\n"
1769 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
1771 " vec3 specdir = reflect( -dir, wnormal );\n"
1772 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
1775 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
1776 " float dist = pow(fdist*0.0010,0.78);\n"
1777 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
1780 "vec3 scene_calculate_light( int light_index, \n"
1781 " vec3 halfview, vec3 co, vec3 normal )\n"
1783 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
1784 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
1785 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
1787 " vec3 light_delta = light_co.xyz-co;\n"
1788 " float dist2 = dot(light_delta,light_delta);\n"
1790 " light_delta = normalize( light_delta );\n"
1792 " float quadratic = dist2*100.0;\n"
1793 " float attenuation = 1.0/( 1.0 + quadratic );\n"
1794 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
1796 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
1798 " if( light_dir.w < 0.999999 ){\n"
1799 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
1800 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
1803 " return light_colour.rgb * attenuation * falloff \n"
1804 " * step( g_day_phase, light_colour.w );\n"
1807 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
1808 " vec3 halfview, vec3 co, vec3 normal )\n"
1810 " uint light_count = packed_index & 0x3u;\n"
1812 " vec3 l = vec3(0.0);\n"
1814 " if( light_count >= 1u ){\n"
1815 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
1816 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
1817 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
1819 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
1821 " if( light_count >= 2u ){\n"
1822 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
1824 " if( light_count >= 3u ){\n"
1825 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
1833 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
1834 " float light_mask )\n"
1836 " if( g_light_preview == 1 )\n"
1837 " diffuse = vec3(0.75);\n"
1840 " vec3 halfview = uCamera - co;\n"
1841 " float fdist = length(halfview);\n"
1842 " halfview /= fdist;\n"
1844 " float world_shadow = newlight_compute_sun_shadow( \n"
1845 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
1847 " vec3 total_light = clearskies_lighting( \n"
1848 " normal, min( light_mask, world_shadow ), halfview );\n"
1850 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
1851 " cube_coord = floor( cube_coord );\n"
1853 " if( g_debug_indices == 1 )\n"
1855 " return rand33(cube_coord);\n"
1858 " if( g_debug_complexity == 1 )\n"
1860 " ivec3 coord = ivec3( cube_coord );\n"
1861 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1863 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
1864 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
1867 " // FIXME: this coord should absolutely must be clamped!\n"
1869 " ivec3 coord = ivec3( cube_coord );\n"
1870 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1872 " total_light += \n"
1873 " scene_calculate_packed_light_patch( index_sample.x,\n"
1874 " halfview, co, normal ) \n"
1876 " total_light += \n"
1877 " scene_calculate_packed_light_patch( index_sample.y,\n"
1878 " halfview, co, normal )\n"
1881 " // Take a section of the sky function to give us a matching fog colour\n"
1883 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
1884 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
1885 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
1886 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
1888 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
1889 " sun_colour *= sun_shape;\n"
1891 " fog_colour += sun_colour;\n"
1892 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
1897 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
1899 " vec3 pa = p - a;\n"
1900 " vec3 ba = b - a;\n"
1902 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
1903 " return length( pa - ba*h );\n"
1906 "float compute_board_shadow()\n"
1908 " // player shadow\n"
1909 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
1910 " g_board_1.xyz )-0.1 );\n"
1911 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
1912 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
1914 " return 1.0 - player_shadow*0.8;\n"
1917 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
1919 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
1924 "const float k_motion_lerp_amount = 0.01;\n"
1928 "layout (location = 1) out vec2 oMotionVec;\n"
1930 "in vec3 aMotionVec0;\n"
1931 "in vec3 aMotionVec1;\n"
1933 "void compute_motion_vectors()\n"
1935 " // Write motion vectors\n"
1936 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
1937 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
1939 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
1944 "vec2 smin( float a, float b, float k ){\n"
1945 " float h = max( k-abs(a-b), 0.0 )/k;\n"
1946 " float m = h*h*0.5;\n"
1947 " float s = m*k*(1.0/2.0);\n"
1950 " return vec2(a-s,m);\n"
1952 " return vec2(b-s,1.0-m);\n"
1956 " vec2 ssuv = gl_FragCoord.xy;\n"
1957 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
1958 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
1960 " float dcam = (-8.0+distance( aCo, uCamera ))/4.0;\n"
1961 " float dy0 = aCo.y - uMapInfo.x;\n"
1962 " float dy1 = uMapInfo.y - aCo.y;\n"
1964 " if( min(min(dy0,dy1)*0.5, dcam) + dither < 0.51 ) \n"
1967 " compute_motion_vectors();\n"
1969 " vec3 vfrag = vec3(0.898,0.811,0.716);\n"
1970 " vec3 qnorm = aNorm.xyz;\n"
1972 " qnorm = normalize(floor(aNorm.xyz*4.0)*0.25);\n"
1973 " qnorm += vec3(0.001,0.0,0.0);\n"
1975 " if( uAlphatest ){\n"
1976 " vec4 vSample = texture( uTexMain, aUv );\n"
1977 " if( vSample.a < 0.5 )\n"
1983 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
1986 " float d0 = distance( aCo, uPlayerPos.xyz )*2.0;\n"
1987 " float d1 = distance( aCo, uSpawnPos.xyz );\n"
1989 " vec2 dm = smin( d0, d1, 10.0 );\n"
1990 " float dd = fract(dm.x*0.2-g_realtime*0.5) * \n"
1991 " max(0.0,1.0-dm.x*0.04) * \n"
1992 " max(0.0,qnorm.y);\n"
1993 " vec3 emit = mix(vec3(1.0,0.0,0.0),vec3(0.0,1.0,0.0),dm.y)*dd;\n"
1996 " vec3 v0 = (uSpawnPos.xyz-uPlayerPos.xyz)*uSpawnPos.w;\n"
1997 " float t = clamp( dot(aCo-uPlayerPos.xyz,v0), 0.0, uPlayerPos.w );\n"
1998 " vec3 p0 = uPlayerPos.xyz + v0*t;\n"
1999 " float d3 = distance(p0,aCo);\n"
2000 " emit += vec3(fract(t*0.2-g_realtime+d3*0.2)*max(0.0,1.0-d3*0.2));\n"
2004 " if( uMapInfo.z > 0.0 ){\n"
2005 " float height = fract( aCo.y * 0.1 );\n"
2006 " float lg = 2.0*length(vec2(dFdx(height), dFdy(height)));\n"
2007 " vfrag *= 1.0f+(lg*0.2*uMapInfo.z);\n"
2010 " oColour = vec4( vfrag, 1.0 );\n"
2011 " //oColour = vec4( vfrag, 1.0 );\n"
2016 GLuint _uniform_scene_override_uMdl
;
2017 GLuint _uniform_scene_override_uPv
;
2018 GLuint _uniform_scene_override_uPvmPrev
;
2019 GLuint _uniform_scene_override_uNormalMtx
;
2020 GLuint _uniform_scene_override_uTexGarbage
;
2021 GLuint _uniform_scene_override_uTexMain
;
2022 GLuint _uniform_scene_override_uCamera
;
2023 GLuint _uniform_scene_override_uPlane
;
2024 GLuint _uniform_scene_override_uPlayerPos
;
2025 GLuint _uniform_scene_override_uSpawnPos
;
2026 GLuint _uniform_scene_override_uAlphatest
;
2027 GLuint _uniform_scene_override_uMapInfo
;
2028 GLuint _uniform_scene_override_g_world_depth
;
2029 GLuint _uniform_scene_override_uLightsArray
;
2030 GLuint _uniform_scene_override_uLightsIndex
;
2031 #include "shaders/scene_fxglow.h"
2032 struct vg_shader _shader_scene_fxglow
= {
2033 .name
= "scene_fxglow",
2036 .orig_file
= "shaders/scene_fxglow.vs",
2038 "layout (location=0) in vec3 a_co;\n"
2039 "layout (location=1) in vec4 a_norm;\n"
2040 "layout (location=2) in vec2 a_uv;\n"
2043 "const float k_motion_lerp_amount = 0.01;\n"
2047 "out vec3 aMotionVec0;\n"
2048 "out vec3 aMotionVec1;\n"
2050 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
2052 " // This magically solves some artifacting errors!\n"
2054 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
2056 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
2057 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
2062 "uniform mat4x3 uMdl;\n"
2063 "uniform mat4 uPv;\n"
2064 "uniform mat4 uPvmPrev;\n"
2065 "uniform vec2 uUvOffset;\n"
2070 "out vec3 aWorldCo;\n"
2074 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
2075 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
2076 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
2078 " vs_motion_out( vproj0, vproj1 );\n"
2080 " gl_Position = vproj0;\n"
2082 " aUv = a_uv + uUvOffset;\n"
2083 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
2085 " aWorldCo = world_pos0;\n"
2090 .orig_file
= "shaders/scene_fxglow.fs",
2092 "uniform sampler2D uTexMain;\n"
2093 "uniform vec3 uCamera;\n"
2097 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
2106 "in vec3 aWorldCo;\n"
2109 "layout (location = 0) out vec4 oColour;\n"
2111 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
2112 "layout (std140) uniform ub_world_lighting\n"
2114 " vec4 g_cube_min;\n"
2115 " vec4 g_cube_inv_range;\n"
2117 " vec4 g_water_plane;\n"
2118 " vec4 g_depth_bounds;\n"
2120 " vec4 g_daysky_colour;\n"
2121 " vec4 g_nightsky_colour;\n"
2122 " vec4 g_sunset_colour;\n"
2123 " vec4 g_ambient_colour;\n"
2124 " vec4 g_sunset_ambient;\n"
2125 " vec4 g_sun_colour;\n"
2126 " vec4 g_sun_dir;\n"
2127 " vec4 g_board_0;\n"
2128 " vec4 g_board_1;\n"
2130 " float g_water_fog;\n"
2132 " float g_realtime;\n"
2133 " float g_shadow_length;\n"
2134 " float g_shadow_spread;\n"
2136 " float g_time_of_day;\n"
2137 " float g_day_phase;\n"
2138 " float g_sunset_phase;\n"
2140 " int g_light_preview;\n"
2141 " int g_shadow_samples;\n"
2143 " int g_debug_indices;\n"
2144 " int g_debug_complexity;\n"
2147 "uniform sampler2D g_world_depth;\n"
2148 "uniform samplerBuffer uLightsArray;\n"
2149 "uniform usampler3D uLightsIndex;\n"
2152 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
2153 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
2154 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
2155 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
2156 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
2157 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
2159 "const float SUN_ANGLE = 0.0001;\n"
2160 "const float PI = 3.14159265358979323846264;\n"
2162 "//struct world_info\n"
2167 "// sunset_phase;\n"
2169 "// vec3 sun_dir;\n"
2172 "vec3 rand33(vec3 p3)\n"
2174 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
2175 " p3 += dot(p3, p3.yxz+33.33);\n"
2176 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
2179 "float stars( vec3 rd, float rr, float size ){\n"
2180 " vec3 co = rd * rr;\n"
2182 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
2184 " float spaces = 1.0 / rr;\n"
2185 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
2186 " a -= mod(a, spaces) - spaces * 0.5;\n"
2188 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
2190 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
2191 " plane = plane - mod(plane, PI / count);\n"
2193 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
2195 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
2196 " float ydist = sqrt(rr * rr - level * level);\n"
2197 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
2198 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
2199 " float star = smoothstep(size, 0.0, distance(center, co));\n"
2203 "float luminance( vec3 v )\n"
2205 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
2208 "vec3 clearskies_ambient( vec3 dir )\n"
2210 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
2211 " float sky_gradient = dir.y;\n"
2213 " /* Blend phase colours */\n"
2214 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
2215 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
2216 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
2218 " /* Add gradient */\n"
2219 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
2221 " return ambient;\n"
2224 "vec3 clearskies_sky( vec3 ray_dir )\n"
2226 " ray_dir.y = abs( ray_dir.y );\n"
2227 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
2230 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
2231 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
2232 " float sun_shape = pow( sun_size, 2000.0 );\n"
2233 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
2235 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
2236 " sun_colour *= sun_shape;\n"
2239 " float star = 0.0;\n"
2240 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
2242 " if( star_blend > 0.001 ){\n"
2243 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
2244 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
2245 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
2249 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
2250 " return composite;\n"
2253 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
2255 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
2257 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
2258 " g_sunset_phase );\n"
2260 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
2261 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
2262 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
2263 " ) * g_sun_colour.rgb * g_day_phase;\n"
2265 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
2266 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
2267 " g_sunset_phase );\n"
2269 " return ambient + (light_sun + sky_reflection) * shadow;\n"
2274 "float world_depth_sample( vec3 pos )\n"
2276 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
2277 " return texture( g_world_depth, depth_coord ).r;\n"
2280 "float world_water_depth( vec3 pos )\n"
2282 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
2283 " return world_depth_sample( pos ) - ref_depth;\n"
2286 "float shadow_sample( vec3 co ){\n"
2287 " float height_sample = world_depth_sample( co );\n"
2289 " float fdelta = height_sample - co.y;\n"
2290 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
2293 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
2294 " if( g_shadow_samples == 0 ){\n"
2298 " float fspread = g_shadow_spread;\n"
2299 " float flength = g_shadow_length;\n"
2301 " float famt = 0.0;\n"
2302 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
2303 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
2304 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
2305 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
2307 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
2308 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
2309 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
2310 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
2312 " return 1.0 - famt;\n"
2315 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
2317 " vec3 specdir = reflect( -dir, wnormal );\n"
2318 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
2321 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
2322 " float dist = pow(fdist*0.0010,0.78);\n"
2323 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
2326 "vec3 scene_calculate_light( int light_index, \n"
2327 " vec3 halfview, vec3 co, vec3 normal )\n"
2329 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
2330 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
2331 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
2333 " vec3 light_delta = light_co.xyz-co;\n"
2334 " float dist2 = dot(light_delta,light_delta);\n"
2336 " light_delta = normalize( light_delta );\n"
2338 " float quadratic = dist2*100.0;\n"
2339 " float attenuation = 1.0/( 1.0 + quadratic );\n"
2340 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
2342 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
2344 " if( light_dir.w < 0.999999 ){\n"
2345 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
2346 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
2349 " return light_colour.rgb * attenuation * falloff \n"
2350 " * step( g_day_phase, light_colour.w );\n"
2353 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
2354 " vec3 halfview, vec3 co, vec3 normal )\n"
2356 " uint light_count = packed_index & 0x3u;\n"
2358 " vec3 l = vec3(0.0);\n"
2360 " if( light_count >= 1u ){\n"
2361 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
2362 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
2363 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
2365 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
2367 " if( light_count >= 2u ){\n"
2368 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
2370 " if( light_count >= 3u ){\n"
2371 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
2379 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
2380 " float light_mask )\n"
2382 " if( g_light_preview == 1 )\n"
2383 " diffuse = vec3(0.75);\n"
2386 " vec3 halfview = uCamera - co;\n"
2387 " float fdist = length(halfview);\n"
2388 " halfview /= fdist;\n"
2390 " float world_shadow = newlight_compute_sun_shadow( \n"
2391 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
2393 " vec3 total_light = clearskies_lighting( \n"
2394 " normal, min( light_mask, world_shadow ), halfview );\n"
2396 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
2397 " cube_coord = floor( cube_coord );\n"
2399 " if( g_debug_indices == 1 )\n"
2401 " return rand33(cube_coord);\n"
2404 " if( g_debug_complexity == 1 )\n"
2406 " ivec3 coord = ivec3( cube_coord );\n"
2407 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2409 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
2410 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
2413 " // FIXME: this coord should absolutely must be clamped!\n"
2415 " ivec3 coord = ivec3( cube_coord );\n"
2416 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2418 " total_light += \n"
2419 " scene_calculate_packed_light_patch( index_sample.x,\n"
2420 " halfview, co, normal ) \n"
2422 " total_light += \n"
2423 " scene_calculate_packed_light_patch( index_sample.y,\n"
2424 " halfview, co, normal )\n"
2427 " // Take a section of the sky function to give us a matching fog colour\n"
2429 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
2430 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
2431 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
2432 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
2434 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
2435 " sun_colour *= sun_shape;\n"
2437 " fog_colour += sun_colour;\n"
2438 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
2443 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
2445 " vec3 pa = p - a;\n"
2446 " vec3 ba = b - a;\n"
2448 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
2449 " return length( pa - ba*h );\n"
2452 "float compute_board_shadow()\n"
2454 " // player shadow\n"
2455 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
2456 " g_board_1.xyz )-0.1 );\n"
2457 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
2458 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
2460 " return 1.0 - player_shadow*0.8;\n"
2463 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
2465 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
2470 "const float k_motion_lerp_amount = 0.01;\n"
2474 "layout (location = 1) out vec2 oMotionVec;\n"
2476 "in vec3 aMotionVec0;\n"
2477 "in vec3 aMotionVec1;\n"
2479 "void compute_motion_vectors()\n"
2481 " // Write motion vectors\n"
2482 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
2483 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
2485 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
2491 " oMotionVec = vec2(0.0);\n"
2493 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
2495 " vec2 ssuv = gl_FragCoord.xy;\n"
2496 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
2497 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
2499 " if( vsamplemain.a+dither<0.5 )\n"
2502 " oColour = vec4( vsamplemain.rgb, 1.0 );\n"
2507 GLuint _uniform_scene_fxglow_uMdl
;
2508 GLuint _uniform_scene_fxglow_uPv
;
2509 GLuint _uniform_scene_fxglow_uPvmPrev
;
2510 GLuint _uniform_scene_fxglow_uUvOffset
;
2511 GLuint _uniform_scene_fxglow_uTexMain
;
2512 GLuint _uniform_scene_fxglow_uCamera
;
2513 GLuint _uniform_scene_fxglow_g_world_depth
;
2514 GLuint _uniform_scene_fxglow_uLightsArray
;
2515 GLuint _uniform_scene_fxglow_uLightsIndex
;
2516 #include "shaders/scene_vertex_blend.h"
2517 struct vg_shader _shader_scene_vertex_blend
= {
2518 .name
= "scene_vertex_blend",
2521 .orig_file
= "shaders/scene.vs",
2523 "layout (location=0) in vec3 a_co;\n"
2524 "layout (location=1) in vec4 a_norm;\n"
2525 "layout (location=2) in vec2 a_uv;\n"
2528 "const float k_motion_lerp_amount = 0.01;\n"
2532 "out vec3 aMotionVec0;\n"
2533 "out vec3 aMotionVec1;\n"
2535 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
2537 " // This magically solves some artifacting errors!\n"
2539 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
2541 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
2542 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
2547 "uniform mat4x3 uMdl;\n"
2548 "uniform mat4 uPv;\n"
2549 "uniform mat4 uPvmPrev;\n"
2554 "out vec3 aWorldCo;\n"
2558 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
2559 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
2560 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
2562 " vs_motion_out( vproj0, vproj1 );\n"
2564 " gl_Position = vproj0;\n"
2567 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
2569 " aWorldCo = world_pos0;\n"
2574 .orig_file
= "shaders/scene_vertex_blend.fs",
2576 "uniform sampler2D uTexGarbage;\n"
2577 "uniform sampler2D uTexGradients;\n"
2578 "uniform vec3 uCamera;\n"
2582 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
2591 "in vec3 aWorldCo;\n"
2594 "layout (location = 0) out vec4 oColour;\n"
2596 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
2597 "layout (std140) uniform ub_world_lighting\n"
2599 " vec4 g_cube_min;\n"
2600 " vec4 g_cube_inv_range;\n"
2602 " vec4 g_water_plane;\n"
2603 " vec4 g_depth_bounds;\n"
2605 " vec4 g_daysky_colour;\n"
2606 " vec4 g_nightsky_colour;\n"
2607 " vec4 g_sunset_colour;\n"
2608 " vec4 g_ambient_colour;\n"
2609 " vec4 g_sunset_ambient;\n"
2610 " vec4 g_sun_colour;\n"
2611 " vec4 g_sun_dir;\n"
2612 " vec4 g_board_0;\n"
2613 " vec4 g_board_1;\n"
2615 " float g_water_fog;\n"
2617 " float g_realtime;\n"
2618 " float g_shadow_length;\n"
2619 " float g_shadow_spread;\n"
2621 " float g_time_of_day;\n"
2622 " float g_day_phase;\n"
2623 " float g_sunset_phase;\n"
2625 " int g_light_preview;\n"
2626 " int g_shadow_samples;\n"
2628 " int g_debug_indices;\n"
2629 " int g_debug_complexity;\n"
2632 "uniform sampler2D g_world_depth;\n"
2633 "uniform samplerBuffer uLightsArray;\n"
2634 "uniform usampler3D uLightsIndex;\n"
2637 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
2638 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
2639 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
2640 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
2641 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
2642 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
2644 "const float SUN_ANGLE = 0.0001;\n"
2645 "const float PI = 3.14159265358979323846264;\n"
2647 "//struct world_info\n"
2652 "// sunset_phase;\n"
2654 "// vec3 sun_dir;\n"
2657 "vec3 rand33(vec3 p3)\n"
2659 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
2660 " p3 += dot(p3, p3.yxz+33.33);\n"
2661 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
2664 "float stars( vec3 rd, float rr, float size ){\n"
2665 " vec3 co = rd * rr;\n"
2667 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
2669 " float spaces = 1.0 / rr;\n"
2670 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
2671 " a -= mod(a, spaces) - spaces * 0.5;\n"
2673 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
2675 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
2676 " plane = plane - mod(plane, PI / count);\n"
2678 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
2680 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
2681 " float ydist = sqrt(rr * rr - level * level);\n"
2682 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
2683 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
2684 " float star = smoothstep(size, 0.0, distance(center, co));\n"
2688 "float luminance( vec3 v )\n"
2690 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
2693 "vec3 clearskies_ambient( vec3 dir )\n"
2695 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
2696 " float sky_gradient = dir.y;\n"
2698 " /* Blend phase colours */\n"
2699 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
2700 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
2701 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
2703 " /* Add gradient */\n"
2704 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
2706 " return ambient;\n"
2709 "vec3 clearskies_sky( vec3 ray_dir )\n"
2711 " ray_dir.y = abs( ray_dir.y );\n"
2712 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
2715 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
2716 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
2717 " float sun_shape = pow( sun_size, 2000.0 );\n"
2718 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
2720 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
2721 " sun_colour *= sun_shape;\n"
2724 " float star = 0.0;\n"
2725 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
2727 " if( star_blend > 0.001 ){\n"
2728 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
2729 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
2730 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
2734 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
2735 " return composite;\n"
2738 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
2740 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
2742 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
2743 " g_sunset_phase );\n"
2745 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
2746 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
2747 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
2748 " ) * g_sun_colour.rgb * g_day_phase;\n"
2750 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
2751 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
2752 " g_sunset_phase );\n"
2754 " return ambient + (light_sun + sky_reflection) * shadow;\n"
2759 "float world_depth_sample( vec3 pos )\n"
2761 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
2762 " return texture( g_world_depth, depth_coord ).r;\n"
2765 "float world_water_depth( vec3 pos )\n"
2767 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
2768 " return world_depth_sample( pos ) - ref_depth;\n"
2771 "float shadow_sample( vec3 co ){\n"
2772 " float height_sample = world_depth_sample( co );\n"
2774 " float fdelta = height_sample - co.y;\n"
2775 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
2778 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
2779 " if( g_shadow_samples == 0 ){\n"
2783 " float fspread = g_shadow_spread;\n"
2784 " float flength = g_shadow_length;\n"
2786 " float famt = 0.0;\n"
2787 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
2788 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
2789 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
2790 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
2792 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
2793 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
2794 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
2795 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
2797 " return 1.0 - famt;\n"
2800 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
2802 " vec3 specdir = reflect( -dir, wnormal );\n"
2803 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
2806 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
2807 " float dist = pow(fdist*0.0010,0.78);\n"
2808 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
2811 "vec3 scene_calculate_light( int light_index, \n"
2812 " vec3 halfview, vec3 co, vec3 normal )\n"
2814 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
2815 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
2816 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
2818 " vec3 light_delta = light_co.xyz-co;\n"
2819 " float dist2 = dot(light_delta,light_delta);\n"
2821 " light_delta = normalize( light_delta );\n"
2823 " float quadratic = dist2*100.0;\n"
2824 " float attenuation = 1.0/( 1.0 + quadratic );\n"
2825 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
2827 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
2829 " if( light_dir.w < 0.999999 ){\n"
2830 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
2831 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
2834 " return light_colour.rgb * attenuation * falloff \n"
2835 " * step( g_day_phase, light_colour.w );\n"
2838 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
2839 " vec3 halfview, vec3 co, vec3 normal )\n"
2841 " uint light_count = packed_index & 0x3u;\n"
2843 " vec3 l = vec3(0.0);\n"
2845 " if( light_count >= 1u ){\n"
2846 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
2847 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
2848 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
2850 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
2852 " if( light_count >= 2u ){\n"
2853 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
2855 " if( light_count >= 3u ){\n"
2856 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
2864 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
2865 " float light_mask )\n"
2867 " if( g_light_preview == 1 )\n"
2868 " diffuse = vec3(0.75);\n"
2871 " vec3 halfview = uCamera - co;\n"
2872 " float fdist = length(halfview);\n"
2873 " halfview /= fdist;\n"
2875 " float world_shadow = newlight_compute_sun_shadow( \n"
2876 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
2878 " vec3 total_light = clearskies_lighting( \n"
2879 " normal, min( light_mask, world_shadow ), halfview );\n"
2881 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
2882 " cube_coord = floor( cube_coord );\n"
2884 " if( g_debug_indices == 1 )\n"
2886 " return rand33(cube_coord);\n"
2889 " if( g_debug_complexity == 1 )\n"
2891 " ivec3 coord = ivec3( cube_coord );\n"
2892 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2894 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
2895 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
2898 " // FIXME: this coord should absolutely must be clamped!\n"
2900 " ivec3 coord = ivec3( cube_coord );\n"
2901 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2903 " total_light += \n"
2904 " scene_calculate_packed_light_patch( index_sample.x,\n"
2905 " halfview, co, normal ) \n"
2907 " total_light += \n"
2908 " scene_calculate_packed_light_patch( index_sample.y,\n"
2909 " halfview, co, normal )\n"
2912 " // Take a section of the sky function to give us a matching fog colour\n"
2914 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
2915 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
2916 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
2917 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
2919 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
2920 " sun_colour *= sun_shape;\n"
2922 " fog_colour += sun_colour;\n"
2923 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
2928 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
2930 " vec3 pa = p - a;\n"
2931 " vec3 ba = b - a;\n"
2933 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
2934 " return length( pa - ba*h );\n"
2937 "float compute_board_shadow()\n"
2939 " // player shadow\n"
2940 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
2941 " g_board_1.xyz )-0.1 );\n"
2942 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
2943 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
2945 " return 1.0 - player_shadow*0.8;\n"
2948 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
2950 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
2955 "const float k_motion_lerp_amount = 0.01;\n"
2959 "layout (location = 1) out vec2 oMotionVec;\n"
2961 "in vec3 aMotionVec0;\n"
2962 "in vec3 aMotionVec1;\n"
2964 "void compute_motion_vectors()\n"
2966 " // Write motion vectors\n"
2967 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
2968 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
2970 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
2977 " compute_motion_vectors();\n"
2979 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
2981 " // ws modulation\n"
2982 " vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);\n"
2984 " // Creating normal patches\n"
2985 " vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
2986 " vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
2987 " qnorm += vec3(0.001,0.0,0.0);\n"
2989 " vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
2990 " vec3 tangent1 = cross(qnorm,tangent0);\n"
2991 " vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;\n"
2993 " // Patch local noise\n"
2994 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
2996 " // Colour blending\n"
2997 " float fblendclip = step(0.380,aNorm.w + (rgarbage.r-0.5)*-1.740)*0.320;\n"
2998 " vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );\n"
3000 " vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
3001 " vfrag -= rgarbage.a*0.04;\n"
3003 " if( g_light_preview == 1 )\n"
3005 " vfrag = vec3(0.5);\n"
3008 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
3009 " oColour = vec4(vfrag, 1.0);\n"
3014 GLuint _uniform_scene_vertex_blend_uMdl
;
3015 GLuint _uniform_scene_vertex_blend_uPv
;
3016 GLuint _uniform_scene_vertex_blend_uPvmPrev
;
3017 GLuint _uniform_scene_vertex_blend_uTexGarbage
;
3018 GLuint _uniform_scene_vertex_blend_uTexGradients
;
3019 GLuint _uniform_scene_vertex_blend_uCamera
;
3020 GLuint _uniform_scene_vertex_blend_g_world_depth
;
3021 GLuint _uniform_scene_vertex_blend_uLightsArray
;
3022 GLuint _uniform_scene_vertex_blend_uLightsIndex
;
3023 #include "shaders/scene_terrain.h"
3024 struct vg_shader _shader_scene_terrain
= {
3025 .name
= "scene_terrain",
3028 .orig_file
= "shaders/scene.vs",
3030 "layout (location=0) in vec3 a_co;\n"
3031 "layout (location=1) in vec4 a_norm;\n"
3032 "layout (location=2) in vec2 a_uv;\n"
3035 "const float k_motion_lerp_amount = 0.01;\n"
3039 "out vec3 aMotionVec0;\n"
3040 "out vec3 aMotionVec1;\n"
3042 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
3044 " // This magically solves some artifacting errors!\n"
3046 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
3048 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
3049 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
3054 "uniform mat4x3 uMdl;\n"
3055 "uniform mat4 uPv;\n"
3056 "uniform mat4 uPvmPrev;\n"
3061 "out vec3 aWorldCo;\n"
3065 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
3066 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
3067 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
3069 " vs_motion_out( vproj0, vproj1 );\n"
3071 " gl_Position = vproj0;\n"
3074 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
3076 " aWorldCo = world_pos0;\n"
3081 .orig_file
= "shaders/scene_terrain.fs",
3083 "uniform sampler2D uTexGarbage;\n"
3084 "uniform sampler2D uTexGradients;\n"
3085 "uniform vec3 uCamera;\n"
3086 "uniform vec3 uSandColour;\n"
3087 "uniform vec2 uBlendOffset;\n"
3091 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
3100 "in vec3 aWorldCo;\n"
3103 "layout (location = 0) out vec4 oColour;\n"
3105 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
3106 "layout (std140) uniform ub_world_lighting\n"
3108 " vec4 g_cube_min;\n"
3109 " vec4 g_cube_inv_range;\n"
3111 " vec4 g_water_plane;\n"
3112 " vec4 g_depth_bounds;\n"
3114 " vec4 g_daysky_colour;\n"
3115 " vec4 g_nightsky_colour;\n"
3116 " vec4 g_sunset_colour;\n"
3117 " vec4 g_ambient_colour;\n"
3118 " vec4 g_sunset_ambient;\n"
3119 " vec4 g_sun_colour;\n"
3120 " vec4 g_sun_dir;\n"
3121 " vec4 g_board_0;\n"
3122 " vec4 g_board_1;\n"
3124 " float g_water_fog;\n"
3126 " float g_realtime;\n"
3127 " float g_shadow_length;\n"
3128 " float g_shadow_spread;\n"
3130 " float g_time_of_day;\n"
3131 " float g_day_phase;\n"
3132 " float g_sunset_phase;\n"
3134 " int g_light_preview;\n"
3135 " int g_shadow_samples;\n"
3137 " int g_debug_indices;\n"
3138 " int g_debug_complexity;\n"
3141 "uniform sampler2D g_world_depth;\n"
3142 "uniform samplerBuffer uLightsArray;\n"
3143 "uniform usampler3D uLightsIndex;\n"
3146 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
3147 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
3148 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
3149 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
3150 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
3151 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
3153 "const float SUN_ANGLE = 0.0001;\n"
3154 "const float PI = 3.14159265358979323846264;\n"
3156 "//struct world_info\n"
3161 "// sunset_phase;\n"
3163 "// vec3 sun_dir;\n"
3166 "vec3 rand33(vec3 p3)\n"
3168 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
3169 " p3 += dot(p3, p3.yxz+33.33);\n"
3170 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
3173 "float stars( vec3 rd, float rr, float size ){\n"
3174 " vec3 co = rd * rr;\n"
3176 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
3178 " float spaces = 1.0 / rr;\n"
3179 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
3180 " a -= mod(a, spaces) - spaces * 0.5;\n"
3182 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
3184 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
3185 " plane = plane - mod(plane, PI / count);\n"
3187 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
3189 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
3190 " float ydist = sqrt(rr * rr - level * level);\n"
3191 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
3192 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
3193 " float star = smoothstep(size, 0.0, distance(center, co));\n"
3197 "float luminance( vec3 v )\n"
3199 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
3202 "vec3 clearskies_ambient( vec3 dir )\n"
3204 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
3205 " float sky_gradient = dir.y;\n"
3207 " /* Blend phase colours */\n"
3208 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
3209 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
3210 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
3212 " /* Add gradient */\n"
3213 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
3215 " return ambient;\n"
3218 "vec3 clearskies_sky( vec3 ray_dir )\n"
3220 " ray_dir.y = abs( ray_dir.y );\n"
3221 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
3224 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
3225 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
3226 " float sun_shape = pow( sun_size, 2000.0 );\n"
3227 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
3229 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
3230 " sun_colour *= sun_shape;\n"
3233 " float star = 0.0;\n"
3234 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
3236 " if( star_blend > 0.001 ){\n"
3237 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
3238 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
3239 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
3243 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
3244 " return composite;\n"
3247 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
3249 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
3251 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
3252 " g_sunset_phase );\n"
3254 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
3255 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
3256 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
3257 " ) * g_sun_colour.rgb * g_day_phase;\n"
3259 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
3260 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
3261 " g_sunset_phase );\n"
3263 " return ambient + (light_sun + sky_reflection) * shadow;\n"
3268 "float world_depth_sample( vec3 pos )\n"
3270 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
3271 " return texture( g_world_depth, depth_coord ).r;\n"
3274 "float world_water_depth( vec3 pos )\n"
3276 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
3277 " return world_depth_sample( pos ) - ref_depth;\n"
3280 "float shadow_sample( vec3 co ){\n"
3281 " float height_sample = world_depth_sample( co );\n"
3283 " float fdelta = height_sample - co.y;\n"
3284 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
3287 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
3288 " if( g_shadow_samples == 0 ){\n"
3292 " float fspread = g_shadow_spread;\n"
3293 " float flength = g_shadow_length;\n"
3295 " float famt = 0.0;\n"
3296 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
3297 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
3298 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
3299 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
3301 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
3302 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
3303 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
3304 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
3306 " return 1.0 - famt;\n"
3309 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
3311 " vec3 specdir = reflect( -dir, wnormal );\n"
3312 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
3315 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
3316 " float dist = pow(fdist*0.0010,0.78);\n"
3317 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
3320 "vec3 scene_calculate_light( int light_index, \n"
3321 " vec3 halfview, vec3 co, vec3 normal )\n"
3323 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
3324 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
3325 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
3327 " vec3 light_delta = light_co.xyz-co;\n"
3328 " float dist2 = dot(light_delta,light_delta);\n"
3330 " light_delta = normalize( light_delta );\n"
3332 " float quadratic = dist2*100.0;\n"
3333 " float attenuation = 1.0/( 1.0 + quadratic );\n"
3334 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
3336 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
3338 " if( light_dir.w < 0.999999 ){\n"
3339 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
3340 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
3343 " return light_colour.rgb * attenuation * falloff \n"
3344 " * step( g_day_phase, light_colour.w );\n"
3347 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
3348 " vec3 halfview, vec3 co, vec3 normal )\n"
3350 " uint light_count = packed_index & 0x3u;\n"
3352 " vec3 l = vec3(0.0);\n"
3354 " if( light_count >= 1u ){\n"
3355 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
3356 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
3357 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
3359 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
3361 " if( light_count >= 2u ){\n"
3362 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
3364 " if( light_count >= 3u ){\n"
3365 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
3373 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
3374 " float light_mask )\n"
3376 " if( g_light_preview == 1 )\n"
3377 " diffuse = vec3(0.75);\n"
3380 " vec3 halfview = uCamera - co;\n"
3381 " float fdist = length(halfview);\n"
3382 " halfview /= fdist;\n"
3384 " float world_shadow = newlight_compute_sun_shadow( \n"
3385 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
3387 " vec3 total_light = clearskies_lighting( \n"
3388 " normal, min( light_mask, world_shadow ), halfview );\n"
3390 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
3391 " cube_coord = floor( cube_coord );\n"
3393 " if( g_debug_indices == 1 )\n"
3395 " return rand33(cube_coord);\n"
3398 " if( g_debug_complexity == 1 )\n"
3400 " ivec3 coord = ivec3( cube_coord );\n"
3401 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3403 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
3404 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
3407 " // FIXME: this coord should absolutely must be clamped!\n"
3409 " ivec3 coord = ivec3( cube_coord );\n"
3410 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3412 " total_light += \n"
3413 " scene_calculate_packed_light_patch( index_sample.x,\n"
3414 " halfview, co, normal ) \n"
3416 " total_light += \n"
3417 " scene_calculate_packed_light_patch( index_sample.y,\n"
3418 " halfview, co, normal )\n"
3421 " // Take a section of the sky function to give us a matching fog colour\n"
3423 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
3424 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
3425 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
3426 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
3428 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
3429 " sun_colour *= sun_shape;\n"
3431 " fog_colour += sun_colour;\n"
3432 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
3437 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
3439 " vec3 pa = p - a;\n"
3440 " vec3 ba = b - a;\n"
3442 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
3443 " return length( pa - ba*h );\n"
3446 "float compute_board_shadow()\n"
3448 " // player shadow\n"
3449 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
3450 " g_board_1.xyz )-0.1 );\n"
3451 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
3452 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
3454 " return 1.0 - player_shadow*0.8;\n"
3457 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
3459 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
3464 "const float k_motion_lerp_amount = 0.01;\n"
3468 "layout (location = 1) out vec2 oMotionVec;\n"
3470 "in vec3 aMotionVec0;\n"
3471 "in vec3 aMotionVec1;\n"
3473 "void compute_motion_vectors()\n"
3475 " // Write motion vectors\n"
3476 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
3477 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
3479 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
3486 " compute_motion_vectors();\n"
3490 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
3492 " // ws modulation\n"
3493 " vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
3495 " // Creating normal patches\n"
3496 " vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
3497 " vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
3498 " qnorm += vec3(0.001,0.0,0.0);\n"
3500 " vec2 dir = normalize(qnorm.xz);\n"
3501 " vec2 uvdiffuse = aCo.xz * 0.02;\n"
3502 " uvdiffuse = mat2(dir.y, dir.x, -dir.x, dir.y) * uvdiffuse;\n"
3504 " // Patch local noise\n"
3505 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
3507 " // Colour blending\n"
3508 " float amtgrass = step(qnorm.y,0.6);\n"
3509 " float amtsand = min(max((aCo.y - 10.0) * -0.1,0.0)*qnorm.y,1.0);\n"
3510 " vec2 uvgradients = aUv + vec2( amtgrass + rgarbage.a*0.8 )*uBlendOffset;\n"
3511 " vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
3512 " vfrag = mix( vfrag, uSandColour, amtsand );\n"
3514 " qnorm = mix( qnorm, aNorm.xyz, amtsand );\n"
3516 " if( g_light_preview == 1 )\n"
3518 " vfrag = vec3(0.5);\n"
3521 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
3522 " oColour = vec4(vfrag, 1.0);\n"
3527 GLuint _uniform_scene_terrain_uMdl
;
3528 GLuint _uniform_scene_terrain_uPv
;
3529 GLuint _uniform_scene_terrain_uPvmPrev
;
3530 GLuint _uniform_scene_terrain_uTexGarbage
;
3531 GLuint _uniform_scene_terrain_uTexGradients
;
3532 GLuint _uniform_scene_terrain_uCamera
;
3533 GLuint _uniform_scene_terrain_uSandColour
;
3534 GLuint _uniform_scene_terrain_uBlendOffset
;
3535 GLuint _uniform_scene_terrain_g_world_depth
;
3536 GLuint _uniform_scene_terrain_uLightsArray
;
3537 GLuint _uniform_scene_terrain_uLightsIndex
;
3538 #include "shaders/scene_route.h"
3539 struct vg_shader _shader_scene_route
= {
3540 .name
= "scene_route",
3543 .orig_file
= "shaders/scene_override.vs",
3545 "layout (location=0) in vec3 a_co;\n"
3546 "layout (location=1) in vec4 a_norm;\n"
3547 "layout (location=2) in vec2 a_uv;\n"
3550 "const float k_motion_lerp_amount = 0.01;\n"
3554 "out vec3 aMotionVec0;\n"
3555 "out vec3 aMotionVec1;\n"
3557 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
3559 " // This magically solves some artifacting errors!\n"
3561 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
3563 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
3564 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
3569 "uniform mat4x3 uMdl;\n"
3570 "uniform mat4 uPv;\n"
3571 "uniform mat4 uPvmPrev;\n"
3572 "uniform mat3 uNormalMtx;\n"
3577 "out vec3 aWorldCo;\n"
3581 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
3582 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
3583 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
3585 " vs_motion_out( vproj0, vproj1 );\n"
3587 " gl_Position = vproj0;\n"
3590 " aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
3592 " aWorldCo = world_pos0;\n"
3597 .orig_file
= "shaders/scene_route.fs",
3599 "uniform sampler2D uTexGarbage;\n"
3600 "uniform sampler2D uTexGradients;\n"
3601 "uniform vec3 uCamera;\n"
3602 "uniform vec4 uColour;\n"
3606 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
3615 "in vec3 aWorldCo;\n"
3618 "layout (location = 0) out vec4 oColour;\n"
3620 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
3621 "layout (std140) uniform ub_world_lighting\n"
3623 " vec4 g_cube_min;\n"
3624 " vec4 g_cube_inv_range;\n"
3626 " vec4 g_water_plane;\n"
3627 " vec4 g_depth_bounds;\n"
3629 " vec4 g_daysky_colour;\n"
3630 " vec4 g_nightsky_colour;\n"
3631 " vec4 g_sunset_colour;\n"
3632 " vec4 g_ambient_colour;\n"
3633 " vec4 g_sunset_ambient;\n"
3634 " vec4 g_sun_colour;\n"
3635 " vec4 g_sun_dir;\n"
3636 " vec4 g_board_0;\n"
3637 " vec4 g_board_1;\n"
3639 " float g_water_fog;\n"
3641 " float g_realtime;\n"
3642 " float g_shadow_length;\n"
3643 " float g_shadow_spread;\n"
3645 " float g_time_of_day;\n"
3646 " float g_day_phase;\n"
3647 " float g_sunset_phase;\n"
3649 " int g_light_preview;\n"
3650 " int g_shadow_samples;\n"
3652 " int g_debug_indices;\n"
3653 " int g_debug_complexity;\n"
3656 "uniform sampler2D g_world_depth;\n"
3657 "uniform samplerBuffer uLightsArray;\n"
3658 "uniform usampler3D uLightsIndex;\n"
3661 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
3662 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
3663 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
3664 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
3665 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
3666 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
3668 "const float SUN_ANGLE = 0.0001;\n"
3669 "const float PI = 3.14159265358979323846264;\n"
3671 "//struct world_info\n"
3676 "// sunset_phase;\n"
3678 "// vec3 sun_dir;\n"
3681 "vec3 rand33(vec3 p3)\n"
3683 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
3684 " p3 += dot(p3, p3.yxz+33.33);\n"
3685 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
3688 "float stars( vec3 rd, float rr, float size ){\n"
3689 " vec3 co = rd * rr;\n"
3691 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
3693 " float spaces = 1.0 / rr;\n"
3694 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
3695 " a -= mod(a, spaces) - spaces * 0.5;\n"
3697 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
3699 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
3700 " plane = plane - mod(plane, PI / count);\n"
3702 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
3704 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
3705 " float ydist = sqrt(rr * rr - level * level);\n"
3706 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
3707 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
3708 " float star = smoothstep(size, 0.0, distance(center, co));\n"
3712 "float luminance( vec3 v )\n"
3714 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
3717 "vec3 clearskies_ambient( vec3 dir )\n"
3719 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
3720 " float sky_gradient = dir.y;\n"
3722 " /* Blend phase colours */\n"
3723 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
3724 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
3725 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
3727 " /* Add gradient */\n"
3728 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
3730 " return ambient;\n"
3733 "vec3 clearskies_sky( vec3 ray_dir )\n"
3735 " ray_dir.y = abs( ray_dir.y );\n"
3736 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
3739 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
3740 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
3741 " float sun_shape = pow( sun_size, 2000.0 );\n"
3742 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
3744 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
3745 " sun_colour *= sun_shape;\n"
3748 " float star = 0.0;\n"
3749 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
3751 " if( star_blend > 0.001 ){\n"
3752 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
3753 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
3754 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
3758 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
3759 " return composite;\n"
3762 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
3764 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
3766 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
3767 " g_sunset_phase );\n"
3769 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
3770 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
3771 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
3772 " ) * g_sun_colour.rgb * g_day_phase;\n"
3774 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
3775 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
3776 " g_sunset_phase );\n"
3778 " return ambient + (light_sun + sky_reflection) * shadow;\n"
3783 "float world_depth_sample( vec3 pos )\n"
3785 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
3786 " return texture( g_world_depth, depth_coord ).r;\n"
3789 "float world_water_depth( vec3 pos )\n"
3791 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
3792 " return world_depth_sample( pos ) - ref_depth;\n"
3795 "float shadow_sample( vec3 co ){\n"
3796 " float height_sample = world_depth_sample( co );\n"
3798 " float fdelta = height_sample - co.y;\n"
3799 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
3802 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
3803 " if( g_shadow_samples == 0 ){\n"
3807 " float fspread = g_shadow_spread;\n"
3808 " float flength = g_shadow_length;\n"
3810 " float famt = 0.0;\n"
3811 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
3812 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
3813 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
3814 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
3816 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
3817 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
3818 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
3819 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
3821 " return 1.0 - famt;\n"
3824 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
3826 " vec3 specdir = reflect( -dir, wnormal );\n"
3827 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
3830 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
3831 " float dist = pow(fdist*0.0010,0.78);\n"
3832 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
3835 "vec3 scene_calculate_light( int light_index, \n"
3836 " vec3 halfview, vec3 co, vec3 normal )\n"
3838 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
3839 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
3840 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
3842 " vec3 light_delta = light_co.xyz-co;\n"
3843 " float dist2 = dot(light_delta,light_delta);\n"
3845 " light_delta = normalize( light_delta );\n"
3847 " float quadratic = dist2*100.0;\n"
3848 " float attenuation = 1.0/( 1.0 + quadratic );\n"
3849 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
3851 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
3853 " if( light_dir.w < 0.999999 ){\n"
3854 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
3855 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
3858 " return light_colour.rgb * attenuation * falloff \n"
3859 " * step( g_day_phase, light_colour.w );\n"
3862 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
3863 " vec3 halfview, vec3 co, vec3 normal )\n"
3865 " uint light_count = packed_index & 0x3u;\n"
3867 " vec3 l = vec3(0.0);\n"
3869 " if( light_count >= 1u ){\n"
3870 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
3871 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
3872 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
3874 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
3876 " if( light_count >= 2u ){\n"
3877 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
3879 " if( light_count >= 3u ){\n"
3880 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
3888 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
3889 " float light_mask )\n"
3891 " if( g_light_preview == 1 )\n"
3892 " diffuse = vec3(0.75);\n"
3895 " vec3 halfview = uCamera - co;\n"
3896 " float fdist = length(halfview);\n"
3897 " halfview /= fdist;\n"
3899 " float world_shadow = newlight_compute_sun_shadow( \n"
3900 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
3902 " vec3 total_light = clearskies_lighting( \n"
3903 " normal, min( light_mask, world_shadow ), halfview );\n"
3905 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
3906 " cube_coord = floor( cube_coord );\n"
3908 " if( g_debug_indices == 1 )\n"
3910 " return rand33(cube_coord);\n"
3913 " if( g_debug_complexity == 1 )\n"
3915 " ivec3 coord = ivec3( cube_coord );\n"
3916 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3918 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
3919 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
3922 " // FIXME: this coord should absolutely must be clamped!\n"
3924 " ivec3 coord = ivec3( cube_coord );\n"
3925 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3927 " total_light += \n"
3928 " scene_calculate_packed_light_patch( index_sample.x,\n"
3929 " halfview, co, normal ) \n"
3931 " total_light += \n"
3932 " scene_calculate_packed_light_patch( index_sample.y,\n"
3933 " halfview, co, normal )\n"
3936 " // Take a section of the sky function to give us a matching fog colour\n"
3938 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
3939 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
3940 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
3941 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
3943 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
3944 " sun_colour *= sun_shape;\n"
3946 " fog_colour += sun_colour;\n"
3947 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
3952 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
3954 " vec3 pa = p - a;\n"
3955 " vec3 ba = b - a;\n"
3957 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
3958 " return length( pa - ba*h );\n"
3961 "float compute_board_shadow()\n"
3963 " // player shadow\n"
3964 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
3965 " g_board_1.xyz )-0.1 );\n"
3966 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
3967 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
3969 " return 1.0 - player_shadow*0.8;\n"
3972 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
3974 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
3979 "const float k_motion_lerp_amount = 0.01;\n"
3983 "layout (location = 1) out vec2 oMotionVec;\n"
3985 "in vec3 aMotionVec0;\n"
3986 "in vec3 aMotionVec1;\n"
3988 "void compute_motion_vectors()\n"
3990 " // Write motion vectors\n"
3991 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
3992 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
3994 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
3999 "float filtered_stripe( in float p, in float ddx, in float ddy )\n"
4001 " float w = max(abs(ddx), abs(ddy)) + 0.02;\n"
4002 " float i = (abs(fract((p-0.5*w)/2.0)-0.5)-abs(fract((p+0.5*w)/2.0)-0.5))/w;\n"
4003 " return 0.5 - i;\n"
4008 " compute_motion_vectors();\n"
4010 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
4012 " // ws modulation\n"
4013 " vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
4015 " // Creating normal patches\n"
4016 " vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
4017 " vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
4018 " qnorm += vec3(0.001,0.0,0.0);\n"
4020 " vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
4021 " vec3 tangent1 = cross(qnorm,tangent0);\n"
4022 " vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.035;\n"
4024 " // Patch local noise\n"
4025 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
4027 " vfrag = pow(uColour.rgb,vec3(1.0/2.2));\n"
4028 " vfrag -= rgarbage.a*0.1;\n"
4030 " if( wgarbage.g < 0.1 )\n"
4033 " float movep = (aUv.x + abs(aUv.y-0.5)*0.4 - g_realtime)*2.0;\n"
4034 " float stripe = filtered_stripe( movep, dFdx(movep), dFdy(movep) );\n"
4035 " vfrag *= 0.9+stripe*uColour.a; \n"
4037 " if( g_light_preview == 1 )\n"
4039 " vfrag = vec3(0.5);\n"
4043 " oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );\n"
4048 GLuint _uniform_scene_route_uMdl
;
4049 GLuint _uniform_scene_route_uPv
;
4050 GLuint _uniform_scene_route_uPvmPrev
;
4051 GLuint _uniform_scene_route_uNormalMtx
;
4052 GLuint _uniform_scene_route_uTexGarbage
;
4053 GLuint _uniform_scene_route_uTexGradients
;
4054 GLuint _uniform_scene_route_uCamera
;
4055 GLuint _uniform_scene_route_uColour
;
4056 GLuint _uniform_scene_route_g_world_depth
;
4057 GLuint _uniform_scene_route_uLightsArray
;
4058 GLuint _uniform_scene_route_uLightsIndex
;
4059 #include "shaders/scene_depth.h"
4060 struct vg_shader _shader_scene_depth
= {
4061 .name
= "scene_depth",
4064 .orig_file
= "shaders/scene.vs",
4066 "layout (location=0) in vec3 a_co;\n"
4067 "layout (location=1) in vec4 a_norm;\n"
4068 "layout (location=2) in vec2 a_uv;\n"
4071 "const float k_motion_lerp_amount = 0.01;\n"
4075 "out vec3 aMotionVec0;\n"
4076 "out vec3 aMotionVec1;\n"
4078 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
4080 " // This magically solves some artifacting errors!\n"
4082 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
4084 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
4085 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
4090 "uniform mat4x3 uMdl;\n"
4091 "uniform mat4 uPv;\n"
4092 "uniform mat4 uPvmPrev;\n"
4097 "out vec3 aWorldCo;\n"
4101 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
4102 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
4103 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
4105 " vs_motion_out( vproj0, vproj1 );\n"
4107 " gl_Position = vproj0;\n"
4110 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
4112 " aWorldCo = world_pos0;\n"
4117 .orig_file
= "shaders/scene_depth.fs",
4119 "out vec4 FragColor;\n"
4121 "uniform vec3 uCamera;\n"
4122 "uniform vec3 uBoard0;\n"
4123 "uniform vec3 uBoard1;\n"
4127 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
4136 "in vec3 aWorldCo;\n"
4139 "layout (location = 0) out vec4 oColour;\n"
4141 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
4142 "layout (std140) uniform ub_world_lighting\n"
4144 " vec4 g_cube_min;\n"
4145 " vec4 g_cube_inv_range;\n"
4147 " vec4 g_water_plane;\n"
4148 " vec4 g_depth_bounds;\n"
4150 " vec4 g_daysky_colour;\n"
4151 " vec4 g_nightsky_colour;\n"
4152 " vec4 g_sunset_colour;\n"
4153 " vec4 g_ambient_colour;\n"
4154 " vec4 g_sunset_ambient;\n"
4155 " vec4 g_sun_colour;\n"
4156 " vec4 g_sun_dir;\n"
4157 " vec4 g_board_0;\n"
4158 " vec4 g_board_1;\n"
4160 " float g_water_fog;\n"
4162 " float g_realtime;\n"
4163 " float g_shadow_length;\n"
4164 " float g_shadow_spread;\n"
4166 " float g_time_of_day;\n"
4167 " float g_day_phase;\n"
4168 " float g_sunset_phase;\n"
4170 " int g_light_preview;\n"
4171 " int g_shadow_samples;\n"
4173 " int g_debug_indices;\n"
4174 " int g_debug_complexity;\n"
4177 "uniform sampler2D g_world_depth;\n"
4178 "uniform samplerBuffer uLightsArray;\n"
4179 "uniform usampler3D uLightsIndex;\n"
4182 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
4183 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
4184 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
4185 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
4186 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
4187 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
4189 "const float SUN_ANGLE = 0.0001;\n"
4190 "const float PI = 3.14159265358979323846264;\n"
4192 "//struct world_info\n"
4197 "// sunset_phase;\n"
4199 "// vec3 sun_dir;\n"
4202 "vec3 rand33(vec3 p3)\n"
4204 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
4205 " p3 += dot(p3, p3.yxz+33.33);\n"
4206 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
4209 "float stars( vec3 rd, float rr, float size ){\n"
4210 " vec3 co = rd * rr;\n"
4212 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
4214 " float spaces = 1.0 / rr;\n"
4215 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
4216 " a -= mod(a, spaces) - spaces * 0.5;\n"
4218 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
4220 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
4221 " plane = plane - mod(plane, PI / count);\n"
4223 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
4225 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
4226 " float ydist = sqrt(rr * rr - level * level);\n"
4227 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
4228 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
4229 " float star = smoothstep(size, 0.0, distance(center, co));\n"
4233 "float luminance( vec3 v )\n"
4235 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
4238 "vec3 clearskies_ambient( vec3 dir )\n"
4240 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
4241 " float sky_gradient = dir.y;\n"
4243 " /* Blend phase colours */\n"
4244 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
4245 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
4246 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
4248 " /* Add gradient */\n"
4249 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
4251 " return ambient;\n"
4254 "vec3 clearskies_sky( vec3 ray_dir )\n"
4256 " ray_dir.y = abs( ray_dir.y );\n"
4257 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
4260 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
4261 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
4262 " float sun_shape = pow( sun_size, 2000.0 );\n"
4263 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
4265 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
4266 " sun_colour *= sun_shape;\n"
4269 " float star = 0.0;\n"
4270 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
4272 " if( star_blend > 0.001 ){\n"
4273 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
4274 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
4275 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
4279 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
4280 " return composite;\n"
4283 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
4285 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
4287 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
4288 " g_sunset_phase );\n"
4290 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
4291 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
4292 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
4293 " ) * g_sun_colour.rgb * g_day_phase;\n"
4295 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
4296 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
4297 " g_sunset_phase );\n"
4299 " return ambient + (light_sun + sky_reflection) * shadow;\n"
4304 "float world_depth_sample( vec3 pos )\n"
4306 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
4307 " return texture( g_world_depth, depth_coord ).r;\n"
4310 "float world_water_depth( vec3 pos )\n"
4312 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
4313 " return world_depth_sample( pos ) - ref_depth;\n"
4316 "float shadow_sample( vec3 co ){\n"
4317 " float height_sample = world_depth_sample( co );\n"
4319 " float fdelta = height_sample - co.y;\n"
4320 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
4323 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
4324 " if( g_shadow_samples == 0 ){\n"
4328 " float fspread = g_shadow_spread;\n"
4329 " float flength = g_shadow_length;\n"
4331 " float famt = 0.0;\n"
4332 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
4333 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
4334 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
4335 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
4337 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
4338 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
4339 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
4340 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
4342 " return 1.0 - famt;\n"
4345 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
4347 " vec3 specdir = reflect( -dir, wnormal );\n"
4348 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
4351 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
4352 " float dist = pow(fdist*0.0010,0.78);\n"
4353 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
4356 "vec3 scene_calculate_light( int light_index, \n"
4357 " vec3 halfview, vec3 co, vec3 normal )\n"
4359 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
4360 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
4361 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
4363 " vec3 light_delta = light_co.xyz-co;\n"
4364 " float dist2 = dot(light_delta,light_delta);\n"
4366 " light_delta = normalize( light_delta );\n"
4368 " float quadratic = dist2*100.0;\n"
4369 " float attenuation = 1.0/( 1.0 + quadratic );\n"
4370 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
4372 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
4374 " if( light_dir.w < 0.999999 ){\n"
4375 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
4376 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
4379 " return light_colour.rgb * attenuation * falloff \n"
4380 " * step( g_day_phase, light_colour.w );\n"
4383 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
4384 " vec3 halfview, vec3 co, vec3 normal )\n"
4386 " uint light_count = packed_index & 0x3u;\n"
4388 " vec3 l = vec3(0.0);\n"
4390 " if( light_count >= 1u ){\n"
4391 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
4392 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
4393 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
4395 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
4397 " if( light_count >= 2u ){\n"
4398 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
4400 " if( light_count >= 3u ){\n"
4401 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
4409 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
4410 " float light_mask )\n"
4412 " if( g_light_preview == 1 )\n"
4413 " diffuse = vec3(0.75);\n"
4416 " vec3 halfview = uCamera - co;\n"
4417 " float fdist = length(halfview);\n"
4418 " halfview /= fdist;\n"
4420 " float world_shadow = newlight_compute_sun_shadow( \n"
4421 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
4423 " vec3 total_light = clearskies_lighting( \n"
4424 " normal, min( light_mask, world_shadow ), halfview );\n"
4426 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
4427 " cube_coord = floor( cube_coord );\n"
4429 " if( g_debug_indices == 1 )\n"
4431 " return rand33(cube_coord);\n"
4434 " if( g_debug_complexity == 1 )\n"
4436 " ivec3 coord = ivec3( cube_coord );\n"
4437 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4439 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
4440 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
4443 " // FIXME: this coord should absolutely must be clamped!\n"
4445 " ivec3 coord = ivec3( cube_coord );\n"
4446 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4448 " total_light += \n"
4449 " scene_calculate_packed_light_patch( index_sample.x,\n"
4450 " halfview, co, normal ) \n"
4452 " total_light += \n"
4453 " scene_calculate_packed_light_patch( index_sample.y,\n"
4454 " halfview, co, normal )\n"
4457 " // Take a section of the sky function to give us a matching fog colour\n"
4459 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
4460 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
4461 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
4462 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
4464 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
4465 " sun_colour *= sun_shape;\n"
4467 " fog_colour += sun_colour;\n"
4468 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
4473 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
4475 " vec3 pa = p - a;\n"
4476 " vec3 ba = b - a;\n"
4478 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
4479 " return length( pa - ba*h );\n"
4482 "float compute_board_shadow()\n"
4484 " // player shadow\n"
4485 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
4486 " g_board_1.xyz )-0.1 );\n"
4487 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
4488 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
4490 " return 1.0 - player_shadow*0.8;\n"
4493 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
4495 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
4500 "// Water blending\n"
4501 "// ==============\n"
4503 "float water_depth( vec3 pos, vec3 halfview )\n"
4505 " vec3 pnorm = g_water_plane.xyz;\n"
4506 " float pdist = g_water_plane.w;\n"
4508 " float d = dot( pnorm, halfview );\n"
4509 " float t = dot((pnorm*pdist - pos), pnorm) / d;\n"
4511 " // TODO: Make g_water_fog a material param\n"
4512 " return t * 0.3;//g_water_fog;\n"
4517 " vec3 halfview = normalize( uCamera - aWorldCo );\n"
4518 " float depth = water_depth( aWorldCo, halfview );\n"
4519 " FragColor = vec4( depth, 0.0, 0.0, 0.0 );\n"
4524 GLuint _uniform_scene_depth_uMdl
;
4525 GLuint _uniform_scene_depth_uPv
;
4526 GLuint _uniform_scene_depth_uPvmPrev
;
4527 GLuint _uniform_scene_depth_uCamera
;
4528 GLuint _uniform_scene_depth_uBoard0
;
4529 GLuint _uniform_scene_depth_uBoard1
;
4530 GLuint _uniform_scene_depth_g_world_depth
;
4531 GLuint _uniform_scene_depth_uLightsArray
;
4532 GLuint _uniform_scene_depth_uLightsIndex
;
4533 #include "shaders/scene_position.h"
4534 struct vg_shader _shader_scene_position
= {
4535 .name
= "scene_position",
4538 .orig_file
= "shaders/scene.vs",
4540 "layout (location=0) in vec3 a_co;\n"
4541 "layout (location=1) in vec4 a_norm;\n"
4542 "layout (location=2) in vec2 a_uv;\n"
4545 "const float k_motion_lerp_amount = 0.01;\n"
4549 "out vec3 aMotionVec0;\n"
4550 "out vec3 aMotionVec1;\n"
4552 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
4554 " // This magically solves some artifacting errors!\n"
4556 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
4558 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
4559 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
4564 "uniform mat4x3 uMdl;\n"
4565 "uniform mat4 uPv;\n"
4566 "uniform mat4 uPvmPrev;\n"
4571 "out vec3 aWorldCo;\n"
4575 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
4576 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
4577 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
4579 " vs_motion_out( vproj0, vproj1 );\n"
4581 " gl_Position = vproj0;\n"
4584 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
4586 " aWorldCo = world_pos0;\n"
4591 .orig_file
= "shaders/scene_position.fs",
4593 "out vec4 FragColor;\n"
4595 "uniform vec3 uCamera;\n"
4596 "uniform vec3 uBoard0;\n"
4597 "uniform vec3 uBoard1;\n"
4601 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
4610 "in vec3 aWorldCo;\n"
4613 "layout (location = 0) out vec4 oColour;\n"
4615 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
4616 "layout (std140) uniform ub_world_lighting\n"
4618 " vec4 g_cube_min;\n"
4619 " vec4 g_cube_inv_range;\n"
4621 " vec4 g_water_plane;\n"
4622 " vec4 g_depth_bounds;\n"
4624 " vec4 g_daysky_colour;\n"
4625 " vec4 g_nightsky_colour;\n"
4626 " vec4 g_sunset_colour;\n"
4627 " vec4 g_ambient_colour;\n"
4628 " vec4 g_sunset_ambient;\n"
4629 " vec4 g_sun_colour;\n"
4630 " vec4 g_sun_dir;\n"
4631 " vec4 g_board_0;\n"
4632 " vec4 g_board_1;\n"
4634 " float g_water_fog;\n"
4636 " float g_realtime;\n"
4637 " float g_shadow_length;\n"
4638 " float g_shadow_spread;\n"
4640 " float g_time_of_day;\n"
4641 " float g_day_phase;\n"
4642 " float g_sunset_phase;\n"
4644 " int g_light_preview;\n"
4645 " int g_shadow_samples;\n"
4647 " int g_debug_indices;\n"
4648 " int g_debug_complexity;\n"
4651 "uniform sampler2D g_world_depth;\n"
4652 "uniform samplerBuffer uLightsArray;\n"
4653 "uniform usampler3D uLightsIndex;\n"
4656 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
4657 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
4658 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
4659 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
4660 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
4661 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
4663 "const float SUN_ANGLE = 0.0001;\n"
4664 "const float PI = 3.14159265358979323846264;\n"
4666 "//struct world_info\n"
4671 "// sunset_phase;\n"
4673 "// vec3 sun_dir;\n"
4676 "vec3 rand33(vec3 p3)\n"
4678 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
4679 " p3 += dot(p3, p3.yxz+33.33);\n"
4680 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
4683 "float stars( vec3 rd, float rr, float size ){\n"
4684 " vec3 co = rd * rr;\n"
4686 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
4688 " float spaces = 1.0 / rr;\n"
4689 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
4690 " a -= mod(a, spaces) - spaces * 0.5;\n"
4692 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
4694 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
4695 " plane = plane - mod(plane, PI / count);\n"
4697 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
4699 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
4700 " float ydist = sqrt(rr * rr - level * level);\n"
4701 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
4702 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
4703 " float star = smoothstep(size, 0.0, distance(center, co));\n"
4707 "float luminance( vec3 v )\n"
4709 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
4712 "vec3 clearskies_ambient( vec3 dir )\n"
4714 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
4715 " float sky_gradient = dir.y;\n"
4717 " /* Blend phase colours */\n"
4718 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
4719 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
4720 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
4722 " /* Add gradient */\n"
4723 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
4725 " return ambient;\n"
4728 "vec3 clearskies_sky( vec3 ray_dir )\n"
4730 " ray_dir.y = abs( ray_dir.y );\n"
4731 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
4734 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
4735 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
4736 " float sun_shape = pow( sun_size, 2000.0 );\n"
4737 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
4739 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
4740 " sun_colour *= sun_shape;\n"
4743 " float star = 0.0;\n"
4744 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
4746 " if( star_blend > 0.001 ){\n"
4747 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
4748 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
4749 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
4753 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
4754 " return composite;\n"
4757 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
4759 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
4761 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
4762 " g_sunset_phase );\n"
4764 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
4765 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
4766 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
4767 " ) * g_sun_colour.rgb * g_day_phase;\n"
4769 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
4770 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
4771 " g_sunset_phase );\n"
4773 " return ambient + (light_sun + sky_reflection) * shadow;\n"
4778 "float world_depth_sample( vec3 pos )\n"
4780 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
4781 " return texture( g_world_depth, depth_coord ).r;\n"
4784 "float world_water_depth( vec3 pos )\n"
4786 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
4787 " return world_depth_sample( pos ) - ref_depth;\n"
4790 "float shadow_sample( vec3 co ){\n"
4791 " float height_sample = world_depth_sample( co );\n"
4793 " float fdelta = height_sample - co.y;\n"
4794 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
4797 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
4798 " if( g_shadow_samples == 0 ){\n"
4802 " float fspread = g_shadow_spread;\n"
4803 " float flength = g_shadow_length;\n"
4805 " float famt = 0.0;\n"
4806 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
4807 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
4808 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
4809 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
4811 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
4812 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
4813 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
4814 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
4816 " return 1.0 - famt;\n"
4819 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
4821 " vec3 specdir = reflect( -dir, wnormal );\n"
4822 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
4825 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
4826 " float dist = pow(fdist*0.0010,0.78);\n"
4827 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
4830 "vec3 scene_calculate_light( int light_index, \n"
4831 " vec3 halfview, vec3 co, vec3 normal )\n"
4833 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
4834 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
4835 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
4837 " vec3 light_delta = light_co.xyz-co;\n"
4838 " float dist2 = dot(light_delta,light_delta);\n"
4840 " light_delta = normalize( light_delta );\n"
4842 " float quadratic = dist2*100.0;\n"
4843 " float attenuation = 1.0/( 1.0 + quadratic );\n"
4844 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
4846 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
4848 " if( light_dir.w < 0.999999 ){\n"
4849 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
4850 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
4853 " return light_colour.rgb * attenuation * falloff \n"
4854 " * step( g_day_phase, light_colour.w );\n"
4857 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
4858 " vec3 halfview, vec3 co, vec3 normal )\n"
4860 " uint light_count = packed_index & 0x3u;\n"
4862 " vec3 l = vec3(0.0);\n"
4864 " if( light_count >= 1u ){\n"
4865 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
4866 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
4867 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
4869 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
4871 " if( light_count >= 2u ){\n"
4872 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
4874 " if( light_count >= 3u ){\n"
4875 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
4883 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
4884 " float light_mask )\n"
4886 " if( g_light_preview == 1 )\n"
4887 " diffuse = vec3(0.75);\n"
4890 " vec3 halfview = uCamera - co;\n"
4891 " float fdist = length(halfview);\n"
4892 " halfview /= fdist;\n"
4894 " float world_shadow = newlight_compute_sun_shadow( \n"
4895 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
4897 " vec3 total_light = clearskies_lighting( \n"
4898 " normal, min( light_mask, world_shadow ), halfview );\n"
4900 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
4901 " cube_coord = floor( cube_coord );\n"
4903 " if( g_debug_indices == 1 )\n"
4905 " return rand33(cube_coord);\n"
4908 " if( g_debug_complexity == 1 )\n"
4910 " ivec3 coord = ivec3( cube_coord );\n"
4911 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4913 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
4914 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
4917 " // FIXME: this coord should absolutely must be clamped!\n"
4919 " ivec3 coord = ivec3( cube_coord );\n"
4920 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4922 " total_light += \n"
4923 " scene_calculate_packed_light_patch( index_sample.x,\n"
4924 " halfview, co, normal ) \n"
4926 " total_light += \n"
4927 " scene_calculate_packed_light_patch( index_sample.y,\n"
4928 " halfview, co, normal )\n"
4931 " // Take a section of the sky function to give us a matching fog colour\n"
4933 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
4934 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
4935 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
4936 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
4938 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
4939 " sun_colour *= sun_shape;\n"
4941 " fog_colour += sun_colour;\n"
4942 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
4947 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
4949 " vec3 pa = p - a;\n"
4950 " vec3 ba = b - a;\n"
4952 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
4953 " return length( pa - ba*h );\n"
4956 "float compute_board_shadow()\n"
4958 " // player shadow\n"
4959 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
4960 " g_board_1.xyz )-0.1 );\n"
4961 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
4962 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
4964 " return 1.0 - player_shadow*0.8;\n"
4967 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
4969 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
4976 " float height_full = aWorldCo.y;\n"
4977 " float height_water = height_full;\n"
4979 " if( height_water > (g_water_plane.y * g_water_plane.w) + 2.0 )\n"
4980 " height_water = -99999.9;\n"
4982 " FragColor = vec4( height_full, height_water, 0.0, 0.0 );\n"
4987 GLuint _uniform_scene_position_uMdl
;
4988 GLuint _uniform_scene_position_uPv
;
4989 GLuint _uniform_scene_position_uPvmPrev
;
4990 GLuint _uniform_scene_position_uCamera
;
4991 GLuint _uniform_scene_position_uBoard0
;
4992 GLuint _uniform_scene_position_uBoard1
;
4993 GLuint _uniform_scene_position_g_world_depth
;
4994 GLuint _uniform_scene_position_uLightsArray
;
4995 GLuint _uniform_scene_position_uLightsIndex
;
4996 #include "shaders/scene_cubemapped.h"
4997 struct vg_shader _shader_scene_cubemapped
= {
4998 .name
= "scene_cubemapped",
5001 .orig_file
= "shaders/scene.vs",
5003 "layout (location=0) in vec3 a_co;\n"
5004 "layout (location=1) in vec4 a_norm;\n"
5005 "layout (location=2) in vec2 a_uv;\n"
5008 "const float k_motion_lerp_amount = 0.01;\n"
5012 "out vec3 aMotionVec0;\n"
5013 "out vec3 aMotionVec1;\n"
5015 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
5017 " // This magically solves some artifacting errors!\n"
5019 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
5021 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
5022 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
5027 "uniform mat4x3 uMdl;\n"
5028 "uniform mat4 uPv;\n"
5029 "uniform mat4 uPvmPrev;\n"
5034 "out vec3 aWorldCo;\n"
5038 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
5039 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
5040 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
5042 " vs_motion_out( vproj0, vproj1 );\n"
5044 " gl_Position = vproj0;\n"
5047 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
5049 " aWorldCo = world_pos0;\n"
5054 .orig_file
= "shaders/scene_cubemapped.fs",
5056 "uniform sampler2D uTexGarbage;\n"
5057 "uniform sampler2D uTexMain;\n"
5058 "uniform samplerCube uTexCubemap;\n"
5059 "uniform vec3 uCamera;\n"
5060 "uniform vec4 uPlane;\n"
5061 "uniform vec4 uColour;\n"
5065 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
5074 "in vec3 aWorldCo;\n"
5077 "layout (location = 0) out vec4 oColour;\n"
5079 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
5080 "layout (std140) uniform ub_world_lighting\n"
5082 " vec4 g_cube_min;\n"
5083 " vec4 g_cube_inv_range;\n"
5085 " vec4 g_water_plane;\n"
5086 " vec4 g_depth_bounds;\n"
5088 " vec4 g_daysky_colour;\n"
5089 " vec4 g_nightsky_colour;\n"
5090 " vec4 g_sunset_colour;\n"
5091 " vec4 g_ambient_colour;\n"
5092 " vec4 g_sunset_ambient;\n"
5093 " vec4 g_sun_colour;\n"
5094 " vec4 g_sun_dir;\n"
5095 " vec4 g_board_0;\n"
5096 " vec4 g_board_1;\n"
5098 " float g_water_fog;\n"
5100 " float g_realtime;\n"
5101 " float g_shadow_length;\n"
5102 " float g_shadow_spread;\n"
5104 " float g_time_of_day;\n"
5105 " float g_day_phase;\n"
5106 " float g_sunset_phase;\n"
5108 " int g_light_preview;\n"
5109 " int g_shadow_samples;\n"
5111 " int g_debug_indices;\n"
5112 " int g_debug_complexity;\n"
5115 "uniform sampler2D g_world_depth;\n"
5116 "uniform samplerBuffer uLightsArray;\n"
5117 "uniform usampler3D uLightsIndex;\n"
5120 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
5121 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
5122 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
5123 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
5124 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
5125 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
5127 "const float SUN_ANGLE = 0.0001;\n"
5128 "const float PI = 3.14159265358979323846264;\n"
5130 "//struct world_info\n"
5135 "// sunset_phase;\n"
5137 "// vec3 sun_dir;\n"
5140 "vec3 rand33(vec3 p3)\n"
5142 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
5143 " p3 += dot(p3, p3.yxz+33.33);\n"
5144 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
5147 "float stars( vec3 rd, float rr, float size ){\n"
5148 " vec3 co = rd * rr;\n"
5150 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
5152 " float spaces = 1.0 / rr;\n"
5153 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
5154 " a -= mod(a, spaces) - spaces * 0.5;\n"
5156 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
5158 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
5159 " plane = plane - mod(plane, PI / count);\n"
5161 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
5163 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
5164 " float ydist = sqrt(rr * rr - level * level);\n"
5165 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
5166 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
5167 " float star = smoothstep(size, 0.0, distance(center, co));\n"
5171 "float luminance( vec3 v )\n"
5173 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
5176 "vec3 clearskies_ambient( vec3 dir )\n"
5178 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
5179 " float sky_gradient = dir.y;\n"
5181 " /* Blend phase colours */\n"
5182 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
5183 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
5184 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
5186 " /* Add gradient */\n"
5187 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
5189 " return ambient;\n"
5192 "vec3 clearskies_sky( vec3 ray_dir )\n"
5194 " ray_dir.y = abs( ray_dir.y );\n"
5195 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
5198 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
5199 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
5200 " float sun_shape = pow( sun_size, 2000.0 );\n"
5201 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
5203 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
5204 " sun_colour *= sun_shape;\n"
5207 " float star = 0.0;\n"
5208 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
5210 " if( star_blend > 0.001 ){\n"
5211 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
5212 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
5213 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
5217 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
5218 " return composite;\n"
5221 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
5223 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
5225 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
5226 " g_sunset_phase );\n"
5228 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
5229 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
5230 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
5231 " ) * g_sun_colour.rgb * g_day_phase;\n"
5233 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
5234 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
5235 " g_sunset_phase );\n"
5237 " return ambient + (light_sun + sky_reflection) * shadow;\n"
5242 "float world_depth_sample( vec3 pos )\n"
5244 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
5245 " return texture( g_world_depth, depth_coord ).r;\n"
5248 "float world_water_depth( vec3 pos )\n"
5250 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
5251 " return world_depth_sample( pos ) - ref_depth;\n"
5254 "float shadow_sample( vec3 co ){\n"
5255 " float height_sample = world_depth_sample( co );\n"
5257 " float fdelta = height_sample - co.y;\n"
5258 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
5261 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
5262 " if( g_shadow_samples == 0 ){\n"
5266 " float fspread = g_shadow_spread;\n"
5267 " float flength = g_shadow_length;\n"
5269 " float famt = 0.0;\n"
5270 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
5271 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
5272 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
5273 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
5275 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
5276 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
5277 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
5278 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
5280 " return 1.0 - famt;\n"
5283 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
5285 " vec3 specdir = reflect( -dir, wnormal );\n"
5286 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
5289 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
5290 " float dist = pow(fdist*0.0010,0.78);\n"
5291 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
5294 "vec3 scene_calculate_light( int light_index, \n"
5295 " vec3 halfview, vec3 co, vec3 normal )\n"
5297 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
5298 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
5299 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
5301 " vec3 light_delta = light_co.xyz-co;\n"
5302 " float dist2 = dot(light_delta,light_delta);\n"
5304 " light_delta = normalize( light_delta );\n"
5306 " float quadratic = dist2*100.0;\n"
5307 " float attenuation = 1.0/( 1.0 + quadratic );\n"
5308 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
5310 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
5312 " if( light_dir.w < 0.999999 ){\n"
5313 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
5314 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
5317 " return light_colour.rgb * attenuation * falloff \n"
5318 " * step( g_day_phase, light_colour.w );\n"
5321 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
5322 " vec3 halfview, vec3 co, vec3 normal )\n"
5324 " uint light_count = packed_index & 0x3u;\n"
5326 " vec3 l = vec3(0.0);\n"
5328 " if( light_count >= 1u ){\n"
5329 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
5330 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
5331 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
5333 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
5335 " if( light_count >= 2u ){\n"
5336 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
5338 " if( light_count >= 3u ){\n"
5339 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
5347 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
5348 " float light_mask )\n"
5350 " if( g_light_preview == 1 )\n"
5351 " diffuse = vec3(0.75);\n"
5354 " vec3 halfview = uCamera - co;\n"
5355 " float fdist = length(halfview);\n"
5356 " halfview /= fdist;\n"
5358 " float world_shadow = newlight_compute_sun_shadow( \n"
5359 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
5361 " vec3 total_light = clearskies_lighting( \n"
5362 " normal, min( light_mask, world_shadow ), halfview );\n"
5364 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
5365 " cube_coord = floor( cube_coord );\n"
5367 " if( g_debug_indices == 1 )\n"
5369 " return rand33(cube_coord);\n"
5372 " if( g_debug_complexity == 1 )\n"
5374 " ivec3 coord = ivec3( cube_coord );\n"
5375 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5377 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
5378 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
5381 " // FIXME: this coord should absolutely must be clamped!\n"
5383 " ivec3 coord = ivec3( cube_coord );\n"
5384 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5386 " total_light += \n"
5387 " scene_calculate_packed_light_patch( index_sample.x,\n"
5388 " halfview, co, normal ) \n"
5390 " total_light += \n"
5391 " scene_calculate_packed_light_patch( index_sample.y,\n"
5392 " halfview, co, normal )\n"
5395 " // Take a section of the sky function to give us a matching fog colour\n"
5397 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
5398 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
5399 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
5400 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
5402 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
5403 " sun_colour *= sun_shape;\n"
5405 " fog_colour += sun_colour;\n"
5406 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
5411 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
5413 " vec3 pa = p - a;\n"
5414 " vec3 ba = b - a;\n"
5416 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
5417 " return length( pa - ba*h );\n"
5420 "float compute_board_shadow()\n"
5422 " // player shadow\n"
5423 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
5424 " g_board_1.xyz )-0.1 );\n"
5425 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
5426 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
5428 " return 1.0 - player_shadow*0.8;\n"
5431 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
5433 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
5438 "const float k_motion_lerp_amount = 0.01;\n"
5442 "layout (location = 1) out vec2 oMotionVec;\n"
5444 "in vec3 aMotionVec0;\n"
5445 "in vec3 aMotionVec1;\n"
5447 "void compute_motion_vectors()\n"
5449 " // Write motion vectors\n"
5450 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
5451 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
5453 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
5460 " compute_motion_vectors();\n"
5462 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
5463 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
5464 " vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.0015 + aCo.yx*0.002 );\n"
5465 " vec3 qnorm = aNorm.xyz;\n"
5466 " vfrag = vsamplemain.rgb;\n"
5468 " if( g_light_preview == 1 ){\n"
5469 " vfrag = vec3(0.5);\n"
5472 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
5473 " oColour = vec4( vfrag, 1.0 );\n"
5475 " vec3 halfdir = normalize( aWorldCo - uCamera );\n"
5476 " vec3 reflectdir = reflect( halfdir, qnorm );\n"
5477 " oColour = mix( oColour, \n"
5478 " vec4(texture(uTexCubemap,reflectdir).rgb * uColour.rgb, 1.0),\n"
5479 " uColour.a*wgarbage.b );\n"
5484 GLuint _uniform_scene_cubemapped_uMdl
;
5485 GLuint _uniform_scene_cubemapped_uPv
;
5486 GLuint _uniform_scene_cubemapped_uPvmPrev
;
5487 GLuint _uniform_scene_cubemapped_uTexGarbage
;
5488 GLuint _uniform_scene_cubemapped_uTexMain
;
5489 GLuint _uniform_scene_cubemapped_uTexCubemap
;
5490 GLuint _uniform_scene_cubemapped_uCamera
;
5491 GLuint _uniform_scene_cubemapped_uPlane
;
5492 GLuint _uniform_scene_cubemapped_uColour
;
5493 GLuint _uniform_scene_cubemapped_g_world_depth
;
5494 GLuint _uniform_scene_cubemapped_uLightsArray
;
5495 GLuint _uniform_scene_cubemapped_uLightsIndex
;
5496 #include "shaders/scene_water.h"
5497 struct vg_shader _shader_scene_water
= {
5498 .name
= "scene_water",
5501 .orig_file
= "shaders/scene.vs",
5503 "layout (location=0) in vec3 a_co;\n"
5504 "layout (location=1) in vec4 a_norm;\n"
5505 "layout (location=2) in vec2 a_uv;\n"
5508 "const float k_motion_lerp_amount = 0.01;\n"
5512 "out vec3 aMotionVec0;\n"
5513 "out vec3 aMotionVec1;\n"
5515 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
5517 " // This magically solves some artifacting errors!\n"
5519 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
5521 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
5522 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
5527 "uniform mat4x3 uMdl;\n"
5528 "uniform mat4 uPv;\n"
5529 "uniform mat4 uPvmPrev;\n"
5534 "out vec3 aWorldCo;\n"
5538 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
5539 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
5540 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
5542 " vs_motion_out( vproj0, vproj1 );\n"
5544 " gl_Position = vproj0;\n"
5547 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
5549 " aWorldCo = world_pos0;\n"
5554 .orig_file
= "shaders/scene_water.fs",
5556 "uniform sampler2D uTexMain;\n"
5557 "uniform sampler2D uTexDudv;\n"
5558 "uniform sampler2D uTexBack;\n"
5560 "uniform vec2 uInvRes;\n"
5561 "uniform float uTime;\n"
5562 "uniform vec3 uCamera;\n"
5563 "uniform float uSurfaceY;\n"
5564 "uniform vec3 uBoard0;\n"
5565 "uniform vec3 uBoard1;\n"
5567 "uniform vec3 uShoreColour;\n"
5568 "uniform vec3 uOceanColour;\n"
5572 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
5581 "in vec3 aWorldCo;\n"
5584 "layout (location = 0) out vec4 oColour;\n"
5586 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
5587 "layout (std140) uniform ub_world_lighting\n"
5589 " vec4 g_cube_min;\n"
5590 " vec4 g_cube_inv_range;\n"
5592 " vec4 g_water_plane;\n"
5593 " vec4 g_depth_bounds;\n"
5595 " vec4 g_daysky_colour;\n"
5596 " vec4 g_nightsky_colour;\n"
5597 " vec4 g_sunset_colour;\n"
5598 " vec4 g_ambient_colour;\n"
5599 " vec4 g_sunset_ambient;\n"
5600 " vec4 g_sun_colour;\n"
5601 " vec4 g_sun_dir;\n"
5602 " vec4 g_board_0;\n"
5603 " vec4 g_board_1;\n"
5605 " float g_water_fog;\n"
5607 " float g_realtime;\n"
5608 " float g_shadow_length;\n"
5609 " float g_shadow_spread;\n"
5611 " float g_time_of_day;\n"
5612 " float g_day_phase;\n"
5613 " float g_sunset_phase;\n"
5615 " int g_light_preview;\n"
5616 " int g_shadow_samples;\n"
5618 " int g_debug_indices;\n"
5619 " int g_debug_complexity;\n"
5622 "uniform sampler2D g_world_depth;\n"
5623 "uniform samplerBuffer uLightsArray;\n"
5624 "uniform usampler3D uLightsIndex;\n"
5627 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
5628 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
5629 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
5630 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
5631 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
5632 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
5634 "const float SUN_ANGLE = 0.0001;\n"
5635 "const float PI = 3.14159265358979323846264;\n"
5637 "//struct world_info\n"
5642 "// sunset_phase;\n"
5644 "// vec3 sun_dir;\n"
5647 "vec3 rand33(vec3 p3)\n"
5649 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
5650 " p3 += dot(p3, p3.yxz+33.33);\n"
5651 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
5654 "float stars( vec3 rd, float rr, float size ){\n"
5655 " vec3 co = rd * rr;\n"
5657 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
5659 " float spaces = 1.0 / rr;\n"
5660 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
5661 " a -= mod(a, spaces) - spaces * 0.5;\n"
5663 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
5665 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
5666 " plane = plane - mod(plane, PI / count);\n"
5668 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
5670 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
5671 " float ydist = sqrt(rr * rr - level * level);\n"
5672 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
5673 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
5674 " float star = smoothstep(size, 0.0, distance(center, co));\n"
5678 "float luminance( vec3 v )\n"
5680 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
5683 "vec3 clearskies_ambient( vec3 dir )\n"
5685 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
5686 " float sky_gradient = dir.y;\n"
5688 " /* Blend phase colours */\n"
5689 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
5690 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
5691 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
5693 " /* Add gradient */\n"
5694 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
5696 " return ambient;\n"
5699 "vec3 clearskies_sky( vec3 ray_dir )\n"
5701 " ray_dir.y = abs( ray_dir.y );\n"
5702 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
5705 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
5706 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
5707 " float sun_shape = pow( sun_size, 2000.0 );\n"
5708 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
5710 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
5711 " sun_colour *= sun_shape;\n"
5714 " float star = 0.0;\n"
5715 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
5717 " if( star_blend > 0.001 ){\n"
5718 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
5719 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
5720 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
5724 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
5725 " return composite;\n"
5728 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
5730 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
5732 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
5733 " g_sunset_phase );\n"
5735 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
5736 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
5737 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
5738 " ) * g_sun_colour.rgb * g_day_phase;\n"
5740 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
5741 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
5742 " g_sunset_phase );\n"
5744 " return ambient + (light_sun + sky_reflection) * shadow;\n"
5749 "float world_depth_sample( vec3 pos )\n"
5751 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
5752 " return texture( g_world_depth, depth_coord ).r;\n"
5755 "float world_water_depth( vec3 pos )\n"
5757 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
5758 " return world_depth_sample( pos ) - ref_depth;\n"
5761 "float shadow_sample( vec3 co ){\n"
5762 " float height_sample = world_depth_sample( co );\n"
5764 " float fdelta = height_sample - co.y;\n"
5765 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
5768 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
5769 " if( g_shadow_samples == 0 ){\n"
5773 " float fspread = g_shadow_spread;\n"
5774 " float flength = g_shadow_length;\n"
5776 " float famt = 0.0;\n"
5777 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
5778 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
5779 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
5780 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
5782 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
5783 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
5784 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
5785 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
5787 " return 1.0 - famt;\n"
5790 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
5792 " vec3 specdir = reflect( -dir, wnormal );\n"
5793 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
5796 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
5797 " float dist = pow(fdist*0.0010,0.78);\n"
5798 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
5801 "vec3 scene_calculate_light( int light_index, \n"
5802 " vec3 halfview, vec3 co, vec3 normal )\n"
5804 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
5805 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
5806 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
5808 " vec3 light_delta = light_co.xyz-co;\n"
5809 " float dist2 = dot(light_delta,light_delta);\n"
5811 " light_delta = normalize( light_delta );\n"
5813 " float quadratic = dist2*100.0;\n"
5814 " float attenuation = 1.0/( 1.0 + quadratic );\n"
5815 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
5817 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
5819 " if( light_dir.w < 0.999999 ){\n"
5820 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
5821 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
5824 " return light_colour.rgb * attenuation * falloff \n"
5825 " * step( g_day_phase, light_colour.w );\n"
5828 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
5829 " vec3 halfview, vec3 co, vec3 normal )\n"
5831 " uint light_count = packed_index & 0x3u;\n"
5833 " vec3 l = vec3(0.0);\n"
5835 " if( light_count >= 1u ){\n"
5836 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
5837 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
5838 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
5840 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
5842 " if( light_count >= 2u ){\n"
5843 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
5845 " if( light_count >= 3u ){\n"
5846 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
5854 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
5855 " float light_mask )\n"
5857 " if( g_light_preview == 1 )\n"
5858 " diffuse = vec3(0.75);\n"
5861 " vec3 halfview = uCamera - co;\n"
5862 " float fdist = length(halfview);\n"
5863 " halfview /= fdist;\n"
5865 " float world_shadow = newlight_compute_sun_shadow( \n"
5866 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
5868 " vec3 total_light = clearskies_lighting( \n"
5869 " normal, min( light_mask, world_shadow ), halfview );\n"
5871 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
5872 " cube_coord = floor( cube_coord );\n"
5874 " if( g_debug_indices == 1 )\n"
5876 " return rand33(cube_coord);\n"
5879 " if( g_debug_complexity == 1 )\n"
5881 " ivec3 coord = ivec3( cube_coord );\n"
5882 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5884 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
5885 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
5888 " // FIXME: this coord should absolutely must be clamped!\n"
5890 " ivec3 coord = ivec3( cube_coord );\n"
5891 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5893 " total_light += \n"
5894 " scene_calculate_packed_light_patch( index_sample.x,\n"
5895 " halfview, co, normal ) \n"
5897 " total_light += \n"
5898 " scene_calculate_packed_light_patch( index_sample.y,\n"
5899 " halfview, co, normal )\n"
5902 " // Take a section of the sky function to give us a matching fog colour\n"
5904 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
5905 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
5906 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
5907 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
5909 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
5910 " sun_colour *= sun_shape;\n"
5912 " fog_colour += sun_colour;\n"
5913 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
5918 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
5920 " vec3 pa = p - a;\n"
5921 " vec3 ba = b - a;\n"
5923 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
5924 " return length( pa - ba*h );\n"
5927 "float compute_board_shadow()\n"
5929 " // player shadow\n"
5930 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
5931 " g_board_1.xyz )-0.1 );\n"
5932 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
5933 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
5935 " return 1.0 - player_shadow*0.8;\n"
5938 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
5940 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
5945 "const float k_motion_lerp_amount = 0.01;\n"
5949 "layout (location = 1) out vec2 oMotionVec;\n"
5951 "in vec3 aMotionVec0;\n"
5952 "in vec3 aMotionVec1;\n"
5954 "void compute_motion_vectors()\n"
5956 " // Write motion vectors\n"
5957 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
5958 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
5960 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
5965 "// Pasted from common_world.glsl\n"
5966 "vec3 water_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
5968 " float light_mask = compute_board_shadow();\n"
5970 " if( g_light_preview == 1 )\n"
5971 " diffuse = vec3(0.75);\n"
5974 " vec3 halfview = uCamera - co;\n"
5975 " float fdist = length(halfview);\n"
5976 " halfview /= fdist;\n"
5978 " float world_shadow = newlight_compute_sun_shadow( \n"
5979 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
5981 " vec3 total_light = clearskies_lighting( \n"
5982 " normal, min( light_mask, world_shadow ), halfview );\n"
5984 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
5985 " cube_coord = floor( cube_coord );\n"
5987 " if( g_debug_indices == 1 )\n"
5989 " return rand33(cube_coord);\n"
5992 " if( g_debug_complexity == 1 )\n"
5994 " ivec3 coord = ivec3( cube_coord );\n"
5995 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5997 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
5998 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
6001 " // FIXME: this coord should absolutely must be clamped!\n"
6003 " ivec3 coord = ivec3( cube_coord );\n"
6004 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
6006 " total_light += \n"
6007 " scene_calculate_packed_light_patch( index_sample.x,\n"
6008 " halfview, co, normal ) \n"
6010 " total_light += \n"
6011 " scene_calculate_packed_light_patch( index_sample.y,\n"
6012 " halfview, co, normal )\n"
6015 " return diffuse * total_light;\n"
6018 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
6019 " vec4 beneath, vec4 above, vec4 dudva )\n"
6021 " vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
6023 " //TODO: Make exponent a material param (default: 5.0)\n"
6024 " float ffresnel = pow(1.0-dot( vnorm, halfview ),0.8);\n"
6026 " vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
6027 " vec3 specdir = reflect( -lightdir, vnorm );\n"
6028 " float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
6031 " float depthblend = pow( beneath.r, 0.8 );\n"
6034 " float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
6035 " fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
6037 " vec4 surf = mix( vec4(surface_tint,depthblend), \n"
6038 " vec4(1.0,1.0,1.0,0.5), fband );\n"
6039 " surf.rgb = water_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );\n"
6040 " surf.rgb = mix(surf.rgb, above.rgb, ffresnel );\n"
6042 " // Take a section of the sky function to give us a matching fog colour\n"
6043 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
6044 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
6045 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
6046 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6048 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6049 " sun_colour *= sun_shape;\n"
6051 " fog_colour += sun_colour;\n"
6052 " surf.rgb = scene_apply_fog( surf.rgb, fog_colour, \n"
6053 " distance(uCamera, aWorldCo) );\n"
6060 " compute_motion_vectors();\n"
6062 " // Create texture coords\n"
6063 " vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
6065 " // Surface colour composite\n"
6066 " float depthvalue = clamp( -world_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );\n"
6068 " //TODO: Material param (default: 0.008)\n"
6069 " vec2 world_coord = aCo.xz * 0.12;\n"
6070 " //TODO: Material param ( 0.008, 0.006, 0.003, 0.03 );\n"
6071 " vec4 time_offsets = vec4( uTime ) * vec4( 0.08, -0.08, -0.03, -0.01 );\n"
6072 " vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
6073 " vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
6075 " vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
6076 " surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
6079 " vec3 halfview = -normalize( aCo-uCamera );\n"
6081 " // Sample textures\n"
6082 " vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );\n"
6083 " vec4 beneath = texture( uTexBack, ssuv );\n"
6086 " float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
6089 " vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above, dudva );\n"
6090 " vsurface.a -= fdist;\n"
6092 " oColour = vsurface;\n"
6097 GLuint _uniform_scene_water_uMdl
;
6098 GLuint _uniform_scene_water_uPv
;
6099 GLuint _uniform_scene_water_uPvmPrev
;
6100 GLuint _uniform_scene_water_uTexMain
;
6101 GLuint _uniform_scene_water_uTexDudv
;
6102 GLuint _uniform_scene_water_uTexBack
;
6103 GLuint _uniform_scene_water_uInvRes
;
6104 GLuint _uniform_scene_water_uTime
;
6105 GLuint _uniform_scene_water_uCamera
;
6106 GLuint _uniform_scene_water_uSurfaceY
;
6107 GLuint _uniform_scene_water_uBoard0
;
6108 GLuint _uniform_scene_water_uBoard1
;
6109 GLuint _uniform_scene_water_uShoreColour
;
6110 GLuint _uniform_scene_water_uOceanColour
;
6111 GLuint _uniform_scene_water_g_world_depth
;
6112 GLuint _uniform_scene_water_uLightsArray
;
6113 GLuint _uniform_scene_water_uLightsIndex
;
6114 #include "shaders/scene_water_fast.h"
6115 struct vg_shader _shader_scene_water_fast
= {
6116 .name
= "scene_water_fast",
6119 .orig_file
= "shaders/scene.vs",
6121 "layout (location=0) in vec3 a_co;\n"
6122 "layout (location=1) in vec4 a_norm;\n"
6123 "layout (location=2) in vec2 a_uv;\n"
6126 "const float k_motion_lerp_amount = 0.01;\n"
6130 "out vec3 aMotionVec0;\n"
6131 "out vec3 aMotionVec1;\n"
6133 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
6135 " // This magically solves some artifacting errors!\n"
6137 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
6139 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
6140 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
6145 "uniform mat4x3 uMdl;\n"
6146 "uniform mat4 uPv;\n"
6147 "uniform mat4 uPvmPrev;\n"
6152 "out vec3 aWorldCo;\n"
6156 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
6157 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
6158 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
6160 " vs_motion_out( vproj0, vproj1 );\n"
6162 " gl_Position = vproj0;\n"
6165 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
6167 " aWorldCo = world_pos0;\n"
6172 .orig_file
= "shaders/scene_water_fast.fs",
6174 "uniform sampler2D uTexDudv;\n"
6176 "uniform float uTime;\n"
6177 "uniform vec3 uCamera;\n"
6178 "uniform float uSurfaceY;\n"
6179 "uniform vec3 uBoard0;\n"
6180 "uniform vec3 uBoard1;\n"
6182 "uniform vec3 uShoreColour;\n"
6183 "uniform vec3 uOceanColour;\n"
6187 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
6196 "in vec3 aWorldCo;\n"
6199 "layout (location = 0) out vec4 oColour;\n"
6201 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
6202 "layout (std140) uniform ub_world_lighting\n"
6204 " vec4 g_cube_min;\n"
6205 " vec4 g_cube_inv_range;\n"
6207 " vec4 g_water_plane;\n"
6208 " vec4 g_depth_bounds;\n"
6210 " vec4 g_daysky_colour;\n"
6211 " vec4 g_nightsky_colour;\n"
6212 " vec4 g_sunset_colour;\n"
6213 " vec4 g_ambient_colour;\n"
6214 " vec4 g_sunset_ambient;\n"
6215 " vec4 g_sun_colour;\n"
6216 " vec4 g_sun_dir;\n"
6217 " vec4 g_board_0;\n"
6218 " vec4 g_board_1;\n"
6220 " float g_water_fog;\n"
6222 " float g_realtime;\n"
6223 " float g_shadow_length;\n"
6224 " float g_shadow_spread;\n"
6226 " float g_time_of_day;\n"
6227 " float g_day_phase;\n"
6228 " float g_sunset_phase;\n"
6230 " int g_light_preview;\n"
6231 " int g_shadow_samples;\n"
6233 " int g_debug_indices;\n"
6234 " int g_debug_complexity;\n"
6237 "uniform sampler2D g_world_depth;\n"
6238 "uniform samplerBuffer uLightsArray;\n"
6239 "uniform usampler3D uLightsIndex;\n"
6242 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
6243 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
6244 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
6245 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
6246 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
6247 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
6249 "const float SUN_ANGLE = 0.0001;\n"
6250 "const float PI = 3.14159265358979323846264;\n"
6252 "//struct world_info\n"
6257 "// sunset_phase;\n"
6259 "// vec3 sun_dir;\n"
6262 "vec3 rand33(vec3 p3)\n"
6264 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
6265 " p3 += dot(p3, p3.yxz+33.33);\n"
6266 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
6269 "float stars( vec3 rd, float rr, float size ){\n"
6270 " vec3 co = rd * rr;\n"
6272 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
6274 " float spaces = 1.0 / rr;\n"
6275 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
6276 " a -= mod(a, spaces) - spaces * 0.5;\n"
6278 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
6280 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
6281 " plane = plane - mod(plane, PI / count);\n"
6283 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
6285 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
6286 " float ydist = sqrt(rr * rr - level * level);\n"
6287 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
6288 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
6289 " float star = smoothstep(size, 0.0, distance(center, co));\n"
6293 "float luminance( vec3 v )\n"
6295 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
6298 "vec3 clearskies_ambient( vec3 dir )\n"
6300 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
6301 " float sky_gradient = dir.y;\n"
6303 " /* Blend phase colours */\n"
6304 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
6305 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
6306 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
6308 " /* Add gradient */\n"
6309 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
6311 " return ambient;\n"
6314 "vec3 clearskies_sky( vec3 ray_dir )\n"
6316 " ray_dir.y = abs( ray_dir.y );\n"
6317 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
6320 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
6321 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
6322 " float sun_shape = pow( sun_size, 2000.0 );\n"
6323 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6325 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6326 " sun_colour *= sun_shape;\n"
6329 " float star = 0.0;\n"
6330 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
6332 " if( star_blend > 0.001 ){\n"
6333 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
6334 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
6335 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
6339 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
6340 " return composite;\n"
6343 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
6345 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
6347 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
6348 " g_sunset_phase );\n"
6350 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
6351 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
6352 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
6353 " ) * g_sun_colour.rgb * g_day_phase;\n"
6355 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
6356 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
6357 " g_sunset_phase );\n"
6359 " return ambient + (light_sun + sky_reflection) * shadow;\n"
6364 "float world_depth_sample( vec3 pos )\n"
6366 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
6367 " return texture( g_world_depth, depth_coord ).r;\n"
6370 "float world_water_depth( vec3 pos )\n"
6372 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
6373 " return world_depth_sample( pos ) - ref_depth;\n"
6376 "float shadow_sample( vec3 co ){\n"
6377 " float height_sample = world_depth_sample( co );\n"
6379 " float fdelta = height_sample - co.y;\n"
6380 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
6383 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
6384 " if( g_shadow_samples == 0 ){\n"
6388 " float fspread = g_shadow_spread;\n"
6389 " float flength = g_shadow_length;\n"
6391 " float famt = 0.0;\n"
6392 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
6393 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
6394 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
6395 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
6397 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
6398 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
6399 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
6400 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
6402 " return 1.0 - famt;\n"
6405 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
6407 " vec3 specdir = reflect( -dir, wnormal );\n"
6408 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
6411 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
6412 " float dist = pow(fdist*0.0010,0.78);\n"
6413 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
6416 "vec3 scene_calculate_light( int light_index, \n"
6417 " vec3 halfview, vec3 co, vec3 normal )\n"
6419 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
6420 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
6421 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
6423 " vec3 light_delta = light_co.xyz-co;\n"
6424 " float dist2 = dot(light_delta,light_delta);\n"
6426 " light_delta = normalize( light_delta );\n"
6428 " float quadratic = dist2*100.0;\n"
6429 " float attenuation = 1.0/( 1.0 + quadratic );\n"
6430 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
6432 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
6434 " if( light_dir.w < 0.999999 ){\n"
6435 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
6436 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
6439 " return light_colour.rgb * attenuation * falloff \n"
6440 " * step( g_day_phase, light_colour.w );\n"
6443 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
6444 " vec3 halfview, vec3 co, vec3 normal )\n"
6446 " uint light_count = packed_index & 0x3u;\n"
6448 " vec3 l = vec3(0.0);\n"
6450 " if( light_count >= 1u ){\n"
6451 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
6452 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
6453 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
6455 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
6457 " if( light_count >= 2u ){\n"
6458 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
6460 " if( light_count >= 3u ){\n"
6461 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
6469 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
6470 " float light_mask )\n"
6472 " if( g_light_preview == 1 )\n"
6473 " diffuse = vec3(0.75);\n"
6476 " vec3 halfview = uCamera - co;\n"
6477 " float fdist = length(halfview);\n"
6478 " halfview /= fdist;\n"
6480 " float world_shadow = newlight_compute_sun_shadow( \n"
6481 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
6483 " vec3 total_light = clearskies_lighting( \n"
6484 " normal, min( light_mask, world_shadow ), halfview );\n"
6486 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
6487 " cube_coord = floor( cube_coord );\n"
6489 " if( g_debug_indices == 1 )\n"
6491 " return rand33(cube_coord);\n"
6494 " if( g_debug_complexity == 1 )\n"
6496 " ivec3 coord = ivec3( cube_coord );\n"
6497 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
6499 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
6500 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
6503 " // FIXME: this coord should absolutely must be clamped!\n"
6505 " ivec3 coord = ivec3( cube_coord );\n"
6506 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
6508 " total_light += \n"
6509 " scene_calculate_packed_light_patch( index_sample.x,\n"
6510 " halfview, co, normal ) \n"
6512 " total_light += \n"
6513 " scene_calculate_packed_light_patch( index_sample.y,\n"
6514 " halfview, co, normal )\n"
6517 " // Take a section of the sky function to give us a matching fog colour\n"
6519 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
6520 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
6521 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
6522 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6524 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6525 " sun_colour *= sun_shape;\n"
6527 " fog_colour += sun_colour;\n"
6528 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
6533 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
6535 " vec3 pa = p - a;\n"
6536 " vec3 ba = b - a;\n"
6538 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
6539 " return length( pa - ba*h );\n"
6542 "float compute_board_shadow()\n"
6544 " // player shadow\n"
6545 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
6546 " g_board_1.xyz )-0.1 );\n"
6547 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
6548 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
6550 " return 1.0 - player_shadow*0.8;\n"
6553 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
6555 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
6560 "const float k_motion_lerp_amount = 0.01;\n"
6564 "layout (location = 1) out vec2 oMotionVec;\n"
6566 "in vec3 aMotionVec0;\n"
6567 "in vec3 aMotionVec1;\n"
6569 "void compute_motion_vectors()\n"
6571 " // Write motion vectors\n"
6572 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
6573 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
6575 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
6580 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )\n"
6582 " vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
6584 " float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
6586 " vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
6587 " vec3 specdir = reflect( -lightdir, vnorm );\n"
6588 " float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
6590 " return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );\n"
6595 " compute_motion_vectors();\n"
6597 " // Surface colour composite\n"
6598 " float depthvalue = clamp( -world_water_depth( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
6600 " vec2 world_coord = aCo.xz * 0.008;\n"
6601 " vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
6602 " vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
6603 " vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
6605 " vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
6606 " surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
6609 " float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
6610 " fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
6613 " vec3 halfview = -normalize( aCo-uCamera );\n"
6616 " float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
6619 " vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );\n"
6620 " vsurface.a -= fdist;\n"
6621 " oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );\n"
6622 " oColour.rgb = scene_compute_lighting( oColour.rgb, aNorm.xyz, aWorldCo );\n"
6627 GLuint _uniform_scene_water_fast_uMdl
;
6628 GLuint _uniform_scene_water_fast_uPv
;
6629 GLuint _uniform_scene_water_fast_uPvmPrev
;
6630 GLuint _uniform_scene_water_fast_uTexDudv
;
6631 GLuint _uniform_scene_water_fast_uTime
;
6632 GLuint _uniform_scene_water_fast_uCamera
;
6633 GLuint _uniform_scene_water_fast_uSurfaceY
;
6634 GLuint _uniform_scene_water_fast_uBoard0
;
6635 GLuint _uniform_scene_water_fast_uBoard1
;
6636 GLuint _uniform_scene_water_fast_uShoreColour
;
6637 GLuint _uniform_scene_water_fast_uOceanColour
;
6638 GLuint _uniform_scene_water_fast_g_world_depth
;
6639 GLuint _uniform_scene_water_fast_uLightsArray
;
6640 GLuint _uniform_scene_water_fast_uLightsIndex
;
6641 #include "shaders/scene_scoretext.h"
6642 struct vg_shader _shader_scene_scoretext
= {
6643 .name
= "scene_scoretext",
6646 .orig_file
= "shaders/scene_sfd.vs",
6648 "layout (location=0) in vec3 a_co;\n"
6649 "layout (location=1) in vec4 a_norm;\n"
6650 "layout (location=2) in vec2 a_uv;\n"
6653 "const float k_motion_lerp_amount = 0.01;\n"
6657 "out vec3 aMotionVec0;\n"
6658 "out vec3 aMotionVec1;\n"
6660 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
6662 " // This magically solves some artifacting errors!\n"
6664 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
6666 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
6667 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
6672 "uniform mat4x3 uMdl;\n"
6673 "uniform mat4 uPv;\n"
6674 "uniform mat4 uPvmPrev;\n"
6675 "uniform vec3 uInfo;\n"
6680 "out vec3 aWorldCo;\n"
6684 " float w = ((a_norm.w)-0.5)*2.0 + fract(uInfo.z) - 0.0;\n"
6685 " float c = -cos(w*0.6);\n"
6686 " float s = -sin(w*0.6);\n"
6689 " float w1 = clamp( w*4.0 - a_co.y*10.0, -1.0, 1.0 ) * (3.14159265*0.5);\n"
6690 " float c1 = cos(w1);\n"
6691 " float s1 = sin(w1);\n"
6693 " float yoff = step(0.01,fract(uInfo.z))*-0.5;\n"
6696 " mlocal[0] = vec3(c1, s1,0.0);\n"
6697 " mlocal[1] = vec3(-s1,c1,0.0);\n"
6698 " mlocal[2] = vec3(0.0,0.0,1.0);\n"
6699 " mlocal[3] = vec3(c*r,uInfo.y*0.875 + s*r,uInfo.x*0.5);\n"
6701 " vec3 local_pos0 = mlocal * vec4( a_co, 1.0 );\n"
6702 " vec3 world_pos0 = uMdl * vec4( local_pos0, 1.0 );\n"
6704 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
6705 " vec4 vproj1 = uPvmPrev * vec4( local_pos0, 1.0 );\n"
6707 " vs_motion_out( vproj0, vproj1 );\n"
6709 " gl_Position = vproj0;\n"
6711 " aUv = a_uv + vec2( floor(uInfo.z+0.5)*(1.0/64.0), yoff );\n"
6712 " aNorm = vec4( mat3(uMdl) * mat3(mlocal) * a_norm.xyz, a_norm.w );\n"
6714 " aWorldCo = world_pos0;\n"
6719 .orig_file
= "shaders/scene_standard.fs",
6721 "uniform sampler2D uTexGarbage;\n"
6722 "uniform sampler2D uTexMain;\n"
6723 "uniform vec3 uCamera;\n"
6724 "uniform vec4 uPlane;\n"
6728 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
6737 "in vec3 aWorldCo;\n"
6740 "layout (location = 0) out vec4 oColour;\n"
6742 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
6743 "layout (std140) uniform ub_world_lighting\n"
6745 " vec4 g_cube_min;\n"
6746 " vec4 g_cube_inv_range;\n"
6748 " vec4 g_water_plane;\n"
6749 " vec4 g_depth_bounds;\n"
6751 " vec4 g_daysky_colour;\n"
6752 " vec4 g_nightsky_colour;\n"
6753 " vec4 g_sunset_colour;\n"
6754 " vec4 g_ambient_colour;\n"
6755 " vec4 g_sunset_ambient;\n"
6756 " vec4 g_sun_colour;\n"
6757 " vec4 g_sun_dir;\n"
6758 " vec4 g_board_0;\n"
6759 " vec4 g_board_1;\n"
6761 " float g_water_fog;\n"
6763 " float g_realtime;\n"
6764 " float g_shadow_length;\n"
6765 " float g_shadow_spread;\n"
6767 " float g_time_of_day;\n"
6768 " float g_day_phase;\n"
6769 " float g_sunset_phase;\n"
6771 " int g_light_preview;\n"
6772 " int g_shadow_samples;\n"
6774 " int g_debug_indices;\n"
6775 " int g_debug_complexity;\n"
6778 "uniform sampler2D g_world_depth;\n"
6779 "uniform samplerBuffer uLightsArray;\n"
6780 "uniform usampler3D uLightsIndex;\n"
6783 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
6784 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
6785 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
6786 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
6787 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
6788 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
6790 "const float SUN_ANGLE = 0.0001;\n"
6791 "const float PI = 3.14159265358979323846264;\n"
6793 "//struct world_info\n"
6798 "// sunset_phase;\n"
6800 "// vec3 sun_dir;\n"
6803 "vec3 rand33(vec3 p3)\n"
6805 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
6806 " p3 += dot(p3, p3.yxz+33.33);\n"
6807 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
6810 "float stars( vec3 rd, float rr, float size ){\n"
6811 " vec3 co = rd * rr;\n"
6813 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
6815 " float spaces = 1.0 / rr;\n"
6816 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
6817 " a -= mod(a, spaces) - spaces * 0.5;\n"
6819 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
6821 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
6822 " plane = plane - mod(plane, PI / count);\n"
6824 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
6826 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
6827 " float ydist = sqrt(rr * rr - level * level);\n"
6828 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
6829 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
6830 " float star = smoothstep(size, 0.0, distance(center, co));\n"
6834 "float luminance( vec3 v )\n"
6836 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
6839 "vec3 clearskies_ambient( vec3 dir )\n"
6841 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
6842 " float sky_gradient = dir.y;\n"
6844 " /* Blend phase colours */\n"
6845 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
6846 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
6847 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
6849 " /* Add gradient */\n"
6850 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
6852 " return ambient;\n"
6855 "vec3 clearskies_sky( vec3 ray_dir )\n"
6857 " ray_dir.y = abs( ray_dir.y );\n"
6858 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
6861 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
6862 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
6863 " float sun_shape = pow( sun_size, 2000.0 );\n"
6864 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6866 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6867 " sun_colour *= sun_shape;\n"
6870 " float star = 0.0;\n"
6871 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
6873 " if( star_blend > 0.001 ){\n"
6874 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
6875 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
6876 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
6880 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
6881 " return composite;\n"
6884 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
6886 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
6888 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
6889 " g_sunset_phase );\n"
6891 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
6892 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
6893 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
6894 " ) * g_sun_colour.rgb * g_day_phase;\n"
6896 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
6897 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
6898 " g_sunset_phase );\n"
6900 " return ambient + (light_sun + sky_reflection) * shadow;\n"
6905 "float world_depth_sample( vec3 pos )\n"
6907 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
6908 " return texture( g_world_depth, depth_coord ).r;\n"
6911 "float world_water_depth( vec3 pos )\n"
6913 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
6914 " return world_depth_sample( pos ) - ref_depth;\n"
6917 "float shadow_sample( vec3 co ){\n"
6918 " float height_sample = world_depth_sample( co );\n"
6920 " float fdelta = height_sample - co.y;\n"
6921 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
6924 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
6925 " if( g_shadow_samples == 0 ){\n"
6929 " float fspread = g_shadow_spread;\n"
6930 " float flength = g_shadow_length;\n"
6932 " float famt = 0.0;\n"
6933 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
6934 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
6935 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
6936 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
6938 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
6939 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
6940 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
6941 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
6943 " return 1.0 - famt;\n"
6946 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
6948 " vec3 specdir = reflect( -dir, wnormal );\n"
6949 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
6952 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
6953 " float dist = pow(fdist*0.0010,0.78);\n"
6954 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
6957 "vec3 scene_calculate_light( int light_index, \n"
6958 " vec3 halfview, vec3 co, vec3 normal )\n"
6960 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
6961 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
6962 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
6964 " vec3 light_delta = light_co.xyz-co;\n"
6965 " float dist2 = dot(light_delta,light_delta);\n"
6967 " light_delta = normalize( light_delta );\n"
6969 " float quadratic = dist2*100.0;\n"
6970 " float attenuation = 1.0/( 1.0 + quadratic );\n"
6971 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
6973 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
6975 " if( light_dir.w < 0.999999 ){\n"
6976 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
6977 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
6980 " return light_colour.rgb * attenuation * falloff \n"
6981 " * step( g_day_phase, light_colour.w );\n"
6984 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
6985 " vec3 halfview, vec3 co, vec3 normal )\n"
6987 " uint light_count = packed_index & 0x3u;\n"
6989 " vec3 l = vec3(0.0);\n"
6991 " if( light_count >= 1u ){\n"
6992 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
6993 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
6994 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
6996 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
6998 " if( light_count >= 2u ){\n"
6999 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
7001 " if( light_count >= 3u ){\n"
7002 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
7010 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
7011 " float light_mask )\n"
7013 " if( g_light_preview == 1 )\n"
7014 " diffuse = vec3(0.75);\n"
7017 " vec3 halfview = uCamera - co;\n"
7018 " float fdist = length(halfview);\n"
7019 " halfview /= fdist;\n"
7021 " float world_shadow = newlight_compute_sun_shadow( \n"
7022 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
7024 " vec3 total_light = clearskies_lighting( \n"
7025 " normal, min( light_mask, world_shadow ), halfview );\n"
7027 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
7028 " cube_coord = floor( cube_coord );\n"
7030 " if( g_debug_indices == 1 )\n"
7032 " return rand33(cube_coord);\n"
7035 " if( g_debug_complexity == 1 )\n"
7037 " ivec3 coord = ivec3( cube_coord );\n"
7038 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7040 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
7041 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
7044 " // FIXME: this coord should absolutely must be clamped!\n"
7046 " ivec3 coord = ivec3( cube_coord );\n"
7047 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7049 " total_light += \n"
7050 " scene_calculate_packed_light_patch( index_sample.x,\n"
7051 " halfview, co, normal ) \n"
7053 " total_light += \n"
7054 " scene_calculate_packed_light_patch( index_sample.y,\n"
7055 " halfview, co, normal )\n"
7058 " // Take a section of the sky function to give us a matching fog colour\n"
7060 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
7061 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
7062 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
7063 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7065 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7066 " sun_colour *= sun_shape;\n"
7068 " fog_colour += sun_colour;\n"
7069 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
7074 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
7076 " vec3 pa = p - a;\n"
7077 " vec3 ba = b - a;\n"
7079 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
7080 " return length( pa - ba*h );\n"
7083 "float compute_board_shadow()\n"
7085 " // player shadow\n"
7086 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
7087 " g_board_1.xyz )-0.1 );\n"
7088 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
7089 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
7091 " return 1.0 - player_shadow*0.8;\n"
7094 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
7096 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
7101 "const float k_motion_lerp_amount = 0.01;\n"
7105 "layout (location = 1) out vec2 oMotionVec;\n"
7107 "in vec3 aMotionVec0;\n"
7108 "in vec3 aMotionVec1;\n"
7110 "void compute_motion_vectors()\n"
7112 " // Write motion vectors\n"
7113 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
7114 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
7116 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
7123 " compute_motion_vectors();\n"
7125 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
7126 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
7127 " vec3 qnorm = aNorm.xyz;\n"
7129 " vfrag = vsamplemain.rgb;\n"
7131 " if( g_light_preview == 1 )\n"
7133 " vfrag = vec3(0.5);\n"
7136 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
7137 " oColour = vec4( vfrag, 1.0 );\n"
7142 GLuint _uniform_scene_scoretext_uMdl
;
7143 GLuint _uniform_scene_scoretext_uPv
;
7144 GLuint _uniform_scene_scoretext_uPvmPrev
;
7145 GLuint _uniform_scene_scoretext_uInfo
;
7146 GLuint _uniform_scene_scoretext_uTexGarbage
;
7147 GLuint _uniform_scene_scoretext_uTexMain
;
7148 GLuint _uniform_scene_scoretext_uCamera
;
7149 GLuint _uniform_scene_scoretext_uPlane
;
7150 GLuint _uniform_scene_scoretext_g_world_depth
;
7151 GLuint _uniform_scene_scoretext_uLightsArray
;
7152 GLuint _uniform_scene_scoretext_uLightsIndex
;
7153 #include "shaders/scene_font.h"
7154 struct vg_shader _shader_scene_font
= {
7155 .name
= "scene_font",
7158 .orig_file
= "shaders/model_font.vs",
7160 "layout (location=0) in vec3 a_co;\n"
7161 "layout (location=1) in vec3 a_norm;\n"
7162 "layout (location=2) in vec2 a_uv;\n"
7165 "const float k_motion_lerp_amount = 0.01;\n"
7169 "out vec3 aMotionVec0;\n"
7170 "out vec3 aMotionVec1;\n"
7172 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
7174 " // This magically solves some artifacting errors!\n"
7176 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
7178 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
7179 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
7184 "uniform mat4x3 uMdl;\n"
7185 "uniform mat4 uPv;\n"
7186 "uniform mat4 uPvmPrev;\n"
7187 "uniform vec4 uOffset;\n"
7192 "out vec3 aWorldCo;\n"
7196 " vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
7197 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
7198 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
7199 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
7201 " vs_motion_out( vproj0, vproj1 );\n"
7203 " gl_Position = vproj0;\n"
7206 " aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
7208 " aWorldCo = world_pos0;\n"
7213 .orig_file
= "shaders/scene_font.fs",
7215 "uniform sampler2D uTexGarbage; // unused\n"
7216 "uniform sampler2D uTexMain; // unused\n"
7217 "uniform vec3 uCamera;\n"
7218 "uniform float uTime;\n"
7219 "uniform float uOpacity;\n"
7220 "uniform float uColourize;\n"
7224 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
7233 "in vec3 aWorldCo;\n"
7236 "layout (location = 0) out vec4 oColour;\n"
7238 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
7239 "layout (std140) uniform ub_world_lighting\n"
7241 " vec4 g_cube_min;\n"
7242 " vec4 g_cube_inv_range;\n"
7244 " vec4 g_water_plane;\n"
7245 " vec4 g_depth_bounds;\n"
7247 " vec4 g_daysky_colour;\n"
7248 " vec4 g_nightsky_colour;\n"
7249 " vec4 g_sunset_colour;\n"
7250 " vec4 g_ambient_colour;\n"
7251 " vec4 g_sunset_ambient;\n"
7252 " vec4 g_sun_colour;\n"
7253 " vec4 g_sun_dir;\n"
7254 " vec4 g_board_0;\n"
7255 " vec4 g_board_1;\n"
7257 " float g_water_fog;\n"
7259 " float g_realtime;\n"
7260 " float g_shadow_length;\n"
7261 " float g_shadow_spread;\n"
7263 " float g_time_of_day;\n"
7264 " float g_day_phase;\n"
7265 " float g_sunset_phase;\n"
7267 " int g_light_preview;\n"
7268 " int g_shadow_samples;\n"
7270 " int g_debug_indices;\n"
7271 " int g_debug_complexity;\n"
7274 "uniform sampler2D g_world_depth;\n"
7275 "uniform samplerBuffer uLightsArray;\n"
7276 "uniform usampler3D uLightsIndex;\n"
7279 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
7280 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
7281 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
7282 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
7283 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
7284 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
7286 "const float SUN_ANGLE = 0.0001;\n"
7287 "const float PI = 3.14159265358979323846264;\n"
7289 "//struct world_info\n"
7294 "// sunset_phase;\n"
7296 "// vec3 sun_dir;\n"
7299 "vec3 rand33(vec3 p3)\n"
7301 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
7302 " p3 += dot(p3, p3.yxz+33.33);\n"
7303 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
7306 "float stars( vec3 rd, float rr, float size ){\n"
7307 " vec3 co = rd * rr;\n"
7309 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
7311 " float spaces = 1.0 / rr;\n"
7312 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
7313 " a -= mod(a, spaces) - spaces * 0.5;\n"
7315 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
7317 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
7318 " plane = plane - mod(plane, PI / count);\n"
7320 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
7322 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
7323 " float ydist = sqrt(rr * rr - level * level);\n"
7324 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
7325 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
7326 " float star = smoothstep(size, 0.0, distance(center, co));\n"
7330 "float luminance( vec3 v )\n"
7332 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
7335 "vec3 clearskies_ambient( vec3 dir )\n"
7337 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
7338 " float sky_gradient = dir.y;\n"
7340 " /* Blend phase colours */\n"
7341 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
7342 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
7343 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
7345 " /* Add gradient */\n"
7346 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
7348 " return ambient;\n"
7351 "vec3 clearskies_sky( vec3 ray_dir )\n"
7353 " ray_dir.y = abs( ray_dir.y );\n"
7354 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
7357 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
7358 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
7359 " float sun_shape = pow( sun_size, 2000.0 );\n"
7360 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7362 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7363 " sun_colour *= sun_shape;\n"
7366 " float star = 0.0;\n"
7367 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
7369 " if( star_blend > 0.001 ){\n"
7370 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
7371 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
7372 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
7376 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
7377 " return composite;\n"
7380 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
7382 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
7384 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
7385 " g_sunset_phase );\n"
7387 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
7388 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
7389 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
7390 " ) * g_sun_colour.rgb * g_day_phase;\n"
7392 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
7393 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
7394 " g_sunset_phase );\n"
7396 " return ambient + (light_sun + sky_reflection) * shadow;\n"
7401 "float world_depth_sample( vec3 pos )\n"
7403 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
7404 " return texture( g_world_depth, depth_coord ).r;\n"
7407 "float world_water_depth( vec3 pos )\n"
7409 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
7410 " return world_depth_sample( pos ) - ref_depth;\n"
7413 "float shadow_sample( vec3 co ){\n"
7414 " float height_sample = world_depth_sample( co );\n"
7416 " float fdelta = height_sample - co.y;\n"
7417 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
7420 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
7421 " if( g_shadow_samples == 0 ){\n"
7425 " float fspread = g_shadow_spread;\n"
7426 " float flength = g_shadow_length;\n"
7428 " float famt = 0.0;\n"
7429 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
7430 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
7431 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
7432 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
7434 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
7435 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
7436 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
7437 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
7439 " return 1.0 - famt;\n"
7442 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
7444 " vec3 specdir = reflect( -dir, wnormal );\n"
7445 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
7448 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
7449 " float dist = pow(fdist*0.0010,0.78);\n"
7450 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
7453 "vec3 scene_calculate_light( int light_index, \n"
7454 " vec3 halfview, vec3 co, vec3 normal )\n"
7456 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
7457 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
7458 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
7460 " vec3 light_delta = light_co.xyz-co;\n"
7461 " float dist2 = dot(light_delta,light_delta);\n"
7463 " light_delta = normalize( light_delta );\n"
7465 " float quadratic = dist2*100.0;\n"
7466 " float attenuation = 1.0/( 1.0 + quadratic );\n"
7467 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
7469 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
7471 " if( light_dir.w < 0.999999 ){\n"
7472 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
7473 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
7476 " return light_colour.rgb * attenuation * falloff \n"
7477 " * step( g_day_phase, light_colour.w );\n"
7480 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
7481 " vec3 halfview, vec3 co, vec3 normal )\n"
7483 " uint light_count = packed_index & 0x3u;\n"
7485 " vec3 l = vec3(0.0);\n"
7487 " if( light_count >= 1u ){\n"
7488 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
7489 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
7490 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
7492 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
7494 " if( light_count >= 2u ){\n"
7495 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
7497 " if( light_count >= 3u ){\n"
7498 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
7506 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
7507 " float light_mask )\n"
7509 " if( g_light_preview == 1 )\n"
7510 " diffuse = vec3(0.75);\n"
7513 " vec3 halfview = uCamera - co;\n"
7514 " float fdist = length(halfview);\n"
7515 " halfview /= fdist;\n"
7517 " float world_shadow = newlight_compute_sun_shadow( \n"
7518 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
7520 " vec3 total_light = clearskies_lighting( \n"
7521 " normal, min( light_mask, world_shadow ), halfview );\n"
7523 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
7524 " cube_coord = floor( cube_coord );\n"
7526 " if( g_debug_indices == 1 )\n"
7528 " return rand33(cube_coord);\n"
7531 " if( g_debug_complexity == 1 )\n"
7533 " ivec3 coord = ivec3( cube_coord );\n"
7534 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7536 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
7537 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
7540 " // FIXME: this coord should absolutely must be clamped!\n"
7542 " ivec3 coord = ivec3( cube_coord );\n"
7543 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7545 " total_light += \n"
7546 " scene_calculate_packed_light_patch( index_sample.x,\n"
7547 " halfview, co, normal ) \n"
7549 " total_light += \n"
7550 " scene_calculate_packed_light_patch( index_sample.y,\n"
7551 " halfview, co, normal )\n"
7554 " // Take a section of the sky function to give us a matching fog colour\n"
7556 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
7557 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
7558 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
7559 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7561 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7562 " sun_colour *= sun_shape;\n"
7564 " fog_colour += sun_colour;\n"
7565 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
7570 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
7572 " vec3 pa = p - a;\n"
7573 " vec3 ba = b - a;\n"
7575 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
7576 " return length( pa - ba*h );\n"
7579 "float compute_board_shadow()\n"
7581 " // player shadow\n"
7582 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
7583 " g_board_1.xyz )-0.1 );\n"
7584 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
7585 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
7587 " return 1.0 - player_shadow*0.8;\n"
7590 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
7592 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
7597 "const float k_motion_lerp_amount = 0.01;\n"
7601 "layout (location = 1) out vec2 oMotionVec;\n"
7603 "in vec3 aMotionVec0;\n"
7604 "in vec3 aMotionVec1;\n"
7606 "void compute_motion_vectors()\n"
7608 " // Write motion vectors\n"
7609 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
7610 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
7612 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
7617 "vec3 pal( float t ){\n"
7618 " vec3 a = vec3(0.30,0.3,0.3);\n"
7619 " vec3 b = vec3(0.8);\n"
7620 " vec3 c = vec3(0.28,0.3,0.4);\n"
7621 " vec3 d = vec3(0.00,0.1,0.1);\n"
7622 " return a + b*cos( 6.28318*(c*t+d) );\n"
7626 " compute_motion_vectors();\n"
7627 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
7628 " vec3 qnorm = aNorm.xyz;\n"
7630 " //vec4 vsamplemain = texture( uTexMain, aUv );\n"
7631 " //vfrag = vsamplemain.rgb;\n"
7633 " vec4 spread0 = uTime*0.0002*vec4( 17.3,-19.6, 23.2,-47.7 );\n"
7634 " vec4 spread1 = uTime*0.0002*vec4( -13.3, 12.6,-28.2, 14.7 );\n"
7636 " vec2 p = aCo.xy + vec2(0.3);\n"
7637 " float a = atan( p.y/p.x );\n"
7638 " vec4 v0 = step( vec4(0.5), fract(vec4(a) + spread0) );\n"
7639 " vec4 v1 = step( vec4(0.5), fract(vec4(a) + spread1) );\n"
7641 " float d = ( v0.x+v0.y+v0.z+v0.w +\n"
7642 " v1.x+v1.y+v1.z+v1.w ) * 0.125;\n"
7644 " float dither = fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0);\n"
7645 " float x = d*0.8+length(p)*0.3;\n"
7646 " x = (floor(x*8.0) + step(dither, fract(x * 8.0))) / 8.0;\n"
7648 " if( x + (uOpacity*2.0-1.0) < 0.5 ) \n"
7651 " vfrag = mix( vec3(x), pal( x ), uColourize );\n"
7653 " if( g_light_preview == 1 ){\n"
7654 " vfrag = vec3(0.5);\n"
7657 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
7658 " oColour = vec4( vfrag, 1.0 );\n"
7663 GLuint _uniform_scene_font_uMdl
;
7664 GLuint _uniform_scene_font_uPv
;
7665 GLuint _uniform_scene_font_uPvmPrev
;
7666 GLuint _uniform_scene_font_uOffset
;
7667 GLuint _uniform_scene_font_uTexGarbage
;
7668 GLuint _uniform_scene_font_uTexMain
;
7669 GLuint _uniform_scene_font_uCamera
;
7670 GLuint _uniform_scene_font_uTime
;
7671 GLuint _uniform_scene_font_uOpacity
;
7672 GLuint _uniform_scene_font_uColourize
;
7673 GLuint _uniform_scene_font_g_world_depth
;
7674 GLuint _uniform_scene_font_uLightsArray
;
7675 GLuint _uniform_scene_font_uLightsIndex
;
7676 #include "shaders/model_sky.h"
7677 struct vg_shader _shader_model_sky
= {
7678 .name
= "model_sky",
7681 .orig_file
= "shaders/model.vs",
7683 "layout (location=0) in vec3 a_co;\n"
7684 "layout (location=1) in vec3 a_norm;\n"
7685 "layout (location=2) in vec2 a_uv;\n"
7686 "layout (location=3) in vec4 a_colour;\n"
7687 "layout (location=4) in vec4 a_weights;\n"
7688 "layout (location=5) in ivec4 a_groups;\n"
7691 "const float k_motion_lerp_amount = 0.01;\n"
7695 "out vec3 aMotionVec0;\n"
7696 "out vec3 aMotionVec1;\n"
7698 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
7700 " // This magically solves some artifacting errors!\n"
7702 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
7704 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
7705 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
7710 "uniform mat4x3 uMdl;\n"
7711 "uniform mat4 uPv;\n"
7712 "uniform mat4 uPvmPrev;\n"
7714 "out vec4 aColour;\n"
7718 "out vec3 aWorldCo;\n"
7722 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
7723 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
7724 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
7726 " vs_motion_out( vproj0, vproj1 );\n"
7728 " gl_Position = vproj0;\n"
7729 " aWorldCo = world_pos0;\n"
7730 " aColour = a_colour;\n"
7732 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
7738 .orig_file
= "shaders/model_sky.fs",
7740 "uniform sampler2D uTexGarbage;\n"
7742 "in vec4 aColour;\n"
7746 "in vec3 aWorldCo;\n"
7749 "const vec3 uCamera = vec3(0.0);\n"
7753 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
7757 "layout (location = 0) out vec4 oColour;\n"
7759 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
7760 "layout (std140) uniform ub_world_lighting\n"
7762 " vec4 g_cube_min;\n"
7763 " vec4 g_cube_inv_range;\n"
7765 " vec4 g_water_plane;\n"
7766 " vec4 g_depth_bounds;\n"
7768 " vec4 g_daysky_colour;\n"
7769 " vec4 g_nightsky_colour;\n"
7770 " vec4 g_sunset_colour;\n"
7771 " vec4 g_ambient_colour;\n"
7772 " vec4 g_sunset_ambient;\n"
7773 " vec4 g_sun_colour;\n"
7774 " vec4 g_sun_dir;\n"
7775 " vec4 g_board_0;\n"
7776 " vec4 g_board_1;\n"
7778 " float g_water_fog;\n"
7780 " float g_realtime;\n"
7781 " float g_shadow_length;\n"
7782 " float g_shadow_spread;\n"
7784 " float g_time_of_day;\n"
7785 " float g_day_phase;\n"
7786 " float g_sunset_phase;\n"
7788 " int g_light_preview;\n"
7789 " int g_shadow_samples;\n"
7791 " int g_debug_indices;\n"
7792 " int g_debug_complexity;\n"
7795 "uniform sampler2D g_world_depth;\n"
7796 "uniform samplerBuffer uLightsArray;\n"
7797 "uniform usampler3D uLightsIndex;\n"
7800 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
7801 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
7802 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
7803 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
7804 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
7805 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
7807 "const float SUN_ANGLE = 0.0001;\n"
7808 "const float PI = 3.14159265358979323846264;\n"
7810 "//struct world_info\n"
7815 "// sunset_phase;\n"
7817 "// vec3 sun_dir;\n"
7820 "vec3 rand33(vec3 p3)\n"
7822 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
7823 " p3 += dot(p3, p3.yxz+33.33);\n"
7824 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
7827 "float stars( vec3 rd, float rr, float size ){\n"
7828 " vec3 co = rd * rr;\n"
7830 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
7832 " float spaces = 1.0 / rr;\n"
7833 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
7834 " a -= mod(a, spaces) - spaces * 0.5;\n"
7836 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
7838 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
7839 " plane = plane - mod(plane, PI / count);\n"
7841 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
7843 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
7844 " float ydist = sqrt(rr * rr - level * level);\n"
7845 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
7846 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
7847 " float star = smoothstep(size, 0.0, distance(center, co));\n"
7851 "float luminance( vec3 v )\n"
7853 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
7856 "vec3 clearskies_ambient( vec3 dir )\n"
7858 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
7859 " float sky_gradient = dir.y;\n"
7861 " /* Blend phase colours */\n"
7862 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
7863 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
7864 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
7866 " /* Add gradient */\n"
7867 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
7869 " return ambient;\n"
7872 "vec3 clearskies_sky( vec3 ray_dir )\n"
7874 " ray_dir.y = abs( ray_dir.y );\n"
7875 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
7878 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
7879 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
7880 " float sun_shape = pow( sun_size, 2000.0 );\n"
7881 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7883 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7884 " sun_colour *= sun_shape;\n"
7887 " float star = 0.0;\n"
7888 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
7890 " if( star_blend > 0.001 ){\n"
7891 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
7892 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
7893 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
7897 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
7898 " return composite;\n"
7901 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
7903 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
7905 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
7906 " g_sunset_phase );\n"
7908 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
7909 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
7910 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
7911 " ) * g_sun_colour.rgb * g_day_phase;\n"
7913 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
7914 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
7915 " g_sunset_phase );\n"
7917 " return ambient + (light_sun + sky_reflection) * shadow;\n"
7922 "float world_depth_sample( vec3 pos )\n"
7924 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
7925 " return texture( g_world_depth, depth_coord ).r;\n"
7928 "float world_water_depth( vec3 pos )\n"
7930 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
7931 " return world_depth_sample( pos ) - ref_depth;\n"
7934 "float shadow_sample( vec3 co ){\n"
7935 " float height_sample = world_depth_sample( co );\n"
7937 " float fdelta = height_sample - co.y;\n"
7938 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
7941 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
7942 " if( g_shadow_samples == 0 ){\n"
7946 " float fspread = g_shadow_spread;\n"
7947 " float flength = g_shadow_length;\n"
7949 " float famt = 0.0;\n"
7950 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
7951 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
7952 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
7953 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
7955 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
7956 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
7957 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
7958 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
7960 " return 1.0 - famt;\n"
7963 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
7965 " vec3 specdir = reflect( -dir, wnormal );\n"
7966 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
7969 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
7970 " float dist = pow(fdist*0.0010,0.78);\n"
7971 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
7974 "vec3 scene_calculate_light( int light_index, \n"
7975 " vec3 halfview, vec3 co, vec3 normal )\n"
7977 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
7978 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
7979 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
7981 " vec3 light_delta = light_co.xyz-co;\n"
7982 " float dist2 = dot(light_delta,light_delta);\n"
7984 " light_delta = normalize( light_delta );\n"
7986 " float quadratic = dist2*100.0;\n"
7987 " float attenuation = 1.0/( 1.0 + quadratic );\n"
7988 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
7990 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
7992 " if( light_dir.w < 0.999999 ){\n"
7993 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
7994 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
7997 " return light_colour.rgb * attenuation * falloff \n"
7998 " * step( g_day_phase, light_colour.w );\n"
8001 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
8002 " vec3 halfview, vec3 co, vec3 normal )\n"
8004 " uint light_count = packed_index & 0x3u;\n"
8006 " vec3 l = vec3(0.0);\n"
8008 " if( light_count >= 1u ){\n"
8009 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
8010 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
8011 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
8013 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
8015 " if( light_count >= 2u ){\n"
8016 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
8018 " if( light_count >= 3u ){\n"
8019 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
8027 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
8028 " float light_mask )\n"
8030 " if( g_light_preview == 1 )\n"
8031 " diffuse = vec3(0.75);\n"
8034 " vec3 halfview = uCamera - co;\n"
8035 " float fdist = length(halfview);\n"
8036 " halfview /= fdist;\n"
8038 " float world_shadow = newlight_compute_sun_shadow( \n"
8039 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
8041 " vec3 total_light = clearskies_lighting( \n"
8042 " normal, min( light_mask, world_shadow ), halfview );\n"
8044 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
8045 " cube_coord = floor( cube_coord );\n"
8047 " if( g_debug_indices == 1 )\n"
8049 " return rand33(cube_coord);\n"
8052 " if( g_debug_complexity == 1 )\n"
8054 " ivec3 coord = ivec3( cube_coord );\n"
8055 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8057 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
8058 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
8061 " // FIXME: this coord should absolutely must be clamped!\n"
8063 " ivec3 coord = ivec3( cube_coord );\n"
8064 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8066 " total_light += \n"
8067 " scene_calculate_packed_light_patch( index_sample.x,\n"
8068 " halfview, co, normal ) \n"
8070 " total_light += \n"
8071 " scene_calculate_packed_light_patch( index_sample.y,\n"
8072 " halfview, co, normal )\n"
8075 " // Take a section of the sky function to give us a matching fog colour\n"
8077 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
8078 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
8079 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
8080 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8082 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8083 " sun_colour *= sun_shape;\n"
8085 " fog_colour += sun_colour;\n"
8086 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
8091 "const float k_motion_lerp_amount = 0.01;\n"
8095 "layout (location = 1) out vec2 oMotionVec;\n"
8097 "in vec3 aMotionVec0;\n"
8098 "in vec3 aMotionVec1;\n"
8100 "void compute_motion_vectors()\n"
8102 " // Write motion vectors\n"
8103 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
8104 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
8106 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
8113 " compute_motion_vectors();\n"
8115 " vec3 rd = normalize(aNorm);\n"
8117 " float fmove = g_time * 5.0;\n"
8118 " vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.025;\n"
8119 " vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );\n"
8120 " vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );\n"
8122 " float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);\n"
8123 " float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;\n"
8125 " oColour = vec4( clearskies_sky( -rd ) ,1.0);\n"
8127 " vec3 cloud_colour = mix( mix(g_nightsky_colour.rgb,vec3(1.0),g_day_phase), \n"
8128 " g_sunset_colour.rgb, g_sunset_phase );\n"
8130 " oColour.rgb = mix( oColour.rgb, cloud_colour, cloud_e );\n"
8135 GLuint _uniform_model_sky_uMdl
;
8136 GLuint _uniform_model_sky_uPv
;
8137 GLuint _uniform_model_sky_uPvmPrev
;
8138 GLuint _uniform_model_sky_uTexGarbage
;
8139 GLuint _uniform_model_sky_g_world_depth
;
8140 GLuint _uniform_model_sky_uLightsArray
;
8141 GLuint _uniform_model_sky_uLightsIndex
;
8142 #include "shaders/model_sky_space.h"
8143 struct vg_shader _shader_model_sky_space
= {
8144 .name
= "model_sky_space",
8147 .orig_file
= "shaders/model.vs",
8149 "layout (location=0) in vec3 a_co;\n"
8150 "layout (location=1) in vec3 a_norm;\n"
8151 "layout (location=2) in vec2 a_uv;\n"
8152 "layout (location=3) in vec4 a_colour;\n"
8153 "layout (location=4) in vec4 a_weights;\n"
8154 "layout (location=5) in ivec4 a_groups;\n"
8157 "const float k_motion_lerp_amount = 0.01;\n"
8161 "out vec3 aMotionVec0;\n"
8162 "out vec3 aMotionVec1;\n"
8164 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
8166 " // This magically solves some artifacting errors!\n"
8168 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
8170 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
8171 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
8176 "uniform mat4x3 uMdl;\n"
8177 "uniform mat4 uPv;\n"
8178 "uniform mat4 uPvmPrev;\n"
8180 "out vec4 aColour;\n"
8184 "out vec3 aWorldCo;\n"
8188 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
8189 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
8190 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
8192 " vs_motion_out( vproj0, vproj1 );\n"
8194 " gl_Position = vproj0;\n"
8195 " aWorldCo = world_pos0;\n"
8196 " aColour = a_colour;\n"
8198 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
8204 .orig_file
= "shaders/model_sky_space.fs",
8206 "uniform sampler2D uTexGarbage;\n"
8208 "in vec4 aColour;\n"
8212 "in vec3 aWorldCo;\n"
8215 "const vec3 uCamera = vec3(0.0);\n"
8219 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
8223 "layout (location = 0) out vec4 oColour;\n"
8225 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
8226 "layout (std140) uniform ub_world_lighting\n"
8228 " vec4 g_cube_min;\n"
8229 " vec4 g_cube_inv_range;\n"
8231 " vec4 g_water_plane;\n"
8232 " vec4 g_depth_bounds;\n"
8234 " vec4 g_daysky_colour;\n"
8235 " vec4 g_nightsky_colour;\n"
8236 " vec4 g_sunset_colour;\n"
8237 " vec4 g_ambient_colour;\n"
8238 " vec4 g_sunset_ambient;\n"
8239 " vec4 g_sun_colour;\n"
8240 " vec4 g_sun_dir;\n"
8241 " vec4 g_board_0;\n"
8242 " vec4 g_board_1;\n"
8244 " float g_water_fog;\n"
8246 " float g_realtime;\n"
8247 " float g_shadow_length;\n"
8248 " float g_shadow_spread;\n"
8250 " float g_time_of_day;\n"
8251 " float g_day_phase;\n"
8252 " float g_sunset_phase;\n"
8254 " int g_light_preview;\n"
8255 " int g_shadow_samples;\n"
8257 " int g_debug_indices;\n"
8258 " int g_debug_complexity;\n"
8261 "uniform sampler2D g_world_depth;\n"
8262 "uniform samplerBuffer uLightsArray;\n"
8263 "uniform usampler3D uLightsIndex;\n"
8266 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
8267 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
8268 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
8269 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
8270 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
8271 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
8273 "const float SUN_ANGLE = 0.0001;\n"
8274 "const float PI = 3.14159265358979323846264;\n"
8276 "//struct world_info\n"
8281 "// sunset_phase;\n"
8283 "// vec3 sun_dir;\n"
8286 "vec3 rand33(vec3 p3)\n"
8288 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
8289 " p3 += dot(p3, p3.yxz+33.33);\n"
8290 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
8293 "float stars( vec3 rd, float rr, float size ){\n"
8294 " vec3 co = rd * rr;\n"
8296 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
8298 " float spaces = 1.0 / rr;\n"
8299 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
8300 " a -= mod(a, spaces) - spaces * 0.5;\n"
8302 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
8304 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
8305 " plane = plane - mod(plane, PI / count);\n"
8307 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
8309 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
8310 " float ydist = sqrt(rr * rr - level * level);\n"
8311 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
8312 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
8313 " float star = smoothstep(size, 0.0, distance(center, co));\n"
8317 "float luminance( vec3 v )\n"
8319 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
8322 "vec3 clearskies_ambient( vec3 dir )\n"
8324 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
8325 " float sky_gradient = dir.y;\n"
8327 " /* Blend phase colours */\n"
8328 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
8329 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
8330 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
8332 " /* Add gradient */\n"
8333 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
8335 " return ambient;\n"
8338 "vec3 clearskies_sky( vec3 ray_dir )\n"
8340 " ray_dir.y = abs( ray_dir.y );\n"
8341 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
8344 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
8345 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
8346 " float sun_shape = pow( sun_size, 2000.0 );\n"
8347 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8349 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8350 " sun_colour *= sun_shape;\n"
8353 " float star = 0.0;\n"
8354 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
8356 " if( star_blend > 0.001 ){\n"
8357 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
8358 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
8359 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
8363 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
8364 " return composite;\n"
8367 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
8369 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
8371 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
8372 " g_sunset_phase );\n"
8374 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
8375 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
8376 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
8377 " ) * g_sun_colour.rgb * g_day_phase;\n"
8379 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
8380 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
8381 " g_sunset_phase );\n"
8383 " return ambient + (light_sun + sky_reflection) * shadow;\n"
8388 "float world_depth_sample( vec3 pos )\n"
8390 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
8391 " return texture( g_world_depth, depth_coord ).r;\n"
8394 "float world_water_depth( vec3 pos )\n"
8396 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
8397 " return world_depth_sample( pos ) - ref_depth;\n"
8400 "float shadow_sample( vec3 co ){\n"
8401 " float height_sample = world_depth_sample( co );\n"
8403 " float fdelta = height_sample - co.y;\n"
8404 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
8407 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
8408 " if( g_shadow_samples == 0 ){\n"
8412 " float fspread = g_shadow_spread;\n"
8413 " float flength = g_shadow_length;\n"
8415 " float famt = 0.0;\n"
8416 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
8417 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
8418 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
8419 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
8421 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
8422 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
8423 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
8424 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
8426 " return 1.0 - famt;\n"
8429 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
8431 " vec3 specdir = reflect( -dir, wnormal );\n"
8432 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
8435 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
8436 " float dist = pow(fdist*0.0010,0.78);\n"
8437 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
8440 "vec3 scene_calculate_light( int light_index, \n"
8441 " vec3 halfview, vec3 co, vec3 normal )\n"
8443 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
8444 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
8445 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
8447 " vec3 light_delta = light_co.xyz-co;\n"
8448 " float dist2 = dot(light_delta,light_delta);\n"
8450 " light_delta = normalize( light_delta );\n"
8452 " float quadratic = dist2*100.0;\n"
8453 " float attenuation = 1.0/( 1.0 + quadratic );\n"
8454 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
8456 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
8458 " if( light_dir.w < 0.999999 ){\n"
8459 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
8460 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
8463 " return light_colour.rgb * attenuation * falloff \n"
8464 " * step( g_day_phase, light_colour.w );\n"
8467 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
8468 " vec3 halfview, vec3 co, vec3 normal )\n"
8470 " uint light_count = packed_index & 0x3u;\n"
8472 " vec3 l = vec3(0.0);\n"
8474 " if( light_count >= 1u ){\n"
8475 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
8476 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
8477 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
8479 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
8481 " if( light_count >= 2u ){\n"
8482 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
8484 " if( light_count >= 3u ){\n"
8485 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
8493 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
8494 " float light_mask )\n"
8496 " if( g_light_preview == 1 )\n"
8497 " diffuse = vec3(0.75);\n"
8500 " vec3 halfview = uCamera - co;\n"
8501 " float fdist = length(halfview);\n"
8502 " halfview /= fdist;\n"
8504 " float world_shadow = newlight_compute_sun_shadow( \n"
8505 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
8507 " vec3 total_light = clearskies_lighting( \n"
8508 " normal, min( light_mask, world_shadow ), halfview );\n"
8510 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
8511 " cube_coord = floor( cube_coord );\n"
8513 " if( g_debug_indices == 1 )\n"
8515 " return rand33(cube_coord);\n"
8518 " if( g_debug_complexity == 1 )\n"
8520 " ivec3 coord = ivec3( cube_coord );\n"
8521 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8523 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
8524 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
8527 " // FIXME: this coord should absolutely must be clamped!\n"
8529 " ivec3 coord = ivec3( cube_coord );\n"
8530 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8532 " total_light += \n"
8533 " scene_calculate_packed_light_patch( index_sample.x,\n"
8534 " halfview, co, normal ) \n"
8536 " total_light += \n"
8537 " scene_calculate_packed_light_patch( index_sample.y,\n"
8538 " halfview, co, normal )\n"
8541 " // Take a section of the sky function to give us a matching fog colour\n"
8543 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
8544 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
8545 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
8546 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8548 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8549 " sun_colour *= sun_shape;\n"
8551 " fog_colour += sun_colour;\n"
8552 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
8557 "const float k_motion_lerp_amount = 0.01;\n"
8561 "layout (location = 1) out vec2 oMotionVec;\n"
8563 "in vec3 aMotionVec0;\n"
8564 "in vec3 aMotionVec1;\n"
8566 "void compute_motion_vectors()\n"
8568 " // Write motion vectors\n"
8569 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
8570 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
8572 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
8577 "float stars1( vec3 rd, float rr, float size ){\n"
8578 " vec3 co = rd * rr;\n"
8580 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
8582 " float spaces = 1.0 / rr;\n"
8583 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
8584 " a -= mod(a, spaces) - spaces * 0.5;\n"
8586 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
8588 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
8589 " plane = plane - mod(plane, PI / count);\n"
8591 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
8593 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
8594 " float ydist = sqrt(rr * rr - level * level);\n"
8595 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
8596 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
8597 " float star = smoothstep(size, 0.0, distance(center, co));\n"
8602 " compute_motion_vectors();\n"
8604 " vec3 rd = -normalize(aNorm);\n"
8606 " float star = 0.0;\n"
8607 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
8608 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
8609 " star += stars( rd, 1.94 * pow( 1.64, j ), m ) * (1.0 / pow(4.0, j));\n"
8612 " oColour = vec4( vec3(star*20.0), 1.0);\n"
8617 GLuint _uniform_model_sky_space_uMdl
;
8618 GLuint _uniform_model_sky_space_uPv
;
8619 GLuint _uniform_model_sky_space_uPvmPrev
;
8620 GLuint _uniform_model_sky_space_uTexGarbage
;
8621 GLuint _uniform_model_sky_space_g_world_depth
;
8622 GLuint _uniform_model_sky_space_uLightsArray
;
8623 GLuint _uniform_model_sky_space_uLightsIndex
;
8624 #include "shaders/model_menu.h"
8625 struct vg_shader _shader_model_menu
= {
8626 .name
= "model_menu",
8629 .orig_file
= "shaders/model.vs",
8631 "layout (location=0) in vec3 a_co;\n"
8632 "layout (location=1) in vec3 a_norm;\n"
8633 "layout (location=2) in vec2 a_uv;\n"
8634 "layout (location=3) in vec4 a_colour;\n"
8635 "layout (location=4) in vec4 a_weights;\n"
8636 "layout (location=5) in ivec4 a_groups;\n"
8639 "const float k_motion_lerp_amount = 0.01;\n"
8643 "out vec3 aMotionVec0;\n"
8644 "out vec3 aMotionVec1;\n"
8646 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
8648 " // This magically solves some artifacting errors!\n"
8650 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
8652 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
8653 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
8658 "uniform mat4x3 uMdl;\n"
8659 "uniform mat4 uPv;\n"
8660 "uniform mat4 uPvmPrev;\n"
8662 "out vec4 aColour;\n"
8666 "out vec3 aWorldCo;\n"
8670 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
8671 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
8672 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
8674 " vs_motion_out( vproj0, vproj1 );\n"
8676 " gl_Position = vproj0;\n"
8677 " aWorldCo = world_pos0;\n"
8678 " aColour = a_colour;\n"
8680 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
8686 .orig_file
= "shaders/model_menu.fs",
8688 "out vec4 FragColor;\n"
8690 "uniform sampler2D uTexMain;\n"
8691 "uniform vec4 uColour;\n"
8693 "in vec4 aColour;\n"
8700 " vec4 diffuse = texture( uTexMain, aUv );\n"
8702 " if( diffuse.a < 0.5 )\n"
8705 " FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;\n"
8710 GLuint _uniform_model_menu_uMdl
;
8711 GLuint _uniform_model_menu_uPv
;
8712 GLuint _uniform_model_menu_uPvmPrev
;
8713 GLuint _uniform_model_menu_uTexMain
;
8714 GLuint _uniform_model_menu_uColour
;
8715 #include "shaders/model_character_view.h"
8716 struct vg_shader _shader_model_character_view
= {
8717 .name
= "model_character_view",
8720 .orig_file
= "shaders/model_skinned.vs",
8722 "layout (location=0) in vec3 a_co;\n"
8723 "layout (location=1) in vec3 a_norm;\n"
8724 "layout (location=2) in vec2 a_uv;\n"
8725 "layout (location=3) in vec4 a_colour;\n"
8726 "layout (location=4) in vec4 a_weights;\n"
8727 "layout (location=5) in ivec4 a_groups;\n"
8730 "const float k_motion_lerp_amount = 0.01;\n"
8734 "out vec3 aMotionVec0;\n"
8735 "out vec3 aMotionVec1;\n"
8737 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
8739 " // This magically solves some artifacting errors!\n"
8741 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
8743 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
8744 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
8749 "uniform mat4 uPv;\n"
8750 "uniform mat4x3 uTransforms[32];\n"
8752 "out vec4 aColour;\n"
8756 "out vec3 aWorldCo;\n"
8760 " vec4 co_local = vec4( a_co, 1.0 );\n"
8761 " vec3 co0 = uTransforms[ a_groups[0] ] * co_local;\n"
8762 " vec3 co1 = uTransforms[ a_groups[1] ] * co_local;\n"
8763 " vec3 co2 = uTransforms[ a_groups[2] ] * co_local;\n"
8764 " vec3 n0 = mat3(uTransforms[ a_groups[0] ]) * a_norm;\n"
8765 " vec3 n1 = mat3(uTransforms[ a_groups[1] ]) * a_norm;\n"
8766 " vec3 n2 = mat3(uTransforms[ a_groups[2] ]) * a_norm;\n"
8768 " vec3 world_pos = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];\n"
8769 " vec3 world_normal = n0*a_weights[0] + n1*a_weights[1] + n2*a_weights[2];\n"
8771 " gl_Position = uPv * vec4( world_pos, 1.0 );\n"
8772 " aColour = a_colour;\n"
8774 " aNorm = world_normal;\n"
8776 " aWorldCo = world_pos;\n"
8778 " // TODO: motion vectors\n"
8779 " aMotionVec0 = vec3(1.0);\n"
8780 " aMotionVec1 = vec3(1.0);\n"
8785 .orig_file
= "shaders/model_character_view.fs",
8787 "uniform sampler2D uTexMain;\n"
8788 "uniform vec3 uCamera;\n"
8790 "in vec4 aColour;\n"
8794 "in vec3 aWorldCo;\n"
8798 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
8802 "layout (location = 0) out vec4 oColour;\n"
8804 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
8805 "layout (std140) uniform ub_world_lighting\n"
8807 " vec4 g_cube_min;\n"
8808 " vec4 g_cube_inv_range;\n"
8810 " vec4 g_water_plane;\n"
8811 " vec4 g_depth_bounds;\n"
8813 " vec4 g_daysky_colour;\n"
8814 " vec4 g_nightsky_colour;\n"
8815 " vec4 g_sunset_colour;\n"
8816 " vec4 g_ambient_colour;\n"
8817 " vec4 g_sunset_ambient;\n"
8818 " vec4 g_sun_colour;\n"
8819 " vec4 g_sun_dir;\n"
8820 " vec4 g_board_0;\n"
8821 " vec4 g_board_1;\n"
8823 " float g_water_fog;\n"
8825 " float g_realtime;\n"
8826 " float g_shadow_length;\n"
8827 " float g_shadow_spread;\n"
8829 " float g_time_of_day;\n"
8830 " float g_day_phase;\n"
8831 " float g_sunset_phase;\n"
8833 " int g_light_preview;\n"
8834 " int g_shadow_samples;\n"
8836 " int g_debug_indices;\n"
8837 " int g_debug_complexity;\n"
8840 "uniform sampler2D g_world_depth;\n"
8841 "uniform samplerBuffer uLightsArray;\n"
8842 "uniform usampler3D uLightsIndex;\n"
8845 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
8846 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
8847 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
8848 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
8849 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
8850 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
8852 "const float SUN_ANGLE = 0.0001;\n"
8853 "const float PI = 3.14159265358979323846264;\n"
8855 "//struct world_info\n"
8860 "// sunset_phase;\n"
8862 "// vec3 sun_dir;\n"
8865 "vec3 rand33(vec3 p3)\n"
8867 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
8868 " p3 += dot(p3, p3.yxz+33.33);\n"
8869 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
8872 "float stars( vec3 rd, float rr, float size ){\n"
8873 " vec3 co = rd * rr;\n"
8875 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
8877 " float spaces = 1.0 / rr;\n"
8878 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
8879 " a -= mod(a, spaces) - spaces * 0.5;\n"
8881 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
8883 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
8884 " plane = plane - mod(plane, PI / count);\n"
8886 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
8888 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
8889 " float ydist = sqrt(rr * rr - level * level);\n"
8890 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
8891 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
8892 " float star = smoothstep(size, 0.0, distance(center, co));\n"
8896 "float luminance( vec3 v )\n"
8898 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
8901 "vec3 clearskies_ambient( vec3 dir )\n"
8903 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
8904 " float sky_gradient = dir.y;\n"
8906 " /* Blend phase colours */\n"
8907 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
8908 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
8909 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
8911 " /* Add gradient */\n"
8912 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
8914 " return ambient;\n"
8917 "vec3 clearskies_sky( vec3 ray_dir )\n"
8919 " ray_dir.y = abs( ray_dir.y );\n"
8920 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
8923 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
8924 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
8925 " float sun_shape = pow( sun_size, 2000.0 );\n"
8926 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8928 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8929 " sun_colour *= sun_shape;\n"
8932 " float star = 0.0;\n"
8933 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
8935 " if( star_blend > 0.001 ){\n"
8936 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
8937 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
8938 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
8942 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
8943 " return composite;\n"
8946 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
8948 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
8950 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
8951 " g_sunset_phase );\n"
8953 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
8954 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
8955 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
8956 " ) * g_sun_colour.rgb * g_day_phase;\n"
8958 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
8959 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
8960 " g_sunset_phase );\n"
8962 " return ambient + (light_sun + sky_reflection) * shadow;\n"
8967 "float world_depth_sample( vec3 pos )\n"
8969 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
8970 " return texture( g_world_depth, depth_coord ).r;\n"
8973 "float world_water_depth( vec3 pos )\n"
8975 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
8976 " return world_depth_sample( pos ) - ref_depth;\n"
8979 "float shadow_sample( vec3 co ){\n"
8980 " float height_sample = world_depth_sample( co );\n"
8982 " float fdelta = height_sample - co.y;\n"
8983 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
8986 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
8987 " if( g_shadow_samples == 0 ){\n"
8991 " float fspread = g_shadow_spread;\n"
8992 " float flength = g_shadow_length;\n"
8994 " float famt = 0.0;\n"
8995 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
8996 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
8997 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
8998 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
9000 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
9001 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
9002 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
9003 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
9005 " return 1.0 - famt;\n"
9008 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
9010 " vec3 specdir = reflect( -dir, wnormal );\n"
9011 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
9014 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
9015 " float dist = pow(fdist*0.0010,0.78);\n"
9016 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
9019 "vec3 scene_calculate_light( int light_index, \n"
9020 " vec3 halfview, vec3 co, vec3 normal )\n"
9022 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
9023 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
9024 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
9026 " vec3 light_delta = light_co.xyz-co;\n"
9027 " float dist2 = dot(light_delta,light_delta);\n"
9029 " light_delta = normalize( light_delta );\n"
9031 " float quadratic = dist2*100.0;\n"
9032 " float attenuation = 1.0/( 1.0 + quadratic );\n"
9033 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
9035 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
9037 " if( light_dir.w < 0.999999 ){\n"
9038 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
9039 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
9042 " return light_colour.rgb * attenuation * falloff \n"
9043 " * step( g_day_phase, light_colour.w );\n"
9046 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
9047 " vec3 halfview, vec3 co, vec3 normal )\n"
9049 " uint light_count = packed_index & 0x3u;\n"
9051 " vec3 l = vec3(0.0);\n"
9053 " if( light_count >= 1u ){\n"
9054 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
9055 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
9056 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
9058 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
9060 " if( light_count >= 2u ){\n"
9061 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
9063 " if( light_count >= 3u ){\n"
9064 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
9072 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9073 " float light_mask )\n"
9075 " if( g_light_preview == 1 )\n"
9076 " diffuse = vec3(0.75);\n"
9079 " vec3 halfview = uCamera - co;\n"
9080 " float fdist = length(halfview);\n"
9081 " halfview /= fdist;\n"
9083 " float world_shadow = newlight_compute_sun_shadow( \n"
9084 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9086 " vec3 total_light = clearskies_lighting( \n"
9087 " normal, min( light_mask, world_shadow ), halfview );\n"
9089 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9090 " cube_coord = floor( cube_coord );\n"
9092 " if( g_debug_indices == 1 )\n"
9094 " return rand33(cube_coord);\n"
9097 " if( g_debug_complexity == 1 )\n"
9099 " ivec3 coord = ivec3( cube_coord );\n"
9100 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9102 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9103 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9106 " // FIXME: this coord should absolutely must be clamped!\n"
9108 " ivec3 coord = ivec3( cube_coord );\n"
9109 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9111 " total_light += \n"
9112 " scene_calculate_packed_light_patch( index_sample.x,\n"
9113 " halfview, co, normal ) \n"
9115 " total_light += \n"
9116 " scene_calculate_packed_light_patch( index_sample.y,\n"
9117 " halfview, co, normal )\n"
9120 " // Take a section of the sky function to give us a matching fog colour\n"
9122 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9123 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9124 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9125 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9127 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9128 " sun_colour *= sun_shape;\n"
9130 " fog_colour += sun_colour;\n"
9131 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9136 "const float k_motion_lerp_amount = 0.01;\n"
9140 "layout (location = 1) out vec2 oMotionVec;\n"
9142 "in vec3 aMotionVec0;\n"
9143 "in vec3 aMotionVec1;\n"
9145 "void compute_motion_vectors()\n"
9147 " // Write motion vectors\n"
9148 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
9149 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
9151 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
9156 "uniform sampler2D uTexSceneDepth;\n"
9157 "uniform vec3 uInverseRatioDepth;\n"
9158 "uniform vec3 uInverseRatioMain;\n"
9159 "uniform int uDepthMode;\n"
9160 "uniform float uDitherCutoff;\n"
9162 "float linear_depth( float depth, float near, float far ) {\n"
9163 " float z = depth * 2.0 - 1.0;\n"
9164 " return (2.0 * near * far) / (far + near - z * (far - near)); \n"
9167 "void depth_compare_dither()\n"
9169 " if( uDepthMode == 1 )\n"
9171 " vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
9172 " * uInverseRatioDepth.xy;\n"
9173 " float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
9174 " float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
9176 " back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
9177 " float diff = back_depth - front_depth;\n"
9179 " vec2 ssuv = gl_FragCoord.xy;\n"
9180 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9181 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
9183 " if( step(0.0,diff)+dither<0.3 )\n"
9187 " if( uDepthMode == 2 )\n"
9189 " vec2 ssuv = gl_FragCoord.xy;\n"
9190 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9191 " float dither = fract( vDither.g / 71.0 );\n"
9192 " if( dither<uDitherCutoff ) discard;\n"
9198 "vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
9200 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
9202 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
9203 " g_sunset_phase );\n"
9206 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
9207 " vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
9208 " * g_sun_colour.rgb * g_day_phase;\n"
9210 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
9211 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
9212 " g_sunset_phase );\n"
9214 " return ambient + (light_sun + sky_reflection) * shadow;\n"
9217 "vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9218 " float light_mask )\n"
9220 " if( g_light_preview == 1 )\n"
9221 " diffuse = vec3(0.75);\n"
9224 " vec3 halfview = uCamera - co;\n"
9225 " float fdist = length(halfview);\n"
9226 " halfview /= fdist;\n"
9228 " float world_shadow = newlight_compute_sun_shadow( \n"
9229 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9231 " vec3 total_light = character_clearskies_lighting( \n"
9232 " normal, min( light_mask, world_shadow ), halfview );\n"
9234 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9235 " cube_coord = floor( cube_coord );\n"
9237 " if( g_debug_indices == 1 )\n"
9239 " return rand33(cube_coord);\n"
9242 " if( g_debug_complexity == 1 )\n"
9244 " ivec3 coord = ivec3( cube_coord );\n"
9245 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9247 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9248 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9251 " // FIXME: this coord should absolutely must be clamped!\n"
9253 " ivec3 coord = ivec3( cube_coord );\n"
9254 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9256 " total_light += \n"
9257 " scene_calculate_packed_light_patch( index_sample.x,\n"
9258 " halfview, co, normal ) \n"
9260 " total_light += \n"
9261 " scene_calculate_packed_light_patch( index_sample.y,\n"
9262 " halfview, co, normal )\n"
9265 " // Take a section of the sky function to give us a matching fog colour\n"
9267 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9268 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9269 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9270 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9272 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9273 " sun_colour *= sun_shape;\n"
9275 " fog_colour += sun_colour;\n"
9276 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9280 " depth_compare_dither();\n"
9281 " compute_motion_vectors();\n"
9283 " vec3 qnorm = aNorm;\n"
9284 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
9285 " vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
9287 " float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
9288 " float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
9290 " oColour = vec4( composite, opacity );\n"
9295 GLuint _uniform_model_character_view_uPv
;
9296 GLuint _uniform_model_character_view_uTransforms
;
9297 GLuint _uniform_model_character_view_uTexMain
;
9298 GLuint _uniform_model_character_view_uCamera
;
9299 GLuint _uniform_model_character_view_g_world_depth
;
9300 GLuint _uniform_model_character_view_uLightsArray
;
9301 GLuint _uniform_model_character_view_uLightsIndex
;
9302 GLuint _uniform_model_character_view_uTexSceneDepth
;
9303 GLuint _uniform_model_character_view_uInverseRatioDepth
;
9304 GLuint _uniform_model_character_view_uInverseRatioMain
;
9305 GLuint _uniform_model_character_view_uDepthMode
;
9306 GLuint _uniform_model_character_view_uDitherCutoff
;
9307 #include "shaders/model_board_view.h"
9308 struct vg_shader _shader_model_board_view
= {
9309 .name
= "model_board_view",
9312 .orig_file
= "shaders/model.vs",
9314 "layout (location=0) in vec3 a_co;\n"
9315 "layout (location=1) in vec3 a_norm;\n"
9316 "layout (location=2) in vec2 a_uv;\n"
9317 "layout (location=3) in vec4 a_colour;\n"
9318 "layout (location=4) in vec4 a_weights;\n"
9319 "layout (location=5) in ivec4 a_groups;\n"
9322 "const float k_motion_lerp_amount = 0.01;\n"
9326 "out vec3 aMotionVec0;\n"
9327 "out vec3 aMotionVec1;\n"
9329 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
9331 " // This magically solves some artifacting errors!\n"
9333 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
9335 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
9336 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
9341 "uniform mat4x3 uMdl;\n"
9342 "uniform mat4 uPv;\n"
9343 "uniform mat4 uPvmPrev;\n"
9345 "out vec4 aColour;\n"
9349 "out vec3 aWorldCo;\n"
9353 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
9354 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
9355 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
9357 " vs_motion_out( vproj0, vproj1 );\n"
9359 " gl_Position = vproj0;\n"
9360 " aWorldCo = world_pos0;\n"
9361 " aColour = a_colour;\n"
9363 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
9369 .orig_file
= "shaders/model_character_view.fs",
9371 "uniform sampler2D uTexMain;\n"
9372 "uniform vec3 uCamera;\n"
9374 "in vec4 aColour;\n"
9378 "in vec3 aWorldCo;\n"
9382 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
9386 "layout (location = 0) out vec4 oColour;\n"
9388 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
9389 "layout (std140) uniform ub_world_lighting\n"
9391 " vec4 g_cube_min;\n"
9392 " vec4 g_cube_inv_range;\n"
9394 " vec4 g_water_plane;\n"
9395 " vec4 g_depth_bounds;\n"
9397 " vec4 g_daysky_colour;\n"
9398 " vec4 g_nightsky_colour;\n"
9399 " vec4 g_sunset_colour;\n"
9400 " vec4 g_ambient_colour;\n"
9401 " vec4 g_sunset_ambient;\n"
9402 " vec4 g_sun_colour;\n"
9403 " vec4 g_sun_dir;\n"
9404 " vec4 g_board_0;\n"
9405 " vec4 g_board_1;\n"
9407 " float g_water_fog;\n"
9409 " float g_realtime;\n"
9410 " float g_shadow_length;\n"
9411 " float g_shadow_spread;\n"
9413 " float g_time_of_day;\n"
9414 " float g_day_phase;\n"
9415 " float g_sunset_phase;\n"
9417 " int g_light_preview;\n"
9418 " int g_shadow_samples;\n"
9420 " int g_debug_indices;\n"
9421 " int g_debug_complexity;\n"
9424 "uniform sampler2D g_world_depth;\n"
9425 "uniform samplerBuffer uLightsArray;\n"
9426 "uniform usampler3D uLightsIndex;\n"
9429 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
9430 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
9431 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
9432 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
9433 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
9434 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
9436 "const float SUN_ANGLE = 0.0001;\n"
9437 "const float PI = 3.14159265358979323846264;\n"
9439 "//struct world_info\n"
9444 "// sunset_phase;\n"
9446 "// vec3 sun_dir;\n"
9449 "vec3 rand33(vec3 p3)\n"
9451 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
9452 " p3 += dot(p3, p3.yxz+33.33);\n"
9453 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
9456 "float stars( vec3 rd, float rr, float size ){\n"
9457 " vec3 co = rd * rr;\n"
9459 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
9461 " float spaces = 1.0 / rr;\n"
9462 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
9463 " a -= mod(a, spaces) - spaces * 0.5;\n"
9465 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
9467 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
9468 " plane = plane - mod(plane, PI / count);\n"
9470 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
9472 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
9473 " float ydist = sqrt(rr * rr - level * level);\n"
9474 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
9475 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
9476 " float star = smoothstep(size, 0.0, distance(center, co));\n"
9480 "float luminance( vec3 v )\n"
9482 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
9485 "vec3 clearskies_ambient( vec3 dir )\n"
9487 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
9488 " float sky_gradient = dir.y;\n"
9490 " /* Blend phase colours */\n"
9491 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
9492 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
9493 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
9495 " /* Add gradient */\n"
9496 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
9498 " return ambient;\n"
9501 "vec3 clearskies_sky( vec3 ray_dir )\n"
9503 " ray_dir.y = abs( ray_dir.y );\n"
9504 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
9507 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
9508 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
9509 " float sun_shape = pow( sun_size, 2000.0 );\n"
9510 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9512 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9513 " sun_colour *= sun_shape;\n"
9516 " float star = 0.0;\n"
9517 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
9519 " if( star_blend > 0.001 ){\n"
9520 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
9521 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
9522 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
9526 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
9527 " return composite;\n"
9530 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
9532 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
9534 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
9535 " g_sunset_phase );\n"
9537 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
9538 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
9539 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
9540 " ) * g_sun_colour.rgb * g_day_phase;\n"
9542 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
9543 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
9544 " g_sunset_phase );\n"
9546 " return ambient + (light_sun + sky_reflection) * shadow;\n"
9551 "float world_depth_sample( vec3 pos )\n"
9553 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
9554 " return texture( g_world_depth, depth_coord ).r;\n"
9557 "float world_water_depth( vec3 pos )\n"
9559 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
9560 " return world_depth_sample( pos ) - ref_depth;\n"
9563 "float shadow_sample( vec3 co ){\n"
9564 " float height_sample = world_depth_sample( co );\n"
9566 " float fdelta = height_sample - co.y;\n"
9567 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
9570 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
9571 " if( g_shadow_samples == 0 ){\n"
9575 " float fspread = g_shadow_spread;\n"
9576 " float flength = g_shadow_length;\n"
9578 " float famt = 0.0;\n"
9579 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
9580 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
9581 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
9582 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
9584 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
9585 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
9586 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
9587 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
9589 " return 1.0 - famt;\n"
9592 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
9594 " vec3 specdir = reflect( -dir, wnormal );\n"
9595 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
9598 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
9599 " float dist = pow(fdist*0.0010,0.78);\n"
9600 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
9603 "vec3 scene_calculate_light( int light_index, \n"
9604 " vec3 halfview, vec3 co, vec3 normal )\n"
9606 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
9607 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
9608 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
9610 " vec3 light_delta = light_co.xyz-co;\n"
9611 " float dist2 = dot(light_delta,light_delta);\n"
9613 " light_delta = normalize( light_delta );\n"
9615 " float quadratic = dist2*100.0;\n"
9616 " float attenuation = 1.0/( 1.0 + quadratic );\n"
9617 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
9619 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
9621 " if( light_dir.w < 0.999999 ){\n"
9622 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
9623 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
9626 " return light_colour.rgb * attenuation * falloff \n"
9627 " * step( g_day_phase, light_colour.w );\n"
9630 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
9631 " vec3 halfview, vec3 co, vec3 normal )\n"
9633 " uint light_count = packed_index & 0x3u;\n"
9635 " vec3 l = vec3(0.0);\n"
9637 " if( light_count >= 1u ){\n"
9638 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
9639 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
9640 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
9642 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
9644 " if( light_count >= 2u ){\n"
9645 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
9647 " if( light_count >= 3u ){\n"
9648 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
9656 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9657 " float light_mask )\n"
9659 " if( g_light_preview == 1 )\n"
9660 " diffuse = vec3(0.75);\n"
9663 " vec3 halfview = uCamera - co;\n"
9664 " float fdist = length(halfview);\n"
9665 " halfview /= fdist;\n"
9667 " float world_shadow = newlight_compute_sun_shadow( \n"
9668 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9670 " vec3 total_light = clearskies_lighting( \n"
9671 " normal, min( light_mask, world_shadow ), halfview );\n"
9673 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9674 " cube_coord = floor( cube_coord );\n"
9676 " if( g_debug_indices == 1 )\n"
9678 " return rand33(cube_coord);\n"
9681 " if( g_debug_complexity == 1 )\n"
9683 " ivec3 coord = ivec3( cube_coord );\n"
9684 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9686 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9687 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9690 " // FIXME: this coord should absolutely must be clamped!\n"
9692 " ivec3 coord = ivec3( cube_coord );\n"
9693 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9695 " total_light += \n"
9696 " scene_calculate_packed_light_patch( index_sample.x,\n"
9697 " halfview, co, normal ) \n"
9699 " total_light += \n"
9700 " scene_calculate_packed_light_patch( index_sample.y,\n"
9701 " halfview, co, normal )\n"
9704 " // Take a section of the sky function to give us a matching fog colour\n"
9706 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9707 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9708 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9709 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9711 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9712 " sun_colour *= sun_shape;\n"
9714 " fog_colour += sun_colour;\n"
9715 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9720 "const float k_motion_lerp_amount = 0.01;\n"
9724 "layout (location = 1) out vec2 oMotionVec;\n"
9726 "in vec3 aMotionVec0;\n"
9727 "in vec3 aMotionVec1;\n"
9729 "void compute_motion_vectors()\n"
9731 " // Write motion vectors\n"
9732 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
9733 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
9735 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
9740 "uniform sampler2D uTexSceneDepth;\n"
9741 "uniform vec3 uInverseRatioDepth;\n"
9742 "uniform vec3 uInverseRatioMain;\n"
9743 "uniform int uDepthMode;\n"
9744 "uniform float uDitherCutoff;\n"
9746 "float linear_depth( float depth, float near, float far ) {\n"
9747 " float z = depth * 2.0 - 1.0;\n"
9748 " return (2.0 * near * far) / (far + near - z * (far - near)); \n"
9751 "void depth_compare_dither()\n"
9753 " if( uDepthMode == 1 )\n"
9755 " vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
9756 " * uInverseRatioDepth.xy;\n"
9757 " float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
9758 " float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
9760 " back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
9761 " float diff = back_depth - front_depth;\n"
9763 " vec2 ssuv = gl_FragCoord.xy;\n"
9764 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9765 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
9767 " if( step(0.0,diff)+dither<0.3 )\n"
9771 " if( uDepthMode == 2 )\n"
9773 " vec2 ssuv = gl_FragCoord.xy;\n"
9774 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9775 " float dither = fract( vDither.g / 71.0 );\n"
9776 " if( dither<uDitherCutoff ) discard;\n"
9782 "vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
9784 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
9786 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
9787 " g_sunset_phase );\n"
9790 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
9791 " vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
9792 " * g_sun_colour.rgb * g_day_phase;\n"
9794 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
9795 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
9796 " g_sunset_phase );\n"
9798 " return ambient + (light_sun + sky_reflection) * shadow;\n"
9801 "vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9802 " float light_mask )\n"
9804 " if( g_light_preview == 1 )\n"
9805 " diffuse = vec3(0.75);\n"
9808 " vec3 halfview = uCamera - co;\n"
9809 " float fdist = length(halfview);\n"
9810 " halfview /= fdist;\n"
9812 " float world_shadow = newlight_compute_sun_shadow( \n"
9813 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9815 " vec3 total_light = character_clearskies_lighting( \n"
9816 " normal, min( light_mask, world_shadow ), halfview );\n"
9818 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9819 " cube_coord = floor( cube_coord );\n"
9821 " if( g_debug_indices == 1 )\n"
9823 " return rand33(cube_coord);\n"
9826 " if( g_debug_complexity == 1 )\n"
9828 " ivec3 coord = ivec3( cube_coord );\n"
9829 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9831 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9832 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9835 " // FIXME: this coord should absolutely must be clamped!\n"
9837 " ivec3 coord = ivec3( cube_coord );\n"
9838 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9840 " total_light += \n"
9841 " scene_calculate_packed_light_patch( index_sample.x,\n"
9842 " halfview, co, normal ) \n"
9844 " total_light += \n"
9845 " scene_calculate_packed_light_patch( index_sample.y,\n"
9846 " halfview, co, normal )\n"
9849 " // Take a section of the sky function to give us a matching fog colour\n"
9851 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9852 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9853 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9854 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9856 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9857 " sun_colour *= sun_shape;\n"
9859 " fog_colour += sun_colour;\n"
9860 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9864 " depth_compare_dither();\n"
9865 " compute_motion_vectors();\n"
9867 " vec3 qnorm = aNorm;\n"
9868 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
9869 " vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
9871 " float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
9872 " float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
9874 " oColour = vec4( composite, opacity );\n"
9879 GLuint _uniform_model_board_view_uMdl
;
9880 GLuint _uniform_model_board_view_uPv
;
9881 GLuint _uniform_model_board_view_uPvmPrev
;
9882 GLuint _uniform_model_board_view_uTexMain
;
9883 GLuint _uniform_model_board_view_uCamera
;
9884 GLuint _uniform_model_board_view_g_world_depth
;
9885 GLuint _uniform_model_board_view_uLightsArray
;
9886 GLuint _uniform_model_board_view_uLightsIndex
;
9887 GLuint _uniform_model_board_view_uTexSceneDepth
;
9888 GLuint _uniform_model_board_view_uInverseRatioDepth
;
9889 GLuint _uniform_model_board_view_uInverseRatioMain
;
9890 GLuint _uniform_model_board_view_uDepthMode
;
9891 GLuint _uniform_model_board_view_uDitherCutoff
;
9892 #include "shaders/model_entity.h"
9893 struct vg_shader _shader_model_entity
= {
9894 .name
= "model_entity",
9897 .orig_file
= "shaders/model.vs",
9899 "layout (location=0) in vec3 a_co;\n"
9900 "layout (location=1) in vec3 a_norm;\n"
9901 "layout (location=2) in vec2 a_uv;\n"
9902 "layout (location=3) in vec4 a_colour;\n"
9903 "layout (location=4) in vec4 a_weights;\n"
9904 "layout (location=5) in ivec4 a_groups;\n"
9907 "const float k_motion_lerp_amount = 0.01;\n"
9911 "out vec3 aMotionVec0;\n"
9912 "out vec3 aMotionVec1;\n"
9914 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
9916 " // This magically solves some artifacting errors!\n"
9918 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
9920 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
9921 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
9926 "uniform mat4x3 uMdl;\n"
9927 "uniform mat4 uPv;\n"
9928 "uniform mat4 uPvmPrev;\n"
9930 "out vec4 aColour;\n"
9934 "out vec3 aWorldCo;\n"
9938 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
9939 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
9940 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
9942 " vs_motion_out( vproj0, vproj1 );\n"
9944 " gl_Position = vproj0;\n"
9945 " aWorldCo = world_pos0;\n"
9946 " aColour = a_colour;\n"
9948 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
9954 .orig_file
= "shaders/model_entity.fs",
9956 "uniform sampler2D uTexMain;\n"
9957 "uniform vec3 uCamera;\n"
9959 "in vec4 aColour;\n"
9963 "in vec3 aWorldCo;\n"
9967 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
9971 "layout (location = 0) out vec4 oColour;\n"
9973 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
9974 "layout (std140) uniform ub_world_lighting\n"
9976 " vec4 g_cube_min;\n"
9977 " vec4 g_cube_inv_range;\n"
9979 " vec4 g_water_plane;\n"
9980 " vec4 g_depth_bounds;\n"
9982 " vec4 g_daysky_colour;\n"
9983 " vec4 g_nightsky_colour;\n"
9984 " vec4 g_sunset_colour;\n"
9985 " vec4 g_ambient_colour;\n"
9986 " vec4 g_sunset_ambient;\n"
9987 " vec4 g_sun_colour;\n"
9988 " vec4 g_sun_dir;\n"
9989 " vec4 g_board_0;\n"
9990 " vec4 g_board_1;\n"
9992 " float g_water_fog;\n"
9994 " float g_realtime;\n"
9995 " float g_shadow_length;\n"
9996 " float g_shadow_spread;\n"
9998 " float g_time_of_day;\n"
9999 " float g_day_phase;\n"
10000 " float g_sunset_phase;\n"
10002 " int g_light_preview;\n"
10003 " int g_shadow_samples;\n"
10005 " int g_debug_indices;\n"
10006 " int g_debug_complexity;\n"
10009 "uniform sampler2D g_world_depth;\n"
10010 "uniform samplerBuffer uLightsArray;\n"
10011 "uniform usampler3D uLightsIndex;\n"
10014 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
10015 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
10016 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
10017 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
10018 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
10019 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
10021 "const float SUN_ANGLE = 0.0001;\n"
10022 "const float PI = 3.14159265358979323846264;\n"
10024 "//struct world_info\n"
10027 "// time_of_day,\n"
10029 "// sunset_phase;\n"
10031 "// vec3 sun_dir;\n"
10034 "vec3 rand33(vec3 p3)\n"
10036 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
10037 " p3 += dot(p3, p3.yxz+33.33);\n"
10038 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
10041 "float stars( vec3 rd, float rr, float size ){\n"
10042 " vec3 co = rd * rr;\n"
10044 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
10046 " float spaces = 1.0 / rr;\n"
10047 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
10048 " a -= mod(a, spaces) - spaces * 0.5;\n"
10050 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
10052 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
10053 " plane = plane - mod(plane, PI / count);\n"
10055 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
10057 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
10058 " float ydist = sqrt(rr * rr - level * level);\n"
10059 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
10060 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
10061 " float star = smoothstep(size, 0.0, distance(center, co));\n"
10065 "float luminance( vec3 v )\n"
10067 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
10070 "vec3 clearskies_ambient( vec3 dir )\n"
10072 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
10073 " float sky_gradient = dir.y;\n"
10075 " /* Blend phase colours */\n"
10076 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
10077 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
10078 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
10080 " /* Add gradient */\n"
10081 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
10083 " return ambient;\n"
10086 "vec3 clearskies_sky( vec3 ray_dir )\n"
10088 " ray_dir.y = abs( ray_dir.y );\n"
10089 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
10092 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
10093 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
10094 " float sun_shape = pow( sun_size, 2000.0 );\n"
10095 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
10097 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
10098 " sun_colour *= sun_shape;\n"
10101 " float star = 0.0;\n"
10102 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
10104 " if( star_blend > 0.001 ){\n"
10105 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
10106 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
10107 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
10111 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
10112 " return composite;\n"
10115 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
10117 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
10119 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
10120 " g_sunset_phase );\n"
10122 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
10123 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
10124 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
10125 " ) * g_sun_colour.rgb * g_day_phase;\n"
10127 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
10128 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
10129 " g_sunset_phase );\n"
10131 " return ambient + (light_sun + sky_reflection) * shadow;\n"
10136 "float world_depth_sample( vec3 pos )\n"
10138 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
10139 " return texture( g_world_depth, depth_coord ).r;\n"
10142 "float world_water_depth( vec3 pos )\n"
10144 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
10145 " return world_depth_sample( pos ) - ref_depth;\n"
10148 "float shadow_sample( vec3 co ){\n"
10149 " float height_sample = world_depth_sample( co );\n"
10151 " float fdelta = height_sample - co.y;\n"
10152 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
10155 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
10156 " if( g_shadow_samples == 0 ){\n"
10160 " float fspread = g_shadow_spread;\n"
10161 " float flength = g_shadow_length;\n"
10163 " float famt = 0.0;\n"
10164 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
10165 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
10166 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
10167 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
10169 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
10170 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
10171 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
10172 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
10174 " return 1.0 - famt;\n"
10177 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
10179 " vec3 specdir = reflect( -dir, wnormal );\n"
10180 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
10183 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
10184 " float dist = pow(fdist*0.0010,0.78);\n"
10185 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
10188 "vec3 scene_calculate_light( int light_index, \n"
10189 " vec3 halfview, vec3 co, vec3 normal )\n"
10191 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
10192 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
10193 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
10195 " vec3 light_delta = light_co.xyz-co;\n"
10196 " float dist2 = dot(light_delta,light_delta);\n"
10198 " light_delta = normalize( light_delta );\n"
10200 " float quadratic = dist2*100.0;\n"
10201 " float attenuation = 1.0/( 1.0 + quadratic );\n"
10202 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
10204 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
10206 " if( light_dir.w < 0.999999 ){\n"
10207 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
10208 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
10211 " return light_colour.rgb * attenuation * falloff \n"
10212 " * step( g_day_phase, light_colour.w );\n"
10215 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
10216 " vec3 halfview, vec3 co, vec3 normal )\n"
10218 " uint light_count = packed_index & 0x3u;\n"
10220 " vec3 l = vec3(0.0);\n"
10222 " if( light_count >= 1u ){\n"
10223 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
10224 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
10225 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
10227 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
10229 " if( light_count >= 2u ){\n"
10230 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
10232 " if( light_count >= 3u ){\n"
10233 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
10241 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
10242 " float light_mask )\n"
10244 " if( g_light_preview == 1 )\n"
10245 " diffuse = vec3(0.75);\n"
10248 " vec3 halfview = uCamera - co;\n"
10249 " float fdist = length(halfview);\n"
10250 " halfview /= fdist;\n"
10252 " float world_shadow = newlight_compute_sun_shadow( \n"
10253 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
10255 " vec3 total_light = clearskies_lighting( \n"
10256 " normal, min( light_mask, world_shadow ), halfview );\n"
10258 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
10259 " cube_coord = floor( cube_coord );\n"
10261 " if( g_debug_indices == 1 )\n"
10263 " return rand33(cube_coord);\n"
10266 " if( g_debug_complexity == 1 )\n"
10268 " ivec3 coord = ivec3( cube_coord );\n"
10269 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
10271 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
10272 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
10275 " // FIXME: this coord should absolutely must be clamped!\n"
10277 " ivec3 coord = ivec3( cube_coord );\n"
10278 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
10280 " total_light += \n"
10281 " scene_calculate_packed_light_patch( index_sample.x,\n"
10282 " halfview, co, normal ) \n"
10284 " total_light += \n"
10285 " scene_calculate_packed_light_patch( index_sample.y,\n"
10286 " halfview, co, normal )\n"
10289 " // Take a section of the sky function to give us a matching fog colour\n"
10291 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
10292 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
10293 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
10294 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
10296 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
10297 " sun_colour *= sun_shape;\n"
10299 " fog_colour += sun_colour;\n"
10300 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
10305 "const float k_motion_lerp_amount = 0.01;\n"
10309 "layout (location = 1) out vec2 oMotionVec;\n"
10311 "in vec3 aMotionVec0;\n"
10312 "in vec3 aMotionVec1;\n"
10314 "void compute_motion_vectors()\n"
10316 " // Write motion vectors\n"
10317 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10318 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10320 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10327 " compute_motion_vectors();\n"
10329 " vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n"
10330 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
10331 " vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
10333 " oColour = vec4( composite, 1.0 );\n"
10338 GLuint _uniform_model_entity_uMdl
;
10339 GLuint _uniform_model_entity_uPv
;
10340 GLuint _uniform_model_entity_uPvmPrev
;
10341 GLuint _uniform_model_entity_uTexMain
;
10342 GLuint _uniform_model_entity_uCamera
;
10343 GLuint _uniform_model_entity_g_world_depth
;
10344 GLuint _uniform_model_entity_uLightsArray
;
10345 GLuint _uniform_model_entity_uLightsIndex
;
10346 #include "shaders/model_gate.h"
10347 struct vg_shader _shader_model_gate
= {
10348 .name
= "model_gate",
10351 .orig_file
= "shaders/model.vs",
10353 "layout (location=0) in vec3 a_co;\n"
10354 "layout (location=1) in vec3 a_norm;\n"
10355 "layout (location=2) in vec2 a_uv;\n"
10356 "layout (location=3) in vec4 a_colour;\n"
10357 "layout (location=4) in vec4 a_weights;\n"
10358 "layout (location=5) in ivec4 a_groups;\n"
10361 "const float k_motion_lerp_amount = 0.01;\n"
10365 "out vec3 aMotionVec0;\n"
10366 "out vec3 aMotionVec1;\n"
10368 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10370 " // This magically solves some artifacting errors!\n"
10372 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10374 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10375 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10380 "uniform mat4x3 uMdl;\n"
10381 "uniform mat4 uPv;\n"
10382 "uniform mat4 uPvmPrev;\n"
10384 "out vec4 aColour;\n"
10386 "out vec3 aNorm;\n"
10388 "out vec3 aWorldCo;\n"
10392 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
10393 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
10394 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
10396 " vs_motion_out( vproj0, vproj1 );\n"
10398 " gl_Position = vproj0;\n"
10399 " aWorldCo = world_pos0;\n"
10400 " aColour = a_colour;\n"
10402 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
10408 .orig_file
= "shaders/model_gate_lq.fs",
10410 "out vec4 FragColor;\n"
10412 "uniform float uTime;\n"
10413 "uniform vec3 uCam;\n"
10414 "uniform vec2 uInvRes;\n"
10415 "uniform vec4 uColour;\n"
10423 " vec2 ssuv = gl_FragCoord.xy;\n"
10424 " float opacity = 1.0-smoothstep(0.0,1.0,aUv.y+uColour.a);\n"
10426 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10427 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10429 " if( opacity+dither<0.5 )\n"
10432 " FragColor = uColour;\n"
10437 GLuint _uniform_model_gate_uMdl
;
10438 GLuint _uniform_model_gate_uPv
;
10439 GLuint _uniform_model_gate_uPvmPrev
;
10440 GLuint _uniform_model_gate_uTime
;
10441 GLuint _uniform_model_gate_uCam
;
10442 GLuint _uniform_model_gate_uInvRes
;
10443 GLuint _uniform_model_gate_uColour
;
10444 #include "shaders/model_gate_unlinked.h"
10445 struct vg_shader _shader_model_gate_unlinked
= {
10446 .name
= "model_gate_unlinked",
10449 .orig_file
= "shaders/model.vs",
10451 "layout (location=0) in vec3 a_co;\n"
10452 "layout (location=1) in vec3 a_norm;\n"
10453 "layout (location=2) in vec2 a_uv;\n"
10454 "layout (location=3) in vec4 a_colour;\n"
10455 "layout (location=4) in vec4 a_weights;\n"
10456 "layout (location=5) in ivec4 a_groups;\n"
10459 "const float k_motion_lerp_amount = 0.01;\n"
10463 "out vec3 aMotionVec0;\n"
10464 "out vec3 aMotionVec1;\n"
10466 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10468 " // This magically solves some artifacting errors!\n"
10470 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10472 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10473 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10478 "uniform mat4x3 uMdl;\n"
10479 "uniform mat4 uPv;\n"
10480 "uniform mat4 uPvmPrev;\n"
10482 "out vec4 aColour;\n"
10484 "out vec3 aNorm;\n"
10486 "out vec3 aWorldCo;\n"
10490 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
10491 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
10492 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
10494 " vs_motion_out( vproj0, vproj1 );\n"
10496 " gl_Position = vproj0;\n"
10497 " aWorldCo = world_pos0;\n"
10498 " aColour = a_colour;\n"
10500 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
10506 .orig_file
= "shaders/model_gate_unlinked.fs",
10508 "out vec4 FragColor;\n"
10510 "uniform float uTime;\n"
10511 "uniform vec3 uCam;\n"
10512 "uniform vec4 uColour;\n"
10519 "const float k_motion_lerp_amount = 0.01;\n"
10523 "layout (location = 1) out vec2 oMotionVec;\n"
10525 "in vec3 aMotionVec0;\n"
10526 "in vec3 aMotionVec1;\n"
10528 "void compute_motion_vectors()\n"
10530 " // Write motion vectors\n"
10531 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10532 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10534 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10539 "const int NOISE_LOOP = 3;\n"
10540 "vec3 digital_noise( uvec3 iuv ){\n"
10541 " iuv *=uvec3(8,2524,7552);\n"
10542 " for( int i=0; i<NOISE_LOOP; i++ )\n"
10543 " iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
10544 " return vec3(iuv)*(1.0/float(0xffffffffU));\n"
10547 "vec2 rand_hash22( vec2 p ){\n"
10548 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
10549 " p3 += dot(p3, p3.yzx+19.19);\n"
10550 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
10554 " compute_motion_vectors();\n"
10556 " vec2 ssuv = gl_FragCoord.xy;\n"
10557 " float grad = 1.0-aUv.y*0.1;\n"
10558 " float opacity = rand_hash22( vec2(floor(aUv.y*100.0),floor(aCo.z*10.0+uTime*40.0)) ).r*grad;\n"
10560 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10561 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10563 " if( opacity<0.9 )\n"
10566 " FragColor = vec4(0.7,0.5,0.5,1.0);\n"
10571 GLuint _uniform_model_gate_unlinked_uMdl
;
10572 GLuint _uniform_model_gate_unlinked_uPv
;
10573 GLuint _uniform_model_gate_unlinked_uPvmPrev
;
10574 GLuint _uniform_model_gate_unlinked_uTime
;
10575 GLuint _uniform_model_gate_unlinked_uCam
;
10576 GLuint _uniform_model_gate_unlinked_uColour
;
10577 #include "shaders/model_font.h"
10578 struct vg_shader _shader_model_font
= {
10579 .name
= "model_font",
10582 .orig_file
= "shaders/model_font.vs",
10584 "layout (location=0) in vec3 a_co;\n"
10585 "layout (location=1) in vec3 a_norm;\n"
10586 "layout (location=2) in vec2 a_uv;\n"
10589 "const float k_motion_lerp_amount = 0.01;\n"
10593 "out vec3 aMotionVec0;\n"
10594 "out vec3 aMotionVec1;\n"
10596 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10598 " // This magically solves some artifacting errors!\n"
10600 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10602 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10603 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10608 "uniform mat4x3 uMdl;\n"
10609 "uniform mat4 uPv;\n"
10610 "uniform mat4 uPvmPrev;\n"
10611 "uniform vec4 uOffset;\n"
10614 "out vec4 aNorm;\n"
10616 "out vec3 aWorldCo;\n"
10620 " vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
10621 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
10622 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
10623 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
10625 " vs_motion_out( vproj0, vproj1 );\n"
10627 " gl_Position = vproj0;\n"
10630 " aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
10632 " aWorldCo = world_pos0;\n"
10637 .orig_file
= "shaders/model_font.fs",
10639 "layout (location = 0) out vec4 oColour;\n"
10641 "uniform sampler2D uTexMain;\n"
10642 "uniform vec4 uColour;\n"
10649 "const float k_motion_lerp_amount = 0.01;\n"
10653 "layout (location = 1) out vec2 oMotionVec;\n"
10655 "in vec3 aMotionVec0;\n"
10656 "in vec3 aMotionVec1;\n"
10658 "void compute_motion_vectors()\n"
10660 " // Write motion vectors\n"
10661 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10662 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10664 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10669 "uniform sampler2D uTexSceneDepth;\n"
10670 "uniform vec3 uInverseRatioDepth;\n"
10671 "uniform vec3 uInverseRatioMain;\n"
10672 "uniform int uDepthMode;\n"
10673 "uniform float uDitherCutoff;\n"
10675 "float linear_depth( float depth, float near, float far ) {\n"
10676 " float z = depth * 2.0 - 1.0;\n"
10677 " return (2.0 * near * far) / (far + near - z * (far - near)); \n"
10680 "void depth_compare_dither()\n"
10682 " if( uDepthMode == 1 )\n"
10684 " vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
10685 " * uInverseRatioDepth.xy;\n"
10686 " float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
10687 " float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
10689 " back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
10690 " float diff = back_depth - front_depth;\n"
10692 " vec2 ssuv = gl_FragCoord.xy;\n"
10693 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10694 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10696 " if( step(0.0,diff)+dither<0.3 )\n"
10700 " if( uDepthMode == 2 )\n"
10702 " vec2 ssuv = gl_FragCoord.xy;\n"
10703 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10704 " float dither = fract( vDither.g / 71.0 );\n"
10705 " if( dither<uDitherCutoff ) discard;\n"
10712 " depth_compare_dither();\n"
10713 " compute_motion_vectors();\n"
10714 " oColour = texture( uTexMain, aUv ) * uColour;\n"
10719 GLuint _uniform_model_font_uMdl
;
10720 GLuint _uniform_model_font_uPv
;
10721 GLuint _uniform_model_font_uPvmPrev
;
10722 GLuint _uniform_model_font_uOffset
;
10723 GLuint _uniform_model_font_uTexMain
;
10724 GLuint _uniform_model_font_uColour
;
10725 GLuint _uniform_model_font_uTexSceneDepth
;
10726 GLuint _uniform_model_font_uInverseRatioDepth
;
10727 GLuint _uniform_model_font_uInverseRatioMain
;
10728 GLuint _uniform_model_font_uDepthMode
;
10729 GLuint _uniform_model_font_uDitherCutoff
;
10730 #include "shaders/particle.h"
10731 struct vg_shader _shader_particle
= {
10732 .name
= "particle",
10735 .orig_file
= "shaders/particle.vs",
10737 "layout (location=0) in vec3 a_co;\n"
10738 "layout (location=1) in vec4 a_colour;\n"
10741 "const float k_motion_lerp_amount = 0.01;\n"
10745 "out vec3 aMotionVec0;\n"
10746 "out vec3 aMotionVec1;\n"
10748 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10750 " // This magically solves some artifacting errors!\n"
10752 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10754 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10755 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10760 "uniform mat4 uPv;\n"
10761 "uniform mat4 uPvPrev;\n"
10763 "out vec4 aColour;\n"
10766 " vec4 vproj0 = uPv * vec4( a_co, 1.0 );\n"
10767 " vec4 vproj1 = uPvPrev * vec4( a_co, 1.0 );\n"
10768 " vs_motion_out( vproj0, vproj1 );\n"
10770 " gl_Position = vproj0;\n"
10771 " aColour = a_colour;\n"
10776 .orig_file
= "shaders/particle.fs",
10778 "layout (location = 0) out vec4 oColour;\n"
10779 "in vec4 aColour;\n"
10782 "const float k_motion_lerp_amount = 0.01;\n"
10786 "layout (location = 1) out vec2 oMotionVec;\n"
10788 "in vec3 aMotionVec0;\n"
10789 "in vec3 aMotionVec1;\n"
10791 "void compute_motion_vectors()\n"
10793 " // Write motion vectors\n"
10794 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10795 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10797 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10803 " compute_motion_vectors();\n"
10805 " //vec2 ssuv = gl_FragCoord.xy;\n"
10806 " //vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10807 " //float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10809 " //if( vsamplemain.a+dither<0.5 )\n"
10812 " oColour = aColour;\n"
10817 GLuint _uniform_particle_uPv
;
10818 GLuint _uniform_particle_uPvPrev
;
10819 #include "shaders/trail.h"
10820 struct vg_shader _shader_trail
= {
10824 .orig_file
= "shaders/trail.vs",
10826 "layout (location=0) in vec4 a_co;\n"
10829 "const float k_motion_lerp_amount = 0.01;\n"
10833 "out vec3 aMotionVec0;\n"
10834 "out vec3 aMotionVec1;\n"
10836 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10838 " // This magically solves some artifacting errors!\n"
10840 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10842 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10843 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10848 "uniform mat4 uPv;\n"
10849 "uniform mat4 uPvPrev;\n"
10851 "out float aAlpha;\n"
10854 " vec4 vproj0 = uPv * vec4( a_co.xyz, 1.0 );\n"
10855 " vec4 vproj1 = uPvPrev * vec4( a_co.xyz, 1.0 );\n"
10856 " vs_motion_out( vproj0, vproj1 );\n"
10858 " gl_Position = vproj0;\n"
10859 " aAlpha = a_co.w;\n"
10864 .orig_file
= "shaders/trail.fs",
10866 "layout (location = 0) out vec4 oColour;\n"
10867 "in float aAlpha;\n"
10868 "uniform vec4 uColour;\n"
10871 "const float k_motion_lerp_amount = 0.01;\n"
10875 "layout (location = 1) out vec2 oMotionVec;\n"
10877 "in vec3 aMotionVec0;\n"
10878 "in vec3 aMotionVec1;\n"
10880 "void compute_motion_vectors()\n"
10882 " // Write motion vectors\n"
10883 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10884 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10886 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10892 " compute_motion_vectors();\n"
10894 " vec2 ssuv = gl_FragCoord.xy;\n"
10895 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10896 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10898 " if( aAlpha+dither<0.5 )\n"
10901 " oColour = vec4( uColour.rgb, uColour.a * aAlpha );\n"
10906 GLuint _uniform_trail_uPv
;
10907 GLuint _uniform_trail_uPvPrev
;
10908 GLuint _uniform_trail_uColour
;
10909 #include "shaders/blit.h"
10910 struct vg_shader _shader_blit
= {
10914 .orig_file
= "shaders/blit.vs",
10916 "layout (location=0) in vec2 a_co;\n"
10919 "uniform vec2 uInverseRatio;\n"
10923 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
10924 " aUv = a_co * uInverseRatio;\n"
10929 .orig_file
= "shaders/blit.fs",
10931 "out vec4 FragColor;\n"
10932 "uniform sampler2D uTexMain;\n"
10936 "float kPi = 3.14159265358979;\n"
10938 "vec2 fisheye_distort(vec2 xy)\n"
10940 " float aperture = 1350.0;\n"
10941 " float apertureHalf = 0.5 * aperture * (kPi / 180.0);\n"
10942 " float maxFactor = sin(apertureHalf);\n"
10945 " float d = length(xy);\n"
10946 " if(d < (2.0-maxFactor))\n"
10948 " d = length(xy * maxFactor);\n"
10949 " float z = sqrt(1.0 - d * d);\n"
10950 " float r = atan(d, z) / kPi;\n"
10951 " float phi = atan(xy.y, xy.x);\n"
10953 " uv.x = r * cos(phi) + 0.5;\n"
10954 " uv.y = r * sin(phi) + 0.5;\n"
10958 " uv = 0.5*xy + 0.5;\n"
10967 " vec2 vwarp = 2.0*aUv - 1.0;\n"
10968 " vwarp = fisheye_distort( vwarp );\n"
10970 " FragColor = texture( uTexMain, aUv );\n"
10975 GLuint _uniform_blit_uInverseRatio
;
10976 GLuint _uniform_blit_uTexMain
;
10977 #include "shaders/blitblur.h"
10978 struct vg_shader _shader_blitblur
= {
10979 .name
= "blitblur",
10982 .orig_file
= "shaders/blit.vs",
10984 "layout (location=0) in vec2 a_co;\n"
10987 "uniform vec2 uInverseRatio;\n"
10991 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
10992 " aUv = a_co * uInverseRatio;\n"
10997 .orig_file
= "shaders/blitblur.fs",
10999 "out vec4 FragColor;\n"
11000 "uniform sampler2D uTexMain;\n"
11001 "uniform sampler2D uTexMotion;\n"
11002 "uniform float uBlurStrength;\n"
11003 "uniform vec2 uOverrideDir;\n"
11004 "uniform float uTime;\n"
11005 "uniform float uGlitchStrength;\n"
11006 "uniform vec2 uClampUv;\n"
11010 "vec2 rand_hash22( vec2 p ){\n"
11011 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
11012 " p3 += dot(p3, p3.yzx+19.19);\n"
11013 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
11016 "const int NOISE_LOOP = 3;\n"
11017 "vec3 digital_noise( uvec3 iuv ){\n"
11018 " iuv *=uvec3(8,2524,7552);\n"
11019 " for( int i=0; i<NOISE_LOOP; i++ )\n"
11020 " iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
11021 " return vec3(iuv)*(1.0/float(0xffffffffU));\n"
11025 " vec2 vuv = aUv; \n"
11027 " //if( uGlitchStrength > 0.0 ){\n"
11028 " // uvec3 p = uvec3( gl_FragCoord.xy, uint(uTime*30.0) );\n"
11029 " // vec2 g = digital_noise(p).xy;\n"
11030 " // vuv = aUv + g.xy*uGlitchStrength - uGlitchStrength*0.5;\n"
11033 " vec2 vrand = rand_hash22( vuv ) * 2.0 - vec2(1.0);\n"
11034 " vec2 vrand1 = rand_hash22( vrand ) * 2.0 - vec2(1.0);\n"
11036 " vec2 vdir = texture( uTexMotion, vuv ).xy * uBlurStrength + uOverrideDir;\n"
11038 " vec4 vcolour0 = texture( uTexMain, min(vuv + vdir*vrand.x,uClampUv) );\n"
11039 " vec4 vcolour1 = texture( uTexMain, min(vuv + vdir*vrand.y,uClampUv) );\n"
11040 " vec4 vcolour2 = texture( uTexMain, min(vuv + vdir*vrand1.x,uClampUv) );\n"
11041 " vec4 vcolour3 = texture( uTexMain, min(vuv + vdir*vrand1.y,uClampUv) );\n"
11043 " FragColor = ( vcolour0 + vcolour1 + vcolour2 + vcolour3 ) * 0.25;\n"
11048 GLuint _uniform_blitblur_uInverseRatio
;
11049 GLuint _uniform_blitblur_uTexMain
;
11050 GLuint _uniform_blitblur_uTexMotion
;
11051 GLuint _uniform_blitblur_uBlurStrength
;
11052 GLuint _uniform_blitblur_uOverrideDir
;
11053 GLuint _uniform_blitblur_uTime
;
11054 GLuint _uniform_blitblur_uGlitchStrength
;
11055 GLuint _uniform_blitblur_uClampUv
;
11056 #include "shaders/blitcolour.h"
11057 struct vg_shader _shader_blitcolour
= {
11058 .name
= "blitcolour",
11061 .orig_file
= "shaders/blit.vs",
11063 "layout (location=0) in vec2 a_co;\n"
11066 "uniform vec2 uInverseRatio;\n"
11070 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
11071 " aUv = a_co * uInverseRatio;\n"
11076 .orig_file
= "shaders/colour.fs",
11078 "out vec4 FragColor;\n"
11079 "uniform vec4 uColour;\n"
11085 " FragColor = uColour;\n"
11090 GLuint _uniform_blitcolour_uInverseRatio
;
11091 GLuint _uniform_blitcolour_uColour
;
11092 #include "shaders/blit_transition.h"
11093 struct vg_shader _shader_blit_transition
= {
11094 .name
= "blit_transition",
11097 .orig_file
= "shaders/blit.vs",
11099 "layout (location=0) in vec2 a_co;\n"
11102 "uniform vec2 uInverseRatio;\n"
11106 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
11107 " aUv = a_co * uInverseRatio;\n"
11112 .orig_file
= "shaders/blit_transition.fs",
11114 "out vec4 FragColor;\n"
11116 "uniform float uT;\n"
11119 " float d = uT + distance( aUv, vec2(0.5,0.5) );\n"
11121 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), gl_FragCoord.xy) );\n"
11122 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
11124 " if( d+dither < -0.5 )\n"
11127 " FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n"
11132 GLuint _uniform_blit_transition_uInverseRatio
;
11133 GLuint _uniform_blit_transition_uT
;
11134 #include "shaders/routeui.h"
11135 struct vg_shader _shader_routeui
= {
11139 .orig_file
= "shaders/routeui.vs",
11141 "layout (location=0) in vec2 a_co;\n"
11143 "uniform vec4 uOffset;\n"
11147 " vec2 vpos = a_co * uOffset.zw + uOffset.xy;\n"
11148 " gl_Position = vec4(vpos,0.0,1.0);\n"
11153 .orig_file
= "shaders/routeui.fs",
11155 "out vec4 FragColor;\n"
11157 "uniform vec4 uColour;\n"
11161 " FragColor = uColour;\n"
11166 GLuint _uniform_routeui_uOffset
;
11167 GLuint _uniform_routeui_uColour
;
11170 void vg_auto_shader_link(void)
11172 _uniform_scene_standard_uMdl
= glGetUniformLocation( _shader_scene_standard
.id
, "uMdl" );
11173 _uniform_scene_standard_uPv
= glGetUniformLocation( _shader_scene_standard
.id
, "uPv" );
11174 _uniform_scene_standard_uPvmPrev
= glGetUniformLocation( _shader_scene_standard
.id
, "uPvmPrev" );
11175 _uniform_scene_standard_uTexGarbage
= glGetUniformLocation( _shader_scene_standard
.id
, "uTexGarbage" );
11176 _uniform_scene_standard_uTexMain
= glGetUniformLocation( _shader_scene_standard
.id
, "uTexMain" );
11177 _uniform_scene_standard_uCamera
= glGetUniformLocation( _shader_scene_standard
.id
, "uCamera" );
11178 _uniform_scene_standard_uPlane
= glGetUniformLocation( _shader_scene_standard
.id
, "uPlane" );
11179 _uniform_scene_standard_g_world_depth
= glGetUniformLocation( _shader_scene_standard
.id
, "g_world_depth" );
11180 _uniform_scene_standard_uLightsArray
= glGetUniformLocation( _shader_scene_standard
.id
, "uLightsArray" );
11181 _uniform_scene_standard_uLightsIndex
= glGetUniformLocation( _shader_scene_standard
.id
, "uLightsIndex" );
11182 _uniform_scene_standard_alphatest_uMdl
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uMdl" );
11183 _uniform_scene_standard_alphatest_uPv
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uPv" );
11184 _uniform_scene_standard_alphatest_uPvmPrev
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uPvmPrev" );
11185 _uniform_scene_standard_alphatest_uTexGarbage
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uTexGarbage" );
11186 _uniform_scene_standard_alphatest_uTexMain
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uTexMain" );
11187 _uniform_scene_standard_alphatest_uCamera
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uCamera" );
11188 _uniform_scene_standard_alphatest_uPlane
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uPlane" );
11189 _uniform_scene_standard_alphatest_g_world_depth
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "g_world_depth" );
11190 _uniform_scene_standard_alphatest_uLightsArray
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uLightsArray" );
11191 _uniform_scene_standard_alphatest_uLightsIndex
= glGetUniformLocation( _shader_scene_standard_alphatest
.id
, "uLightsIndex" );
11192 _uniform_scene_foliage_uMdl
= glGetUniformLocation( _shader_scene_foliage
.id
, "uMdl" );
11193 _uniform_scene_foliage_uPv
= glGetUniformLocation( _shader_scene_foliage
.id
, "uPv" );
11194 _uniform_scene_foliage_uPvmPrev
= glGetUniformLocation( _shader_scene_foliage
.id
, "uPvmPrev" );
11195 _uniform_scene_foliage_uTime
= glGetUniformLocation( _shader_scene_foliage
.id
, "uTime" );
11196 _uniform_scene_foliage_uTexGarbage
= glGetUniformLocation( _shader_scene_foliage
.id
, "uTexGarbage" );
11197 _uniform_scene_foliage_uTexMain
= glGetUniformLocation( _shader_scene_foliage
.id
, "uTexMain" );
11198 _uniform_scene_foliage_uCamera
= glGetUniformLocation( _shader_scene_foliage
.id
, "uCamera" );
11199 _uniform_scene_foliage_uPlane
= glGetUniformLocation( _shader_scene_foliage
.id
, "uPlane" );
11200 _uniform_scene_foliage_g_world_depth
= glGetUniformLocation( _shader_scene_foliage
.id
, "g_world_depth" );
11201 _uniform_scene_foliage_uLightsArray
= glGetUniformLocation( _shader_scene_foliage
.id
, "uLightsArray" );
11202 _uniform_scene_foliage_uLightsIndex
= glGetUniformLocation( _shader_scene_foliage
.id
, "uLightsIndex" );
11203 _uniform_scene_override_uMdl
= glGetUniformLocation( _shader_scene_override
.id
, "uMdl" );
11204 _uniform_scene_override_uPv
= glGetUniformLocation( _shader_scene_override
.id
, "uPv" );
11205 _uniform_scene_override_uPvmPrev
= glGetUniformLocation( _shader_scene_override
.id
, "uPvmPrev" );
11206 _uniform_scene_override_uNormalMtx
= glGetUniformLocation( _shader_scene_override
.id
, "uNormalMtx" );
11207 _uniform_scene_override_uTexGarbage
= glGetUniformLocation( _shader_scene_override
.id
, "uTexGarbage" );
11208 _uniform_scene_override_uTexMain
= glGetUniformLocation( _shader_scene_override
.id
, "uTexMain" );
11209 _uniform_scene_override_uCamera
= glGetUniformLocation( _shader_scene_override
.id
, "uCamera" );
11210 _uniform_scene_override_uPlane
= glGetUniformLocation( _shader_scene_override
.id
, "uPlane" );
11211 _uniform_scene_override_uPlayerPos
= glGetUniformLocation( _shader_scene_override
.id
, "uPlayerPos" );
11212 _uniform_scene_override_uSpawnPos
= glGetUniformLocation( _shader_scene_override
.id
, "uSpawnPos" );
11213 _uniform_scene_override_uAlphatest
= glGetUniformLocation( _shader_scene_override
.id
, "uAlphatest" );
11214 _uniform_scene_override_uMapInfo
= glGetUniformLocation( _shader_scene_override
.id
, "uMapInfo" );
11215 _uniform_scene_override_g_world_depth
= glGetUniformLocation( _shader_scene_override
.id
, "g_world_depth" );
11216 _uniform_scene_override_uLightsArray
= glGetUniformLocation( _shader_scene_override
.id
, "uLightsArray" );
11217 _uniform_scene_override_uLightsIndex
= glGetUniformLocation( _shader_scene_override
.id
, "uLightsIndex" );
11218 _uniform_scene_fxglow_uMdl
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uMdl" );
11219 _uniform_scene_fxglow_uPv
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uPv" );
11220 _uniform_scene_fxglow_uPvmPrev
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uPvmPrev" );
11221 _uniform_scene_fxglow_uUvOffset
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uUvOffset" );
11222 _uniform_scene_fxglow_uTexMain
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uTexMain" );
11223 _uniform_scene_fxglow_uCamera
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uCamera" );
11224 _uniform_scene_fxglow_g_world_depth
= glGetUniformLocation( _shader_scene_fxglow
.id
, "g_world_depth" );
11225 _uniform_scene_fxglow_uLightsArray
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uLightsArray" );
11226 _uniform_scene_fxglow_uLightsIndex
= glGetUniformLocation( _shader_scene_fxglow
.id
, "uLightsIndex" );
11227 _uniform_scene_vertex_blend_uMdl
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uMdl" );
11228 _uniform_scene_vertex_blend_uPv
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uPv" );
11229 _uniform_scene_vertex_blend_uPvmPrev
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uPvmPrev" );
11230 _uniform_scene_vertex_blend_uTexGarbage
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uTexGarbage" );
11231 _uniform_scene_vertex_blend_uTexGradients
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uTexGradients" );
11232 _uniform_scene_vertex_blend_uCamera
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uCamera" );
11233 _uniform_scene_vertex_blend_g_world_depth
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "g_world_depth" );
11234 _uniform_scene_vertex_blend_uLightsArray
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uLightsArray" );
11235 _uniform_scene_vertex_blend_uLightsIndex
= glGetUniformLocation( _shader_scene_vertex_blend
.id
, "uLightsIndex" );
11236 _uniform_scene_terrain_uMdl
= glGetUniformLocation( _shader_scene_terrain
.id
, "uMdl" );
11237 _uniform_scene_terrain_uPv
= glGetUniformLocation( _shader_scene_terrain
.id
, "uPv" );
11238 _uniform_scene_terrain_uPvmPrev
= glGetUniformLocation( _shader_scene_terrain
.id
, "uPvmPrev" );
11239 _uniform_scene_terrain_uTexGarbage
= glGetUniformLocation( _shader_scene_terrain
.id
, "uTexGarbage" );
11240 _uniform_scene_terrain_uTexGradients
= glGetUniformLocation( _shader_scene_terrain
.id
, "uTexGradients" );
11241 _uniform_scene_terrain_uCamera
= glGetUniformLocation( _shader_scene_terrain
.id
, "uCamera" );
11242 _uniform_scene_terrain_uSandColour
= glGetUniformLocation( _shader_scene_terrain
.id
, "uSandColour" );
11243 _uniform_scene_terrain_uBlendOffset
= glGetUniformLocation( _shader_scene_terrain
.id
, "uBlendOffset" );
11244 _uniform_scene_terrain_g_world_depth
= glGetUniformLocation( _shader_scene_terrain
.id
, "g_world_depth" );
11245 _uniform_scene_terrain_uLightsArray
= glGetUniformLocation( _shader_scene_terrain
.id
, "uLightsArray" );
11246 _uniform_scene_terrain_uLightsIndex
= glGetUniformLocation( _shader_scene_terrain
.id
, "uLightsIndex" );
11247 _uniform_scene_route_uMdl
= glGetUniformLocation( _shader_scene_route
.id
, "uMdl" );
11248 _uniform_scene_route_uPv
= glGetUniformLocation( _shader_scene_route
.id
, "uPv" );
11249 _uniform_scene_route_uPvmPrev
= glGetUniformLocation( _shader_scene_route
.id
, "uPvmPrev" );
11250 _uniform_scene_route_uNormalMtx
= glGetUniformLocation( _shader_scene_route
.id
, "uNormalMtx" );
11251 _uniform_scene_route_uTexGarbage
= glGetUniformLocation( _shader_scene_route
.id
, "uTexGarbage" );
11252 _uniform_scene_route_uTexGradients
= glGetUniformLocation( _shader_scene_route
.id
, "uTexGradients" );
11253 _uniform_scene_route_uCamera
= glGetUniformLocation( _shader_scene_route
.id
, "uCamera" );
11254 _uniform_scene_route_uColour
= glGetUniformLocation( _shader_scene_route
.id
, "uColour" );
11255 _uniform_scene_route_g_world_depth
= glGetUniformLocation( _shader_scene_route
.id
, "g_world_depth" );
11256 _uniform_scene_route_uLightsArray
= glGetUniformLocation( _shader_scene_route
.id
, "uLightsArray" );
11257 _uniform_scene_route_uLightsIndex
= glGetUniformLocation( _shader_scene_route
.id
, "uLightsIndex" );
11258 _uniform_scene_depth_uMdl
= glGetUniformLocation( _shader_scene_depth
.id
, "uMdl" );
11259 _uniform_scene_depth_uPv
= glGetUniformLocation( _shader_scene_depth
.id
, "uPv" );
11260 _uniform_scene_depth_uPvmPrev
= glGetUniformLocation( _shader_scene_depth
.id
, "uPvmPrev" );
11261 _uniform_scene_depth_uCamera
= glGetUniformLocation( _shader_scene_depth
.id
, "uCamera" );
11262 _uniform_scene_depth_uBoard0
= glGetUniformLocation( _shader_scene_depth
.id
, "uBoard0" );
11263 _uniform_scene_depth_uBoard1
= glGetUniformLocation( _shader_scene_depth
.id
, "uBoard1" );
11264 _uniform_scene_depth_g_world_depth
= glGetUniformLocation( _shader_scene_depth
.id
, "g_world_depth" );
11265 _uniform_scene_depth_uLightsArray
= glGetUniformLocation( _shader_scene_depth
.id
, "uLightsArray" );
11266 _uniform_scene_depth_uLightsIndex
= glGetUniformLocation( _shader_scene_depth
.id
, "uLightsIndex" );
11267 _uniform_scene_position_uMdl
= glGetUniformLocation( _shader_scene_position
.id
, "uMdl" );
11268 _uniform_scene_position_uPv
= glGetUniformLocation( _shader_scene_position
.id
, "uPv" );
11269 _uniform_scene_position_uPvmPrev
= glGetUniformLocation( _shader_scene_position
.id
, "uPvmPrev" );
11270 _uniform_scene_position_uCamera
= glGetUniformLocation( _shader_scene_position
.id
, "uCamera" );
11271 _uniform_scene_position_uBoard0
= glGetUniformLocation( _shader_scene_position
.id
, "uBoard0" );
11272 _uniform_scene_position_uBoard1
= glGetUniformLocation( _shader_scene_position
.id
, "uBoard1" );
11273 _uniform_scene_position_g_world_depth
= glGetUniformLocation( _shader_scene_position
.id
, "g_world_depth" );
11274 _uniform_scene_position_uLightsArray
= glGetUniformLocation( _shader_scene_position
.id
, "uLightsArray" );
11275 _uniform_scene_position_uLightsIndex
= glGetUniformLocation( _shader_scene_position
.id
, "uLightsIndex" );
11276 _uniform_scene_cubemapped_uMdl
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uMdl" );
11277 _uniform_scene_cubemapped_uPv
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uPv" );
11278 _uniform_scene_cubemapped_uPvmPrev
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uPvmPrev" );
11279 _uniform_scene_cubemapped_uTexGarbage
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uTexGarbage" );
11280 _uniform_scene_cubemapped_uTexMain
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uTexMain" );
11281 _uniform_scene_cubemapped_uTexCubemap
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uTexCubemap" );
11282 _uniform_scene_cubemapped_uCamera
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uCamera" );
11283 _uniform_scene_cubemapped_uPlane
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uPlane" );
11284 _uniform_scene_cubemapped_uColour
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uColour" );
11285 _uniform_scene_cubemapped_g_world_depth
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "g_world_depth" );
11286 _uniform_scene_cubemapped_uLightsArray
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uLightsArray" );
11287 _uniform_scene_cubemapped_uLightsIndex
= glGetUniformLocation( _shader_scene_cubemapped
.id
, "uLightsIndex" );
11288 _uniform_scene_water_uMdl
= glGetUniformLocation( _shader_scene_water
.id
, "uMdl" );
11289 _uniform_scene_water_uPv
= glGetUniformLocation( _shader_scene_water
.id
, "uPv" );
11290 _uniform_scene_water_uPvmPrev
= glGetUniformLocation( _shader_scene_water
.id
, "uPvmPrev" );
11291 _uniform_scene_water_uTexMain
= glGetUniformLocation( _shader_scene_water
.id
, "uTexMain" );
11292 _uniform_scene_water_uTexDudv
= glGetUniformLocation( _shader_scene_water
.id
, "uTexDudv" );
11293 _uniform_scene_water_uTexBack
= glGetUniformLocation( _shader_scene_water
.id
, "uTexBack" );
11294 _uniform_scene_water_uInvRes
= glGetUniformLocation( _shader_scene_water
.id
, "uInvRes" );
11295 _uniform_scene_water_uTime
= glGetUniformLocation( _shader_scene_water
.id
, "uTime" );
11296 _uniform_scene_water_uCamera
= glGetUniformLocation( _shader_scene_water
.id
, "uCamera" );
11297 _uniform_scene_water_uSurfaceY
= glGetUniformLocation( _shader_scene_water
.id
, "uSurfaceY" );
11298 _uniform_scene_water_uBoard0
= glGetUniformLocation( _shader_scene_water
.id
, "uBoard0" );
11299 _uniform_scene_water_uBoard1
= glGetUniformLocation( _shader_scene_water
.id
, "uBoard1" );
11300 _uniform_scene_water_uShoreColour
= glGetUniformLocation( _shader_scene_water
.id
, "uShoreColour" );
11301 _uniform_scene_water_uOceanColour
= glGetUniformLocation( _shader_scene_water
.id
, "uOceanColour" );
11302 _uniform_scene_water_g_world_depth
= glGetUniformLocation( _shader_scene_water
.id
, "g_world_depth" );
11303 _uniform_scene_water_uLightsArray
= glGetUniformLocation( _shader_scene_water
.id
, "uLightsArray" );
11304 _uniform_scene_water_uLightsIndex
= glGetUniformLocation( _shader_scene_water
.id
, "uLightsIndex" );
11305 _uniform_scene_water_fast_uMdl
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uMdl" );
11306 _uniform_scene_water_fast_uPv
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uPv" );
11307 _uniform_scene_water_fast_uPvmPrev
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uPvmPrev" );
11308 _uniform_scene_water_fast_uTexDudv
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uTexDudv" );
11309 _uniform_scene_water_fast_uTime
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uTime" );
11310 _uniform_scene_water_fast_uCamera
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uCamera" );
11311 _uniform_scene_water_fast_uSurfaceY
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uSurfaceY" );
11312 _uniform_scene_water_fast_uBoard0
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uBoard0" );
11313 _uniform_scene_water_fast_uBoard1
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uBoard1" );
11314 _uniform_scene_water_fast_uShoreColour
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uShoreColour" );
11315 _uniform_scene_water_fast_uOceanColour
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uOceanColour" );
11316 _uniform_scene_water_fast_g_world_depth
= glGetUniformLocation( _shader_scene_water_fast
.id
, "g_world_depth" );
11317 _uniform_scene_water_fast_uLightsArray
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uLightsArray" );
11318 _uniform_scene_water_fast_uLightsIndex
= glGetUniformLocation( _shader_scene_water_fast
.id
, "uLightsIndex" );
11319 _uniform_scene_scoretext_uMdl
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uMdl" );
11320 _uniform_scene_scoretext_uPv
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uPv" );
11321 _uniform_scene_scoretext_uPvmPrev
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uPvmPrev" );
11322 _uniform_scene_scoretext_uInfo
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uInfo" );
11323 _uniform_scene_scoretext_uTexGarbage
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uTexGarbage" );
11324 _uniform_scene_scoretext_uTexMain
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uTexMain" );
11325 _uniform_scene_scoretext_uCamera
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uCamera" );
11326 _uniform_scene_scoretext_uPlane
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uPlane" );
11327 _uniform_scene_scoretext_g_world_depth
= glGetUniformLocation( _shader_scene_scoretext
.id
, "g_world_depth" );
11328 _uniform_scene_scoretext_uLightsArray
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uLightsArray" );
11329 _uniform_scene_scoretext_uLightsIndex
= glGetUniformLocation( _shader_scene_scoretext
.id
, "uLightsIndex" );
11330 _uniform_scene_font_uMdl
= glGetUniformLocation( _shader_scene_font
.id
, "uMdl" );
11331 _uniform_scene_font_uPv
= glGetUniformLocation( _shader_scene_font
.id
, "uPv" );
11332 _uniform_scene_font_uPvmPrev
= glGetUniformLocation( _shader_scene_font
.id
, "uPvmPrev" );
11333 _uniform_scene_font_uOffset
= glGetUniformLocation( _shader_scene_font
.id
, "uOffset" );
11334 _uniform_scene_font_uTexGarbage
= glGetUniformLocation( _shader_scene_font
.id
, "uTexGarbage" );
11335 _uniform_scene_font_uTexMain
= glGetUniformLocation( _shader_scene_font
.id
, "uTexMain" );
11336 _uniform_scene_font_uCamera
= glGetUniformLocation( _shader_scene_font
.id
, "uCamera" );
11337 _uniform_scene_font_uTime
= glGetUniformLocation( _shader_scene_font
.id
, "uTime" );
11338 _uniform_scene_font_uOpacity
= glGetUniformLocation( _shader_scene_font
.id
, "uOpacity" );
11339 _uniform_scene_font_uColourize
= glGetUniformLocation( _shader_scene_font
.id
, "uColourize" );
11340 _uniform_scene_font_g_world_depth
= glGetUniformLocation( _shader_scene_font
.id
, "g_world_depth" );
11341 _uniform_scene_font_uLightsArray
= glGetUniformLocation( _shader_scene_font
.id
, "uLightsArray" );
11342 _uniform_scene_font_uLightsIndex
= glGetUniformLocation( _shader_scene_font
.id
, "uLightsIndex" );
11343 _uniform_model_sky_uMdl
= glGetUniformLocation( _shader_model_sky
.id
, "uMdl" );
11344 _uniform_model_sky_uPv
= glGetUniformLocation( _shader_model_sky
.id
, "uPv" );
11345 _uniform_model_sky_uPvmPrev
= glGetUniformLocation( _shader_model_sky
.id
, "uPvmPrev" );
11346 _uniform_model_sky_uTexGarbage
= glGetUniformLocation( _shader_model_sky
.id
, "uTexGarbage" );
11347 _uniform_model_sky_g_world_depth
= glGetUniformLocation( _shader_model_sky
.id
, "g_world_depth" );
11348 _uniform_model_sky_uLightsArray
= glGetUniformLocation( _shader_model_sky
.id
, "uLightsArray" );
11349 _uniform_model_sky_uLightsIndex
= glGetUniformLocation( _shader_model_sky
.id
, "uLightsIndex" );
11350 _uniform_model_sky_space_uMdl
= glGetUniformLocation( _shader_model_sky_space
.id
, "uMdl" );
11351 _uniform_model_sky_space_uPv
= glGetUniformLocation( _shader_model_sky_space
.id
, "uPv" );
11352 _uniform_model_sky_space_uPvmPrev
= glGetUniformLocation( _shader_model_sky_space
.id
, "uPvmPrev" );
11353 _uniform_model_sky_space_uTexGarbage
= glGetUniformLocation( _shader_model_sky_space
.id
, "uTexGarbage" );
11354 _uniform_model_sky_space_g_world_depth
= glGetUniformLocation( _shader_model_sky_space
.id
, "g_world_depth" );
11355 _uniform_model_sky_space_uLightsArray
= glGetUniformLocation( _shader_model_sky_space
.id
, "uLightsArray" );
11356 _uniform_model_sky_space_uLightsIndex
= glGetUniformLocation( _shader_model_sky_space
.id
, "uLightsIndex" );
11357 _uniform_model_menu_uMdl
= glGetUniformLocation( _shader_model_menu
.id
, "uMdl" );
11358 _uniform_model_menu_uPv
= glGetUniformLocation( _shader_model_menu
.id
, "uPv" );
11359 _uniform_model_menu_uPvmPrev
= glGetUniformLocation( _shader_model_menu
.id
, "uPvmPrev" );
11360 _uniform_model_menu_uTexMain
= glGetUniformLocation( _shader_model_menu
.id
, "uTexMain" );
11361 _uniform_model_menu_uColour
= glGetUniformLocation( _shader_model_menu
.id
, "uColour" );
11362 _uniform_model_character_view_uPv
= glGetUniformLocation( _shader_model_character_view
.id
, "uPv" );
11363 _uniform_model_character_view_uTransforms
= glGetUniformLocation( _shader_model_character_view
.id
, "uTransforms" );
11364 _uniform_model_character_view_uTexMain
= glGetUniformLocation( _shader_model_character_view
.id
, "uTexMain" );
11365 _uniform_model_character_view_uCamera
= glGetUniformLocation( _shader_model_character_view
.id
, "uCamera" );
11366 _uniform_model_character_view_g_world_depth
= glGetUniformLocation( _shader_model_character_view
.id
, "g_world_depth" );
11367 _uniform_model_character_view_uLightsArray
= glGetUniformLocation( _shader_model_character_view
.id
, "uLightsArray" );
11368 _uniform_model_character_view_uLightsIndex
= glGetUniformLocation( _shader_model_character_view
.id
, "uLightsIndex" );
11369 _uniform_model_character_view_uTexSceneDepth
= glGetUniformLocation( _shader_model_character_view
.id
, "uTexSceneDepth" );
11370 _uniform_model_character_view_uInverseRatioDepth
= glGetUniformLocation( _shader_model_character_view
.id
, "uInverseRatioDepth" );
11371 _uniform_model_character_view_uInverseRatioMain
= glGetUniformLocation( _shader_model_character_view
.id
, "uInverseRatioMain" );
11372 _uniform_model_character_view_uDepthMode
= glGetUniformLocation( _shader_model_character_view
.id
, "uDepthMode" );
11373 _uniform_model_character_view_uDitherCutoff
= glGetUniformLocation( _shader_model_character_view
.id
, "uDitherCutoff" );
11374 _uniform_model_board_view_uMdl
= glGetUniformLocation( _shader_model_board_view
.id
, "uMdl" );
11375 _uniform_model_board_view_uPv
= glGetUniformLocation( _shader_model_board_view
.id
, "uPv" );
11376 _uniform_model_board_view_uPvmPrev
= glGetUniformLocation( _shader_model_board_view
.id
, "uPvmPrev" );
11377 _uniform_model_board_view_uTexMain
= glGetUniformLocation( _shader_model_board_view
.id
, "uTexMain" );
11378 _uniform_model_board_view_uCamera
= glGetUniformLocation( _shader_model_board_view
.id
, "uCamera" );
11379 _uniform_model_board_view_g_world_depth
= glGetUniformLocation( _shader_model_board_view
.id
, "g_world_depth" );
11380 _uniform_model_board_view_uLightsArray
= glGetUniformLocation( _shader_model_board_view
.id
, "uLightsArray" );
11381 _uniform_model_board_view_uLightsIndex
= glGetUniformLocation( _shader_model_board_view
.id
, "uLightsIndex" );
11382 _uniform_model_board_view_uTexSceneDepth
= glGetUniformLocation( _shader_model_board_view
.id
, "uTexSceneDepth" );
11383 _uniform_model_board_view_uInverseRatioDepth
= glGetUniformLocation( _shader_model_board_view
.id
, "uInverseRatioDepth" );
11384 _uniform_model_board_view_uInverseRatioMain
= glGetUniformLocation( _shader_model_board_view
.id
, "uInverseRatioMain" );
11385 _uniform_model_board_view_uDepthMode
= glGetUniformLocation( _shader_model_board_view
.id
, "uDepthMode" );
11386 _uniform_model_board_view_uDitherCutoff
= glGetUniformLocation( _shader_model_board_view
.id
, "uDitherCutoff" );
11387 _uniform_model_entity_uMdl
= glGetUniformLocation( _shader_model_entity
.id
, "uMdl" );
11388 _uniform_model_entity_uPv
= glGetUniformLocation( _shader_model_entity
.id
, "uPv" );
11389 _uniform_model_entity_uPvmPrev
= glGetUniformLocation( _shader_model_entity
.id
, "uPvmPrev" );
11390 _uniform_model_entity_uTexMain
= glGetUniformLocation( _shader_model_entity
.id
, "uTexMain" );
11391 _uniform_model_entity_uCamera
= glGetUniformLocation( _shader_model_entity
.id
, "uCamera" );
11392 _uniform_model_entity_g_world_depth
= glGetUniformLocation( _shader_model_entity
.id
, "g_world_depth" );
11393 _uniform_model_entity_uLightsArray
= glGetUniformLocation( _shader_model_entity
.id
, "uLightsArray" );
11394 _uniform_model_entity_uLightsIndex
= glGetUniformLocation( _shader_model_entity
.id
, "uLightsIndex" );
11395 _uniform_model_gate_uMdl
= glGetUniformLocation( _shader_model_gate
.id
, "uMdl" );
11396 _uniform_model_gate_uPv
= glGetUniformLocation( _shader_model_gate
.id
, "uPv" );
11397 _uniform_model_gate_uPvmPrev
= glGetUniformLocation( _shader_model_gate
.id
, "uPvmPrev" );
11398 _uniform_model_gate_uTime
= glGetUniformLocation( _shader_model_gate
.id
, "uTime" );
11399 _uniform_model_gate_uCam
= glGetUniformLocation( _shader_model_gate
.id
, "uCam" );
11400 _uniform_model_gate_uInvRes
= glGetUniformLocation( _shader_model_gate
.id
, "uInvRes" );
11401 _uniform_model_gate_uColour
= glGetUniformLocation( _shader_model_gate
.id
, "uColour" );
11402 _uniform_model_gate_unlinked_uMdl
= glGetUniformLocation( _shader_model_gate_unlinked
.id
, "uMdl" );
11403 _uniform_model_gate_unlinked_uPv
= glGetUniformLocation( _shader_model_gate_unlinked
.id
, "uPv" );
11404 _uniform_model_gate_unlinked_uPvmPrev
= glGetUniformLocation( _shader_model_gate_unlinked
.id
, "uPvmPrev" );
11405 _uniform_model_gate_unlinked_uTime
= glGetUniformLocation( _shader_model_gate_unlinked
.id
, "uTime" );
11406 _uniform_model_gate_unlinked_uCam
= glGetUniformLocation( _shader_model_gate_unlinked
.id
, "uCam" );
11407 _uniform_model_gate_unlinked_uColour
= glGetUniformLocation( _shader_model_gate_unlinked
.id
, "uColour" );
11408 _uniform_model_font_uMdl
= glGetUniformLocation( _shader_model_font
.id
, "uMdl" );
11409 _uniform_model_font_uPv
= glGetUniformLocation( _shader_model_font
.id
, "uPv" );
11410 _uniform_model_font_uPvmPrev
= glGetUniformLocation( _shader_model_font
.id
, "uPvmPrev" );
11411 _uniform_model_font_uOffset
= glGetUniformLocation( _shader_model_font
.id
, "uOffset" );
11412 _uniform_model_font_uTexMain
= glGetUniformLocation( _shader_model_font
.id
, "uTexMain" );
11413 _uniform_model_font_uColour
= glGetUniformLocation( _shader_model_font
.id
, "uColour" );
11414 _uniform_model_font_uTexSceneDepth
= glGetUniformLocation( _shader_model_font
.id
, "uTexSceneDepth" );
11415 _uniform_model_font_uInverseRatioDepth
= glGetUniformLocation( _shader_model_font
.id
, "uInverseRatioDepth" );
11416 _uniform_model_font_uInverseRatioMain
= glGetUniformLocation( _shader_model_font
.id
, "uInverseRatioMain" );
11417 _uniform_model_font_uDepthMode
= glGetUniformLocation( _shader_model_font
.id
, "uDepthMode" );
11418 _uniform_model_font_uDitherCutoff
= glGetUniformLocation( _shader_model_font
.id
, "uDitherCutoff" );
11419 _uniform_particle_uPv
= glGetUniformLocation( _shader_particle
.id
, "uPv" );
11420 _uniform_particle_uPvPrev
= glGetUniformLocation( _shader_particle
.id
, "uPvPrev" );
11421 _uniform_trail_uPv
= glGetUniformLocation( _shader_trail
.id
, "uPv" );
11422 _uniform_trail_uPvPrev
= glGetUniformLocation( _shader_trail
.id
, "uPvPrev" );
11423 _uniform_trail_uColour
= glGetUniformLocation( _shader_trail
.id
, "uColour" );
11424 _uniform_blit_uInverseRatio
= glGetUniformLocation( _shader_blit
.id
, "uInverseRatio" );
11425 _uniform_blit_uTexMain
= glGetUniformLocation( _shader_blit
.id
, "uTexMain" );
11426 _uniform_blitblur_uInverseRatio
= glGetUniformLocation( _shader_blitblur
.id
, "uInverseRatio" );
11427 _uniform_blitblur_uTexMain
= glGetUniformLocation( _shader_blitblur
.id
, "uTexMain" );
11428 _uniform_blitblur_uTexMotion
= glGetUniformLocation( _shader_blitblur
.id
, "uTexMotion" );
11429 _uniform_blitblur_uBlurStrength
= glGetUniformLocation( _shader_blitblur
.id
, "uBlurStrength" );
11430 _uniform_blitblur_uOverrideDir
= glGetUniformLocation( _shader_blitblur
.id
, "uOverrideDir" );
11431 _uniform_blitblur_uTime
= glGetUniformLocation( _shader_blitblur
.id
, "uTime" );
11432 _uniform_blitblur_uGlitchStrength
= glGetUniformLocation( _shader_blitblur
.id
, "uGlitchStrength" );
11433 _uniform_blitblur_uClampUv
= glGetUniformLocation( _shader_blitblur
.id
, "uClampUv" );
11434 _uniform_blitcolour_uInverseRatio
= glGetUniformLocation( _shader_blitcolour
.id
, "uInverseRatio" );
11435 _uniform_blitcolour_uColour
= glGetUniformLocation( _shader_blitcolour
.id
, "uColour" );
11436 _uniform_blit_transition_uInverseRatio
= glGetUniformLocation( _shader_blit_transition
.id
, "uInverseRatio" );
11437 _uniform_blit_transition_uT
= glGetUniformLocation( _shader_blit_transition
.id
, "uT" );
11438 _uniform_routeui_uOffset
= glGetUniformLocation( _shader_routeui
.id
, "uOffset" );
11439 _uniform_routeui_uColour
= glGetUniformLocation( _shader_routeui
.id
, "uColour" );
11442 void vg_auto_shader_register(void)
11444 vg_shader_register( &_shader_scene_standard
);
11445 vg_shader_register( &_shader_scene_standard_alphatest
);
11446 vg_shader_register( &_shader_scene_foliage
);
11447 vg_shader_register( &_shader_scene_override
);
11448 vg_shader_register( &_shader_scene_fxglow
);
11449 vg_shader_register( &_shader_scene_vertex_blend
);
11450 vg_shader_register( &_shader_scene_terrain
);
11451 vg_shader_register( &_shader_scene_route
);
11452 vg_shader_register( &_shader_scene_depth
);
11453 vg_shader_register( &_shader_scene_position
);
11454 vg_shader_register( &_shader_scene_cubemapped
);
11455 vg_shader_register( &_shader_scene_water
);
11456 vg_shader_register( &_shader_scene_water_fast
);
11457 vg_shader_register( &_shader_scene_scoretext
);
11458 vg_shader_register( &_shader_scene_font
);
11459 vg_shader_register( &_shader_model_sky
);
11460 vg_shader_register( &_shader_model_sky_space
);
11461 vg_shader_register( &_shader_model_menu
);
11462 vg_shader_register( &_shader_model_character_view
);
11463 vg_shader_register( &_shader_model_board_view
);
11464 vg_shader_register( &_shader_model_entity
);
11465 vg_shader_register( &_shader_model_gate
);
11466 vg_shader_register( &_shader_model_gate_unlinked
);
11467 vg_shader_register( &_shader_model_font
);
11468 vg_shader_register( &_shader_particle
);
11469 vg_shader_register( &_shader_trail
);
11470 vg_shader_register( &_shader_blit
);
11471 vg_shader_register( &_shader_blitblur
);
11472 vg_shader_register( &_shader_blitcolour
);
11473 vg_shader_register( &_shader_blit_transition
);
11474 vg_shader_register( &_shader_routeui
);