change shader properties to be vg_msg based
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / impl.c
1 #include "shaders/scene_standard.h"
2 struct vg_shader _shader_scene_standard = {
3 .name = "scene_standard",
4 .vs =
5 {
6 .orig_file = "shaders/scene.vs",
7 .static_src =
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"
11 "\n"
12 "#line 1 1 \n"
13 "const float k_motion_lerp_amount = 0.01;\n"
14 "\n"
15 "#line 2 0 \n"
16 "\n"
17 "out vec3 aMotionVec0;\n"
18 "out vec3 aMotionVec1;\n"
19 "\n"
20 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
21 "{\n"
22 " // This magically solves some artifacting errors!\n"
23 " //\n"
24 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
25 "\n"
26 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
27 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
28 "}\n"
29 "\n"
30 "#line 6 0 \n"
31 "\n"
32 "uniform mat4x3 uMdl;\n"
33 "uniform mat4 uPv;\n"
34 "uniform mat4 uPvmPrev;\n"
35 "\n"
36 "out vec2 aUv;\n"
37 "out vec4 aNorm;\n"
38 "out vec3 aCo;\n"
39 "out vec3 aWorldCo;\n"
40 "\n"
41 "void main()\n"
42 "{\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"
46 "\n"
47 " vs_motion_out( vproj0, vproj1 );\n"
48 "\n"
49 " gl_Position = vproj0;\n"
50 "\n"
51 " aUv = a_uv;\n"
52 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
53 " aCo = a_co;\n"
54 " aWorldCo = world_pos0;\n"
55 "}\n"
56 ""},
57 .fs =
58 {
59 .orig_file = "shaders/scene_standard.fs",
60 .static_src =
61 "uniform sampler2D uTexGarbage;\n"
62 "uniform sampler2D uTexMain;\n"
63 "uniform vec3 uCamera;\n"
64 "uniform vec4 uPlane;\n"
65 "\n"
66 "#line 1 1 \n"
67 "// :D\n"
68 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
69 "\n"
70 "#line 7 0 \n"
71 "#line 1 2 \n"
72 "// :D\n"
73 "\n"
74 "in vec2 aUv;\n"
75 "in vec4 aNorm;\n"
76 "in vec3 aCo;\n"
77 "in vec3 aWorldCo;\n"
78 "\n"
79 "#line 1 1 \n"
80 "layout (location = 0) out vec4 oColour;\n"
81 "\n"
82 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
83 "layout (std140) uniform ub_world_lighting\n"
84 "{\n"
85 " vec4 g_cube_min;\n"
86 " vec4 g_cube_inv_range;\n"
87 "\n"
88 " vec4 g_water_plane;\n"
89 " vec4 g_depth_bounds;\n"
90 "\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"
97 " vec4 g_sun_dir;\n"
98 " vec4 g_board_0;\n"
99 " vec4 g_board_1;\n"
100 "\n"
101 " float g_water_fog;\n"
102 " float g_time;\n"
103 " float g_realtime;\n"
104 " float g_shadow_length;\n"
105 " float g_shadow_spread;\n"
106 "\n"
107 " float g_time_of_day;\n"
108 " float g_day_phase;\n"
109 " float g_sunset_phase;\n"
110 "\n"
111 " int g_light_preview;\n"
112 " int g_shadow_samples;\n"
113 "\n"
114 " int g_debug_indices;\n"
115 " int g_debug_complexity;\n"
116 "};\n"
117 "\n"
118 "uniform sampler2D g_world_depth;\n"
119 "uniform samplerBuffer uLightsArray;\n"
120 "uniform usampler3D uLightsIndex;\n"
121 "\n"
122 "#line 1 1 \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"
129 "\n"
130 "const float SUN_ANGLE = 0.0001;\n"
131 "const float PI = 3.14159265358979323846264;\n"
132 "\n"
133 "//struct world_info\n"
134 "//{\n"
135 "// float time,\n"
136 "// time_of_day,\n"
137 "// day_phase,\n"
138 "// sunset_phase;\n"
139 "// \n"
140 "// vec3 sun_dir;\n"
141 "//};\n"
142 "\n"
143 "vec3 rand33(vec3 p3)\n"
144 "{\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"
148 "}\n"
149 "\n"
150 "float stars( vec3 rd, float rr, float size ){\n"
151 " vec3 co = rd * rr;\n"
152 "\n"
153 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
154 "\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"
158 "\n"
159 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
160 " \n"
161 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
162 " plane = plane - mod(plane, PI / count);\n"
163 "\n"
164 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
165 "\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"
171 " return star;\n"
172 "}\n"
173 "\n"
174 "float luminance( vec3 v )\n"
175 "{\n"
176 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
177 "}\n"
178 "\n"
179 "vec3 clearskies_ambient( vec3 dir )\n"
180 "{\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"
183 " \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"
188 " \n"
189 " /* Add gradient */\n"
190 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
191 " \n"
192 " return ambient;\n"
193 "}\n"
194 "\n"
195 "vec3 clearskies_sky( vec3 ray_dir )\n"
196 "{\n"
197 " ray_dir.y = abs( ray_dir.y );\n"
198 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
199 " \n"
200 " /* Sun */\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"
205 " \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"
208 "\n"
209 " \n"
210 " float star = 0.0;\n"
211 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
212 "\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"
217 " }\n"
218 " }\n"
219 " \n"
220 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
221 " return composite;\n"
222 "}\n"
223 "\n"
224 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
225 "{\n"
226 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
227 "\n"
228 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
229 " g_sunset_phase );\n"
230 "\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"
235 "\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"
239 "\n"
240 " return ambient + (light_sun + sky_reflection) * shadow;\n"
241 "}\n"
242 "\n"
243 "#line 44 0 \n"
244 "\n"
245 "float world_depth_sample( vec3 pos )\n"
246 "{\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"
249 "}\n"
250 "\n"
251 "float world_water_depth( vec3 pos )\n"
252 "{\n"
253 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
254 " return world_depth_sample( pos ) - ref_depth;\n"
255 "}\n"
256 "\n"
257 "float shadow_sample( vec3 co ){\n"
258 " float height_sample = world_depth_sample( co );\n"
259 "\n"
260 " float fdelta = height_sample - co.y;\n"
261 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
262 "}\n"
263 "\n"
264 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
265 " if( g_shadow_samples == 0 ){\n"
266 " return 1.0;\n"
267 " }\n"
268 "\n"
269 " float fspread = g_shadow_spread;\n"
270 " float flength = g_shadow_length;\n"
271 "\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"
277 "\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"
282 "\n"
283 " return 1.0 - famt;\n"
284 "}\n"
285 "\n"
286 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
287 "{\n"
288 " vec3 specdir = reflect( -dir, wnormal );\n"
289 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
290 "}\n"
291 "\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"
295 "}\n"
296 "\n"
297 "vec3 scene_calculate_light( int light_index, \n"
298 " vec3 halfview, vec3 co, vec3 normal )\n"
299 "{\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"
303 "\n"
304 " vec3 light_delta = light_co.xyz-co;\n"
305 " float dist2 = dot(light_delta,light_delta);\n"
306 "\n"
307 " light_delta = normalize( light_delta );\n"
308 "\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"
312 "\n"
313 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
314 "\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"
318 " }\n"
319 "\n"
320 " return light_colour.rgb * attenuation * falloff \n"
321 " * step( g_day_phase, light_colour.w );\n"
322 "}\n"
323 "\n"
324 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
325 " vec3 halfview, vec3 co, vec3 normal )\n"
326 "{\n"
327 " uint light_count = packed_index & 0x3u;\n"
328 "\n"
329 " vec3 l = vec3(0.0);\n"
330 "\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"
335 "\n"
336 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
337 "\n"
338 " if( light_count >= 2u ){\n"
339 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
340 "\n"
341 " if( light_count >= 3u ){\n"
342 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
343 " }\n"
344 " }\n"
345 " }\n"
346 "\n"
347 " return l;\n"
348 "}\n"
349 "\n"
350 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
351 " float light_mask )\n"
352 "{\n"
353 " if( g_light_preview == 1 )\n"
354 " diffuse = vec3(0.75);\n"
355 "\n"
356 " // Lighting\n"
357 " vec3 halfview = uCamera - co;\n"
358 " float fdist = length(halfview);\n"
359 " halfview /= fdist;\n"
360 "\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"
363 "\n"
364 " vec3 total_light = clearskies_lighting( \n"
365 " normal, min( light_mask, world_shadow ), halfview );\n"
366 "\n"
367 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
368 " cube_coord = floor( cube_coord );\n"
369 "\n"
370 " if( g_debug_indices == 1 )\n"
371 " {\n"
372 " return rand33(cube_coord);\n"
373 " }\n"
374 "\n"
375 " if( g_debug_complexity == 1 )\n"
376 " {\n"
377 " ivec3 coord = ivec3( cube_coord );\n"
378 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
379 "\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"
382 " }\n"
383 "\n"
384 " // FIXME: this coord should absolutely must be clamped!\n"
385 " \n"
386 " ivec3 coord = ivec3( cube_coord );\n"
387 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
388 "\n"
389 " total_light += \n"
390 " scene_calculate_packed_light_patch( index_sample.x,\n"
391 " halfview, co, normal ) \n"
392 " * light_mask;\n"
393 " total_light += \n"
394 " scene_calculate_packed_light_patch( index_sample.y,\n"
395 " halfview, co, normal )\n"
396 " * light_mask;\n"
397 "\n"
398 " // Take a section of the sky function to give us a matching fog colour\n"
399 "\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"
404 " \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"
407 "\n"
408 " fog_colour += sun_colour;\n"
409 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
410 "}\n"
411 "\n"
412 "#line 9 0 \n"
413 "\n"
414 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
415 "{\n"
416 " vec3 pa = p - a;\n"
417 " vec3 ba = b - a;\n"
418 "\n"
419 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
420 " return length( pa - ba*h );\n"
421 "}\n"
422 "\n"
423 "float compute_board_shadow()\n"
424 "{\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"
430 "\n"
431 " return 1.0 - player_shadow*0.8;\n"
432 "}\n"
433 "\n"
434 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
435 "{\n"
436 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
437 "}\n"
438 "\n"
439 "#line 8 0 \n"
440 "#line 1 3 \n"
441 "const float k_motion_lerp_amount = 0.01;\n"
442 "\n"
443 "#line 2 0 \n"
444 "\n"
445 "layout (location = 1) out vec2 oMotionVec;\n"
446 "\n"
447 "in vec3 aMotionVec0;\n"
448 "in vec3 aMotionVec1;\n"
449 "\n"
450 "void compute_motion_vectors()\n"
451 "{\n"
452 " // Write motion vectors\n"
453 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
454 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
455 "\n"
456 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
457 "}\n"
458 "\n"
459 "#line 9 0 \n"
460 "\n"
461 "void main()\n"
462 "{\n"
463 " compute_motion_vectors();\n"
464 "\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"
468 "\n"
469 " vfrag = vsamplemain.rgb;\n"
470 "\n"
471 " if( g_light_preview == 1 )\n"
472 " {\n"
473 " vfrag = vec3(0.5);\n"
474 " }\n"
475 "\n"
476 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
477 " oColour = vec4( vfrag, 1.0 );\n"
478 "}\n"
479 ""},
480 };
481
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",
495 .vs =
496 {
497 .orig_file = "shaders/scene.vs",
498 .static_src =
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"
502 "\n"
503 "#line 1 1 \n"
504 "const float k_motion_lerp_amount = 0.01;\n"
505 "\n"
506 "#line 2 0 \n"
507 "\n"
508 "out vec3 aMotionVec0;\n"
509 "out vec3 aMotionVec1;\n"
510 "\n"
511 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
512 "{\n"
513 " // This magically solves some artifacting errors!\n"
514 " //\n"
515 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
516 "\n"
517 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
518 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
519 "}\n"
520 "\n"
521 "#line 6 0 \n"
522 "\n"
523 "uniform mat4x3 uMdl;\n"
524 "uniform mat4 uPv;\n"
525 "uniform mat4 uPvmPrev;\n"
526 "\n"
527 "out vec2 aUv;\n"
528 "out vec4 aNorm;\n"
529 "out vec3 aCo;\n"
530 "out vec3 aWorldCo;\n"
531 "\n"
532 "void main()\n"
533 "{\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"
537 "\n"
538 " vs_motion_out( vproj0, vproj1 );\n"
539 "\n"
540 " gl_Position = vproj0;\n"
541 "\n"
542 " aUv = a_uv;\n"
543 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
544 " aCo = a_co;\n"
545 " aWorldCo = world_pos0;\n"
546 "}\n"
547 ""},
548 .fs =
549 {
550 .orig_file = "shaders/scene_standard_alphatest.fs",
551 .static_src =
552 "uniform sampler2D uTexGarbage;\n"
553 "uniform sampler2D uTexMain;\n"
554 "uniform vec3 uCamera;\n"
555 "uniform vec4 uPlane;\n"
556 "\n"
557 "#line 1 1 \n"
558 "// :D\n"
559 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
560 "\n"
561 "#line 7 0 \n"
562 "#line 1 2 \n"
563 "// :D\n"
564 "\n"
565 "in vec2 aUv;\n"
566 "in vec4 aNorm;\n"
567 "in vec3 aCo;\n"
568 "in vec3 aWorldCo;\n"
569 "\n"
570 "#line 1 1 \n"
571 "layout (location = 0) out vec4 oColour;\n"
572 "\n"
573 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
574 "layout (std140) uniform ub_world_lighting\n"
575 "{\n"
576 " vec4 g_cube_min;\n"
577 " vec4 g_cube_inv_range;\n"
578 "\n"
579 " vec4 g_water_plane;\n"
580 " vec4 g_depth_bounds;\n"
581 "\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"
588 " vec4 g_sun_dir;\n"
589 " vec4 g_board_0;\n"
590 " vec4 g_board_1;\n"
591 "\n"
592 " float g_water_fog;\n"
593 " float g_time;\n"
594 " float g_realtime;\n"
595 " float g_shadow_length;\n"
596 " float g_shadow_spread;\n"
597 "\n"
598 " float g_time_of_day;\n"
599 " float g_day_phase;\n"
600 " float g_sunset_phase;\n"
601 "\n"
602 " int g_light_preview;\n"
603 " int g_shadow_samples;\n"
604 "\n"
605 " int g_debug_indices;\n"
606 " int g_debug_complexity;\n"
607 "};\n"
608 "\n"
609 "uniform sampler2D g_world_depth;\n"
610 "uniform samplerBuffer uLightsArray;\n"
611 "uniform usampler3D uLightsIndex;\n"
612 "\n"
613 "#line 1 1 \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"
620 "\n"
621 "const float SUN_ANGLE = 0.0001;\n"
622 "const float PI = 3.14159265358979323846264;\n"
623 "\n"
624 "//struct world_info\n"
625 "//{\n"
626 "// float time,\n"
627 "// time_of_day,\n"
628 "// day_phase,\n"
629 "// sunset_phase;\n"
630 "// \n"
631 "// vec3 sun_dir;\n"
632 "//};\n"
633 "\n"
634 "vec3 rand33(vec3 p3)\n"
635 "{\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"
639 "}\n"
640 "\n"
641 "float stars( vec3 rd, float rr, float size ){\n"
642 " vec3 co = rd * rr;\n"
643 "\n"
644 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
645 "\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"
649 "\n"
650 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
651 " \n"
652 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
653 " plane = plane - mod(plane, PI / count);\n"
654 "\n"
655 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
656 "\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"
662 " return star;\n"
663 "}\n"
664 "\n"
665 "float luminance( vec3 v )\n"
666 "{\n"
667 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
668 "}\n"
669 "\n"
670 "vec3 clearskies_ambient( vec3 dir )\n"
671 "{\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"
674 " \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"
679 " \n"
680 " /* Add gradient */\n"
681 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
682 " \n"
683 " return ambient;\n"
684 "}\n"
685 "\n"
686 "vec3 clearskies_sky( vec3 ray_dir )\n"
687 "{\n"
688 " ray_dir.y = abs( ray_dir.y );\n"
689 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
690 " \n"
691 " /* Sun */\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"
696 " \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"
699 "\n"
700 " \n"
701 " float star = 0.0;\n"
702 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
703 "\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"
708 " }\n"
709 " }\n"
710 " \n"
711 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
712 " return composite;\n"
713 "}\n"
714 "\n"
715 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
716 "{\n"
717 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
718 "\n"
719 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
720 " g_sunset_phase );\n"
721 "\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"
726 "\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"
730 "\n"
731 " return ambient + (light_sun + sky_reflection) * shadow;\n"
732 "}\n"
733 "\n"
734 "#line 44 0 \n"
735 "\n"
736 "float world_depth_sample( vec3 pos )\n"
737 "{\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"
740 "}\n"
741 "\n"
742 "float world_water_depth( vec3 pos )\n"
743 "{\n"
744 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
745 " return world_depth_sample( pos ) - ref_depth;\n"
746 "}\n"
747 "\n"
748 "float shadow_sample( vec3 co ){\n"
749 " float height_sample = world_depth_sample( co );\n"
750 "\n"
751 " float fdelta = height_sample - co.y;\n"
752 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
753 "}\n"
754 "\n"
755 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
756 " if( g_shadow_samples == 0 ){\n"
757 " return 1.0;\n"
758 " }\n"
759 "\n"
760 " float fspread = g_shadow_spread;\n"
761 " float flength = g_shadow_length;\n"
762 "\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"
768 "\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"
773 "\n"
774 " return 1.0 - famt;\n"
775 "}\n"
776 "\n"
777 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
778 "{\n"
779 " vec3 specdir = reflect( -dir, wnormal );\n"
780 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
781 "}\n"
782 "\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"
786 "}\n"
787 "\n"
788 "vec3 scene_calculate_light( int light_index, \n"
789 " vec3 halfview, vec3 co, vec3 normal )\n"
790 "{\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"
794 "\n"
795 " vec3 light_delta = light_co.xyz-co;\n"
796 " float dist2 = dot(light_delta,light_delta);\n"
797 "\n"
798 " light_delta = normalize( light_delta );\n"
799 "\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"
803 "\n"
804 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
805 "\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"
809 " }\n"
810 "\n"
811 " return light_colour.rgb * attenuation * falloff \n"
812 " * step( g_day_phase, light_colour.w );\n"
813 "}\n"
814 "\n"
815 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
816 " vec3 halfview, vec3 co, vec3 normal )\n"
817 "{\n"
818 " uint light_count = packed_index & 0x3u;\n"
819 "\n"
820 " vec3 l = vec3(0.0);\n"
821 "\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"
826 "\n"
827 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
828 "\n"
829 " if( light_count >= 2u ){\n"
830 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
831 "\n"
832 " if( light_count >= 3u ){\n"
833 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
834 " }\n"
835 " }\n"
836 " }\n"
837 "\n"
838 " return l;\n"
839 "}\n"
840 "\n"
841 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
842 " float light_mask )\n"
843 "{\n"
844 " if( g_light_preview == 1 )\n"
845 " diffuse = vec3(0.75);\n"
846 "\n"
847 " // Lighting\n"
848 " vec3 halfview = uCamera - co;\n"
849 " float fdist = length(halfview);\n"
850 " halfview /= fdist;\n"
851 "\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"
854 "\n"
855 " vec3 total_light = clearskies_lighting( \n"
856 " normal, min( light_mask, world_shadow ), halfview );\n"
857 "\n"
858 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
859 " cube_coord = floor( cube_coord );\n"
860 "\n"
861 " if( g_debug_indices == 1 )\n"
862 " {\n"
863 " return rand33(cube_coord);\n"
864 " }\n"
865 "\n"
866 " if( g_debug_complexity == 1 )\n"
867 " {\n"
868 " ivec3 coord = ivec3( cube_coord );\n"
869 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
870 "\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"
873 " }\n"
874 "\n"
875 " // FIXME: this coord should absolutely must be clamped!\n"
876 " \n"
877 " ivec3 coord = ivec3( cube_coord );\n"
878 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
879 "\n"
880 " total_light += \n"
881 " scene_calculate_packed_light_patch( index_sample.x,\n"
882 " halfview, co, normal ) \n"
883 " * light_mask;\n"
884 " total_light += \n"
885 " scene_calculate_packed_light_patch( index_sample.y,\n"
886 " halfview, co, normal )\n"
887 " * light_mask;\n"
888 "\n"
889 " // Take a section of the sky function to give us a matching fog colour\n"
890 "\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"
895 " \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"
898 "\n"
899 " fog_colour += sun_colour;\n"
900 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
901 "}\n"
902 "\n"
903 "#line 9 0 \n"
904 "\n"
905 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
906 "{\n"
907 " vec3 pa = p - a;\n"
908 " vec3 ba = b - a;\n"
909 "\n"
910 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
911 " return length( pa - ba*h );\n"
912 "}\n"
913 "\n"
914 "float compute_board_shadow()\n"
915 "{\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"
921 "\n"
922 " return 1.0 - player_shadow*0.8;\n"
923 "}\n"
924 "\n"
925 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
926 "{\n"
927 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
928 "}\n"
929 "\n"
930 "#line 8 0 \n"
931 "#line 1 3 \n"
932 "const float k_motion_lerp_amount = 0.01;\n"
933 "\n"
934 "#line 2 0 \n"
935 "\n"
936 "layout (location = 1) out vec2 oMotionVec;\n"
937 "\n"
938 "in vec3 aMotionVec0;\n"
939 "in vec3 aMotionVec1;\n"
940 "\n"
941 "void compute_motion_vectors()\n"
942 "{\n"
943 " // Write motion vectors\n"
944 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
945 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
946 "\n"
947 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
948 "}\n"
949 "\n"
950 "#line 9 0 \n"
951 "\n"
952 "void main()\n"
953 "{\n"
954 " compute_motion_vectors();\n"
955 "\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"
959 "\n"
960 " if( vsamplemain.a < 0.15 )\n"
961 " discard;\n"
962 "\n"
963 " vfrag = vsamplemain.rgb;\n"
964 "\n"
965 " if( g_light_preview == 1 )\n"
966 " {\n"
967 " vfrag = vec3(0.5);\n"
968 " }\n"
969 "\n"
970 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
971 " oColour = vec4(vfrag, 1.0);\n"
972 "}\n"
973 ""},
974 };
975
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",
989 .vs =
990 {
991 .orig_file = "shaders/scene_foliage.vs",
992 .static_src =
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"
996 "\n"
997 "#line 1 1 \n"
998 "const float k_motion_lerp_amount = 0.01;\n"
999 "\n"
1000 "#line 2 0 \n"
1001 "\n"
1002 "out vec3 aMotionVec0;\n"
1003 "out vec3 aMotionVec1;\n"
1004 "\n"
1005 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
1006 "{\n"
1007 " // This magically solves some artifacting errors!\n"
1008 " //\n"
1009 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
1010 "\n"
1011 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
1012 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
1013 "}\n"
1014 "\n"
1015 "#line 6 0 \n"
1016 "\n"
1017 "uniform mat4x3 uMdl;\n"
1018 "uniform mat4 uPv;\n"
1019 "uniform mat4 uPvmPrev;\n"
1020 "uniform float uTime;\n"
1021 "\n"
1022 "out vec2 aUv;\n"
1023 "out vec4 aNorm;\n"
1024 "out vec3 aCo;\n"
1025 "out vec3 aWorldCo;\n"
1026 "\n"
1027 "void main(){\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"
1030 " \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"
1034 "\n"
1035 " vs_motion_out( vproj0, vproj1 );\n"
1036 "\n"
1037 " gl_Position = vproj0;\n"
1038 "\n"
1039 " aUv = a_uv;\n"
1040 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
1041 " aCo = a_co;\n"
1042 " aWorldCo = world_pos0;\n"
1043 "}\n"
1044 ""},
1045 .fs =
1046 {
1047 .orig_file = "shaders/scene_foliage.fs",
1048 .static_src =
1049 "uniform sampler2D uTexGarbage;\n"
1050 "uniform sampler2D uTexMain;\n"
1051 "uniform vec3 uCamera;\n"
1052 "uniform vec4 uPlane;\n"
1053 "\n"
1054 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.4;\n"
1055 "#line 1 1 \n"
1056 "// :D\n"
1057 "\n"
1058 "in vec2 aUv;\n"
1059 "in vec4 aNorm;\n"
1060 "in vec3 aCo;\n"
1061 "in vec3 aWorldCo;\n"
1062 "\n"
1063 "#line 1 1 \n"
1064 "layout (location = 0) out vec4 oColour;\n"
1065 "\n"
1066 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
1067 "layout (std140) uniform ub_world_lighting\n"
1068 "{\n"
1069 " vec4 g_cube_min;\n"
1070 " vec4 g_cube_inv_range;\n"
1071 "\n"
1072 " vec4 g_water_plane;\n"
1073 " vec4 g_depth_bounds;\n"
1074 "\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"
1084 "\n"
1085 " float g_water_fog;\n"
1086 " float g_time;\n"
1087 " float g_realtime;\n"
1088 " float g_shadow_length;\n"
1089 " float g_shadow_spread;\n"
1090 "\n"
1091 " float g_time_of_day;\n"
1092 " float g_day_phase;\n"
1093 " float g_sunset_phase;\n"
1094 "\n"
1095 " int g_light_preview;\n"
1096 " int g_shadow_samples;\n"
1097 "\n"
1098 " int g_debug_indices;\n"
1099 " int g_debug_complexity;\n"
1100 "};\n"
1101 "\n"
1102 "uniform sampler2D g_world_depth;\n"
1103 "uniform samplerBuffer uLightsArray;\n"
1104 "uniform usampler3D uLightsIndex;\n"
1105 "\n"
1106 "#line 1 1 \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"
1113 "\n"
1114 "const float SUN_ANGLE = 0.0001;\n"
1115 "const float PI = 3.14159265358979323846264;\n"
1116 "\n"
1117 "//struct world_info\n"
1118 "//{\n"
1119 "// float time,\n"
1120 "// time_of_day,\n"
1121 "// day_phase,\n"
1122 "// sunset_phase;\n"
1123 "// \n"
1124 "// vec3 sun_dir;\n"
1125 "//};\n"
1126 "\n"
1127 "vec3 rand33(vec3 p3)\n"
1128 "{\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"
1132 "}\n"
1133 "\n"
1134 "float stars( vec3 rd, float rr, float size ){\n"
1135 " vec3 co = rd * rr;\n"
1136 "\n"
1137 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
1138 "\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"
1142 "\n"
1143 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
1144 " \n"
1145 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
1146 " plane = plane - mod(plane, PI / count);\n"
1147 "\n"
1148 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
1149 "\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"
1155 " return star;\n"
1156 "}\n"
1157 "\n"
1158 "float luminance( vec3 v )\n"
1159 "{\n"
1160 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
1161 "}\n"
1162 "\n"
1163 "vec3 clearskies_ambient( vec3 dir )\n"
1164 "{\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"
1167 " \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"
1172 " \n"
1173 " /* Add gradient */\n"
1174 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
1175 " \n"
1176 " return ambient;\n"
1177 "}\n"
1178 "\n"
1179 "vec3 clearskies_sky( vec3 ray_dir )\n"
1180 "{\n"
1181 " ray_dir.y = abs( ray_dir.y );\n"
1182 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
1183 " \n"
1184 " /* Sun */\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"
1189 " \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"
1192 "\n"
1193 " \n"
1194 " float star = 0.0;\n"
1195 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
1196 "\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"
1201 " }\n"
1202 " }\n"
1203 " \n"
1204 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
1205 " return composite;\n"
1206 "}\n"
1207 "\n"
1208 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
1209 "{\n"
1210 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
1211 "\n"
1212 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
1213 " g_sunset_phase );\n"
1214 "\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"
1219 "\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"
1223 "\n"
1224 " return ambient + (light_sun + sky_reflection) * shadow;\n"
1225 "}\n"
1226 "\n"
1227 "#line 44 0 \n"
1228 "\n"
1229 "float world_depth_sample( vec3 pos )\n"
1230 "{\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"
1233 "}\n"
1234 "\n"
1235 "float world_water_depth( vec3 pos )\n"
1236 "{\n"
1237 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
1238 " return world_depth_sample( pos ) - ref_depth;\n"
1239 "}\n"
1240 "\n"
1241 "float shadow_sample( vec3 co ){\n"
1242 " float height_sample = world_depth_sample( co );\n"
1243 "\n"
1244 " float fdelta = height_sample - co.y;\n"
1245 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
1246 "}\n"
1247 "\n"
1248 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
1249 " if( g_shadow_samples == 0 ){\n"
1250 " return 1.0;\n"
1251 " }\n"
1252 "\n"
1253 " float fspread = g_shadow_spread;\n"
1254 " float flength = g_shadow_length;\n"
1255 "\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"
1261 "\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"
1266 "\n"
1267 " return 1.0 - famt;\n"
1268 "}\n"
1269 "\n"
1270 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
1271 "{\n"
1272 " vec3 specdir = reflect( -dir, wnormal );\n"
1273 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
1274 "}\n"
1275 "\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"
1279 "}\n"
1280 "\n"
1281 "vec3 scene_calculate_light( int light_index, \n"
1282 " vec3 halfview, vec3 co, vec3 normal )\n"
1283 "{\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"
1287 "\n"
1288 " vec3 light_delta = light_co.xyz-co;\n"
1289 " float dist2 = dot(light_delta,light_delta);\n"
1290 "\n"
1291 " light_delta = normalize( light_delta );\n"
1292 "\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"
1296 "\n"
1297 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
1298 "\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"
1302 " }\n"
1303 "\n"
1304 " return light_colour.rgb * attenuation * falloff \n"
1305 " * step( g_day_phase, light_colour.w );\n"
1306 "}\n"
1307 "\n"
1308 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
1309 " vec3 halfview, vec3 co, vec3 normal )\n"
1310 "{\n"
1311 " uint light_count = packed_index & 0x3u;\n"
1312 "\n"
1313 " vec3 l = vec3(0.0);\n"
1314 "\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"
1319 "\n"
1320 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
1321 "\n"
1322 " if( light_count >= 2u ){\n"
1323 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
1324 "\n"
1325 " if( light_count >= 3u ){\n"
1326 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
1327 " }\n"
1328 " }\n"
1329 " }\n"
1330 "\n"
1331 " return l;\n"
1332 "}\n"
1333 "\n"
1334 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
1335 " float light_mask )\n"
1336 "{\n"
1337 " if( g_light_preview == 1 )\n"
1338 " diffuse = vec3(0.75);\n"
1339 "\n"
1340 " // Lighting\n"
1341 " vec3 halfview = uCamera - co;\n"
1342 " float fdist = length(halfview);\n"
1343 " halfview /= fdist;\n"
1344 "\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"
1347 "\n"
1348 " vec3 total_light = clearskies_lighting( \n"
1349 " normal, min( light_mask, world_shadow ), halfview );\n"
1350 "\n"
1351 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
1352 " cube_coord = floor( cube_coord );\n"
1353 "\n"
1354 " if( g_debug_indices == 1 )\n"
1355 " {\n"
1356 " return rand33(cube_coord);\n"
1357 " }\n"
1358 "\n"
1359 " if( g_debug_complexity == 1 )\n"
1360 " {\n"
1361 " ivec3 coord = ivec3( cube_coord );\n"
1362 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1363 "\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"
1366 " }\n"
1367 "\n"
1368 " // FIXME: this coord should absolutely must be clamped!\n"
1369 " \n"
1370 " ivec3 coord = ivec3( cube_coord );\n"
1371 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1372 "\n"
1373 " total_light += \n"
1374 " scene_calculate_packed_light_patch( index_sample.x,\n"
1375 " halfview, co, normal ) \n"
1376 " * light_mask;\n"
1377 " total_light += \n"
1378 " scene_calculate_packed_light_patch( index_sample.y,\n"
1379 " halfview, co, normal )\n"
1380 " * light_mask;\n"
1381 "\n"
1382 " // Take a section of the sky function to give us a matching fog colour\n"
1383 "\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"
1388 " \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"
1391 "\n"
1392 " fog_colour += sun_colour;\n"
1393 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
1394 "}\n"
1395 "\n"
1396 "#line 9 0 \n"
1397 "\n"
1398 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
1399 "{\n"
1400 " vec3 pa = p - a;\n"
1401 " vec3 ba = b - a;\n"
1402 "\n"
1403 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
1404 " return length( pa - ba*h );\n"
1405 "}\n"
1406 "\n"
1407 "float compute_board_shadow()\n"
1408 "{\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"
1414 "\n"
1415 " return 1.0 - player_shadow*0.8;\n"
1416 "}\n"
1417 "\n"
1418 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
1419 "{\n"
1420 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
1421 "}\n"
1422 "\n"
1423 "#line 8 0 \n"
1424 "#line 1 2 \n"
1425 "const float k_motion_lerp_amount = 0.01;\n"
1426 "\n"
1427 "#line 2 0 \n"
1428 "\n"
1429 "layout (location = 1) out vec2 oMotionVec;\n"
1430 "\n"
1431 "in vec3 aMotionVec0;\n"
1432 "in vec3 aMotionVec1;\n"
1433 "\n"
1434 "void compute_motion_vectors()\n"
1435 "{\n"
1436 " // Write motion vectors\n"
1437 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
1438 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
1439 "\n"
1440 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
1441 "}\n"
1442 "\n"
1443 "#line 9 0 \n"
1444 "\n"
1445 "void main(){\n"
1446 " compute_motion_vectors();\n"
1447 "\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"
1451 "\n"
1452 " if( vsamplemain.a < 0.15 )\n"
1453 " discard;\n"
1454 "\n"
1455 " vfrag = vsamplemain.rgb;\n"
1456 "\n"
1457 " if( g_light_preview == 1 ){\n"
1458 " vfrag = vec3(0.5);\n"
1459 " }\n"
1460 "\n"
1461 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
1462 " oColour = vec4(vfrag, 1.0);\n"
1463 "}\n"
1464 ""},
1465 };
1466
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",
1481 .vs =
1482 {
1483 .orig_file = "shaders/scene_override.vs",
1484 .static_src =
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"
1488 "\n"
1489 "#line 1 1 \n"
1490 "const float k_motion_lerp_amount = 0.01;\n"
1491 "\n"
1492 "#line 2 0 \n"
1493 "\n"
1494 "out vec3 aMotionVec0;\n"
1495 "out vec3 aMotionVec1;\n"
1496 "\n"
1497 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
1498 "{\n"
1499 " // This magically solves some artifacting errors!\n"
1500 " //\n"
1501 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
1502 "\n"
1503 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
1504 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
1505 "}\n"
1506 "\n"
1507 "#line 6 0 \n"
1508 "\n"
1509 "uniform mat4x3 uMdl;\n"
1510 "uniform mat4 uPv;\n"
1511 "uniform mat4 uPvmPrev;\n"
1512 "uniform mat3 uNormalMtx;\n"
1513 "\n"
1514 "out vec2 aUv;\n"
1515 "out vec4 aNorm;\n"
1516 "out vec3 aCo;\n"
1517 "out vec3 aWorldCo;\n"
1518 "\n"
1519 "void main()\n"
1520 "{\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"
1524 "\n"
1525 " vs_motion_out( vproj0, vproj1 );\n"
1526 "\n"
1527 " gl_Position = vproj0;\n"
1528 "\n"
1529 " aUv = a_uv;\n"
1530 " aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
1531 " aCo = a_co;\n"
1532 " aWorldCo = world_pos0;\n"
1533 "}\n"
1534 ""},
1535 .fs =
1536 {
1537 .orig_file = "shaders/scene_override.fs",
1538 .static_src =
1539 "uniform sampler2D uTexGarbage;\n"
1540 "uniform sampler2D uTexMain;\n"
1541 "uniform vec3 uCamera;\n"
1542 "uniform vec4 uPlane;\n"
1543 "\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"
1548 "\n"
1549 "#line 1 1 \n"
1550 "// :D\n"
1551 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
1552 "\n"
1553 "#line 12 0 \n"
1554 "#line 1 2 \n"
1555 "// :D\n"
1556 "\n"
1557 "in vec2 aUv;\n"
1558 "in vec4 aNorm;\n"
1559 "in vec3 aCo;\n"
1560 "in vec3 aWorldCo;\n"
1561 "\n"
1562 "#line 1 1 \n"
1563 "layout (location = 0) out vec4 oColour;\n"
1564 "\n"
1565 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
1566 "layout (std140) uniform ub_world_lighting\n"
1567 "{\n"
1568 " vec4 g_cube_min;\n"
1569 " vec4 g_cube_inv_range;\n"
1570 "\n"
1571 " vec4 g_water_plane;\n"
1572 " vec4 g_depth_bounds;\n"
1573 "\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"
1583 "\n"
1584 " float g_water_fog;\n"
1585 " float g_time;\n"
1586 " float g_realtime;\n"
1587 " float g_shadow_length;\n"
1588 " float g_shadow_spread;\n"
1589 "\n"
1590 " float g_time_of_day;\n"
1591 " float g_day_phase;\n"
1592 " float g_sunset_phase;\n"
1593 "\n"
1594 " int g_light_preview;\n"
1595 " int g_shadow_samples;\n"
1596 "\n"
1597 " int g_debug_indices;\n"
1598 " int g_debug_complexity;\n"
1599 "};\n"
1600 "\n"
1601 "uniform sampler2D g_world_depth;\n"
1602 "uniform samplerBuffer uLightsArray;\n"
1603 "uniform usampler3D uLightsIndex;\n"
1604 "\n"
1605 "#line 1 1 \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"
1612 "\n"
1613 "const float SUN_ANGLE = 0.0001;\n"
1614 "const float PI = 3.14159265358979323846264;\n"
1615 "\n"
1616 "//struct world_info\n"
1617 "//{\n"
1618 "// float time,\n"
1619 "// time_of_day,\n"
1620 "// day_phase,\n"
1621 "// sunset_phase;\n"
1622 "// \n"
1623 "// vec3 sun_dir;\n"
1624 "//};\n"
1625 "\n"
1626 "vec3 rand33(vec3 p3)\n"
1627 "{\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"
1631 "}\n"
1632 "\n"
1633 "float stars( vec3 rd, float rr, float size ){\n"
1634 " vec3 co = rd * rr;\n"
1635 "\n"
1636 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
1637 "\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"
1641 "\n"
1642 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
1643 " \n"
1644 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
1645 " plane = plane - mod(plane, PI / count);\n"
1646 "\n"
1647 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
1648 "\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"
1654 " return star;\n"
1655 "}\n"
1656 "\n"
1657 "float luminance( vec3 v )\n"
1658 "{\n"
1659 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
1660 "}\n"
1661 "\n"
1662 "vec3 clearskies_ambient( vec3 dir )\n"
1663 "{\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"
1666 " \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"
1671 " \n"
1672 " /* Add gradient */\n"
1673 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
1674 " \n"
1675 " return ambient;\n"
1676 "}\n"
1677 "\n"
1678 "vec3 clearskies_sky( vec3 ray_dir )\n"
1679 "{\n"
1680 " ray_dir.y = abs( ray_dir.y );\n"
1681 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
1682 " \n"
1683 " /* Sun */\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"
1688 " \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"
1691 "\n"
1692 " \n"
1693 " float star = 0.0;\n"
1694 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
1695 "\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"
1700 " }\n"
1701 " }\n"
1702 " \n"
1703 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
1704 " return composite;\n"
1705 "}\n"
1706 "\n"
1707 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
1708 "{\n"
1709 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
1710 "\n"
1711 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
1712 " g_sunset_phase );\n"
1713 "\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"
1718 "\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"
1722 "\n"
1723 " return ambient + (light_sun + sky_reflection) * shadow;\n"
1724 "}\n"
1725 "\n"
1726 "#line 44 0 \n"
1727 "\n"
1728 "float world_depth_sample( vec3 pos )\n"
1729 "{\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"
1732 "}\n"
1733 "\n"
1734 "float world_water_depth( vec3 pos )\n"
1735 "{\n"
1736 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
1737 " return world_depth_sample( pos ) - ref_depth;\n"
1738 "}\n"
1739 "\n"
1740 "float shadow_sample( vec3 co ){\n"
1741 " float height_sample = world_depth_sample( co );\n"
1742 "\n"
1743 " float fdelta = height_sample - co.y;\n"
1744 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
1745 "}\n"
1746 "\n"
1747 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
1748 " if( g_shadow_samples == 0 ){\n"
1749 " return 1.0;\n"
1750 " }\n"
1751 "\n"
1752 " float fspread = g_shadow_spread;\n"
1753 " float flength = g_shadow_length;\n"
1754 "\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"
1760 "\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"
1765 "\n"
1766 " return 1.0 - famt;\n"
1767 "}\n"
1768 "\n"
1769 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
1770 "{\n"
1771 " vec3 specdir = reflect( -dir, wnormal );\n"
1772 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
1773 "}\n"
1774 "\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"
1778 "}\n"
1779 "\n"
1780 "vec3 scene_calculate_light( int light_index, \n"
1781 " vec3 halfview, vec3 co, vec3 normal )\n"
1782 "{\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"
1786 "\n"
1787 " vec3 light_delta = light_co.xyz-co;\n"
1788 " float dist2 = dot(light_delta,light_delta);\n"
1789 "\n"
1790 " light_delta = normalize( light_delta );\n"
1791 "\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"
1795 "\n"
1796 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
1797 "\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"
1801 " }\n"
1802 "\n"
1803 " return light_colour.rgb * attenuation * falloff \n"
1804 " * step( g_day_phase, light_colour.w );\n"
1805 "}\n"
1806 "\n"
1807 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
1808 " vec3 halfview, vec3 co, vec3 normal )\n"
1809 "{\n"
1810 " uint light_count = packed_index & 0x3u;\n"
1811 "\n"
1812 " vec3 l = vec3(0.0);\n"
1813 "\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"
1818 "\n"
1819 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
1820 "\n"
1821 " if( light_count >= 2u ){\n"
1822 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
1823 "\n"
1824 " if( light_count >= 3u ){\n"
1825 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
1826 " }\n"
1827 " }\n"
1828 " }\n"
1829 "\n"
1830 " return l;\n"
1831 "}\n"
1832 "\n"
1833 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
1834 " float light_mask )\n"
1835 "{\n"
1836 " if( g_light_preview == 1 )\n"
1837 " diffuse = vec3(0.75);\n"
1838 "\n"
1839 " // Lighting\n"
1840 " vec3 halfview = uCamera - co;\n"
1841 " float fdist = length(halfview);\n"
1842 " halfview /= fdist;\n"
1843 "\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"
1846 "\n"
1847 " vec3 total_light = clearskies_lighting( \n"
1848 " normal, min( light_mask, world_shadow ), halfview );\n"
1849 "\n"
1850 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
1851 " cube_coord = floor( cube_coord );\n"
1852 "\n"
1853 " if( g_debug_indices == 1 )\n"
1854 " {\n"
1855 " return rand33(cube_coord);\n"
1856 " }\n"
1857 "\n"
1858 " if( g_debug_complexity == 1 )\n"
1859 " {\n"
1860 " ivec3 coord = ivec3( cube_coord );\n"
1861 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1862 "\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"
1865 " }\n"
1866 "\n"
1867 " // FIXME: this coord should absolutely must be clamped!\n"
1868 " \n"
1869 " ivec3 coord = ivec3( cube_coord );\n"
1870 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
1871 "\n"
1872 " total_light += \n"
1873 " scene_calculate_packed_light_patch( index_sample.x,\n"
1874 " halfview, co, normal ) \n"
1875 " * light_mask;\n"
1876 " total_light += \n"
1877 " scene_calculate_packed_light_patch( index_sample.y,\n"
1878 " halfview, co, normal )\n"
1879 " * light_mask;\n"
1880 "\n"
1881 " // Take a section of the sky function to give us a matching fog colour\n"
1882 "\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"
1887 " \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"
1890 "\n"
1891 " fog_colour += sun_colour;\n"
1892 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
1893 "}\n"
1894 "\n"
1895 "#line 9 0 \n"
1896 "\n"
1897 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
1898 "{\n"
1899 " vec3 pa = p - a;\n"
1900 " vec3 ba = b - a;\n"
1901 "\n"
1902 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
1903 " return length( pa - ba*h );\n"
1904 "}\n"
1905 "\n"
1906 "float compute_board_shadow()\n"
1907 "{\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"
1913 "\n"
1914 " return 1.0 - player_shadow*0.8;\n"
1915 "}\n"
1916 "\n"
1917 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
1918 "{\n"
1919 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
1920 "}\n"
1921 "\n"
1922 "#line 13 0 \n"
1923 "#line 1 3 \n"
1924 "const float k_motion_lerp_amount = 0.01;\n"
1925 "\n"
1926 "#line 2 0 \n"
1927 "\n"
1928 "layout (location = 1) out vec2 oMotionVec;\n"
1929 "\n"
1930 "in vec3 aMotionVec0;\n"
1931 "in vec3 aMotionVec1;\n"
1932 "\n"
1933 "void compute_motion_vectors()\n"
1934 "{\n"
1935 " // Write motion vectors\n"
1936 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
1937 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
1938 "\n"
1939 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
1940 "}\n"
1941 "\n"
1942 "#line 14 0 \n"
1943 "\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"
1948 "\n"
1949 " if( a < b )\n"
1950 " return vec2(a-s,m);\n"
1951 " else\n"
1952 " return vec2(b-s,1.0-m);\n"
1953 "}\n"
1954 "\n"
1955 "void main(){\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"
1959 "\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"
1963 "\n"
1964 " if( min(min(dy0,dy1)*0.5, dcam) + dither < 0.51 ) \n"
1965 " discard;\n"
1966 "\n"
1967 " compute_motion_vectors();\n"
1968 "\n"
1969 " vec3 vfrag = vec3(0.898,0.811,0.716);\n"
1970 " vec3 qnorm = aNorm.xyz;\n"
1971 "\n"
1972 " qnorm = normalize(floor(aNorm.xyz*4.0)*0.25);\n"
1973 " qnorm += vec3(0.001,0.0,0.0);\n"
1974 "\n"
1975 " if( uAlphatest ){\n"
1976 " vec4 vSample = texture( uTexMain, aUv );\n"
1977 " if( vSample.a < 0.5 )\n"
1978 " discard;\n"
1979 " }\n"
1980 " else{\n"
1981 " }\n"
1982 "\n"
1983 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
1984 " \n"
1985 " // dots\n"
1986 " float d0 = distance( aCo, uPlayerPos.xyz )*2.0;\n"
1987 " float d1 = distance( aCo, uSpawnPos.xyz );\n"
1988 "\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"
1994 "\n"
1995 " // line\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"
2001 "\n"
2002 " vfrag += emit;\n"
2003 "\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"
2008 " }\n"
2009 "\n"
2010 " oColour = vec4( vfrag, 1.0 );\n"
2011 " //oColour = vec4( vfrag, 1.0 );\n"
2012 "}\n"
2013 ""},
2014 };
2015
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",
2034 .vs =
2035 {
2036 .orig_file = "shaders/scene_fxglow.vs",
2037 .static_src =
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"
2041 "\n"
2042 "#line 1 1 \n"
2043 "const float k_motion_lerp_amount = 0.01;\n"
2044 "\n"
2045 "#line 2 0 \n"
2046 "\n"
2047 "out vec3 aMotionVec0;\n"
2048 "out vec3 aMotionVec1;\n"
2049 "\n"
2050 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
2051 "{\n"
2052 " // This magically solves some artifacting errors!\n"
2053 " //\n"
2054 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
2055 "\n"
2056 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
2057 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
2058 "}\n"
2059 "\n"
2060 "#line 6 0 \n"
2061 "\n"
2062 "uniform mat4x3 uMdl;\n"
2063 "uniform mat4 uPv;\n"
2064 "uniform mat4 uPvmPrev;\n"
2065 "uniform vec2 uUvOffset;\n"
2066 "\n"
2067 "out vec2 aUv;\n"
2068 "out vec4 aNorm;\n"
2069 "out vec3 aCo;\n"
2070 "out vec3 aWorldCo;\n"
2071 "\n"
2072 "void main()\n"
2073 "{\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"
2077 "\n"
2078 " vs_motion_out( vproj0, vproj1 );\n"
2079 "\n"
2080 " gl_Position = vproj0;\n"
2081 "\n"
2082 " aUv = a_uv + uUvOffset;\n"
2083 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
2084 " aCo = a_co;\n"
2085 " aWorldCo = world_pos0;\n"
2086 "}\n"
2087 ""},
2088 .fs =
2089 {
2090 .orig_file = "shaders/scene_fxglow.fs",
2091 .static_src =
2092 "uniform sampler2D uTexMain;\n"
2093 "uniform vec3 uCamera;\n"
2094 "\n"
2095 "#line 1 1 \n"
2096 "// :D\n"
2097 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
2098 "\n"
2099 "#line 5 0 \n"
2100 "#line 1 2 \n"
2101 "// :D\n"
2102 "\n"
2103 "in vec2 aUv;\n"
2104 "in vec4 aNorm;\n"
2105 "in vec3 aCo;\n"
2106 "in vec3 aWorldCo;\n"
2107 "\n"
2108 "#line 1 1 \n"
2109 "layout (location = 0) out vec4 oColour;\n"
2110 "\n"
2111 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
2112 "layout (std140) uniform ub_world_lighting\n"
2113 "{\n"
2114 " vec4 g_cube_min;\n"
2115 " vec4 g_cube_inv_range;\n"
2116 "\n"
2117 " vec4 g_water_plane;\n"
2118 " vec4 g_depth_bounds;\n"
2119 "\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"
2129 "\n"
2130 " float g_water_fog;\n"
2131 " float g_time;\n"
2132 " float g_realtime;\n"
2133 " float g_shadow_length;\n"
2134 " float g_shadow_spread;\n"
2135 "\n"
2136 " float g_time_of_day;\n"
2137 " float g_day_phase;\n"
2138 " float g_sunset_phase;\n"
2139 "\n"
2140 " int g_light_preview;\n"
2141 " int g_shadow_samples;\n"
2142 "\n"
2143 " int g_debug_indices;\n"
2144 " int g_debug_complexity;\n"
2145 "};\n"
2146 "\n"
2147 "uniform sampler2D g_world_depth;\n"
2148 "uniform samplerBuffer uLightsArray;\n"
2149 "uniform usampler3D uLightsIndex;\n"
2150 "\n"
2151 "#line 1 1 \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"
2158 "\n"
2159 "const float SUN_ANGLE = 0.0001;\n"
2160 "const float PI = 3.14159265358979323846264;\n"
2161 "\n"
2162 "//struct world_info\n"
2163 "//{\n"
2164 "// float time,\n"
2165 "// time_of_day,\n"
2166 "// day_phase,\n"
2167 "// sunset_phase;\n"
2168 "// \n"
2169 "// vec3 sun_dir;\n"
2170 "//};\n"
2171 "\n"
2172 "vec3 rand33(vec3 p3)\n"
2173 "{\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"
2177 "}\n"
2178 "\n"
2179 "float stars( vec3 rd, float rr, float size ){\n"
2180 " vec3 co = rd * rr;\n"
2181 "\n"
2182 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
2183 "\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"
2187 "\n"
2188 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
2189 " \n"
2190 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
2191 " plane = plane - mod(plane, PI / count);\n"
2192 "\n"
2193 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
2194 "\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"
2200 " return star;\n"
2201 "}\n"
2202 "\n"
2203 "float luminance( vec3 v )\n"
2204 "{\n"
2205 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
2206 "}\n"
2207 "\n"
2208 "vec3 clearskies_ambient( vec3 dir )\n"
2209 "{\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"
2212 " \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"
2217 " \n"
2218 " /* Add gradient */\n"
2219 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
2220 " \n"
2221 " return ambient;\n"
2222 "}\n"
2223 "\n"
2224 "vec3 clearskies_sky( vec3 ray_dir )\n"
2225 "{\n"
2226 " ray_dir.y = abs( ray_dir.y );\n"
2227 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
2228 " \n"
2229 " /* Sun */\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"
2234 " \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"
2237 "\n"
2238 " \n"
2239 " float star = 0.0;\n"
2240 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
2241 "\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"
2246 " }\n"
2247 " }\n"
2248 " \n"
2249 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
2250 " return composite;\n"
2251 "}\n"
2252 "\n"
2253 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
2254 "{\n"
2255 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
2256 "\n"
2257 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
2258 " g_sunset_phase );\n"
2259 "\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"
2264 "\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"
2268 "\n"
2269 " return ambient + (light_sun + sky_reflection) * shadow;\n"
2270 "}\n"
2271 "\n"
2272 "#line 44 0 \n"
2273 "\n"
2274 "float world_depth_sample( vec3 pos )\n"
2275 "{\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"
2278 "}\n"
2279 "\n"
2280 "float world_water_depth( vec3 pos )\n"
2281 "{\n"
2282 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
2283 " return world_depth_sample( pos ) - ref_depth;\n"
2284 "}\n"
2285 "\n"
2286 "float shadow_sample( vec3 co ){\n"
2287 " float height_sample = world_depth_sample( co );\n"
2288 "\n"
2289 " float fdelta = height_sample - co.y;\n"
2290 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
2291 "}\n"
2292 "\n"
2293 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
2294 " if( g_shadow_samples == 0 ){\n"
2295 " return 1.0;\n"
2296 " }\n"
2297 "\n"
2298 " float fspread = g_shadow_spread;\n"
2299 " float flength = g_shadow_length;\n"
2300 "\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"
2306 "\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"
2311 "\n"
2312 " return 1.0 - famt;\n"
2313 "}\n"
2314 "\n"
2315 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
2316 "{\n"
2317 " vec3 specdir = reflect( -dir, wnormal );\n"
2318 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
2319 "}\n"
2320 "\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"
2324 "}\n"
2325 "\n"
2326 "vec3 scene_calculate_light( int light_index, \n"
2327 " vec3 halfview, vec3 co, vec3 normal )\n"
2328 "{\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"
2332 "\n"
2333 " vec3 light_delta = light_co.xyz-co;\n"
2334 " float dist2 = dot(light_delta,light_delta);\n"
2335 "\n"
2336 " light_delta = normalize( light_delta );\n"
2337 "\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"
2341 "\n"
2342 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
2343 "\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"
2347 " }\n"
2348 "\n"
2349 " return light_colour.rgb * attenuation * falloff \n"
2350 " * step( g_day_phase, light_colour.w );\n"
2351 "}\n"
2352 "\n"
2353 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
2354 " vec3 halfview, vec3 co, vec3 normal )\n"
2355 "{\n"
2356 " uint light_count = packed_index & 0x3u;\n"
2357 "\n"
2358 " vec3 l = vec3(0.0);\n"
2359 "\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"
2364 "\n"
2365 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
2366 "\n"
2367 " if( light_count >= 2u ){\n"
2368 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
2369 "\n"
2370 " if( light_count >= 3u ){\n"
2371 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
2372 " }\n"
2373 " }\n"
2374 " }\n"
2375 "\n"
2376 " return l;\n"
2377 "}\n"
2378 "\n"
2379 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
2380 " float light_mask )\n"
2381 "{\n"
2382 " if( g_light_preview == 1 )\n"
2383 " diffuse = vec3(0.75);\n"
2384 "\n"
2385 " // Lighting\n"
2386 " vec3 halfview = uCamera - co;\n"
2387 " float fdist = length(halfview);\n"
2388 " halfview /= fdist;\n"
2389 "\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"
2392 "\n"
2393 " vec3 total_light = clearskies_lighting( \n"
2394 " normal, min( light_mask, world_shadow ), halfview );\n"
2395 "\n"
2396 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
2397 " cube_coord = floor( cube_coord );\n"
2398 "\n"
2399 " if( g_debug_indices == 1 )\n"
2400 " {\n"
2401 " return rand33(cube_coord);\n"
2402 " }\n"
2403 "\n"
2404 " if( g_debug_complexity == 1 )\n"
2405 " {\n"
2406 " ivec3 coord = ivec3( cube_coord );\n"
2407 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2408 "\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"
2411 " }\n"
2412 "\n"
2413 " // FIXME: this coord should absolutely must be clamped!\n"
2414 " \n"
2415 " ivec3 coord = ivec3( cube_coord );\n"
2416 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2417 "\n"
2418 " total_light += \n"
2419 " scene_calculate_packed_light_patch( index_sample.x,\n"
2420 " halfview, co, normal ) \n"
2421 " * light_mask;\n"
2422 " total_light += \n"
2423 " scene_calculate_packed_light_patch( index_sample.y,\n"
2424 " halfview, co, normal )\n"
2425 " * light_mask;\n"
2426 "\n"
2427 " // Take a section of the sky function to give us a matching fog colour\n"
2428 "\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"
2433 " \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"
2436 "\n"
2437 " fog_colour += sun_colour;\n"
2438 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
2439 "}\n"
2440 "\n"
2441 "#line 9 0 \n"
2442 "\n"
2443 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
2444 "{\n"
2445 " vec3 pa = p - a;\n"
2446 " vec3 ba = b - a;\n"
2447 "\n"
2448 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
2449 " return length( pa - ba*h );\n"
2450 "}\n"
2451 "\n"
2452 "float compute_board_shadow()\n"
2453 "{\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"
2459 "\n"
2460 " return 1.0 - player_shadow*0.8;\n"
2461 "}\n"
2462 "\n"
2463 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
2464 "{\n"
2465 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
2466 "}\n"
2467 "\n"
2468 "#line 6 0 \n"
2469 "#line 1 3 \n"
2470 "const float k_motion_lerp_amount = 0.01;\n"
2471 "\n"
2472 "#line 2 0 \n"
2473 "\n"
2474 "layout (location = 1) out vec2 oMotionVec;\n"
2475 "\n"
2476 "in vec3 aMotionVec0;\n"
2477 "in vec3 aMotionVec1;\n"
2478 "\n"
2479 "void compute_motion_vectors()\n"
2480 "{\n"
2481 " // Write motion vectors\n"
2482 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
2483 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
2484 "\n"
2485 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
2486 "}\n"
2487 "\n"
2488 "#line 7 0 \n"
2489 "\n"
2490 "void main(){\n"
2491 " oMotionVec = vec2(0.0);\n"
2492 "\n"
2493 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
2494 "\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"
2498 "\n"
2499 " if( vsamplemain.a+dither<0.5 )\n"
2500 " discard;\n"
2501 "\n"
2502 " oColour = vec4( vsamplemain.rgb, 1.0 );\n"
2503 "}\n"
2504 ""},
2505 };
2506
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",
2519 .vs =
2520 {
2521 .orig_file = "shaders/scene.vs",
2522 .static_src =
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"
2526 "\n"
2527 "#line 1 1 \n"
2528 "const float k_motion_lerp_amount = 0.01;\n"
2529 "\n"
2530 "#line 2 0 \n"
2531 "\n"
2532 "out vec3 aMotionVec0;\n"
2533 "out vec3 aMotionVec1;\n"
2534 "\n"
2535 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
2536 "{\n"
2537 " // This magically solves some artifacting errors!\n"
2538 " //\n"
2539 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
2540 "\n"
2541 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
2542 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
2543 "}\n"
2544 "\n"
2545 "#line 6 0 \n"
2546 "\n"
2547 "uniform mat4x3 uMdl;\n"
2548 "uniform mat4 uPv;\n"
2549 "uniform mat4 uPvmPrev;\n"
2550 "\n"
2551 "out vec2 aUv;\n"
2552 "out vec4 aNorm;\n"
2553 "out vec3 aCo;\n"
2554 "out vec3 aWorldCo;\n"
2555 "\n"
2556 "void main()\n"
2557 "{\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"
2561 "\n"
2562 " vs_motion_out( vproj0, vproj1 );\n"
2563 "\n"
2564 " gl_Position = vproj0;\n"
2565 "\n"
2566 " aUv = a_uv;\n"
2567 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
2568 " aCo = a_co;\n"
2569 " aWorldCo = world_pos0;\n"
2570 "}\n"
2571 ""},
2572 .fs =
2573 {
2574 .orig_file = "shaders/scene_vertex_blend.fs",
2575 .static_src =
2576 "uniform sampler2D uTexGarbage;\n"
2577 "uniform sampler2D uTexGradients;\n"
2578 "uniform vec3 uCamera;\n"
2579 "\n"
2580 "#line 1 1 \n"
2581 "// :D\n"
2582 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
2583 "\n"
2584 "#line 6 0 \n"
2585 "#line 1 2 \n"
2586 "// :D\n"
2587 "\n"
2588 "in vec2 aUv;\n"
2589 "in vec4 aNorm;\n"
2590 "in vec3 aCo;\n"
2591 "in vec3 aWorldCo;\n"
2592 "\n"
2593 "#line 1 1 \n"
2594 "layout (location = 0) out vec4 oColour;\n"
2595 "\n"
2596 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
2597 "layout (std140) uniform ub_world_lighting\n"
2598 "{\n"
2599 " vec4 g_cube_min;\n"
2600 " vec4 g_cube_inv_range;\n"
2601 "\n"
2602 " vec4 g_water_plane;\n"
2603 " vec4 g_depth_bounds;\n"
2604 "\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"
2614 "\n"
2615 " float g_water_fog;\n"
2616 " float g_time;\n"
2617 " float g_realtime;\n"
2618 " float g_shadow_length;\n"
2619 " float g_shadow_spread;\n"
2620 "\n"
2621 " float g_time_of_day;\n"
2622 " float g_day_phase;\n"
2623 " float g_sunset_phase;\n"
2624 "\n"
2625 " int g_light_preview;\n"
2626 " int g_shadow_samples;\n"
2627 "\n"
2628 " int g_debug_indices;\n"
2629 " int g_debug_complexity;\n"
2630 "};\n"
2631 "\n"
2632 "uniform sampler2D g_world_depth;\n"
2633 "uniform samplerBuffer uLightsArray;\n"
2634 "uniform usampler3D uLightsIndex;\n"
2635 "\n"
2636 "#line 1 1 \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"
2643 "\n"
2644 "const float SUN_ANGLE = 0.0001;\n"
2645 "const float PI = 3.14159265358979323846264;\n"
2646 "\n"
2647 "//struct world_info\n"
2648 "//{\n"
2649 "// float time,\n"
2650 "// time_of_day,\n"
2651 "// day_phase,\n"
2652 "// sunset_phase;\n"
2653 "// \n"
2654 "// vec3 sun_dir;\n"
2655 "//};\n"
2656 "\n"
2657 "vec3 rand33(vec3 p3)\n"
2658 "{\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"
2662 "}\n"
2663 "\n"
2664 "float stars( vec3 rd, float rr, float size ){\n"
2665 " vec3 co = rd * rr;\n"
2666 "\n"
2667 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
2668 "\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"
2672 "\n"
2673 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
2674 " \n"
2675 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
2676 " plane = plane - mod(plane, PI / count);\n"
2677 "\n"
2678 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
2679 "\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"
2685 " return star;\n"
2686 "}\n"
2687 "\n"
2688 "float luminance( vec3 v )\n"
2689 "{\n"
2690 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
2691 "}\n"
2692 "\n"
2693 "vec3 clearskies_ambient( vec3 dir )\n"
2694 "{\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"
2697 " \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"
2702 " \n"
2703 " /* Add gradient */\n"
2704 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
2705 " \n"
2706 " return ambient;\n"
2707 "}\n"
2708 "\n"
2709 "vec3 clearskies_sky( vec3 ray_dir )\n"
2710 "{\n"
2711 " ray_dir.y = abs( ray_dir.y );\n"
2712 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
2713 " \n"
2714 " /* Sun */\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"
2719 " \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"
2722 "\n"
2723 " \n"
2724 " float star = 0.0;\n"
2725 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
2726 "\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"
2731 " }\n"
2732 " }\n"
2733 " \n"
2734 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
2735 " return composite;\n"
2736 "}\n"
2737 "\n"
2738 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
2739 "{\n"
2740 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
2741 "\n"
2742 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
2743 " g_sunset_phase );\n"
2744 "\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"
2749 "\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"
2753 "\n"
2754 " return ambient + (light_sun + sky_reflection) * shadow;\n"
2755 "}\n"
2756 "\n"
2757 "#line 44 0 \n"
2758 "\n"
2759 "float world_depth_sample( vec3 pos )\n"
2760 "{\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"
2763 "}\n"
2764 "\n"
2765 "float world_water_depth( vec3 pos )\n"
2766 "{\n"
2767 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
2768 " return world_depth_sample( pos ) - ref_depth;\n"
2769 "}\n"
2770 "\n"
2771 "float shadow_sample( vec3 co ){\n"
2772 " float height_sample = world_depth_sample( co );\n"
2773 "\n"
2774 " float fdelta = height_sample - co.y;\n"
2775 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
2776 "}\n"
2777 "\n"
2778 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
2779 " if( g_shadow_samples == 0 ){\n"
2780 " return 1.0;\n"
2781 " }\n"
2782 "\n"
2783 " float fspread = g_shadow_spread;\n"
2784 " float flength = g_shadow_length;\n"
2785 "\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"
2791 "\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"
2796 "\n"
2797 " return 1.0 - famt;\n"
2798 "}\n"
2799 "\n"
2800 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
2801 "{\n"
2802 " vec3 specdir = reflect( -dir, wnormal );\n"
2803 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
2804 "}\n"
2805 "\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"
2809 "}\n"
2810 "\n"
2811 "vec3 scene_calculate_light( int light_index, \n"
2812 " vec3 halfview, vec3 co, vec3 normal )\n"
2813 "{\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"
2817 "\n"
2818 " vec3 light_delta = light_co.xyz-co;\n"
2819 " float dist2 = dot(light_delta,light_delta);\n"
2820 "\n"
2821 " light_delta = normalize( light_delta );\n"
2822 "\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"
2826 "\n"
2827 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
2828 "\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"
2832 " }\n"
2833 "\n"
2834 " return light_colour.rgb * attenuation * falloff \n"
2835 " * step( g_day_phase, light_colour.w );\n"
2836 "}\n"
2837 "\n"
2838 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
2839 " vec3 halfview, vec3 co, vec3 normal )\n"
2840 "{\n"
2841 " uint light_count = packed_index & 0x3u;\n"
2842 "\n"
2843 " vec3 l = vec3(0.0);\n"
2844 "\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"
2849 "\n"
2850 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
2851 "\n"
2852 " if( light_count >= 2u ){\n"
2853 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
2854 "\n"
2855 " if( light_count >= 3u ){\n"
2856 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
2857 " }\n"
2858 " }\n"
2859 " }\n"
2860 "\n"
2861 " return l;\n"
2862 "}\n"
2863 "\n"
2864 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
2865 " float light_mask )\n"
2866 "{\n"
2867 " if( g_light_preview == 1 )\n"
2868 " diffuse = vec3(0.75);\n"
2869 "\n"
2870 " // Lighting\n"
2871 " vec3 halfview = uCamera - co;\n"
2872 " float fdist = length(halfview);\n"
2873 " halfview /= fdist;\n"
2874 "\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"
2877 "\n"
2878 " vec3 total_light = clearskies_lighting( \n"
2879 " normal, min( light_mask, world_shadow ), halfview );\n"
2880 "\n"
2881 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
2882 " cube_coord = floor( cube_coord );\n"
2883 "\n"
2884 " if( g_debug_indices == 1 )\n"
2885 " {\n"
2886 " return rand33(cube_coord);\n"
2887 " }\n"
2888 "\n"
2889 " if( g_debug_complexity == 1 )\n"
2890 " {\n"
2891 " ivec3 coord = ivec3( cube_coord );\n"
2892 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2893 "\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"
2896 " }\n"
2897 "\n"
2898 " // FIXME: this coord should absolutely must be clamped!\n"
2899 " \n"
2900 " ivec3 coord = ivec3( cube_coord );\n"
2901 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
2902 "\n"
2903 " total_light += \n"
2904 " scene_calculate_packed_light_patch( index_sample.x,\n"
2905 " halfview, co, normal ) \n"
2906 " * light_mask;\n"
2907 " total_light += \n"
2908 " scene_calculate_packed_light_patch( index_sample.y,\n"
2909 " halfview, co, normal )\n"
2910 " * light_mask;\n"
2911 "\n"
2912 " // Take a section of the sky function to give us a matching fog colour\n"
2913 "\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"
2918 " \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"
2921 "\n"
2922 " fog_colour += sun_colour;\n"
2923 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
2924 "}\n"
2925 "\n"
2926 "#line 9 0 \n"
2927 "\n"
2928 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
2929 "{\n"
2930 " vec3 pa = p - a;\n"
2931 " vec3 ba = b - a;\n"
2932 "\n"
2933 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
2934 " return length( pa - ba*h );\n"
2935 "}\n"
2936 "\n"
2937 "float compute_board_shadow()\n"
2938 "{\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"
2944 "\n"
2945 " return 1.0 - player_shadow*0.8;\n"
2946 "}\n"
2947 "\n"
2948 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
2949 "{\n"
2950 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
2951 "}\n"
2952 "\n"
2953 "#line 7 0 \n"
2954 "#line 1 3 \n"
2955 "const float k_motion_lerp_amount = 0.01;\n"
2956 "\n"
2957 "#line 2 0 \n"
2958 "\n"
2959 "layout (location = 1) out vec2 oMotionVec;\n"
2960 "\n"
2961 "in vec3 aMotionVec0;\n"
2962 "in vec3 aMotionVec1;\n"
2963 "\n"
2964 "void compute_motion_vectors()\n"
2965 "{\n"
2966 " // Write motion vectors\n"
2967 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
2968 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
2969 "\n"
2970 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
2971 "}\n"
2972 "\n"
2973 "#line 8 0 \n"
2974 "\n"
2975 "void main()\n"
2976 "{\n"
2977 " compute_motion_vectors();\n"
2978 "\n"
2979 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
2980 "\n"
2981 " // ws modulation\n"
2982 " vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);\n"
2983 " \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"
2988 "\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"
2992 " \n"
2993 " // Patch local noise\n"
2994 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
2995 "\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"
2999 "\n"
3000 " vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
3001 " vfrag -= rgarbage.a*0.04;\n"
3002 "\n"
3003 " if( g_light_preview == 1 )\n"
3004 " {\n"
3005 " vfrag = vec3(0.5);\n"
3006 " }\n"
3007 "\n"
3008 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
3009 " oColour = vec4(vfrag, 1.0);\n"
3010 "}\n"
3011 ""},
3012 };
3013
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",
3026 .vs =
3027 {
3028 .orig_file = "shaders/scene.vs",
3029 .static_src =
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"
3033 "\n"
3034 "#line 1 1 \n"
3035 "const float k_motion_lerp_amount = 0.01;\n"
3036 "\n"
3037 "#line 2 0 \n"
3038 "\n"
3039 "out vec3 aMotionVec0;\n"
3040 "out vec3 aMotionVec1;\n"
3041 "\n"
3042 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
3043 "{\n"
3044 " // This magically solves some artifacting errors!\n"
3045 " //\n"
3046 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
3047 "\n"
3048 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
3049 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
3050 "}\n"
3051 "\n"
3052 "#line 6 0 \n"
3053 "\n"
3054 "uniform mat4x3 uMdl;\n"
3055 "uniform mat4 uPv;\n"
3056 "uniform mat4 uPvmPrev;\n"
3057 "\n"
3058 "out vec2 aUv;\n"
3059 "out vec4 aNorm;\n"
3060 "out vec3 aCo;\n"
3061 "out vec3 aWorldCo;\n"
3062 "\n"
3063 "void main()\n"
3064 "{\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"
3068 "\n"
3069 " vs_motion_out( vproj0, vproj1 );\n"
3070 "\n"
3071 " gl_Position = vproj0;\n"
3072 "\n"
3073 " aUv = a_uv;\n"
3074 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
3075 " aCo = a_co;\n"
3076 " aWorldCo = world_pos0;\n"
3077 "}\n"
3078 ""},
3079 .fs =
3080 {
3081 .orig_file = "shaders/scene_terrain.fs",
3082 .static_src =
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"
3088 "\n"
3089 "#line 1 1 \n"
3090 "// :D\n"
3091 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
3092 "\n"
3093 "#line 8 0 \n"
3094 "#line 1 2 \n"
3095 "// :D\n"
3096 "\n"
3097 "in vec2 aUv;\n"
3098 "in vec4 aNorm;\n"
3099 "in vec3 aCo;\n"
3100 "in vec3 aWorldCo;\n"
3101 "\n"
3102 "#line 1 1 \n"
3103 "layout (location = 0) out vec4 oColour;\n"
3104 "\n"
3105 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
3106 "layout (std140) uniform ub_world_lighting\n"
3107 "{\n"
3108 " vec4 g_cube_min;\n"
3109 " vec4 g_cube_inv_range;\n"
3110 "\n"
3111 " vec4 g_water_plane;\n"
3112 " vec4 g_depth_bounds;\n"
3113 "\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"
3123 "\n"
3124 " float g_water_fog;\n"
3125 " float g_time;\n"
3126 " float g_realtime;\n"
3127 " float g_shadow_length;\n"
3128 " float g_shadow_spread;\n"
3129 "\n"
3130 " float g_time_of_day;\n"
3131 " float g_day_phase;\n"
3132 " float g_sunset_phase;\n"
3133 "\n"
3134 " int g_light_preview;\n"
3135 " int g_shadow_samples;\n"
3136 "\n"
3137 " int g_debug_indices;\n"
3138 " int g_debug_complexity;\n"
3139 "};\n"
3140 "\n"
3141 "uniform sampler2D g_world_depth;\n"
3142 "uniform samplerBuffer uLightsArray;\n"
3143 "uniform usampler3D uLightsIndex;\n"
3144 "\n"
3145 "#line 1 1 \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"
3152 "\n"
3153 "const float SUN_ANGLE = 0.0001;\n"
3154 "const float PI = 3.14159265358979323846264;\n"
3155 "\n"
3156 "//struct world_info\n"
3157 "//{\n"
3158 "// float time,\n"
3159 "// time_of_day,\n"
3160 "// day_phase,\n"
3161 "// sunset_phase;\n"
3162 "// \n"
3163 "// vec3 sun_dir;\n"
3164 "//};\n"
3165 "\n"
3166 "vec3 rand33(vec3 p3)\n"
3167 "{\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"
3171 "}\n"
3172 "\n"
3173 "float stars( vec3 rd, float rr, float size ){\n"
3174 " vec3 co = rd * rr;\n"
3175 "\n"
3176 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
3177 "\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"
3181 "\n"
3182 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
3183 " \n"
3184 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
3185 " plane = plane - mod(plane, PI / count);\n"
3186 "\n"
3187 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
3188 "\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"
3194 " return star;\n"
3195 "}\n"
3196 "\n"
3197 "float luminance( vec3 v )\n"
3198 "{\n"
3199 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
3200 "}\n"
3201 "\n"
3202 "vec3 clearskies_ambient( vec3 dir )\n"
3203 "{\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"
3206 " \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"
3211 " \n"
3212 " /* Add gradient */\n"
3213 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
3214 " \n"
3215 " return ambient;\n"
3216 "}\n"
3217 "\n"
3218 "vec3 clearskies_sky( vec3 ray_dir )\n"
3219 "{\n"
3220 " ray_dir.y = abs( ray_dir.y );\n"
3221 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
3222 " \n"
3223 " /* Sun */\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"
3228 " \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"
3231 "\n"
3232 " \n"
3233 " float star = 0.0;\n"
3234 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
3235 "\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"
3240 " }\n"
3241 " }\n"
3242 " \n"
3243 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
3244 " return composite;\n"
3245 "}\n"
3246 "\n"
3247 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
3248 "{\n"
3249 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
3250 "\n"
3251 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
3252 " g_sunset_phase );\n"
3253 "\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"
3258 "\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"
3262 "\n"
3263 " return ambient + (light_sun + sky_reflection) * shadow;\n"
3264 "}\n"
3265 "\n"
3266 "#line 44 0 \n"
3267 "\n"
3268 "float world_depth_sample( vec3 pos )\n"
3269 "{\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"
3272 "}\n"
3273 "\n"
3274 "float world_water_depth( vec3 pos )\n"
3275 "{\n"
3276 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
3277 " return world_depth_sample( pos ) - ref_depth;\n"
3278 "}\n"
3279 "\n"
3280 "float shadow_sample( vec3 co ){\n"
3281 " float height_sample = world_depth_sample( co );\n"
3282 "\n"
3283 " float fdelta = height_sample - co.y;\n"
3284 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
3285 "}\n"
3286 "\n"
3287 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
3288 " if( g_shadow_samples == 0 ){\n"
3289 " return 1.0;\n"
3290 " }\n"
3291 "\n"
3292 " float fspread = g_shadow_spread;\n"
3293 " float flength = g_shadow_length;\n"
3294 "\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"
3300 "\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"
3305 "\n"
3306 " return 1.0 - famt;\n"
3307 "}\n"
3308 "\n"
3309 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
3310 "{\n"
3311 " vec3 specdir = reflect( -dir, wnormal );\n"
3312 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
3313 "}\n"
3314 "\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"
3318 "}\n"
3319 "\n"
3320 "vec3 scene_calculate_light( int light_index, \n"
3321 " vec3 halfview, vec3 co, vec3 normal )\n"
3322 "{\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"
3326 "\n"
3327 " vec3 light_delta = light_co.xyz-co;\n"
3328 " float dist2 = dot(light_delta,light_delta);\n"
3329 "\n"
3330 " light_delta = normalize( light_delta );\n"
3331 "\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"
3335 "\n"
3336 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
3337 "\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"
3341 " }\n"
3342 "\n"
3343 " return light_colour.rgb * attenuation * falloff \n"
3344 " * step( g_day_phase, light_colour.w );\n"
3345 "}\n"
3346 "\n"
3347 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
3348 " vec3 halfview, vec3 co, vec3 normal )\n"
3349 "{\n"
3350 " uint light_count = packed_index & 0x3u;\n"
3351 "\n"
3352 " vec3 l = vec3(0.0);\n"
3353 "\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"
3358 "\n"
3359 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
3360 "\n"
3361 " if( light_count >= 2u ){\n"
3362 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
3363 "\n"
3364 " if( light_count >= 3u ){\n"
3365 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
3366 " }\n"
3367 " }\n"
3368 " }\n"
3369 "\n"
3370 " return l;\n"
3371 "}\n"
3372 "\n"
3373 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
3374 " float light_mask )\n"
3375 "{\n"
3376 " if( g_light_preview == 1 )\n"
3377 " diffuse = vec3(0.75);\n"
3378 "\n"
3379 " // Lighting\n"
3380 " vec3 halfview = uCamera - co;\n"
3381 " float fdist = length(halfview);\n"
3382 " halfview /= fdist;\n"
3383 "\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"
3386 "\n"
3387 " vec3 total_light = clearskies_lighting( \n"
3388 " normal, min( light_mask, world_shadow ), halfview );\n"
3389 "\n"
3390 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
3391 " cube_coord = floor( cube_coord );\n"
3392 "\n"
3393 " if( g_debug_indices == 1 )\n"
3394 " {\n"
3395 " return rand33(cube_coord);\n"
3396 " }\n"
3397 "\n"
3398 " if( g_debug_complexity == 1 )\n"
3399 " {\n"
3400 " ivec3 coord = ivec3( cube_coord );\n"
3401 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3402 "\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"
3405 " }\n"
3406 "\n"
3407 " // FIXME: this coord should absolutely must be clamped!\n"
3408 " \n"
3409 " ivec3 coord = ivec3( cube_coord );\n"
3410 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3411 "\n"
3412 " total_light += \n"
3413 " scene_calculate_packed_light_patch( index_sample.x,\n"
3414 " halfview, co, normal ) \n"
3415 " * light_mask;\n"
3416 " total_light += \n"
3417 " scene_calculate_packed_light_patch( index_sample.y,\n"
3418 " halfview, co, normal )\n"
3419 " * light_mask;\n"
3420 "\n"
3421 " // Take a section of the sky function to give us a matching fog colour\n"
3422 "\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"
3427 " \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"
3430 "\n"
3431 " fog_colour += sun_colour;\n"
3432 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
3433 "}\n"
3434 "\n"
3435 "#line 9 0 \n"
3436 "\n"
3437 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
3438 "{\n"
3439 " vec3 pa = p - a;\n"
3440 " vec3 ba = b - a;\n"
3441 "\n"
3442 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
3443 " return length( pa - ba*h );\n"
3444 "}\n"
3445 "\n"
3446 "float compute_board_shadow()\n"
3447 "{\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"
3453 "\n"
3454 " return 1.0 - player_shadow*0.8;\n"
3455 "}\n"
3456 "\n"
3457 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
3458 "{\n"
3459 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
3460 "}\n"
3461 "\n"
3462 "#line 9 0 \n"
3463 "#line 1 3 \n"
3464 "const float k_motion_lerp_amount = 0.01;\n"
3465 "\n"
3466 "#line 2 0 \n"
3467 "\n"
3468 "layout (location = 1) out vec2 oMotionVec;\n"
3469 "\n"
3470 "in vec3 aMotionVec0;\n"
3471 "in vec3 aMotionVec1;\n"
3472 "\n"
3473 "void compute_motion_vectors()\n"
3474 "{\n"
3475 " // Write motion vectors\n"
3476 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
3477 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
3478 "\n"
3479 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
3480 "}\n"
3481 "\n"
3482 "#line 10 0 \n"
3483 "\n"
3484 "void main()\n"
3485 "{\n"
3486 " compute_motion_vectors();\n"
3487 "\n"
3488 " // Colour\n"
3489 " // ------\n"
3490 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
3491 "\n"
3492 " // ws modulation\n"
3493 " vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
3494 " \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"
3499 "\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"
3503 " \n"
3504 " // Patch local noise\n"
3505 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
3506 "\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"
3513 "\n"
3514 " qnorm = mix( qnorm, aNorm.xyz, amtsand );\n"
3515 " \n"
3516 " if( g_light_preview == 1 )\n"
3517 " {\n"
3518 " vfrag = vec3(0.5);\n"
3519 " }\n"
3520 "\n"
3521 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
3522 " oColour = vec4(vfrag, 1.0);\n"
3523 "}\n"
3524 ""},
3525 };
3526
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",
3541 .vs =
3542 {
3543 .orig_file = "shaders/scene_override.vs",
3544 .static_src =
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"
3548 "\n"
3549 "#line 1 1 \n"
3550 "const float k_motion_lerp_amount = 0.01;\n"
3551 "\n"
3552 "#line 2 0 \n"
3553 "\n"
3554 "out vec3 aMotionVec0;\n"
3555 "out vec3 aMotionVec1;\n"
3556 "\n"
3557 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
3558 "{\n"
3559 " // This magically solves some artifacting errors!\n"
3560 " //\n"
3561 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
3562 "\n"
3563 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
3564 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
3565 "}\n"
3566 "\n"
3567 "#line 6 0 \n"
3568 "\n"
3569 "uniform mat4x3 uMdl;\n"
3570 "uniform mat4 uPv;\n"
3571 "uniform mat4 uPvmPrev;\n"
3572 "uniform mat3 uNormalMtx;\n"
3573 "\n"
3574 "out vec2 aUv;\n"
3575 "out vec4 aNorm;\n"
3576 "out vec3 aCo;\n"
3577 "out vec3 aWorldCo;\n"
3578 "\n"
3579 "void main()\n"
3580 "{\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"
3584 "\n"
3585 " vs_motion_out( vproj0, vproj1 );\n"
3586 "\n"
3587 " gl_Position = vproj0;\n"
3588 "\n"
3589 " aUv = a_uv;\n"
3590 " aNorm = vec4( uNormalMtx * a_norm.xyz, a_norm.w );\n"
3591 " aCo = a_co;\n"
3592 " aWorldCo = world_pos0;\n"
3593 "}\n"
3594 ""},
3595 .fs =
3596 {
3597 .orig_file = "shaders/scene_route.fs",
3598 .static_src =
3599 "uniform sampler2D uTexGarbage;\n"
3600 "uniform sampler2D uTexGradients;\n"
3601 "uniform vec3 uCamera;\n"
3602 "uniform vec4 uColour;\n"
3603 "\n"
3604 "#line 1 1 \n"
3605 "// :D\n"
3606 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
3607 "\n"
3608 "#line 7 0 \n"
3609 "#line 1 2 \n"
3610 "// :D\n"
3611 "\n"
3612 "in vec2 aUv;\n"
3613 "in vec4 aNorm;\n"
3614 "in vec3 aCo;\n"
3615 "in vec3 aWorldCo;\n"
3616 "\n"
3617 "#line 1 1 \n"
3618 "layout (location = 0) out vec4 oColour;\n"
3619 "\n"
3620 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
3621 "layout (std140) uniform ub_world_lighting\n"
3622 "{\n"
3623 " vec4 g_cube_min;\n"
3624 " vec4 g_cube_inv_range;\n"
3625 "\n"
3626 " vec4 g_water_plane;\n"
3627 " vec4 g_depth_bounds;\n"
3628 "\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"
3638 "\n"
3639 " float g_water_fog;\n"
3640 " float g_time;\n"
3641 " float g_realtime;\n"
3642 " float g_shadow_length;\n"
3643 " float g_shadow_spread;\n"
3644 "\n"
3645 " float g_time_of_day;\n"
3646 " float g_day_phase;\n"
3647 " float g_sunset_phase;\n"
3648 "\n"
3649 " int g_light_preview;\n"
3650 " int g_shadow_samples;\n"
3651 "\n"
3652 " int g_debug_indices;\n"
3653 " int g_debug_complexity;\n"
3654 "};\n"
3655 "\n"
3656 "uniform sampler2D g_world_depth;\n"
3657 "uniform samplerBuffer uLightsArray;\n"
3658 "uniform usampler3D uLightsIndex;\n"
3659 "\n"
3660 "#line 1 1 \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"
3667 "\n"
3668 "const float SUN_ANGLE = 0.0001;\n"
3669 "const float PI = 3.14159265358979323846264;\n"
3670 "\n"
3671 "//struct world_info\n"
3672 "//{\n"
3673 "// float time,\n"
3674 "// time_of_day,\n"
3675 "// day_phase,\n"
3676 "// sunset_phase;\n"
3677 "// \n"
3678 "// vec3 sun_dir;\n"
3679 "//};\n"
3680 "\n"
3681 "vec3 rand33(vec3 p3)\n"
3682 "{\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"
3686 "}\n"
3687 "\n"
3688 "float stars( vec3 rd, float rr, float size ){\n"
3689 " vec3 co = rd * rr;\n"
3690 "\n"
3691 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
3692 "\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"
3696 "\n"
3697 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
3698 " \n"
3699 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
3700 " plane = plane - mod(plane, PI / count);\n"
3701 "\n"
3702 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
3703 "\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"
3709 " return star;\n"
3710 "}\n"
3711 "\n"
3712 "float luminance( vec3 v )\n"
3713 "{\n"
3714 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
3715 "}\n"
3716 "\n"
3717 "vec3 clearskies_ambient( vec3 dir )\n"
3718 "{\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"
3721 " \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"
3726 " \n"
3727 " /* Add gradient */\n"
3728 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
3729 " \n"
3730 " return ambient;\n"
3731 "}\n"
3732 "\n"
3733 "vec3 clearskies_sky( vec3 ray_dir )\n"
3734 "{\n"
3735 " ray_dir.y = abs( ray_dir.y );\n"
3736 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
3737 " \n"
3738 " /* Sun */\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"
3743 " \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"
3746 "\n"
3747 " \n"
3748 " float star = 0.0;\n"
3749 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
3750 "\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"
3755 " }\n"
3756 " }\n"
3757 " \n"
3758 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
3759 " return composite;\n"
3760 "}\n"
3761 "\n"
3762 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
3763 "{\n"
3764 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
3765 "\n"
3766 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
3767 " g_sunset_phase );\n"
3768 "\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"
3773 "\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"
3777 "\n"
3778 " return ambient + (light_sun + sky_reflection) * shadow;\n"
3779 "}\n"
3780 "\n"
3781 "#line 44 0 \n"
3782 "\n"
3783 "float world_depth_sample( vec3 pos )\n"
3784 "{\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"
3787 "}\n"
3788 "\n"
3789 "float world_water_depth( vec3 pos )\n"
3790 "{\n"
3791 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
3792 " return world_depth_sample( pos ) - ref_depth;\n"
3793 "}\n"
3794 "\n"
3795 "float shadow_sample( vec3 co ){\n"
3796 " float height_sample = world_depth_sample( co );\n"
3797 "\n"
3798 " float fdelta = height_sample - co.y;\n"
3799 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
3800 "}\n"
3801 "\n"
3802 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
3803 " if( g_shadow_samples == 0 ){\n"
3804 " return 1.0;\n"
3805 " }\n"
3806 "\n"
3807 " float fspread = g_shadow_spread;\n"
3808 " float flength = g_shadow_length;\n"
3809 "\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"
3815 "\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"
3820 "\n"
3821 " return 1.0 - famt;\n"
3822 "}\n"
3823 "\n"
3824 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
3825 "{\n"
3826 " vec3 specdir = reflect( -dir, wnormal );\n"
3827 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
3828 "}\n"
3829 "\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"
3833 "}\n"
3834 "\n"
3835 "vec3 scene_calculate_light( int light_index, \n"
3836 " vec3 halfview, vec3 co, vec3 normal )\n"
3837 "{\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"
3841 "\n"
3842 " vec3 light_delta = light_co.xyz-co;\n"
3843 " float dist2 = dot(light_delta,light_delta);\n"
3844 "\n"
3845 " light_delta = normalize( light_delta );\n"
3846 "\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"
3850 "\n"
3851 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
3852 "\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"
3856 " }\n"
3857 "\n"
3858 " return light_colour.rgb * attenuation * falloff \n"
3859 " * step( g_day_phase, light_colour.w );\n"
3860 "}\n"
3861 "\n"
3862 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
3863 " vec3 halfview, vec3 co, vec3 normal )\n"
3864 "{\n"
3865 " uint light_count = packed_index & 0x3u;\n"
3866 "\n"
3867 " vec3 l = vec3(0.0);\n"
3868 "\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"
3873 "\n"
3874 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
3875 "\n"
3876 " if( light_count >= 2u ){\n"
3877 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
3878 "\n"
3879 " if( light_count >= 3u ){\n"
3880 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
3881 " }\n"
3882 " }\n"
3883 " }\n"
3884 "\n"
3885 " return l;\n"
3886 "}\n"
3887 "\n"
3888 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
3889 " float light_mask )\n"
3890 "{\n"
3891 " if( g_light_preview == 1 )\n"
3892 " diffuse = vec3(0.75);\n"
3893 "\n"
3894 " // Lighting\n"
3895 " vec3 halfview = uCamera - co;\n"
3896 " float fdist = length(halfview);\n"
3897 " halfview /= fdist;\n"
3898 "\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"
3901 "\n"
3902 " vec3 total_light = clearskies_lighting( \n"
3903 " normal, min( light_mask, world_shadow ), halfview );\n"
3904 "\n"
3905 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
3906 " cube_coord = floor( cube_coord );\n"
3907 "\n"
3908 " if( g_debug_indices == 1 )\n"
3909 " {\n"
3910 " return rand33(cube_coord);\n"
3911 " }\n"
3912 "\n"
3913 " if( g_debug_complexity == 1 )\n"
3914 " {\n"
3915 " ivec3 coord = ivec3( cube_coord );\n"
3916 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3917 "\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"
3920 " }\n"
3921 "\n"
3922 " // FIXME: this coord should absolutely must be clamped!\n"
3923 " \n"
3924 " ivec3 coord = ivec3( cube_coord );\n"
3925 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
3926 "\n"
3927 " total_light += \n"
3928 " scene_calculate_packed_light_patch( index_sample.x,\n"
3929 " halfview, co, normal ) \n"
3930 " * light_mask;\n"
3931 " total_light += \n"
3932 " scene_calculate_packed_light_patch( index_sample.y,\n"
3933 " halfview, co, normal )\n"
3934 " * light_mask;\n"
3935 "\n"
3936 " // Take a section of the sky function to give us a matching fog colour\n"
3937 "\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"
3942 " \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"
3945 "\n"
3946 " fog_colour += sun_colour;\n"
3947 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
3948 "}\n"
3949 "\n"
3950 "#line 9 0 \n"
3951 "\n"
3952 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
3953 "{\n"
3954 " vec3 pa = p - a;\n"
3955 " vec3 ba = b - a;\n"
3956 "\n"
3957 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
3958 " return length( pa - ba*h );\n"
3959 "}\n"
3960 "\n"
3961 "float compute_board_shadow()\n"
3962 "{\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"
3968 "\n"
3969 " return 1.0 - player_shadow*0.8;\n"
3970 "}\n"
3971 "\n"
3972 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
3973 "{\n"
3974 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
3975 "}\n"
3976 "\n"
3977 "#line 8 0 \n"
3978 "#line 1 3 \n"
3979 "const float k_motion_lerp_amount = 0.01;\n"
3980 "\n"
3981 "#line 2 0 \n"
3982 "\n"
3983 "layout (location = 1) out vec2 oMotionVec;\n"
3984 "\n"
3985 "in vec3 aMotionVec0;\n"
3986 "in vec3 aMotionVec1;\n"
3987 "\n"
3988 "void compute_motion_vectors()\n"
3989 "{\n"
3990 " // Write motion vectors\n"
3991 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
3992 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
3993 "\n"
3994 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
3995 "}\n"
3996 "\n"
3997 "#line 9 0 \n"
3998 "\n"
3999 "float filtered_stripe( in float p, in float ddx, in float ddy )\n"
4000 "{\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"
4004 "}\n"
4005 "\n"
4006 "void main()\n"
4007 "{\n"
4008 " compute_motion_vectors();\n"
4009 "\n"
4010 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
4011 "\n"
4012 " // ws modulation\n"
4013 " vec4 wgarbage = texture( uTexGarbage, aCo.xz * 0.015 );\n"
4014 "\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"
4019 "\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"
4023 " \n"
4024 " // Patch local noise\n"
4025 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
4026 "\n"
4027 " vfrag = pow(uColour.rgb,vec3(1.0/2.2));\n"
4028 " vfrag -= rgarbage.a*0.1;\n"
4029 "\n"
4030 " if( wgarbage.g < 0.1 )\n"
4031 " discard;\n"
4032 "\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"
4036 "\n"
4037 " if( g_light_preview == 1 )\n"
4038 " {\n"
4039 " vfrag = vec3(0.5);\n"
4040 " }\n"
4041 "\n"
4042 " // Lighting\n"
4043 " oColour = vec4( scene_compute_lighting( vfrag, qnorm, aWorldCo ), 1.0 );\n"
4044 "}\n"
4045 ""},
4046 };
4047
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",
4062 .vs =
4063 {
4064 .orig_file = "shaders/scene.vs",
4065 .static_src =
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"
4069 "\n"
4070 "#line 1 1 \n"
4071 "const float k_motion_lerp_amount = 0.01;\n"
4072 "\n"
4073 "#line 2 0 \n"
4074 "\n"
4075 "out vec3 aMotionVec0;\n"
4076 "out vec3 aMotionVec1;\n"
4077 "\n"
4078 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
4079 "{\n"
4080 " // This magically solves some artifacting errors!\n"
4081 " //\n"
4082 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
4083 "\n"
4084 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
4085 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
4086 "}\n"
4087 "\n"
4088 "#line 6 0 \n"
4089 "\n"
4090 "uniform mat4x3 uMdl;\n"
4091 "uniform mat4 uPv;\n"
4092 "uniform mat4 uPvmPrev;\n"
4093 "\n"
4094 "out vec2 aUv;\n"
4095 "out vec4 aNorm;\n"
4096 "out vec3 aCo;\n"
4097 "out vec3 aWorldCo;\n"
4098 "\n"
4099 "void main()\n"
4100 "{\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"
4104 "\n"
4105 " vs_motion_out( vproj0, vproj1 );\n"
4106 "\n"
4107 " gl_Position = vproj0;\n"
4108 "\n"
4109 " aUv = a_uv;\n"
4110 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
4111 " aCo = a_co;\n"
4112 " aWorldCo = world_pos0;\n"
4113 "}\n"
4114 ""},
4115 .fs =
4116 {
4117 .orig_file = "shaders/scene_depth.fs",
4118 .static_src =
4119 "out vec4 FragColor;\n"
4120 "\n"
4121 "uniform vec3 uCamera;\n"
4122 "uniform vec3 uBoard0;\n"
4123 "uniform vec3 uBoard1;\n"
4124 "\n"
4125 "#line 1 1 \n"
4126 "// :D\n"
4127 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
4128 "\n"
4129 "#line 8 0 \n"
4130 "#line 1 2 \n"
4131 "// :D\n"
4132 "\n"
4133 "in vec2 aUv;\n"
4134 "in vec4 aNorm;\n"
4135 "in vec3 aCo;\n"
4136 "in vec3 aWorldCo;\n"
4137 "\n"
4138 "#line 1 1 \n"
4139 "layout (location = 0) out vec4 oColour;\n"
4140 "\n"
4141 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
4142 "layout (std140) uniform ub_world_lighting\n"
4143 "{\n"
4144 " vec4 g_cube_min;\n"
4145 " vec4 g_cube_inv_range;\n"
4146 "\n"
4147 " vec4 g_water_plane;\n"
4148 " vec4 g_depth_bounds;\n"
4149 "\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"
4159 "\n"
4160 " float g_water_fog;\n"
4161 " float g_time;\n"
4162 " float g_realtime;\n"
4163 " float g_shadow_length;\n"
4164 " float g_shadow_spread;\n"
4165 "\n"
4166 " float g_time_of_day;\n"
4167 " float g_day_phase;\n"
4168 " float g_sunset_phase;\n"
4169 "\n"
4170 " int g_light_preview;\n"
4171 " int g_shadow_samples;\n"
4172 "\n"
4173 " int g_debug_indices;\n"
4174 " int g_debug_complexity;\n"
4175 "};\n"
4176 "\n"
4177 "uniform sampler2D g_world_depth;\n"
4178 "uniform samplerBuffer uLightsArray;\n"
4179 "uniform usampler3D uLightsIndex;\n"
4180 "\n"
4181 "#line 1 1 \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"
4188 "\n"
4189 "const float SUN_ANGLE = 0.0001;\n"
4190 "const float PI = 3.14159265358979323846264;\n"
4191 "\n"
4192 "//struct world_info\n"
4193 "//{\n"
4194 "// float time,\n"
4195 "// time_of_day,\n"
4196 "// day_phase,\n"
4197 "// sunset_phase;\n"
4198 "// \n"
4199 "// vec3 sun_dir;\n"
4200 "//};\n"
4201 "\n"
4202 "vec3 rand33(vec3 p3)\n"
4203 "{\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"
4207 "}\n"
4208 "\n"
4209 "float stars( vec3 rd, float rr, float size ){\n"
4210 " vec3 co = rd * rr;\n"
4211 "\n"
4212 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
4213 "\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"
4217 "\n"
4218 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
4219 " \n"
4220 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
4221 " plane = plane - mod(plane, PI / count);\n"
4222 "\n"
4223 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
4224 "\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"
4230 " return star;\n"
4231 "}\n"
4232 "\n"
4233 "float luminance( vec3 v )\n"
4234 "{\n"
4235 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
4236 "}\n"
4237 "\n"
4238 "vec3 clearskies_ambient( vec3 dir )\n"
4239 "{\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"
4242 " \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"
4247 " \n"
4248 " /* Add gradient */\n"
4249 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
4250 " \n"
4251 " return ambient;\n"
4252 "}\n"
4253 "\n"
4254 "vec3 clearskies_sky( vec3 ray_dir )\n"
4255 "{\n"
4256 " ray_dir.y = abs( ray_dir.y );\n"
4257 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
4258 " \n"
4259 " /* Sun */\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"
4264 " \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"
4267 "\n"
4268 " \n"
4269 " float star = 0.0;\n"
4270 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
4271 "\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"
4276 " }\n"
4277 " }\n"
4278 " \n"
4279 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
4280 " return composite;\n"
4281 "}\n"
4282 "\n"
4283 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
4284 "{\n"
4285 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
4286 "\n"
4287 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
4288 " g_sunset_phase );\n"
4289 "\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"
4294 "\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"
4298 "\n"
4299 " return ambient + (light_sun + sky_reflection) * shadow;\n"
4300 "}\n"
4301 "\n"
4302 "#line 44 0 \n"
4303 "\n"
4304 "float world_depth_sample( vec3 pos )\n"
4305 "{\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"
4308 "}\n"
4309 "\n"
4310 "float world_water_depth( vec3 pos )\n"
4311 "{\n"
4312 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
4313 " return world_depth_sample( pos ) - ref_depth;\n"
4314 "}\n"
4315 "\n"
4316 "float shadow_sample( vec3 co ){\n"
4317 " float height_sample = world_depth_sample( co );\n"
4318 "\n"
4319 " float fdelta = height_sample - co.y;\n"
4320 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
4321 "}\n"
4322 "\n"
4323 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
4324 " if( g_shadow_samples == 0 ){\n"
4325 " return 1.0;\n"
4326 " }\n"
4327 "\n"
4328 " float fspread = g_shadow_spread;\n"
4329 " float flength = g_shadow_length;\n"
4330 "\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"
4336 "\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"
4341 "\n"
4342 " return 1.0 - famt;\n"
4343 "}\n"
4344 "\n"
4345 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
4346 "{\n"
4347 " vec3 specdir = reflect( -dir, wnormal );\n"
4348 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
4349 "}\n"
4350 "\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"
4354 "}\n"
4355 "\n"
4356 "vec3 scene_calculate_light( int light_index, \n"
4357 " vec3 halfview, vec3 co, vec3 normal )\n"
4358 "{\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"
4362 "\n"
4363 " vec3 light_delta = light_co.xyz-co;\n"
4364 " float dist2 = dot(light_delta,light_delta);\n"
4365 "\n"
4366 " light_delta = normalize( light_delta );\n"
4367 "\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"
4371 "\n"
4372 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
4373 "\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"
4377 " }\n"
4378 "\n"
4379 " return light_colour.rgb * attenuation * falloff \n"
4380 " * step( g_day_phase, light_colour.w );\n"
4381 "}\n"
4382 "\n"
4383 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
4384 " vec3 halfview, vec3 co, vec3 normal )\n"
4385 "{\n"
4386 " uint light_count = packed_index & 0x3u;\n"
4387 "\n"
4388 " vec3 l = vec3(0.0);\n"
4389 "\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"
4394 "\n"
4395 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
4396 "\n"
4397 " if( light_count >= 2u ){\n"
4398 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
4399 "\n"
4400 " if( light_count >= 3u ){\n"
4401 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
4402 " }\n"
4403 " }\n"
4404 " }\n"
4405 "\n"
4406 " return l;\n"
4407 "}\n"
4408 "\n"
4409 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
4410 " float light_mask )\n"
4411 "{\n"
4412 " if( g_light_preview == 1 )\n"
4413 " diffuse = vec3(0.75);\n"
4414 "\n"
4415 " // Lighting\n"
4416 " vec3 halfview = uCamera - co;\n"
4417 " float fdist = length(halfview);\n"
4418 " halfview /= fdist;\n"
4419 "\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"
4422 "\n"
4423 " vec3 total_light = clearskies_lighting( \n"
4424 " normal, min( light_mask, world_shadow ), halfview );\n"
4425 "\n"
4426 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
4427 " cube_coord = floor( cube_coord );\n"
4428 "\n"
4429 " if( g_debug_indices == 1 )\n"
4430 " {\n"
4431 " return rand33(cube_coord);\n"
4432 " }\n"
4433 "\n"
4434 " if( g_debug_complexity == 1 )\n"
4435 " {\n"
4436 " ivec3 coord = ivec3( cube_coord );\n"
4437 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4438 "\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"
4441 " }\n"
4442 "\n"
4443 " // FIXME: this coord should absolutely must be clamped!\n"
4444 " \n"
4445 " ivec3 coord = ivec3( cube_coord );\n"
4446 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4447 "\n"
4448 " total_light += \n"
4449 " scene_calculate_packed_light_patch( index_sample.x,\n"
4450 " halfview, co, normal ) \n"
4451 " * light_mask;\n"
4452 " total_light += \n"
4453 " scene_calculate_packed_light_patch( index_sample.y,\n"
4454 " halfview, co, normal )\n"
4455 " * light_mask;\n"
4456 "\n"
4457 " // Take a section of the sky function to give us a matching fog colour\n"
4458 "\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"
4463 " \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"
4466 "\n"
4467 " fog_colour += sun_colour;\n"
4468 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
4469 "}\n"
4470 "\n"
4471 "#line 9 0 \n"
4472 "\n"
4473 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
4474 "{\n"
4475 " vec3 pa = p - a;\n"
4476 " vec3 ba = b - a;\n"
4477 "\n"
4478 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
4479 " return length( pa - ba*h );\n"
4480 "}\n"
4481 "\n"
4482 "float compute_board_shadow()\n"
4483 "{\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"
4489 "\n"
4490 " return 1.0 - player_shadow*0.8;\n"
4491 "}\n"
4492 "\n"
4493 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
4494 "{\n"
4495 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
4496 "}\n"
4497 "\n"
4498 "#line 9 0 \n"
4499 "\n"
4500 "// Water blending\n"
4501 "// ==============\n"
4502 "\n"
4503 "float water_depth( vec3 pos, vec3 halfview )\n"
4504 "{\n"
4505 " vec3 pnorm = g_water_plane.xyz;\n"
4506 " float pdist = g_water_plane.w;\n"
4507 "\n"
4508 " float d = dot( pnorm, halfview );\n"
4509 " float t = dot((pnorm*pdist - pos), pnorm) / d;\n"
4510 "\n"
4511 " // TODO: Make g_water_fog a material param\n"
4512 " return t * 0.3;//g_water_fog;\n"
4513 "}\n"
4514 "\n"
4515 "void main()\n"
4516 "{\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"
4520 "}\n"
4521 ""},
4522 };
4523
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",
4536 .vs =
4537 {
4538 .orig_file = "shaders/scene.vs",
4539 .static_src =
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"
4543 "\n"
4544 "#line 1 1 \n"
4545 "const float k_motion_lerp_amount = 0.01;\n"
4546 "\n"
4547 "#line 2 0 \n"
4548 "\n"
4549 "out vec3 aMotionVec0;\n"
4550 "out vec3 aMotionVec1;\n"
4551 "\n"
4552 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
4553 "{\n"
4554 " // This magically solves some artifacting errors!\n"
4555 " //\n"
4556 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
4557 "\n"
4558 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
4559 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
4560 "}\n"
4561 "\n"
4562 "#line 6 0 \n"
4563 "\n"
4564 "uniform mat4x3 uMdl;\n"
4565 "uniform mat4 uPv;\n"
4566 "uniform mat4 uPvmPrev;\n"
4567 "\n"
4568 "out vec2 aUv;\n"
4569 "out vec4 aNorm;\n"
4570 "out vec3 aCo;\n"
4571 "out vec3 aWorldCo;\n"
4572 "\n"
4573 "void main()\n"
4574 "{\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"
4578 "\n"
4579 " vs_motion_out( vproj0, vproj1 );\n"
4580 "\n"
4581 " gl_Position = vproj0;\n"
4582 "\n"
4583 " aUv = a_uv;\n"
4584 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
4585 " aCo = a_co;\n"
4586 " aWorldCo = world_pos0;\n"
4587 "}\n"
4588 ""},
4589 .fs =
4590 {
4591 .orig_file = "shaders/scene_position.fs",
4592 .static_src =
4593 "out vec4 FragColor;\n"
4594 "\n"
4595 "uniform vec3 uCamera;\n"
4596 "uniform vec3 uBoard0;\n"
4597 "uniform vec3 uBoard1;\n"
4598 "\n"
4599 "#line 1 1 \n"
4600 "// :D\n"
4601 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
4602 "\n"
4603 "#line 8 0 \n"
4604 "#line 1 2 \n"
4605 "// :D\n"
4606 "\n"
4607 "in vec2 aUv;\n"
4608 "in vec4 aNorm;\n"
4609 "in vec3 aCo;\n"
4610 "in vec3 aWorldCo;\n"
4611 "\n"
4612 "#line 1 1 \n"
4613 "layout (location = 0) out vec4 oColour;\n"
4614 "\n"
4615 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
4616 "layout (std140) uniform ub_world_lighting\n"
4617 "{\n"
4618 " vec4 g_cube_min;\n"
4619 " vec4 g_cube_inv_range;\n"
4620 "\n"
4621 " vec4 g_water_plane;\n"
4622 " vec4 g_depth_bounds;\n"
4623 "\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"
4633 "\n"
4634 " float g_water_fog;\n"
4635 " float g_time;\n"
4636 " float g_realtime;\n"
4637 " float g_shadow_length;\n"
4638 " float g_shadow_spread;\n"
4639 "\n"
4640 " float g_time_of_day;\n"
4641 " float g_day_phase;\n"
4642 " float g_sunset_phase;\n"
4643 "\n"
4644 " int g_light_preview;\n"
4645 " int g_shadow_samples;\n"
4646 "\n"
4647 " int g_debug_indices;\n"
4648 " int g_debug_complexity;\n"
4649 "};\n"
4650 "\n"
4651 "uniform sampler2D g_world_depth;\n"
4652 "uniform samplerBuffer uLightsArray;\n"
4653 "uniform usampler3D uLightsIndex;\n"
4654 "\n"
4655 "#line 1 1 \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"
4662 "\n"
4663 "const float SUN_ANGLE = 0.0001;\n"
4664 "const float PI = 3.14159265358979323846264;\n"
4665 "\n"
4666 "//struct world_info\n"
4667 "//{\n"
4668 "// float time,\n"
4669 "// time_of_day,\n"
4670 "// day_phase,\n"
4671 "// sunset_phase;\n"
4672 "// \n"
4673 "// vec3 sun_dir;\n"
4674 "//};\n"
4675 "\n"
4676 "vec3 rand33(vec3 p3)\n"
4677 "{\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"
4681 "}\n"
4682 "\n"
4683 "float stars( vec3 rd, float rr, float size ){\n"
4684 " vec3 co = rd * rr;\n"
4685 "\n"
4686 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
4687 "\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"
4691 "\n"
4692 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
4693 " \n"
4694 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
4695 " plane = plane - mod(plane, PI / count);\n"
4696 "\n"
4697 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
4698 "\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"
4704 " return star;\n"
4705 "}\n"
4706 "\n"
4707 "float luminance( vec3 v )\n"
4708 "{\n"
4709 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
4710 "}\n"
4711 "\n"
4712 "vec3 clearskies_ambient( vec3 dir )\n"
4713 "{\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"
4716 " \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"
4721 " \n"
4722 " /* Add gradient */\n"
4723 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
4724 " \n"
4725 " return ambient;\n"
4726 "}\n"
4727 "\n"
4728 "vec3 clearskies_sky( vec3 ray_dir )\n"
4729 "{\n"
4730 " ray_dir.y = abs( ray_dir.y );\n"
4731 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
4732 " \n"
4733 " /* Sun */\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"
4738 " \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"
4741 "\n"
4742 " \n"
4743 " float star = 0.0;\n"
4744 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
4745 "\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"
4750 " }\n"
4751 " }\n"
4752 " \n"
4753 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
4754 " return composite;\n"
4755 "}\n"
4756 "\n"
4757 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
4758 "{\n"
4759 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
4760 "\n"
4761 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
4762 " g_sunset_phase );\n"
4763 "\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"
4768 "\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"
4772 "\n"
4773 " return ambient + (light_sun + sky_reflection) * shadow;\n"
4774 "}\n"
4775 "\n"
4776 "#line 44 0 \n"
4777 "\n"
4778 "float world_depth_sample( vec3 pos )\n"
4779 "{\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"
4782 "}\n"
4783 "\n"
4784 "float world_water_depth( vec3 pos )\n"
4785 "{\n"
4786 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
4787 " return world_depth_sample( pos ) - ref_depth;\n"
4788 "}\n"
4789 "\n"
4790 "float shadow_sample( vec3 co ){\n"
4791 " float height_sample = world_depth_sample( co );\n"
4792 "\n"
4793 " float fdelta = height_sample - co.y;\n"
4794 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
4795 "}\n"
4796 "\n"
4797 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
4798 " if( g_shadow_samples == 0 ){\n"
4799 " return 1.0;\n"
4800 " }\n"
4801 "\n"
4802 " float fspread = g_shadow_spread;\n"
4803 " float flength = g_shadow_length;\n"
4804 "\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"
4810 "\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"
4815 "\n"
4816 " return 1.0 - famt;\n"
4817 "}\n"
4818 "\n"
4819 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
4820 "{\n"
4821 " vec3 specdir = reflect( -dir, wnormal );\n"
4822 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
4823 "}\n"
4824 "\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"
4828 "}\n"
4829 "\n"
4830 "vec3 scene_calculate_light( int light_index, \n"
4831 " vec3 halfview, vec3 co, vec3 normal )\n"
4832 "{\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"
4836 "\n"
4837 " vec3 light_delta = light_co.xyz-co;\n"
4838 " float dist2 = dot(light_delta,light_delta);\n"
4839 "\n"
4840 " light_delta = normalize( light_delta );\n"
4841 "\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"
4845 "\n"
4846 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
4847 "\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"
4851 " }\n"
4852 "\n"
4853 " return light_colour.rgb * attenuation * falloff \n"
4854 " * step( g_day_phase, light_colour.w );\n"
4855 "}\n"
4856 "\n"
4857 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
4858 " vec3 halfview, vec3 co, vec3 normal )\n"
4859 "{\n"
4860 " uint light_count = packed_index & 0x3u;\n"
4861 "\n"
4862 " vec3 l = vec3(0.0);\n"
4863 "\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"
4868 "\n"
4869 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
4870 "\n"
4871 " if( light_count >= 2u ){\n"
4872 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
4873 "\n"
4874 " if( light_count >= 3u ){\n"
4875 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
4876 " }\n"
4877 " }\n"
4878 " }\n"
4879 "\n"
4880 " return l;\n"
4881 "}\n"
4882 "\n"
4883 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
4884 " float light_mask )\n"
4885 "{\n"
4886 " if( g_light_preview == 1 )\n"
4887 " diffuse = vec3(0.75);\n"
4888 "\n"
4889 " // Lighting\n"
4890 " vec3 halfview = uCamera - co;\n"
4891 " float fdist = length(halfview);\n"
4892 " halfview /= fdist;\n"
4893 "\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"
4896 "\n"
4897 " vec3 total_light = clearskies_lighting( \n"
4898 " normal, min( light_mask, world_shadow ), halfview );\n"
4899 "\n"
4900 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
4901 " cube_coord = floor( cube_coord );\n"
4902 "\n"
4903 " if( g_debug_indices == 1 )\n"
4904 " {\n"
4905 " return rand33(cube_coord);\n"
4906 " }\n"
4907 "\n"
4908 " if( g_debug_complexity == 1 )\n"
4909 " {\n"
4910 " ivec3 coord = ivec3( cube_coord );\n"
4911 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4912 "\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"
4915 " }\n"
4916 "\n"
4917 " // FIXME: this coord should absolutely must be clamped!\n"
4918 " \n"
4919 " ivec3 coord = ivec3( cube_coord );\n"
4920 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
4921 "\n"
4922 " total_light += \n"
4923 " scene_calculate_packed_light_patch( index_sample.x,\n"
4924 " halfview, co, normal ) \n"
4925 " * light_mask;\n"
4926 " total_light += \n"
4927 " scene_calculate_packed_light_patch( index_sample.y,\n"
4928 " halfview, co, normal )\n"
4929 " * light_mask;\n"
4930 "\n"
4931 " // Take a section of the sky function to give us a matching fog colour\n"
4932 "\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"
4937 " \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"
4940 "\n"
4941 " fog_colour += sun_colour;\n"
4942 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
4943 "}\n"
4944 "\n"
4945 "#line 9 0 \n"
4946 "\n"
4947 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
4948 "{\n"
4949 " vec3 pa = p - a;\n"
4950 " vec3 ba = b - a;\n"
4951 "\n"
4952 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
4953 " return length( pa - ba*h );\n"
4954 "}\n"
4955 "\n"
4956 "float compute_board_shadow()\n"
4957 "{\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"
4963 "\n"
4964 " return 1.0 - player_shadow*0.8;\n"
4965 "}\n"
4966 "\n"
4967 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
4968 "{\n"
4969 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
4970 "}\n"
4971 "\n"
4972 "#line 9 0 \n"
4973 "\n"
4974 "void main()\n"
4975 "{\n"
4976 " float height_full = aWorldCo.y;\n"
4977 " float height_water = height_full;\n"
4978 "\n"
4979 " if( height_water > (g_water_plane.y * g_water_plane.w) + 2.0 )\n"
4980 " height_water = -99999.9;\n"
4981 "\n"
4982 " FragColor = vec4( height_full, height_water, 0.0, 0.0 );\n"
4983 "}\n"
4984 ""},
4985 };
4986
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",
4999 .vs =
5000 {
5001 .orig_file = "shaders/scene.vs",
5002 .static_src =
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"
5006 "\n"
5007 "#line 1 1 \n"
5008 "const float k_motion_lerp_amount = 0.01;\n"
5009 "\n"
5010 "#line 2 0 \n"
5011 "\n"
5012 "out vec3 aMotionVec0;\n"
5013 "out vec3 aMotionVec1;\n"
5014 "\n"
5015 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
5016 "{\n"
5017 " // This magically solves some artifacting errors!\n"
5018 " //\n"
5019 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
5020 "\n"
5021 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
5022 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
5023 "}\n"
5024 "\n"
5025 "#line 6 0 \n"
5026 "\n"
5027 "uniform mat4x3 uMdl;\n"
5028 "uniform mat4 uPv;\n"
5029 "uniform mat4 uPvmPrev;\n"
5030 "\n"
5031 "out vec2 aUv;\n"
5032 "out vec4 aNorm;\n"
5033 "out vec3 aCo;\n"
5034 "out vec3 aWorldCo;\n"
5035 "\n"
5036 "void main()\n"
5037 "{\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"
5041 "\n"
5042 " vs_motion_out( vproj0, vproj1 );\n"
5043 "\n"
5044 " gl_Position = vproj0;\n"
5045 "\n"
5046 " aUv = a_uv;\n"
5047 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
5048 " aCo = a_co;\n"
5049 " aWorldCo = world_pos0;\n"
5050 "}\n"
5051 ""},
5052 .fs =
5053 {
5054 .orig_file = "shaders/scene_cubemapped.fs",
5055 .static_src =
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"
5062 "\n"
5063 "#line 1 1 \n"
5064 "// :D\n"
5065 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
5066 "\n"
5067 "#line 9 0 \n"
5068 "#line 1 2 \n"
5069 "// :D\n"
5070 "\n"
5071 "in vec2 aUv;\n"
5072 "in vec4 aNorm;\n"
5073 "in vec3 aCo;\n"
5074 "in vec3 aWorldCo;\n"
5075 "\n"
5076 "#line 1 1 \n"
5077 "layout (location = 0) out vec4 oColour;\n"
5078 "\n"
5079 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
5080 "layout (std140) uniform ub_world_lighting\n"
5081 "{\n"
5082 " vec4 g_cube_min;\n"
5083 " vec4 g_cube_inv_range;\n"
5084 "\n"
5085 " vec4 g_water_plane;\n"
5086 " vec4 g_depth_bounds;\n"
5087 "\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"
5097 "\n"
5098 " float g_water_fog;\n"
5099 " float g_time;\n"
5100 " float g_realtime;\n"
5101 " float g_shadow_length;\n"
5102 " float g_shadow_spread;\n"
5103 "\n"
5104 " float g_time_of_day;\n"
5105 " float g_day_phase;\n"
5106 " float g_sunset_phase;\n"
5107 "\n"
5108 " int g_light_preview;\n"
5109 " int g_shadow_samples;\n"
5110 "\n"
5111 " int g_debug_indices;\n"
5112 " int g_debug_complexity;\n"
5113 "};\n"
5114 "\n"
5115 "uniform sampler2D g_world_depth;\n"
5116 "uniform samplerBuffer uLightsArray;\n"
5117 "uniform usampler3D uLightsIndex;\n"
5118 "\n"
5119 "#line 1 1 \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"
5126 "\n"
5127 "const float SUN_ANGLE = 0.0001;\n"
5128 "const float PI = 3.14159265358979323846264;\n"
5129 "\n"
5130 "//struct world_info\n"
5131 "//{\n"
5132 "// float time,\n"
5133 "// time_of_day,\n"
5134 "// day_phase,\n"
5135 "// sunset_phase;\n"
5136 "// \n"
5137 "// vec3 sun_dir;\n"
5138 "//};\n"
5139 "\n"
5140 "vec3 rand33(vec3 p3)\n"
5141 "{\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"
5145 "}\n"
5146 "\n"
5147 "float stars( vec3 rd, float rr, float size ){\n"
5148 " vec3 co = rd * rr;\n"
5149 "\n"
5150 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
5151 "\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"
5155 "\n"
5156 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
5157 " \n"
5158 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
5159 " plane = plane - mod(plane, PI / count);\n"
5160 "\n"
5161 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
5162 "\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"
5168 " return star;\n"
5169 "}\n"
5170 "\n"
5171 "float luminance( vec3 v )\n"
5172 "{\n"
5173 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
5174 "}\n"
5175 "\n"
5176 "vec3 clearskies_ambient( vec3 dir )\n"
5177 "{\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"
5180 " \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"
5185 " \n"
5186 " /* Add gradient */\n"
5187 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
5188 " \n"
5189 " return ambient;\n"
5190 "}\n"
5191 "\n"
5192 "vec3 clearskies_sky( vec3 ray_dir )\n"
5193 "{\n"
5194 " ray_dir.y = abs( ray_dir.y );\n"
5195 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
5196 " \n"
5197 " /* Sun */\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"
5202 " \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"
5205 "\n"
5206 " \n"
5207 " float star = 0.0;\n"
5208 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
5209 "\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"
5214 " }\n"
5215 " }\n"
5216 " \n"
5217 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
5218 " return composite;\n"
5219 "}\n"
5220 "\n"
5221 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
5222 "{\n"
5223 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
5224 "\n"
5225 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
5226 " g_sunset_phase );\n"
5227 "\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"
5232 "\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"
5236 "\n"
5237 " return ambient + (light_sun + sky_reflection) * shadow;\n"
5238 "}\n"
5239 "\n"
5240 "#line 44 0 \n"
5241 "\n"
5242 "float world_depth_sample( vec3 pos )\n"
5243 "{\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"
5246 "}\n"
5247 "\n"
5248 "float world_water_depth( vec3 pos )\n"
5249 "{\n"
5250 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
5251 " return world_depth_sample( pos ) - ref_depth;\n"
5252 "}\n"
5253 "\n"
5254 "float shadow_sample( vec3 co ){\n"
5255 " float height_sample = world_depth_sample( co );\n"
5256 "\n"
5257 " float fdelta = height_sample - co.y;\n"
5258 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
5259 "}\n"
5260 "\n"
5261 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
5262 " if( g_shadow_samples == 0 ){\n"
5263 " return 1.0;\n"
5264 " }\n"
5265 "\n"
5266 " float fspread = g_shadow_spread;\n"
5267 " float flength = g_shadow_length;\n"
5268 "\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"
5274 "\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"
5279 "\n"
5280 " return 1.0 - famt;\n"
5281 "}\n"
5282 "\n"
5283 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
5284 "{\n"
5285 " vec3 specdir = reflect( -dir, wnormal );\n"
5286 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
5287 "}\n"
5288 "\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"
5292 "}\n"
5293 "\n"
5294 "vec3 scene_calculate_light( int light_index, \n"
5295 " vec3 halfview, vec3 co, vec3 normal )\n"
5296 "{\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"
5300 "\n"
5301 " vec3 light_delta = light_co.xyz-co;\n"
5302 " float dist2 = dot(light_delta,light_delta);\n"
5303 "\n"
5304 " light_delta = normalize( light_delta );\n"
5305 "\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"
5309 "\n"
5310 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
5311 "\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"
5315 " }\n"
5316 "\n"
5317 " return light_colour.rgb * attenuation * falloff \n"
5318 " * step( g_day_phase, light_colour.w );\n"
5319 "}\n"
5320 "\n"
5321 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
5322 " vec3 halfview, vec3 co, vec3 normal )\n"
5323 "{\n"
5324 " uint light_count = packed_index & 0x3u;\n"
5325 "\n"
5326 " vec3 l = vec3(0.0);\n"
5327 "\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"
5332 "\n"
5333 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
5334 "\n"
5335 " if( light_count >= 2u ){\n"
5336 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
5337 "\n"
5338 " if( light_count >= 3u ){\n"
5339 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
5340 " }\n"
5341 " }\n"
5342 " }\n"
5343 "\n"
5344 " return l;\n"
5345 "}\n"
5346 "\n"
5347 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
5348 " float light_mask )\n"
5349 "{\n"
5350 " if( g_light_preview == 1 )\n"
5351 " diffuse = vec3(0.75);\n"
5352 "\n"
5353 " // Lighting\n"
5354 " vec3 halfview = uCamera - co;\n"
5355 " float fdist = length(halfview);\n"
5356 " halfview /= fdist;\n"
5357 "\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"
5360 "\n"
5361 " vec3 total_light = clearskies_lighting( \n"
5362 " normal, min( light_mask, world_shadow ), halfview );\n"
5363 "\n"
5364 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
5365 " cube_coord = floor( cube_coord );\n"
5366 "\n"
5367 " if( g_debug_indices == 1 )\n"
5368 " {\n"
5369 " return rand33(cube_coord);\n"
5370 " }\n"
5371 "\n"
5372 " if( g_debug_complexity == 1 )\n"
5373 " {\n"
5374 " ivec3 coord = ivec3( cube_coord );\n"
5375 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5376 "\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"
5379 " }\n"
5380 "\n"
5381 " // FIXME: this coord should absolutely must be clamped!\n"
5382 " \n"
5383 " ivec3 coord = ivec3( cube_coord );\n"
5384 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5385 "\n"
5386 " total_light += \n"
5387 " scene_calculate_packed_light_patch( index_sample.x,\n"
5388 " halfview, co, normal ) \n"
5389 " * light_mask;\n"
5390 " total_light += \n"
5391 " scene_calculate_packed_light_patch( index_sample.y,\n"
5392 " halfview, co, normal )\n"
5393 " * light_mask;\n"
5394 "\n"
5395 " // Take a section of the sky function to give us a matching fog colour\n"
5396 "\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"
5401 " \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"
5404 "\n"
5405 " fog_colour += sun_colour;\n"
5406 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
5407 "}\n"
5408 "\n"
5409 "#line 9 0 \n"
5410 "\n"
5411 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
5412 "{\n"
5413 " vec3 pa = p - a;\n"
5414 " vec3 ba = b - a;\n"
5415 "\n"
5416 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
5417 " return length( pa - ba*h );\n"
5418 "}\n"
5419 "\n"
5420 "float compute_board_shadow()\n"
5421 "{\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"
5427 "\n"
5428 " return 1.0 - player_shadow*0.8;\n"
5429 "}\n"
5430 "\n"
5431 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
5432 "{\n"
5433 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
5434 "}\n"
5435 "\n"
5436 "#line 10 0 \n"
5437 "#line 1 3 \n"
5438 "const float k_motion_lerp_amount = 0.01;\n"
5439 "\n"
5440 "#line 2 0 \n"
5441 "\n"
5442 "layout (location = 1) out vec2 oMotionVec;\n"
5443 "\n"
5444 "in vec3 aMotionVec0;\n"
5445 "in vec3 aMotionVec1;\n"
5446 "\n"
5447 "void compute_motion_vectors()\n"
5448 "{\n"
5449 " // Write motion vectors\n"
5450 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
5451 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
5452 "\n"
5453 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
5454 "}\n"
5455 "\n"
5456 "#line 11 0 \n"
5457 "\n"
5458 "void main()\n"
5459 "{\n"
5460 " compute_motion_vectors();\n"
5461 "\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"
5467 "\n"
5468 " if( g_light_preview == 1 ){\n"
5469 " vfrag = vec3(0.5);\n"
5470 " }\n"
5471 "\n"
5472 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
5473 " oColour = vec4( vfrag, 1.0 );\n"
5474 "\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"
5480 "}\n"
5481 ""},
5482 };
5483
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",
5499 .vs =
5500 {
5501 .orig_file = "shaders/scene.vs",
5502 .static_src =
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"
5506 "\n"
5507 "#line 1 1 \n"
5508 "const float k_motion_lerp_amount = 0.01;\n"
5509 "\n"
5510 "#line 2 0 \n"
5511 "\n"
5512 "out vec3 aMotionVec0;\n"
5513 "out vec3 aMotionVec1;\n"
5514 "\n"
5515 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
5516 "{\n"
5517 " // This magically solves some artifacting errors!\n"
5518 " //\n"
5519 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
5520 "\n"
5521 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
5522 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
5523 "}\n"
5524 "\n"
5525 "#line 6 0 \n"
5526 "\n"
5527 "uniform mat4x3 uMdl;\n"
5528 "uniform mat4 uPv;\n"
5529 "uniform mat4 uPvmPrev;\n"
5530 "\n"
5531 "out vec2 aUv;\n"
5532 "out vec4 aNorm;\n"
5533 "out vec3 aCo;\n"
5534 "out vec3 aWorldCo;\n"
5535 "\n"
5536 "void main()\n"
5537 "{\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"
5541 "\n"
5542 " vs_motion_out( vproj0, vproj1 );\n"
5543 "\n"
5544 " gl_Position = vproj0;\n"
5545 "\n"
5546 " aUv = a_uv;\n"
5547 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
5548 " aCo = a_co;\n"
5549 " aWorldCo = world_pos0;\n"
5550 "}\n"
5551 ""},
5552 .fs =
5553 {
5554 .orig_file = "shaders/scene_water.fs",
5555 .static_src =
5556 "uniform sampler2D uTexMain;\n"
5557 "uniform sampler2D uTexDudv;\n"
5558 "uniform sampler2D uTexBack;\n"
5559 "\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"
5566 "\n"
5567 "uniform vec3 uShoreColour;\n"
5568 "uniform vec3 uOceanColour;\n"
5569 "uniform float uFresnel;\n"
5570 "uniform float uWaterScale;\n"
5571 "uniform vec4 uWaveSpeed;\n"
5572 "\n"
5573 "#line 1 1 \n"
5574 "// :D\n"
5575 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
5576 "\n"
5577 "#line 19 0 \n"
5578 "#line 1 2 \n"
5579 "// :D\n"
5580 "\n"
5581 "in vec2 aUv;\n"
5582 "in vec4 aNorm;\n"
5583 "in vec3 aCo;\n"
5584 "in vec3 aWorldCo;\n"
5585 "\n"
5586 "#line 1 1 \n"
5587 "layout (location = 0) out vec4 oColour;\n"
5588 "\n"
5589 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
5590 "layout (std140) uniform ub_world_lighting\n"
5591 "{\n"
5592 " vec4 g_cube_min;\n"
5593 " vec4 g_cube_inv_range;\n"
5594 "\n"
5595 " vec4 g_water_plane;\n"
5596 " vec4 g_depth_bounds;\n"
5597 "\n"
5598 " vec4 g_daysky_colour;\n"
5599 " vec4 g_nightsky_colour;\n"
5600 " vec4 g_sunset_colour;\n"
5601 " vec4 g_ambient_colour;\n"
5602 " vec4 g_sunset_ambient;\n"
5603 " vec4 g_sun_colour;\n"
5604 " vec4 g_sun_dir;\n"
5605 " vec4 g_board_0;\n"
5606 " vec4 g_board_1;\n"
5607 "\n"
5608 " float g_water_fog;\n"
5609 " float g_time;\n"
5610 " float g_realtime;\n"
5611 " float g_shadow_length;\n"
5612 " float g_shadow_spread;\n"
5613 "\n"
5614 " float g_time_of_day;\n"
5615 " float g_day_phase;\n"
5616 " float g_sunset_phase;\n"
5617 "\n"
5618 " int g_light_preview;\n"
5619 " int g_shadow_samples;\n"
5620 "\n"
5621 " int g_debug_indices;\n"
5622 " int g_debug_complexity;\n"
5623 "};\n"
5624 "\n"
5625 "uniform sampler2D g_world_depth;\n"
5626 "uniform samplerBuffer uLightsArray;\n"
5627 "uniform usampler3D uLightsIndex;\n"
5628 "\n"
5629 "#line 1 1 \n"
5630 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
5631 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
5632 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
5633 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
5634 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
5635 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
5636 "\n"
5637 "const float SUN_ANGLE = 0.0001;\n"
5638 "const float PI = 3.14159265358979323846264;\n"
5639 "\n"
5640 "//struct world_info\n"
5641 "//{\n"
5642 "// float time,\n"
5643 "// time_of_day,\n"
5644 "// day_phase,\n"
5645 "// sunset_phase;\n"
5646 "// \n"
5647 "// vec3 sun_dir;\n"
5648 "//};\n"
5649 "\n"
5650 "vec3 rand33(vec3 p3)\n"
5651 "{\n"
5652 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
5653 " p3 += dot(p3, p3.yxz+33.33);\n"
5654 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
5655 "}\n"
5656 "\n"
5657 "float stars( vec3 rd, float rr, float size ){\n"
5658 " vec3 co = rd * rr;\n"
5659 "\n"
5660 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
5661 "\n"
5662 " float spaces = 1.0 / rr;\n"
5663 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
5664 " a -= mod(a, spaces) - spaces * 0.5;\n"
5665 "\n"
5666 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
5667 " \n"
5668 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
5669 " plane = plane - mod(plane, PI / count);\n"
5670 "\n"
5671 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
5672 "\n"
5673 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
5674 " float ydist = sqrt(rr * rr - level * level);\n"
5675 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
5676 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
5677 " float star = smoothstep(size, 0.0, distance(center, co));\n"
5678 " return star;\n"
5679 "}\n"
5680 "\n"
5681 "float luminance( vec3 v )\n"
5682 "{\n"
5683 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
5684 "}\n"
5685 "\n"
5686 "vec3 clearskies_ambient( vec3 dir )\n"
5687 "{\n"
5688 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
5689 " float sky_gradient = dir.y;\n"
5690 " \n"
5691 " /* Blend phase colours */\n"
5692 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
5693 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
5694 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
5695 " \n"
5696 " /* Add gradient */\n"
5697 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
5698 " \n"
5699 " return ambient;\n"
5700 "}\n"
5701 "\n"
5702 "vec3 clearskies_sky( vec3 ray_dir )\n"
5703 "{\n"
5704 " ray_dir.y = abs( ray_dir.y );\n"
5705 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
5706 " \n"
5707 " /* Sun */\n"
5708 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
5709 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
5710 " float sun_shape = pow( sun_size, 2000.0 );\n"
5711 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
5712 " \n"
5713 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
5714 " sun_colour *= sun_shape;\n"
5715 "\n"
5716 " \n"
5717 " float star = 0.0;\n"
5718 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
5719 "\n"
5720 " if( star_blend > 0.001 ){\n"
5721 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
5722 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
5723 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
5724 " }\n"
5725 " }\n"
5726 " \n"
5727 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
5728 " return composite;\n"
5729 "}\n"
5730 "\n"
5731 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
5732 "{\n"
5733 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
5734 "\n"
5735 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
5736 " g_sunset_phase );\n"
5737 "\n"
5738 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
5739 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
5740 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
5741 " ) * g_sun_colour.rgb * g_day_phase;\n"
5742 "\n"
5743 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
5744 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
5745 " g_sunset_phase );\n"
5746 "\n"
5747 " return ambient + (light_sun + sky_reflection) * shadow;\n"
5748 "}\n"
5749 "\n"
5750 "#line 44 0 \n"
5751 "\n"
5752 "float world_depth_sample( vec3 pos )\n"
5753 "{\n"
5754 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
5755 " return texture( g_world_depth, depth_coord ).r;\n"
5756 "}\n"
5757 "\n"
5758 "float world_water_depth( vec3 pos )\n"
5759 "{\n"
5760 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
5761 " return world_depth_sample( pos ) - ref_depth;\n"
5762 "}\n"
5763 "\n"
5764 "float shadow_sample( vec3 co ){\n"
5765 " float height_sample = world_depth_sample( co );\n"
5766 "\n"
5767 " float fdelta = height_sample - co.y;\n"
5768 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
5769 "}\n"
5770 "\n"
5771 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
5772 " if( g_shadow_samples == 0 ){\n"
5773 " return 1.0;\n"
5774 " }\n"
5775 "\n"
5776 " float fspread = g_shadow_spread;\n"
5777 " float flength = g_shadow_length;\n"
5778 "\n"
5779 " float famt = 0.0;\n"
5780 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
5781 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
5782 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
5783 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
5784 "\n"
5785 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
5786 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
5787 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
5788 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
5789 "\n"
5790 " return 1.0 - famt;\n"
5791 "}\n"
5792 "\n"
5793 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
5794 "{\n"
5795 " vec3 specdir = reflect( -dir, wnormal );\n"
5796 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
5797 "}\n"
5798 "\n"
5799 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
5800 " float dist = pow(fdist*0.0010,0.78);\n"
5801 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
5802 "}\n"
5803 "\n"
5804 "vec3 scene_calculate_light( int light_index, \n"
5805 " vec3 halfview, vec3 co, vec3 normal )\n"
5806 "{\n"
5807 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
5808 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
5809 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
5810 "\n"
5811 " vec3 light_delta = light_co.xyz-co;\n"
5812 " float dist2 = dot(light_delta,light_delta);\n"
5813 "\n"
5814 " light_delta = normalize( light_delta );\n"
5815 "\n"
5816 " float quadratic = dist2*100.0;\n"
5817 " float attenuation = 1.0/( 1.0 + quadratic );\n"
5818 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
5819 "\n"
5820 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
5821 "\n"
5822 " if( light_dir.w < 0.999999 ){\n"
5823 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
5824 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
5825 " }\n"
5826 "\n"
5827 " return light_colour.rgb * attenuation * falloff \n"
5828 " * step( g_day_phase, light_colour.w );\n"
5829 "}\n"
5830 "\n"
5831 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
5832 " vec3 halfview, vec3 co, vec3 normal )\n"
5833 "{\n"
5834 " uint light_count = packed_index & 0x3u;\n"
5835 "\n"
5836 " vec3 l = vec3(0.0);\n"
5837 "\n"
5838 " if( light_count >= 1u ){\n"
5839 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
5840 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
5841 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
5842 "\n"
5843 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
5844 "\n"
5845 " if( light_count >= 2u ){\n"
5846 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
5847 "\n"
5848 " if( light_count >= 3u ){\n"
5849 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
5850 " }\n"
5851 " }\n"
5852 " }\n"
5853 "\n"
5854 " return l;\n"
5855 "}\n"
5856 "\n"
5857 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
5858 " float light_mask )\n"
5859 "{\n"
5860 " if( g_light_preview == 1 )\n"
5861 " diffuse = vec3(0.75);\n"
5862 "\n"
5863 " // Lighting\n"
5864 " vec3 halfview = uCamera - co;\n"
5865 " float fdist = length(halfview);\n"
5866 " halfview /= fdist;\n"
5867 "\n"
5868 " float world_shadow = newlight_compute_sun_shadow( \n"
5869 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
5870 "\n"
5871 " vec3 total_light = clearskies_lighting( \n"
5872 " normal, min( light_mask, world_shadow ), halfview );\n"
5873 "\n"
5874 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
5875 " cube_coord = floor( cube_coord );\n"
5876 "\n"
5877 " if( g_debug_indices == 1 )\n"
5878 " {\n"
5879 " return rand33(cube_coord);\n"
5880 " }\n"
5881 "\n"
5882 " if( g_debug_complexity == 1 )\n"
5883 " {\n"
5884 " ivec3 coord = ivec3( cube_coord );\n"
5885 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5886 "\n"
5887 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
5888 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
5889 " }\n"
5890 "\n"
5891 " // FIXME: this coord should absolutely must be clamped!\n"
5892 " \n"
5893 " ivec3 coord = ivec3( cube_coord );\n"
5894 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5895 "\n"
5896 " total_light += \n"
5897 " scene_calculate_packed_light_patch( index_sample.x,\n"
5898 " halfview, co, normal ) \n"
5899 " * light_mask;\n"
5900 " total_light += \n"
5901 " scene_calculate_packed_light_patch( index_sample.y,\n"
5902 " halfview, co, normal )\n"
5903 " * light_mask;\n"
5904 "\n"
5905 " // Take a section of the sky function to give us a matching fog colour\n"
5906 "\n"
5907 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
5908 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
5909 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
5910 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
5911 " \n"
5912 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
5913 " sun_colour *= sun_shape;\n"
5914 "\n"
5915 " fog_colour += sun_colour;\n"
5916 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
5917 "}\n"
5918 "\n"
5919 "#line 9 0 \n"
5920 "\n"
5921 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
5922 "{\n"
5923 " vec3 pa = p - a;\n"
5924 " vec3 ba = b - a;\n"
5925 "\n"
5926 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
5927 " return length( pa - ba*h );\n"
5928 "}\n"
5929 "\n"
5930 "float compute_board_shadow()\n"
5931 "{\n"
5932 " // player shadow\n"
5933 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
5934 " g_board_1.xyz )-0.1 );\n"
5935 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
5936 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
5937 "\n"
5938 " return 1.0 - player_shadow*0.8;\n"
5939 "}\n"
5940 "\n"
5941 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
5942 "{\n"
5943 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
5944 "}\n"
5945 "\n"
5946 "#line 20 0 \n"
5947 "#line 1 3 \n"
5948 "const float k_motion_lerp_amount = 0.01;\n"
5949 "\n"
5950 "#line 2 0 \n"
5951 "\n"
5952 "layout (location = 1) out vec2 oMotionVec;\n"
5953 "\n"
5954 "in vec3 aMotionVec0;\n"
5955 "in vec3 aMotionVec1;\n"
5956 "\n"
5957 "void compute_motion_vectors()\n"
5958 "{\n"
5959 " // Write motion vectors\n"
5960 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
5961 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
5962 "\n"
5963 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
5964 "}\n"
5965 "\n"
5966 "#line 21 0 \n"
5967 "\n"
5968 "// Pasted from common_world.glsl\n"
5969 "vec3 water_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
5970 "{\n"
5971 " float light_mask = compute_board_shadow();\n"
5972 "\n"
5973 " if( g_light_preview == 1 )\n"
5974 " diffuse = vec3(0.75);\n"
5975 "\n"
5976 " // Lighting\n"
5977 " vec3 halfview = uCamera - co;\n"
5978 " float fdist = length(halfview);\n"
5979 " halfview /= fdist;\n"
5980 "\n"
5981 " float world_shadow = newlight_compute_sun_shadow( \n"
5982 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
5983 "\n"
5984 " vec3 total_light = clearskies_lighting( \n"
5985 " normal, min( light_mask, world_shadow ), halfview );\n"
5986 "\n"
5987 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
5988 " cube_coord = floor( cube_coord );\n"
5989 "\n"
5990 " if( g_debug_indices == 1 )\n"
5991 " {\n"
5992 " return rand33(cube_coord);\n"
5993 " }\n"
5994 "\n"
5995 " if( g_debug_complexity == 1 )\n"
5996 " {\n"
5997 " ivec3 coord = ivec3( cube_coord );\n"
5998 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
5999 "\n"
6000 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
6001 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
6002 " }\n"
6003 "\n"
6004 " // FIXME: this coord should absolutely must be clamped!\n"
6005 " \n"
6006 " ivec3 coord = ivec3( cube_coord );\n"
6007 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
6008 "\n"
6009 " total_light += \n"
6010 " scene_calculate_packed_light_patch( index_sample.x,\n"
6011 " halfview, co, normal ) \n"
6012 " * light_mask;\n"
6013 " total_light += \n"
6014 " scene_calculate_packed_light_patch( index_sample.y,\n"
6015 " halfview, co, normal )\n"
6016 " * light_mask;\n"
6017 "\n"
6018 " return diffuse * total_light;\n"
6019 "}\n"
6020 "\n"
6021 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue, \n"
6022 " vec4 beneath, vec4 above, vec4 dudva )\n"
6023 "{\n"
6024 " vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
6025 "\n"
6026 " float ffresnel = pow(1.0-dot( vnorm, halfview ),uFresnel);\n"
6027 "\n"
6028 " vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
6029 " vec3 specdir = reflect( -lightdir, vnorm );\n"
6030 " float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
6031 " \n"
6032 " // Depth \n"
6033 " float depthblend = pow( beneath.r, 0.8 );\n"
6034 "\n"
6035 " // Foam\n"
6036 " float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
6037 " fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
6038 "\n"
6039 " vec4 surf = mix( vec4(surface_tint,depthblend), \n"
6040 " vec4(1.0,1.0,1.0,0.5), fband );\n"
6041 " surf.rgb = water_compute_lighting( surf.rgb, aNorm.xyz, aWorldCo );\n"
6042 " surf.rgb = mix(surf.rgb, above.rgb, ffresnel );\n"
6043 "\n"
6044 " // Take a section of the sky function to give us a matching fog colour\n"
6045 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
6046 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
6047 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
6048 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6049 " \n"
6050 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6051 " sun_colour *= sun_shape;\n"
6052 "\n"
6053 " fog_colour += sun_colour;\n"
6054 " surf.rgb = scene_apply_fog( surf.rgb, fog_colour, \n"
6055 " distance(uCamera, aWorldCo) );\n"
6056 "\n"
6057 " return surf;\n"
6058 "}\n"
6059 "\n"
6060 "void main()\n"
6061 "{\n"
6062 " compute_motion_vectors();\n"
6063 "\n"
6064 " // Create texture coords\n"
6065 " vec2 ssuv = gl_FragCoord.xy*uInvRes;\n"
6066 " \n"
6067 " // Surface colour composite\n"
6068 " float depthvalue = clamp( -world_water_depth(aCo)*(1.0/25.0), 0.0,1.0 );\n"
6069 "\n"
6070 " vec2 world_coord = aCo.xz * uWaterScale;\n"
6071 " //TODO: Material param ( 0.008, 0.006, 0.003, 0.03 );\n"
6072 " vec4 time_offsets = vec4( uTime ) * vec4( 0.08, -0.08, -0.03, -0.01 );\n"
6073 " vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
6074 " vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
6075 "\n"
6076 " vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
6077 " surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
6078 " \n"
6079 " // Lighting\n"
6080 " vec3 halfview = -normalize( aCo-uCamera );\n"
6081 "\n"
6082 " // Sample textures\n"
6083 " vec4 above = texture( uTexMain, ssuv+ surfnorm.xz*0.2 );\n"
6084 " vec4 beneath = texture( uTexBack, ssuv );\n"
6085 "\n"
6086 " // Fog\n"
6087 " float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
6088 "\n"
6089 " // Composite\n"
6090 " vec4 vsurface = water_surf( halfview, surfnorm, depthvalue, beneath, above, dudva );\n"
6091 " vsurface.a -= fdist;\n"
6092 "\n"
6093 " oColour = vsurface;\n"
6094 "}\n"
6095 ""},
6096 };
6097
6098 GLuint _uniform_scene_water_uMdl;
6099 GLuint _uniform_scene_water_uPv;
6100 GLuint _uniform_scene_water_uPvmPrev;
6101 GLuint _uniform_scene_water_uTexMain;
6102 GLuint _uniform_scene_water_uTexDudv;
6103 GLuint _uniform_scene_water_uTexBack;
6104 GLuint _uniform_scene_water_uInvRes;
6105 GLuint _uniform_scene_water_uTime;
6106 GLuint _uniform_scene_water_uCamera;
6107 GLuint _uniform_scene_water_uSurfaceY;
6108 GLuint _uniform_scene_water_uBoard0;
6109 GLuint _uniform_scene_water_uBoard1;
6110 GLuint _uniform_scene_water_uShoreColour;
6111 GLuint _uniform_scene_water_uOceanColour;
6112 GLuint _uniform_scene_water_uFresnel;
6113 GLuint _uniform_scene_water_uWaterScale;
6114 GLuint _uniform_scene_water_uWaveSpeed;
6115 GLuint _uniform_scene_water_g_world_depth;
6116 GLuint _uniform_scene_water_uLightsArray;
6117 GLuint _uniform_scene_water_uLightsIndex;
6118 #include "shaders/scene_water_fast.h"
6119 struct vg_shader _shader_scene_water_fast = {
6120 .name = "scene_water_fast",
6121 .vs =
6122 {
6123 .orig_file = "shaders/scene.vs",
6124 .static_src =
6125 "layout (location=0) in vec3 a_co;\n"
6126 "layout (location=1) in vec4 a_norm;\n"
6127 "layout (location=2) in vec2 a_uv;\n"
6128 "\n"
6129 "#line 1 1 \n"
6130 "const float k_motion_lerp_amount = 0.01;\n"
6131 "\n"
6132 "#line 2 0 \n"
6133 "\n"
6134 "out vec3 aMotionVec0;\n"
6135 "out vec3 aMotionVec1;\n"
6136 "\n"
6137 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
6138 "{\n"
6139 " // This magically solves some artifacting errors!\n"
6140 " //\n"
6141 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
6142 "\n"
6143 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
6144 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
6145 "}\n"
6146 "\n"
6147 "#line 6 0 \n"
6148 "\n"
6149 "uniform mat4x3 uMdl;\n"
6150 "uniform mat4 uPv;\n"
6151 "uniform mat4 uPvmPrev;\n"
6152 "\n"
6153 "out vec2 aUv;\n"
6154 "out vec4 aNorm;\n"
6155 "out vec3 aCo;\n"
6156 "out vec3 aWorldCo;\n"
6157 "\n"
6158 "void main()\n"
6159 "{\n"
6160 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
6161 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
6162 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
6163 "\n"
6164 " vs_motion_out( vproj0, vproj1 );\n"
6165 "\n"
6166 " gl_Position = vproj0;\n"
6167 "\n"
6168 " aUv = a_uv;\n"
6169 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
6170 " aCo = a_co;\n"
6171 " aWorldCo = world_pos0;\n"
6172 "}\n"
6173 ""},
6174 .fs =
6175 {
6176 .orig_file = "shaders/scene_water_fast.fs",
6177 .static_src =
6178 "uniform sampler2D uTexDudv;\n"
6179 "\n"
6180 "uniform float uTime;\n"
6181 "uniform vec3 uCamera;\n"
6182 "uniform float uSurfaceY;\n"
6183 "uniform vec3 uBoard0;\n"
6184 "uniform vec3 uBoard1;\n"
6185 "\n"
6186 "uniform vec3 uShoreColour;\n"
6187 "uniform vec3 uOceanColour;\n"
6188 "\n"
6189 "#line 1 1 \n"
6190 "// :D\n"
6191 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
6192 "\n"
6193 "#line 13 0 \n"
6194 "#line 1 2 \n"
6195 "// :D\n"
6196 "\n"
6197 "in vec2 aUv;\n"
6198 "in vec4 aNorm;\n"
6199 "in vec3 aCo;\n"
6200 "in vec3 aWorldCo;\n"
6201 "\n"
6202 "#line 1 1 \n"
6203 "layout (location = 0) out vec4 oColour;\n"
6204 "\n"
6205 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
6206 "layout (std140) uniform ub_world_lighting\n"
6207 "{\n"
6208 " vec4 g_cube_min;\n"
6209 " vec4 g_cube_inv_range;\n"
6210 "\n"
6211 " vec4 g_water_plane;\n"
6212 " vec4 g_depth_bounds;\n"
6213 "\n"
6214 " vec4 g_daysky_colour;\n"
6215 " vec4 g_nightsky_colour;\n"
6216 " vec4 g_sunset_colour;\n"
6217 " vec4 g_ambient_colour;\n"
6218 " vec4 g_sunset_ambient;\n"
6219 " vec4 g_sun_colour;\n"
6220 " vec4 g_sun_dir;\n"
6221 " vec4 g_board_0;\n"
6222 " vec4 g_board_1;\n"
6223 "\n"
6224 " float g_water_fog;\n"
6225 " float g_time;\n"
6226 " float g_realtime;\n"
6227 " float g_shadow_length;\n"
6228 " float g_shadow_spread;\n"
6229 "\n"
6230 " float g_time_of_day;\n"
6231 " float g_day_phase;\n"
6232 " float g_sunset_phase;\n"
6233 "\n"
6234 " int g_light_preview;\n"
6235 " int g_shadow_samples;\n"
6236 "\n"
6237 " int g_debug_indices;\n"
6238 " int g_debug_complexity;\n"
6239 "};\n"
6240 "\n"
6241 "uniform sampler2D g_world_depth;\n"
6242 "uniform samplerBuffer uLightsArray;\n"
6243 "uniform usampler3D uLightsIndex;\n"
6244 "\n"
6245 "#line 1 1 \n"
6246 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
6247 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
6248 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
6249 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
6250 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
6251 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
6252 "\n"
6253 "const float SUN_ANGLE = 0.0001;\n"
6254 "const float PI = 3.14159265358979323846264;\n"
6255 "\n"
6256 "//struct world_info\n"
6257 "//{\n"
6258 "// float time,\n"
6259 "// time_of_day,\n"
6260 "// day_phase,\n"
6261 "// sunset_phase;\n"
6262 "// \n"
6263 "// vec3 sun_dir;\n"
6264 "//};\n"
6265 "\n"
6266 "vec3 rand33(vec3 p3)\n"
6267 "{\n"
6268 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
6269 " p3 += dot(p3, p3.yxz+33.33);\n"
6270 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
6271 "}\n"
6272 "\n"
6273 "float stars( vec3 rd, float rr, float size ){\n"
6274 " vec3 co = rd * rr;\n"
6275 "\n"
6276 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
6277 "\n"
6278 " float spaces = 1.0 / rr;\n"
6279 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
6280 " a -= mod(a, spaces) - spaces * 0.5;\n"
6281 "\n"
6282 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
6283 " \n"
6284 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
6285 " plane = plane - mod(plane, PI / count);\n"
6286 "\n"
6287 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
6288 "\n"
6289 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
6290 " float ydist = sqrt(rr * rr - level * level);\n"
6291 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
6292 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
6293 " float star = smoothstep(size, 0.0, distance(center, co));\n"
6294 " return star;\n"
6295 "}\n"
6296 "\n"
6297 "float luminance( vec3 v )\n"
6298 "{\n"
6299 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
6300 "}\n"
6301 "\n"
6302 "vec3 clearskies_ambient( vec3 dir )\n"
6303 "{\n"
6304 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
6305 " float sky_gradient = dir.y;\n"
6306 " \n"
6307 " /* Blend phase colours */\n"
6308 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
6309 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
6310 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
6311 " \n"
6312 " /* Add gradient */\n"
6313 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
6314 " \n"
6315 " return ambient;\n"
6316 "}\n"
6317 "\n"
6318 "vec3 clearskies_sky( vec3 ray_dir )\n"
6319 "{\n"
6320 " ray_dir.y = abs( ray_dir.y );\n"
6321 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
6322 " \n"
6323 " /* Sun */\n"
6324 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
6325 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
6326 " float sun_shape = pow( sun_size, 2000.0 );\n"
6327 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6328 " \n"
6329 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6330 " sun_colour *= sun_shape;\n"
6331 "\n"
6332 " \n"
6333 " float star = 0.0;\n"
6334 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
6335 "\n"
6336 " if( star_blend > 0.001 ){\n"
6337 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
6338 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
6339 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
6340 " }\n"
6341 " }\n"
6342 " \n"
6343 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
6344 " return composite;\n"
6345 "}\n"
6346 "\n"
6347 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
6348 "{\n"
6349 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
6350 "\n"
6351 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
6352 " g_sunset_phase );\n"
6353 "\n"
6354 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
6355 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
6356 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
6357 " ) * g_sun_colour.rgb * g_day_phase;\n"
6358 "\n"
6359 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
6360 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
6361 " g_sunset_phase );\n"
6362 "\n"
6363 " return ambient + (light_sun + sky_reflection) * shadow;\n"
6364 "}\n"
6365 "\n"
6366 "#line 44 0 \n"
6367 "\n"
6368 "float world_depth_sample( vec3 pos )\n"
6369 "{\n"
6370 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
6371 " return texture( g_world_depth, depth_coord ).r;\n"
6372 "}\n"
6373 "\n"
6374 "float world_water_depth( vec3 pos )\n"
6375 "{\n"
6376 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
6377 " return world_depth_sample( pos ) - ref_depth;\n"
6378 "}\n"
6379 "\n"
6380 "float shadow_sample( vec3 co ){\n"
6381 " float height_sample = world_depth_sample( co );\n"
6382 "\n"
6383 " float fdelta = height_sample - co.y;\n"
6384 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
6385 "}\n"
6386 "\n"
6387 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
6388 " if( g_shadow_samples == 0 ){\n"
6389 " return 1.0;\n"
6390 " }\n"
6391 "\n"
6392 " float fspread = g_shadow_spread;\n"
6393 " float flength = g_shadow_length;\n"
6394 "\n"
6395 " float famt = 0.0;\n"
6396 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
6397 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
6398 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
6399 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
6400 "\n"
6401 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
6402 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
6403 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
6404 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
6405 "\n"
6406 " return 1.0 - famt;\n"
6407 "}\n"
6408 "\n"
6409 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
6410 "{\n"
6411 " vec3 specdir = reflect( -dir, wnormal );\n"
6412 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
6413 "}\n"
6414 "\n"
6415 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
6416 " float dist = pow(fdist*0.0010,0.78);\n"
6417 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
6418 "}\n"
6419 "\n"
6420 "vec3 scene_calculate_light( int light_index, \n"
6421 " vec3 halfview, vec3 co, vec3 normal )\n"
6422 "{\n"
6423 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
6424 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
6425 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
6426 "\n"
6427 " vec3 light_delta = light_co.xyz-co;\n"
6428 " float dist2 = dot(light_delta,light_delta);\n"
6429 "\n"
6430 " light_delta = normalize( light_delta );\n"
6431 "\n"
6432 " float quadratic = dist2*100.0;\n"
6433 " float attenuation = 1.0/( 1.0 + quadratic );\n"
6434 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
6435 "\n"
6436 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
6437 "\n"
6438 " if( light_dir.w < 0.999999 ){\n"
6439 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
6440 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
6441 " }\n"
6442 "\n"
6443 " return light_colour.rgb * attenuation * falloff \n"
6444 " * step( g_day_phase, light_colour.w );\n"
6445 "}\n"
6446 "\n"
6447 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
6448 " vec3 halfview, vec3 co, vec3 normal )\n"
6449 "{\n"
6450 " uint light_count = packed_index & 0x3u;\n"
6451 "\n"
6452 " vec3 l = vec3(0.0);\n"
6453 "\n"
6454 " if( light_count >= 1u ){\n"
6455 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
6456 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
6457 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
6458 "\n"
6459 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
6460 "\n"
6461 " if( light_count >= 2u ){\n"
6462 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
6463 "\n"
6464 " if( light_count >= 3u ){\n"
6465 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
6466 " }\n"
6467 " }\n"
6468 " }\n"
6469 "\n"
6470 " return l;\n"
6471 "}\n"
6472 "\n"
6473 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
6474 " float light_mask )\n"
6475 "{\n"
6476 " if( g_light_preview == 1 )\n"
6477 " diffuse = vec3(0.75);\n"
6478 "\n"
6479 " // Lighting\n"
6480 " vec3 halfview = uCamera - co;\n"
6481 " float fdist = length(halfview);\n"
6482 " halfview /= fdist;\n"
6483 "\n"
6484 " float world_shadow = newlight_compute_sun_shadow( \n"
6485 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
6486 "\n"
6487 " vec3 total_light = clearskies_lighting( \n"
6488 " normal, min( light_mask, world_shadow ), halfview );\n"
6489 "\n"
6490 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
6491 " cube_coord = floor( cube_coord );\n"
6492 "\n"
6493 " if( g_debug_indices == 1 )\n"
6494 " {\n"
6495 " return rand33(cube_coord);\n"
6496 " }\n"
6497 "\n"
6498 " if( g_debug_complexity == 1 )\n"
6499 " {\n"
6500 " ivec3 coord = ivec3( cube_coord );\n"
6501 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
6502 "\n"
6503 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
6504 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
6505 " }\n"
6506 "\n"
6507 " // FIXME: this coord should absolutely must be clamped!\n"
6508 " \n"
6509 " ivec3 coord = ivec3( cube_coord );\n"
6510 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
6511 "\n"
6512 " total_light += \n"
6513 " scene_calculate_packed_light_patch( index_sample.x,\n"
6514 " halfview, co, normal ) \n"
6515 " * light_mask;\n"
6516 " total_light += \n"
6517 " scene_calculate_packed_light_patch( index_sample.y,\n"
6518 " halfview, co, normal )\n"
6519 " * light_mask;\n"
6520 "\n"
6521 " // Take a section of the sky function to give us a matching fog colour\n"
6522 "\n"
6523 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
6524 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
6525 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
6526 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6527 " \n"
6528 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6529 " sun_colour *= sun_shape;\n"
6530 "\n"
6531 " fog_colour += sun_colour;\n"
6532 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
6533 "}\n"
6534 "\n"
6535 "#line 9 0 \n"
6536 "\n"
6537 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
6538 "{\n"
6539 " vec3 pa = p - a;\n"
6540 " vec3 ba = b - a;\n"
6541 "\n"
6542 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
6543 " return length( pa - ba*h );\n"
6544 "}\n"
6545 "\n"
6546 "float compute_board_shadow()\n"
6547 "{\n"
6548 " // player shadow\n"
6549 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
6550 " g_board_1.xyz )-0.1 );\n"
6551 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
6552 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
6553 "\n"
6554 " return 1.0 - player_shadow*0.8;\n"
6555 "}\n"
6556 "\n"
6557 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
6558 "{\n"
6559 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
6560 "}\n"
6561 "\n"
6562 "#line 14 0 \n"
6563 "#line 1 3 \n"
6564 "const float k_motion_lerp_amount = 0.01;\n"
6565 "\n"
6566 "#line 2 0 \n"
6567 "\n"
6568 "layout (location = 1) out vec2 oMotionVec;\n"
6569 "\n"
6570 "in vec3 aMotionVec0;\n"
6571 "in vec3 aMotionVec1;\n"
6572 "\n"
6573 "void compute_motion_vectors()\n"
6574 "{\n"
6575 " // Write motion vectors\n"
6576 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
6577 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
6578 "\n"
6579 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
6580 "}\n"
6581 "\n"
6582 "#line 15 0 \n"
6583 "\n"
6584 "vec4 water_surf( vec3 halfview, vec3 vnorm, float depthvalue )\n"
6585 "{\n"
6586 " vec3 surface_tint = mix(uShoreColour, uOceanColour, depthvalue);\n"
6587 "\n"
6588 " float ffresnel = pow(1.0-dot( vnorm, halfview ),5.0);\n"
6589 "\n"
6590 " vec3 lightdir = vec3(0.95,0.0,-0.3);\n"
6591 " vec3 specdir = reflect( -lightdir, vnorm );\n"
6592 " float spec = pow(max(dot(halfview,specdir),0.0),20.0)*0.3;\n"
6593 " \n"
6594 " return vec4( surface_tint + spec, max(min(depthvalue*4.0, 1.0),0.0) );\n"
6595 "}\n"
6596 "\n"
6597 "void main()\n"
6598 "{\n"
6599 " compute_motion_vectors();\n"
6600 "\n"
6601 " // Surface colour composite\n"
6602 " float depthvalue = clamp( -world_water_depth( aCo )*(1.0/25.0), 0.0, 1.0 );\n"
6603 "\n"
6604 " vec2 world_coord = aCo.xz * 0.008;\n"
6605 " vec4 time_offsets = vec4( uTime ) * vec4( 0.008, 0.006, 0.003, 0.03 );\n"
6606 " vec4 dudva = texture( uTexDudv, world_coord + time_offsets.xy )-0.5;\n"
6607 " vec4 dudvb = texture( uTexDudv, world_coord *7.0 - time_offsets.zw )-0.5;\n"
6608 "\n"
6609 " vec3 surfnorm = dudva.rgb + dudvb.rgb;\n"
6610 " surfnorm = normalize(vec3(0.0,1.0,0.0) + dudva.xyz*0.4 + dudvb.xyz*0.1);\n"
6611 " \n"
6612 " // Foam\n"
6613 " float fband = fract( aCo.z*0.02+uTime*0.1+depthvalue*10.0 );\n"
6614 " fband = step( fband+dudva.a*0.8, 0.3 ) * max((1.0-depthvalue*4.0),0.0);\n"
6615 "\n"
6616 " // Lighting\n"
6617 " vec3 halfview = -normalize( aCo-uCamera );\n"
6618 "\n"
6619 " // Fog\n"
6620 " float fdist = pow(length( aCo.xz-uCamera.xz ) * 0.00047, 2.6);\n"
6621 "\n"
6622 " // Composite\n"
6623 " vec4 vsurface = water_surf( halfview, surfnorm, depthvalue );\n"
6624 " vsurface.a -= fdist;\n"
6625 " oColour = mix( vsurface, vec4(1.0,1.0,1.0,0.5), fband );\n"
6626 " oColour.rgb = scene_compute_lighting( oColour.rgb, aNorm.xyz, aWorldCo );\n"
6627 "}\n"
6628 ""},
6629 };
6630
6631 GLuint _uniform_scene_water_fast_uMdl;
6632 GLuint _uniform_scene_water_fast_uPv;
6633 GLuint _uniform_scene_water_fast_uPvmPrev;
6634 GLuint _uniform_scene_water_fast_uTexDudv;
6635 GLuint _uniform_scene_water_fast_uTime;
6636 GLuint _uniform_scene_water_fast_uCamera;
6637 GLuint _uniform_scene_water_fast_uSurfaceY;
6638 GLuint _uniform_scene_water_fast_uBoard0;
6639 GLuint _uniform_scene_water_fast_uBoard1;
6640 GLuint _uniform_scene_water_fast_uShoreColour;
6641 GLuint _uniform_scene_water_fast_uOceanColour;
6642 GLuint _uniform_scene_water_fast_g_world_depth;
6643 GLuint _uniform_scene_water_fast_uLightsArray;
6644 GLuint _uniform_scene_water_fast_uLightsIndex;
6645 #include "shaders/scene_scoretext.h"
6646 struct vg_shader _shader_scene_scoretext = {
6647 .name = "scene_scoretext",
6648 .vs =
6649 {
6650 .orig_file = "shaders/scene_sfd.vs",
6651 .static_src =
6652 "layout (location=0) in vec3 a_co;\n"
6653 "layout (location=1) in vec4 a_norm;\n"
6654 "layout (location=2) in vec2 a_uv;\n"
6655 "\n"
6656 "#line 1 1 \n"
6657 "const float k_motion_lerp_amount = 0.01;\n"
6658 "\n"
6659 "#line 2 0 \n"
6660 "\n"
6661 "out vec3 aMotionVec0;\n"
6662 "out vec3 aMotionVec1;\n"
6663 "\n"
6664 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
6665 "{\n"
6666 " // This magically solves some artifacting errors!\n"
6667 " //\n"
6668 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
6669 "\n"
6670 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
6671 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
6672 "}\n"
6673 "\n"
6674 "#line 6 0 \n"
6675 "\n"
6676 "uniform mat4x3 uMdl;\n"
6677 "uniform mat4 uPv;\n"
6678 "uniform mat4 uPvmPrev;\n"
6679 "uniform vec3 uInfo;\n"
6680 "\n"
6681 "out vec2 aUv;\n"
6682 "out vec4 aNorm;\n"
6683 "out vec3 aCo;\n"
6684 "out vec3 aWorldCo;\n"
6685 "\n"
6686 "void main()\n"
6687 "{\n"
6688 " float w = ((a_norm.w)-0.5)*2.0 + fract(uInfo.z) - 0.0;\n"
6689 " float c = -cos(w*0.6);\n"
6690 " float s = -sin(w*0.6);\n"
6691 " float r = 0.2;\n"
6692 "\n"
6693 " float w1 = clamp( w*4.0 - a_co.y*10.0, -1.0, 1.0 ) * (3.14159265*0.5);\n"
6694 " float c1 = cos(w1);\n"
6695 " float s1 = sin(w1);\n"
6696 "\n"
6697 " float yoff = step(0.01,fract(uInfo.z))*-0.5;\n"
6698 "\n"
6699 " mat4x3 mlocal;\n"
6700 " mlocal[0] = vec3(c1, s1,0.0);\n"
6701 " mlocal[1] = vec3(-s1,c1,0.0);\n"
6702 " mlocal[2] = vec3(0.0,0.0,1.0);\n"
6703 " mlocal[3] = vec3(c*r,uInfo.y*0.875 + s*r,uInfo.x*0.5);\n"
6704 "\n"
6705 " vec3 local_pos0 = mlocal * vec4( a_co, 1.0 );\n"
6706 " vec3 world_pos0 = uMdl * vec4( local_pos0, 1.0 );\n"
6707 "\n"
6708 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
6709 " vec4 vproj1 = uPvmPrev * vec4( local_pos0, 1.0 );\n"
6710 "\n"
6711 " vs_motion_out( vproj0, vproj1 );\n"
6712 "\n"
6713 " gl_Position = vproj0;\n"
6714 "\n"
6715 " aUv = a_uv + vec2( floor(uInfo.z+0.5)*(1.0/64.0), yoff );\n"
6716 " aNorm = vec4( mat3(uMdl) * mat3(mlocal) * a_norm.xyz, a_norm.w );\n"
6717 " aCo = a_co;\n"
6718 " aWorldCo = world_pos0;\n"
6719 "}\n"
6720 ""},
6721 .fs =
6722 {
6723 .orig_file = "shaders/scene_standard.fs",
6724 .static_src =
6725 "uniform sampler2D uTexGarbage;\n"
6726 "uniform sampler2D uTexMain;\n"
6727 "uniform vec3 uCamera;\n"
6728 "uniform vec4 uPlane;\n"
6729 "\n"
6730 "#line 1 1 \n"
6731 "// :D\n"
6732 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
6733 "\n"
6734 "#line 7 0 \n"
6735 "#line 1 2 \n"
6736 "// :D\n"
6737 "\n"
6738 "in vec2 aUv;\n"
6739 "in vec4 aNorm;\n"
6740 "in vec3 aCo;\n"
6741 "in vec3 aWorldCo;\n"
6742 "\n"
6743 "#line 1 1 \n"
6744 "layout (location = 0) out vec4 oColour;\n"
6745 "\n"
6746 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
6747 "layout (std140) uniform ub_world_lighting\n"
6748 "{\n"
6749 " vec4 g_cube_min;\n"
6750 " vec4 g_cube_inv_range;\n"
6751 "\n"
6752 " vec4 g_water_plane;\n"
6753 " vec4 g_depth_bounds;\n"
6754 "\n"
6755 " vec4 g_daysky_colour;\n"
6756 " vec4 g_nightsky_colour;\n"
6757 " vec4 g_sunset_colour;\n"
6758 " vec4 g_ambient_colour;\n"
6759 " vec4 g_sunset_ambient;\n"
6760 " vec4 g_sun_colour;\n"
6761 " vec4 g_sun_dir;\n"
6762 " vec4 g_board_0;\n"
6763 " vec4 g_board_1;\n"
6764 "\n"
6765 " float g_water_fog;\n"
6766 " float g_time;\n"
6767 " float g_realtime;\n"
6768 " float g_shadow_length;\n"
6769 " float g_shadow_spread;\n"
6770 "\n"
6771 " float g_time_of_day;\n"
6772 " float g_day_phase;\n"
6773 " float g_sunset_phase;\n"
6774 "\n"
6775 " int g_light_preview;\n"
6776 " int g_shadow_samples;\n"
6777 "\n"
6778 " int g_debug_indices;\n"
6779 " int g_debug_complexity;\n"
6780 "};\n"
6781 "\n"
6782 "uniform sampler2D g_world_depth;\n"
6783 "uniform samplerBuffer uLightsArray;\n"
6784 "uniform usampler3D uLightsIndex;\n"
6785 "\n"
6786 "#line 1 1 \n"
6787 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
6788 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
6789 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
6790 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
6791 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
6792 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
6793 "\n"
6794 "const float SUN_ANGLE = 0.0001;\n"
6795 "const float PI = 3.14159265358979323846264;\n"
6796 "\n"
6797 "//struct world_info\n"
6798 "//{\n"
6799 "// float time,\n"
6800 "// time_of_day,\n"
6801 "// day_phase,\n"
6802 "// sunset_phase;\n"
6803 "// \n"
6804 "// vec3 sun_dir;\n"
6805 "//};\n"
6806 "\n"
6807 "vec3 rand33(vec3 p3)\n"
6808 "{\n"
6809 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
6810 " p3 += dot(p3, p3.yxz+33.33);\n"
6811 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
6812 "}\n"
6813 "\n"
6814 "float stars( vec3 rd, float rr, float size ){\n"
6815 " vec3 co = rd * rr;\n"
6816 "\n"
6817 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
6818 "\n"
6819 " float spaces = 1.0 / rr;\n"
6820 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
6821 " a -= mod(a, spaces) - spaces * 0.5;\n"
6822 "\n"
6823 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
6824 " \n"
6825 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
6826 " plane = plane - mod(plane, PI / count);\n"
6827 "\n"
6828 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
6829 "\n"
6830 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
6831 " float ydist = sqrt(rr * rr - level * level);\n"
6832 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
6833 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
6834 " float star = smoothstep(size, 0.0, distance(center, co));\n"
6835 " return star;\n"
6836 "}\n"
6837 "\n"
6838 "float luminance( vec3 v )\n"
6839 "{\n"
6840 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
6841 "}\n"
6842 "\n"
6843 "vec3 clearskies_ambient( vec3 dir )\n"
6844 "{\n"
6845 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
6846 " float sky_gradient = dir.y;\n"
6847 " \n"
6848 " /* Blend phase colours */\n"
6849 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
6850 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
6851 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
6852 " \n"
6853 " /* Add gradient */\n"
6854 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
6855 " \n"
6856 " return ambient;\n"
6857 "}\n"
6858 "\n"
6859 "vec3 clearskies_sky( vec3 ray_dir )\n"
6860 "{\n"
6861 " ray_dir.y = abs( ray_dir.y );\n"
6862 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
6863 " \n"
6864 " /* Sun */\n"
6865 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
6866 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
6867 " float sun_shape = pow( sun_size, 2000.0 );\n"
6868 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
6869 " \n"
6870 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
6871 " sun_colour *= sun_shape;\n"
6872 "\n"
6873 " \n"
6874 " float star = 0.0;\n"
6875 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
6876 "\n"
6877 " if( star_blend > 0.001 ){\n"
6878 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
6879 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
6880 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
6881 " }\n"
6882 " }\n"
6883 " \n"
6884 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
6885 " return composite;\n"
6886 "}\n"
6887 "\n"
6888 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
6889 "{\n"
6890 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
6891 "\n"
6892 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
6893 " g_sunset_phase );\n"
6894 "\n"
6895 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
6896 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
6897 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
6898 " ) * g_sun_colour.rgb * g_day_phase;\n"
6899 "\n"
6900 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
6901 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
6902 " g_sunset_phase );\n"
6903 "\n"
6904 " return ambient + (light_sun + sky_reflection) * shadow;\n"
6905 "}\n"
6906 "\n"
6907 "#line 44 0 \n"
6908 "\n"
6909 "float world_depth_sample( vec3 pos )\n"
6910 "{\n"
6911 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
6912 " return texture( g_world_depth, depth_coord ).r;\n"
6913 "}\n"
6914 "\n"
6915 "float world_water_depth( vec3 pos )\n"
6916 "{\n"
6917 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
6918 " return world_depth_sample( pos ) - ref_depth;\n"
6919 "}\n"
6920 "\n"
6921 "float shadow_sample( vec3 co ){\n"
6922 " float height_sample = world_depth_sample( co );\n"
6923 "\n"
6924 " float fdelta = height_sample - co.y;\n"
6925 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
6926 "}\n"
6927 "\n"
6928 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
6929 " if( g_shadow_samples == 0 ){\n"
6930 " return 1.0;\n"
6931 " }\n"
6932 "\n"
6933 " float fspread = g_shadow_spread;\n"
6934 " float flength = g_shadow_length;\n"
6935 "\n"
6936 " float famt = 0.0;\n"
6937 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
6938 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
6939 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
6940 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
6941 "\n"
6942 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
6943 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
6944 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
6945 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
6946 "\n"
6947 " return 1.0 - famt;\n"
6948 "}\n"
6949 "\n"
6950 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
6951 "{\n"
6952 " vec3 specdir = reflect( -dir, wnormal );\n"
6953 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
6954 "}\n"
6955 "\n"
6956 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
6957 " float dist = pow(fdist*0.0010,0.78);\n"
6958 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
6959 "}\n"
6960 "\n"
6961 "vec3 scene_calculate_light( int light_index, \n"
6962 " vec3 halfview, vec3 co, vec3 normal )\n"
6963 "{\n"
6964 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
6965 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
6966 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
6967 "\n"
6968 " vec3 light_delta = light_co.xyz-co;\n"
6969 " float dist2 = dot(light_delta,light_delta);\n"
6970 "\n"
6971 " light_delta = normalize( light_delta );\n"
6972 "\n"
6973 " float quadratic = dist2*100.0;\n"
6974 " float attenuation = 1.0/( 1.0 + quadratic );\n"
6975 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
6976 "\n"
6977 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
6978 "\n"
6979 " if( light_dir.w < 0.999999 ){\n"
6980 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
6981 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
6982 " }\n"
6983 "\n"
6984 " return light_colour.rgb * attenuation * falloff \n"
6985 " * step( g_day_phase, light_colour.w );\n"
6986 "}\n"
6987 "\n"
6988 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
6989 " vec3 halfview, vec3 co, vec3 normal )\n"
6990 "{\n"
6991 " uint light_count = packed_index & 0x3u;\n"
6992 "\n"
6993 " vec3 l = vec3(0.0);\n"
6994 "\n"
6995 " if( light_count >= 1u ){\n"
6996 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
6997 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
6998 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
6999 "\n"
7000 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
7001 "\n"
7002 " if( light_count >= 2u ){\n"
7003 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
7004 "\n"
7005 " if( light_count >= 3u ){\n"
7006 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
7007 " }\n"
7008 " }\n"
7009 " }\n"
7010 "\n"
7011 " return l;\n"
7012 "}\n"
7013 "\n"
7014 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
7015 " float light_mask )\n"
7016 "{\n"
7017 " if( g_light_preview == 1 )\n"
7018 " diffuse = vec3(0.75);\n"
7019 "\n"
7020 " // Lighting\n"
7021 " vec3 halfview = uCamera - co;\n"
7022 " float fdist = length(halfview);\n"
7023 " halfview /= fdist;\n"
7024 "\n"
7025 " float world_shadow = newlight_compute_sun_shadow( \n"
7026 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
7027 "\n"
7028 " vec3 total_light = clearskies_lighting( \n"
7029 " normal, min( light_mask, world_shadow ), halfview );\n"
7030 "\n"
7031 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
7032 " cube_coord = floor( cube_coord );\n"
7033 "\n"
7034 " if( g_debug_indices == 1 )\n"
7035 " {\n"
7036 " return rand33(cube_coord);\n"
7037 " }\n"
7038 "\n"
7039 " if( g_debug_complexity == 1 )\n"
7040 " {\n"
7041 " ivec3 coord = ivec3( cube_coord );\n"
7042 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7043 "\n"
7044 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
7045 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
7046 " }\n"
7047 "\n"
7048 " // FIXME: this coord should absolutely must be clamped!\n"
7049 " \n"
7050 " ivec3 coord = ivec3( cube_coord );\n"
7051 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7052 "\n"
7053 " total_light += \n"
7054 " scene_calculate_packed_light_patch( index_sample.x,\n"
7055 " halfview, co, normal ) \n"
7056 " * light_mask;\n"
7057 " total_light += \n"
7058 " scene_calculate_packed_light_patch( index_sample.y,\n"
7059 " halfview, co, normal )\n"
7060 " * light_mask;\n"
7061 "\n"
7062 " // Take a section of the sky function to give us a matching fog colour\n"
7063 "\n"
7064 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
7065 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
7066 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
7067 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7068 " \n"
7069 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7070 " sun_colour *= sun_shape;\n"
7071 "\n"
7072 " fog_colour += sun_colour;\n"
7073 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
7074 "}\n"
7075 "\n"
7076 "#line 9 0 \n"
7077 "\n"
7078 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
7079 "{\n"
7080 " vec3 pa = p - a;\n"
7081 " vec3 ba = b - a;\n"
7082 "\n"
7083 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
7084 " return length( pa - ba*h );\n"
7085 "}\n"
7086 "\n"
7087 "float compute_board_shadow()\n"
7088 "{\n"
7089 " // player shadow\n"
7090 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
7091 " g_board_1.xyz )-0.1 );\n"
7092 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
7093 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
7094 "\n"
7095 " return 1.0 - player_shadow*0.8;\n"
7096 "}\n"
7097 "\n"
7098 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
7099 "{\n"
7100 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
7101 "}\n"
7102 "\n"
7103 "#line 8 0 \n"
7104 "#line 1 3 \n"
7105 "const float k_motion_lerp_amount = 0.01;\n"
7106 "\n"
7107 "#line 2 0 \n"
7108 "\n"
7109 "layout (location = 1) out vec2 oMotionVec;\n"
7110 "\n"
7111 "in vec3 aMotionVec0;\n"
7112 "in vec3 aMotionVec1;\n"
7113 "\n"
7114 "void compute_motion_vectors()\n"
7115 "{\n"
7116 " // Write motion vectors\n"
7117 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
7118 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
7119 "\n"
7120 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
7121 "}\n"
7122 "\n"
7123 "#line 9 0 \n"
7124 "\n"
7125 "void main()\n"
7126 "{\n"
7127 " compute_motion_vectors();\n"
7128 "\n"
7129 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
7130 " vec4 vsamplemain = texture( uTexMain, aUv );\n"
7131 " vec3 qnorm = aNorm.xyz;\n"
7132 "\n"
7133 " vfrag = vsamplemain.rgb;\n"
7134 "\n"
7135 " if( g_light_preview == 1 )\n"
7136 " {\n"
7137 " vfrag = vec3(0.5);\n"
7138 " }\n"
7139 "\n"
7140 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
7141 " oColour = vec4( vfrag, 1.0 );\n"
7142 "}\n"
7143 ""},
7144 };
7145
7146 GLuint _uniform_scene_scoretext_uMdl;
7147 GLuint _uniform_scene_scoretext_uPv;
7148 GLuint _uniform_scene_scoretext_uPvmPrev;
7149 GLuint _uniform_scene_scoretext_uInfo;
7150 GLuint _uniform_scene_scoretext_uTexGarbage;
7151 GLuint _uniform_scene_scoretext_uTexMain;
7152 GLuint _uniform_scene_scoretext_uCamera;
7153 GLuint _uniform_scene_scoretext_uPlane;
7154 GLuint _uniform_scene_scoretext_g_world_depth;
7155 GLuint _uniform_scene_scoretext_uLightsArray;
7156 GLuint _uniform_scene_scoretext_uLightsIndex;
7157 #include "shaders/scene_font.h"
7158 struct vg_shader _shader_scene_font = {
7159 .name = "scene_font",
7160 .vs =
7161 {
7162 .orig_file = "shaders/model_font.vs",
7163 .static_src =
7164 "layout (location=0) in vec3 a_co;\n"
7165 "layout (location=1) in vec3 a_norm;\n"
7166 "layout (location=2) in vec2 a_uv;\n"
7167 "\n"
7168 "#line 1 1 \n"
7169 "const float k_motion_lerp_amount = 0.01;\n"
7170 "\n"
7171 "#line 2 0 \n"
7172 "\n"
7173 "out vec3 aMotionVec0;\n"
7174 "out vec3 aMotionVec1;\n"
7175 "\n"
7176 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
7177 "{\n"
7178 " // This magically solves some artifacting errors!\n"
7179 " //\n"
7180 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
7181 "\n"
7182 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
7183 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
7184 "}\n"
7185 "\n"
7186 "#line 6 0 \n"
7187 "\n"
7188 "uniform mat4x3 uMdl;\n"
7189 "uniform mat4 uPv;\n"
7190 "uniform mat4 uPvmPrev;\n"
7191 "uniform vec4 uOffset;\n"
7192 "\n"
7193 "out vec2 aUv;\n"
7194 "out vec4 aNorm;\n"
7195 "out vec3 aCo;\n"
7196 "out vec3 aWorldCo;\n"
7197 "\n"
7198 "void main()\n"
7199 "{\n"
7200 " vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
7201 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
7202 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
7203 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
7204 "\n"
7205 " vs_motion_out( vproj0, vproj1 );\n"
7206 "\n"
7207 " gl_Position = vproj0;\n"
7208 "\n"
7209 " aUv = a_uv;\n"
7210 " aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
7211 " aCo = co;\n"
7212 " aWorldCo = world_pos0;\n"
7213 "}\n"
7214 ""},
7215 .fs =
7216 {
7217 .orig_file = "shaders/scene_font.fs",
7218 .static_src =
7219 "uniform sampler2D uTexGarbage; // unused\n"
7220 "uniform sampler2D uTexMain; // unused\n"
7221 "uniform vec3 uCamera;\n"
7222 "uniform float uTime;\n"
7223 "uniform float uOpacity;\n"
7224 "uniform float uColourize;\n"
7225 "\n"
7226 "#line 1 1 \n"
7227 "// :D\n"
7228 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
7229 "\n"
7230 "#line 9 0 \n"
7231 "#line 1 2 \n"
7232 "// :D\n"
7233 "\n"
7234 "in vec2 aUv;\n"
7235 "in vec4 aNorm;\n"
7236 "in vec3 aCo;\n"
7237 "in vec3 aWorldCo;\n"
7238 "\n"
7239 "#line 1 1 \n"
7240 "layout (location = 0) out vec4 oColour;\n"
7241 "\n"
7242 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
7243 "layout (std140) uniform ub_world_lighting\n"
7244 "{\n"
7245 " vec4 g_cube_min;\n"
7246 " vec4 g_cube_inv_range;\n"
7247 "\n"
7248 " vec4 g_water_plane;\n"
7249 " vec4 g_depth_bounds;\n"
7250 "\n"
7251 " vec4 g_daysky_colour;\n"
7252 " vec4 g_nightsky_colour;\n"
7253 " vec4 g_sunset_colour;\n"
7254 " vec4 g_ambient_colour;\n"
7255 " vec4 g_sunset_ambient;\n"
7256 " vec4 g_sun_colour;\n"
7257 " vec4 g_sun_dir;\n"
7258 " vec4 g_board_0;\n"
7259 " vec4 g_board_1;\n"
7260 "\n"
7261 " float g_water_fog;\n"
7262 " float g_time;\n"
7263 " float g_realtime;\n"
7264 " float g_shadow_length;\n"
7265 " float g_shadow_spread;\n"
7266 "\n"
7267 " float g_time_of_day;\n"
7268 " float g_day_phase;\n"
7269 " float g_sunset_phase;\n"
7270 "\n"
7271 " int g_light_preview;\n"
7272 " int g_shadow_samples;\n"
7273 "\n"
7274 " int g_debug_indices;\n"
7275 " int g_debug_complexity;\n"
7276 "};\n"
7277 "\n"
7278 "uniform sampler2D g_world_depth;\n"
7279 "uniform samplerBuffer uLightsArray;\n"
7280 "uniform usampler3D uLightsIndex;\n"
7281 "\n"
7282 "#line 1 1 \n"
7283 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
7284 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
7285 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
7286 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
7287 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
7288 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
7289 "\n"
7290 "const float SUN_ANGLE = 0.0001;\n"
7291 "const float PI = 3.14159265358979323846264;\n"
7292 "\n"
7293 "//struct world_info\n"
7294 "//{\n"
7295 "// float time,\n"
7296 "// time_of_day,\n"
7297 "// day_phase,\n"
7298 "// sunset_phase;\n"
7299 "// \n"
7300 "// vec3 sun_dir;\n"
7301 "//};\n"
7302 "\n"
7303 "vec3 rand33(vec3 p3)\n"
7304 "{\n"
7305 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
7306 " p3 += dot(p3, p3.yxz+33.33);\n"
7307 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
7308 "}\n"
7309 "\n"
7310 "float stars( vec3 rd, float rr, float size ){\n"
7311 " vec3 co = rd * rr;\n"
7312 "\n"
7313 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
7314 "\n"
7315 " float spaces = 1.0 / rr;\n"
7316 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
7317 " a -= mod(a, spaces) - spaces * 0.5;\n"
7318 "\n"
7319 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
7320 " \n"
7321 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
7322 " plane = plane - mod(plane, PI / count);\n"
7323 "\n"
7324 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
7325 "\n"
7326 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
7327 " float ydist = sqrt(rr * rr - level * level);\n"
7328 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
7329 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
7330 " float star = smoothstep(size, 0.0, distance(center, co));\n"
7331 " return star;\n"
7332 "}\n"
7333 "\n"
7334 "float luminance( vec3 v )\n"
7335 "{\n"
7336 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
7337 "}\n"
7338 "\n"
7339 "vec3 clearskies_ambient( vec3 dir )\n"
7340 "{\n"
7341 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
7342 " float sky_gradient = dir.y;\n"
7343 " \n"
7344 " /* Blend phase colours */\n"
7345 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
7346 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
7347 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
7348 " \n"
7349 " /* Add gradient */\n"
7350 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
7351 " \n"
7352 " return ambient;\n"
7353 "}\n"
7354 "\n"
7355 "vec3 clearskies_sky( vec3 ray_dir )\n"
7356 "{\n"
7357 " ray_dir.y = abs( ray_dir.y );\n"
7358 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
7359 " \n"
7360 " /* Sun */\n"
7361 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
7362 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
7363 " float sun_shape = pow( sun_size, 2000.0 );\n"
7364 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7365 " \n"
7366 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7367 " sun_colour *= sun_shape;\n"
7368 "\n"
7369 " \n"
7370 " float star = 0.0;\n"
7371 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
7372 "\n"
7373 " if( star_blend > 0.001 ){\n"
7374 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
7375 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
7376 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
7377 " }\n"
7378 " }\n"
7379 " \n"
7380 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
7381 " return composite;\n"
7382 "}\n"
7383 "\n"
7384 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
7385 "{\n"
7386 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
7387 "\n"
7388 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
7389 " g_sunset_phase );\n"
7390 "\n"
7391 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
7392 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
7393 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
7394 " ) * g_sun_colour.rgb * g_day_phase;\n"
7395 "\n"
7396 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
7397 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
7398 " g_sunset_phase );\n"
7399 "\n"
7400 " return ambient + (light_sun + sky_reflection) * shadow;\n"
7401 "}\n"
7402 "\n"
7403 "#line 44 0 \n"
7404 "\n"
7405 "float world_depth_sample( vec3 pos )\n"
7406 "{\n"
7407 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
7408 " return texture( g_world_depth, depth_coord ).r;\n"
7409 "}\n"
7410 "\n"
7411 "float world_water_depth( vec3 pos )\n"
7412 "{\n"
7413 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
7414 " return world_depth_sample( pos ) - ref_depth;\n"
7415 "}\n"
7416 "\n"
7417 "float shadow_sample( vec3 co ){\n"
7418 " float height_sample = world_depth_sample( co );\n"
7419 "\n"
7420 " float fdelta = height_sample - co.y;\n"
7421 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
7422 "}\n"
7423 "\n"
7424 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
7425 " if( g_shadow_samples == 0 ){\n"
7426 " return 1.0;\n"
7427 " }\n"
7428 "\n"
7429 " float fspread = g_shadow_spread;\n"
7430 " float flength = g_shadow_length;\n"
7431 "\n"
7432 " float famt = 0.0;\n"
7433 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
7434 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
7435 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
7436 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
7437 "\n"
7438 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
7439 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
7440 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
7441 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
7442 "\n"
7443 " return 1.0 - famt;\n"
7444 "}\n"
7445 "\n"
7446 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
7447 "{\n"
7448 " vec3 specdir = reflect( -dir, wnormal );\n"
7449 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
7450 "}\n"
7451 "\n"
7452 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
7453 " float dist = pow(fdist*0.0010,0.78);\n"
7454 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
7455 "}\n"
7456 "\n"
7457 "vec3 scene_calculate_light( int light_index, \n"
7458 " vec3 halfview, vec3 co, vec3 normal )\n"
7459 "{\n"
7460 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
7461 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
7462 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
7463 "\n"
7464 " vec3 light_delta = light_co.xyz-co;\n"
7465 " float dist2 = dot(light_delta,light_delta);\n"
7466 "\n"
7467 " light_delta = normalize( light_delta );\n"
7468 "\n"
7469 " float quadratic = dist2*100.0;\n"
7470 " float attenuation = 1.0/( 1.0 + quadratic );\n"
7471 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
7472 "\n"
7473 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
7474 "\n"
7475 " if( light_dir.w < 0.999999 ){\n"
7476 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
7477 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
7478 " }\n"
7479 "\n"
7480 " return light_colour.rgb * attenuation * falloff \n"
7481 " * step( g_day_phase, light_colour.w );\n"
7482 "}\n"
7483 "\n"
7484 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
7485 " vec3 halfview, vec3 co, vec3 normal )\n"
7486 "{\n"
7487 " uint light_count = packed_index & 0x3u;\n"
7488 "\n"
7489 " vec3 l = vec3(0.0);\n"
7490 "\n"
7491 " if( light_count >= 1u ){\n"
7492 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
7493 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
7494 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
7495 "\n"
7496 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
7497 "\n"
7498 " if( light_count >= 2u ){\n"
7499 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
7500 "\n"
7501 " if( light_count >= 3u ){\n"
7502 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
7503 " }\n"
7504 " }\n"
7505 " }\n"
7506 "\n"
7507 " return l;\n"
7508 "}\n"
7509 "\n"
7510 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
7511 " float light_mask )\n"
7512 "{\n"
7513 " if( g_light_preview == 1 )\n"
7514 " diffuse = vec3(0.75);\n"
7515 "\n"
7516 " // Lighting\n"
7517 " vec3 halfview = uCamera - co;\n"
7518 " float fdist = length(halfview);\n"
7519 " halfview /= fdist;\n"
7520 "\n"
7521 " float world_shadow = newlight_compute_sun_shadow( \n"
7522 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
7523 "\n"
7524 " vec3 total_light = clearskies_lighting( \n"
7525 " normal, min( light_mask, world_shadow ), halfview );\n"
7526 "\n"
7527 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
7528 " cube_coord = floor( cube_coord );\n"
7529 "\n"
7530 " if( g_debug_indices == 1 )\n"
7531 " {\n"
7532 " return rand33(cube_coord);\n"
7533 " }\n"
7534 "\n"
7535 " if( g_debug_complexity == 1 )\n"
7536 " {\n"
7537 " ivec3 coord = ivec3( cube_coord );\n"
7538 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7539 "\n"
7540 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
7541 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
7542 " }\n"
7543 "\n"
7544 " // FIXME: this coord should absolutely must be clamped!\n"
7545 " \n"
7546 " ivec3 coord = ivec3( cube_coord );\n"
7547 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
7548 "\n"
7549 " total_light += \n"
7550 " scene_calculate_packed_light_patch( index_sample.x,\n"
7551 " halfview, co, normal ) \n"
7552 " * light_mask;\n"
7553 " total_light += \n"
7554 " scene_calculate_packed_light_patch( index_sample.y,\n"
7555 " halfview, co, normal )\n"
7556 " * light_mask;\n"
7557 "\n"
7558 " // Take a section of the sky function to give us a matching fog colour\n"
7559 "\n"
7560 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
7561 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
7562 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
7563 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7564 " \n"
7565 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7566 " sun_colour *= sun_shape;\n"
7567 "\n"
7568 " fog_colour += sun_colour;\n"
7569 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
7570 "}\n"
7571 "\n"
7572 "#line 9 0 \n"
7573 "\n"
7574 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
7575 "{\n"
7576 " vec3 pa = p - a;\n"
7577 " vec3 ba = b - a;\n"
7578 "\n"
7579 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
7580 " return length( pa - ba*h );\n"
7581 "}\n"
7582 "\n"
7583 "float compute_board_shadow()\n"
7584 "{\n"
7585 " // player shadow\n"
7586 " float dist_to_player = max( 0.0, sdLine( aWorldCo, g_board_0.xyz,\n"
7587 " g_board_1.xyz )-0.1 );\n"
7588 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
7589 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
7590 "\n"
7591 " return 1.0 - player_shadow*0.8;\n"
7592 "}\n"
7593 "\n"
7594 "vec3 scene_compute_lighting( vec3 diffuse, vec3 normal, vec3 co )\n"
7595 "{\n"
7596 " return world_compute_lighting( diffuse, normal, co, compute_board_shadow() );\n"
7597 "}\n"
7598 "\n"
7599 "#line 10 0 \n"
7600 "#line 1 3 \n"
7601 "const float k_motion_lerp_amount = 0.01;\n"
7602 "\n"
7603 "#line 2 0 \n"
7604 "\n"
7605 "layout (location = 1) out vec2 oMotionVec;\n"
7606 "\n"
7607 "in vec3 aMotionVec0;\n"
7608 "in vec3 aMotionVec1;\n"
7609 "\n"
7610 "void compute_motion_vectors()\n"
7611 "{\n"
7612 " // Write motion vectors\n"
7613 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
7614 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
7615 "\n"
7616 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
7617 "}\n"
7618 "\n"
7619 "#line 11 0 \n"
7620 "\n"
7621 "vec3 pal( float t ){\n"
7622 " vec3 a = vec3(0.30,0.3,0.3);\n"
7623 " vec3 b = vec3(0.8);\n"
7624 " vec3 c = vec3(0.28,0.3,0.4);\n"
7625 " vec3 d = vec3(0.00,0.1,0.1);\n"
7626 " return a + b*cos( 6.28318*(c*t+d) );\n"
7627 "}\n"
7628 "\n"
7629 "void main(){\n"
7630 " compute_motion_vectors();\n"
7631 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
7632 " vec3 qnorm = aNorm.xyz;\n"
7633 "\n"
7634 " //vec4 vsamplemain = texture( uTexMain, aUv );\n"
7635 " //vfrag = vsamplemain.rgb;\n"
7636 "\n"
7637 " vec4 spread0 = uTime*0.0002*vec4( 17.3,-19.6, 23.2,-47.7 );\n"
7638 " vec4 spread1 = uTime*0.0002*vec4( -13.3, 12.6,-28.2, 14.7 );\n"
7639 "\n"
7640 " vec2 p = aCo.xy + vec2(0.3);\n"
7641 " float a = atan( p.y/p.x );\n"
7642 " vec4 v0 = step( vec4(0.5), fract(vec4(a) + spread0) );\n"
7643 " vec4 v1 = step( vec4(0.5), fract(vec4(a) + spread1) );\n"
7644 "\n"
7645 " float d = ( v0.x+v0.y+v0.z+v0.w +\n"
7646 " v1.x+v1.y+v1.z+v1.w ) * 0.125;\n"
7647 " \n"
7648 " float dither = fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0);\n"
7649 " float x = d*0.8+length(p)*0.3;\n"
7650 " x = (floor(x*8.0) + step(dither, fract(x * 8.0))) / 8.0;\n"
7651 "\n"
7652 " if( x + (uOpacity*2.0-1.0) < 0.5 ) \n"
7653 " discard;\n"
7654 "\n"
7655 " vfrag = mix( vec3(x), pal( x ), uColourize );\n"
7656 "\n"
7657 " if( g_light_preview == 1 ){\n"
7658 " vfrag = vec3(0.5);\n"
7659 " }\n"
7660 "\n"
7661 " vfrag = scene_compute_lighting( vfrag, qnorm, aWorldCo );\n"
7662 " oColour = vec4( vfrag, 1.0 );\n"
7663 "}\n"
7664 ""},
7665 };
7666
7667 GLuint _uniform_scene_font_uMdl;
7668 GLuint _uniform_scene_font_uPv;
7669 GLuint _uniform_scene_font_uPvmPrev;
7670 GLuint _uniform_scene_font_uOffset;
7671 GLuint _uniform_scene_font_uTexGarbage;
7672 GLuint _uniform_scene_font_uTexMain;
7673 GLuint _uniform_scene_font_uCamera;
7674 GLuint _uniform_scene_font_uTime;
7675 GLuint _uniform_scene_font_uOpacity;
7676 GLuint _uniform_scene_font_uColourize;
7677 GLuint _uniform_scene_font_g_world_depth;
7678 GLuint _uniform_scene_font_uLightsArray;
7679 GLuint _uniform_scene_font_uLightsIndex;
7680 #include "shaders/model_sky.h"
7681 struct vg_shader _shader_model_sky = {
7682 .name = "model_sky",
7683 .vs =
7684 {
7685 .orig_file = "shaders/model.vs",
7686 .static_src =
7687 "layout (location=0) in vec3 a_co;\n"
7688 "layout (location=1) in vec3 a_norm;\n"
7689 "layout (location=2) in vec2 a_uv;\n"
7690 "layout (location=3) in vec4 a_colour;\n"
7691 "layout (location=4) in vec4 a_weights;\n"
7692 "layout (location=5) in ivec4 a_groups;\n"
7693 "\n"
7694 "#line 1 1 \n"
7695 "const float k_motion_lerp_amount = 0.01;\n"
7696 "\n"
7697 "#line 2 0 \n"
7698 "\n"
7699 "out vec3 aMotionVec0;\n"
7700 "out vec3 aMotionVec1;\n"
7701 "\n"
7702 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
7703 "{\n"
7704 " // This magically solves some artifacting errors!\n"
7705 " //\n"
7706 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
7707 "\n"
7708 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
7709 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
7710 "}\n"
7711 "\n"
7712 "#line 9 0 \n"
7713 "\n"
7714 "uniform mat4x3 uMdl;\n"
7715 "uniform mat4 uPv;\n"
7716 "uniform mat4 uPvmPrev;\n"
7717 "\n"
7718 "out vec4 aColour;\n"
7719 "out vec2 aUv;\n"
7720 "out vec3 aNorm;\n"
7721 "out vec3 aCo;\n"
7722 "out vec3 aWorldCo;\n"
7723 "\n"
7724 "void main()\n"
7725 "{\n"
7726 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
7727 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
7728 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
7729 "\n"
7730 " vs_motion_out( vproj0, vproj1 );\n"
7731 "\n"
7732 " gl_Position = vproj0;\n"
7733 " aWorldCo = world_pos0;\n"
7734 " aColour = a_colour;\n"
7735 " aUv = a_uv;\n"
7736 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
7737 " aCo = a_co;\n"
7738 "}\n"
7739 ""},
7740 .fs =
7741 {
7742 .orig_file = "shaders/model_sky.fs",
7743 .static_src =
7744 "uniform sampler2D uTexGarbage;\n"
7745 "\n"
7746 "in vec4 aColour;\n"
7747 "in vec2 aUv;\n"
7748 "in vec3 aNorm;\n"
7749 "in vec3 aCo;\n"
7750 "in vec3 aWorldCo;\n"
7751 "\n"
7752 "// Spooky!\n"
7753 "const vec3 uCamera = vec3(0.0);\n"
7754 "\n"
7755 "#line 1 1 \n"
7756 "// :D\n"
7757 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
7758 "\n"
7759 "#line 13 0 \n"
7760 "#line 1 2 \n"
7761 "layout (location = 0) out vec4 oColour;\n"
7762 "\n"
7763 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
7764 "layout (std140) uniform ub_world_lighting\n"
7765 "{\n"
7766 " vec4 g_cube_min;\n"
7767 " vec4 g_cube_inv_range;\n"
7768 "\n"
7769 " vec4 g_water_plane;\n"
7770 " vec4 g_depth_bounds;\n"
7771 "\n"
7772 " vec4 g_daysky_colour;\n"
7773 " vec4 g_nightsky_colour;\n"
7774 " vec4 g_sunset_colour;\n"
7775 " vec4 g_ambient_colour;\n"
7776 " vec4 g_sunset_ambient;\n"
7777 " vec4 g_sun_colour;\n"
7778 " vec4 g_sun_dir;\n"
7779 " vec4 g_board_0;\n"
7780 " vec4 g_board_1;\n"
7781 "\n"
7782 " float g_water_fog;\n"
7783 " float g_time;\n"
7784 " float g_realtime;\n"
7785 " float g_shadow_length;\n"
7786 " float g_shadow_spread;\n"
7787 "\n"
7788 " float g_time_of_day;\n"
7789 " float g_day_phase;\n"
7790 " float g_sunset_phase;\n"
7791 "\n"
7792 " int g_light_preview;\n"
7793 " int g_shadow_samples;\n"
7794 "\n"
7795 " int g_debug_indices;\n"
7796 " int g_debug_complexity;\n"
7797 "};\n"
7798 "\n"
7799 "uniform sampler2D g_world_depth;\n"
7800 "uniform samplerBuffer uLightsArray;\n"
7801 "uniform usampler3D uLightsIndex;\n"
7802 "\n"
7803 "#line 1 1 \n"
7804 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
7805 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
7806 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
7807 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
7808 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
7809 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
7810 "\n"
7811 "const float SUN_ANGLE = 0.0001;\n"
7812 "const float PI = 3.14159265358979323846264;\n"
7813 "\n"
7814 "//struct world_info\n"
7815 "//{\n"
7816 "// float time,\n"
7817 "// time_of_day,\n"
7818 "// day_phase,\n"
7819 "// sunset_phase;\n"
7820 "// \n"
7821 "// vec3 sun_dir;\n"
7822 "//};\n"
7823 "\n"
7824 "vec3 rand33(vec3 p3)\n"
7825 "{\n"
7826 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
7827 " p3 += dot(p3, p3.yxz+33.33);\n"
7828 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
7829 "}\n"
7830 "\n"
7831 "float stars( vec3 rd, float rr, float size ){\n"
7832 " vec3 co = rd * rr;\n"
7833 "\n"
7834 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
7835 "\n"
7836 " float spaces = 1.0 / rr;\n"
7837 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
7838 " a -= mod(a, spaces) - spaces * 0.5;\n"
7839 "\n"
7840 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
7841 " \n"
7842 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
7843 " plane = plane - mod(plane, PI / count);\n"
7844 "\n"
7845 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
7846 "\n"
7847 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
7848 " float ydist = sqrt(rr * rr - level * level);\n"
7849 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
7850 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
7851 " float star = smoothstep(size, 0.0, distance(center, co));\n"
7852 " return star;\n"
7853 "}\n"
7854 "\n"
7855 "float luminance( vec3 v )\n"
7856 "{\n"
7857 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
7858 "}\n"
7859 "\n"
7860 "vec3 clearskies_ambient( vec3 dir )\n"
7861 "{\n"
7862 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
7863 " float sky_gradient = dir.y;\n"
7864 " \n"
7865 " /* Blend phase colours */\n"
7866 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
7867 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
7868 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
7869 " \n"
7870 " /* Add gradient */\n"
7871 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
7872 " \n"
7873 " return ambient;\n"
7874 "}\n"
7875 "\n"
7876 "vec3 clearskies_sky( vec3 ray_dir )\n"
7877 "{\n"
7878 " ray_dir.y = abs( ray_dir.y );\n"
7879 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
7880 " \n"
7881 " /* Sun */\n"
7882 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
7883 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
7884 " float sun_shape = pow( sun_size, 2000.0 );\n"
7885 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
7886 " \n"
7887 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
7888 " sun_colour *= sun_shape;\n"
7889 "\n"
7890 " \n"
7891 " float star = 0.0;\n"
7892 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
7893 "\n"
7894 " if( star_blend > 0.001 ){\n"
7895 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
7896 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
7897 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
7898 " }\n"
7899 " }\n"
7900 " \n"
7901 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
7902 " return composite;\n"
7903 "}\n"
7904 "\n"
7905 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
7906 "{\n"
7907 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
7908 "\n"
7909 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
7910 " g_sunset_phase );\n"
7911 "\n"
7912 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
7913 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
7914 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
7915 " ) * g_sun_colour.rgb * g_day_phase;\n"
7916 "\n"
7917 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
7918 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
7919 " g_sunset_phase );\n"
7920 "\n"
7921 " return ambient + (light_sun + sky_reflection) * shadow;\n"
7922 "}\n"
7923 "\n"
7924 "#line 44 0 \n"
7925 "\n"
7926 "float world_depth_sample( vec3 pos )\n"
7927 "{\n"
7928 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
7929 " return texture( g_world_depth, depth_coord ).r;\n"
7930 "}\n"
7931 "\n"
7932 "float world_water_depth( vec3 pos )\n"
7933 "{\n"
7934 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
7935 " return world_depth_sample( pos ) - ref_depth;\n"
7936 "}\n"
7937 "\n"
7938 "float shadow_sample( vec3 co ){\n"
7939 " float height_sample = world_depth_sample( co );\n"
7940 "\n"
7941 " float fdelta = height_sample - co.y;\n"
7942 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
7943 "}\n"
7944 "\n"
7945 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
7946 " if( g_shadow_samples == 0 ){\n"
7947 " return 1.0;\n"
7948 " }\n"
7949 "\n"
7950 " float fspread = g_shadow_spread;\n"
7951 " float flength = g_shadow_length;\n"
7952 "\n"
7953 " float famt = 0.0;\n"
7954 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
7955 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
7956 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
7957 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
7958 "\n"
7959 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
7960 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
7961 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
7962 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
7963 "\n"
7964 " return 1.0 - famt;\n"
7965 "}\n"
7966 "\n"
7967 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
7968 "{\n"
7969 " vec3 specdir = reflect( -dir, wnormal );\n"
7970 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
7971 "}\n"
7972 "\n"
7973 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
7974 " float dist = pow(fdist*0.0010,0.78);\n"
7975 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
7976 "}\n"
7977 "\n"
7978 "vec3 scene_calculate_light( int light_index, \n"
7979 " vec3 halfview, vec3 co, vec3 normal )\n"
7980 "{\n"
7981 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
7982 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
7983 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
7984 "\n"
7985 " vec3 light_delta = light_co.xyz-co;\n"
7986 " float dist2 = dot(light_delta,light_delta);\n"
7987 "\n"
7988 " light_delta = normalize( light_delta );\n"
7989 "\n"
7990 " float quadratic = dist2*100.0;\n"
7991 " float attenuation = 1.0/( 1.0 + quadratic );\n"
7992 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
7993 "\n"
7994 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
7995 "\n"
7996 " if( light_dir.w < 0.999999 ){\n"
7997 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
7998 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
7999 " }\n"
8000 "\n"
8001 " return light_colour.rgb * attenuation * falloff \n"
8002 " * step( g_day_phase, light_colour.w );\n"
8003 "}\n"
8004 "\n"
8005 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
8006 " vec3 halfview, vec3 co, vec3 normal )\n"
8007 "{\n"
8008 " uint light_count = packed_index & 0x3u;\n"
8009 "\n"
8010 " vec3 l = vec3(0.0);\n"
8011 "\n"
8012 " if( light_count >= 1u ){\n"
8013 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
8014 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
8015 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
8016 "\n"
8017 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
8018 "\n"
8019 " if( light_count >= 2u ){\n"
8020 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
8021 "\n"
8022 " if( light_count >= 3u ){\n"
8023 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
8024 " }\n"
8025 " }\n"
8026 " }\n"
8027 "\n"
8028 " return l;\n"
8029 "}\n"
8030 "\n"
8031 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
8032 " float light_mask )\n"
8033 "{\n"
8034 " if( g_light_preview == 1 )\n"
8035 " diffuse = vec3(0.75);\n"
8036 "\n"
8037 " // Lighting\n"
8038 " vec3 halfview = uCamera - co;\n"
8039 " float fdist = length(halfview);\n"
8040 " halfview /= fdist;\n"
8041 "\n"
8042 " float world_shadow = newlight_compute_sun_shadow( \n"
8043 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
8044 "\n"
8045 " vec3 total_light = clearskies_lighting( \n"
8046 " normal, min( light_mask, world_shadow ), halfview );\n"
8047 "\n"
8048 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
8049 " cube_coord = floor( cube_coord );\n"
8050 "\n"
8051 " if( g_debug_indices == 1 )\n"
8052 " {\n"
8053 " return rand33(cube_coord);\n"
8054 " }\n"
8055 "\n"
8056 " if( g_debug_complexity == 1 )\n"
8057 " {\n"
8058 " ivec3 coord = ivec3( cube_coord );\n"
8059 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8060 "\n"
8061 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
8062 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
8063 " }\n"
8064 "\n"
8065 " // FIXME: this coord should absolutely must be clamped!\n"
8066 " \n"
8067 " ivec3 coord = ivec3( cube_coord );\n"
8068 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8069 "\n"
8070 " total_light += \n"
8071 " scene_calculate_packed_light_patch( index_sample.x,\n"
8072 " halfview, co, normal ) \n"
8073 " * light_mask;\n"
8074 " total_light += \n"
8075 " scene_calculate_packed_light_patch( index_sample.y,\n"
8076 " halfview, co, normal )\n"
8077 " * light_mask;\n"
8078 "\n"
8079 " // Take a section of the sky function to give us a matching fog colour\n"
8080 "\n"
8081 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
8082 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
8083 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
8084 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8085 " \n"
8086 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8087 " sun_colour *= sun_shape;\n"
8088 "\n"
8089 " fog_colour += sun_colour;\n"
8090 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
8091 "}\n"
8092 "\n"
8093 "#line 14 0 \n"
8094 "#line 1 3 \n"
8095 "const float k_motion_lerp_amount = 0.01;\n"
8096 "\n"
8097 "#line 2 0 \n"
8098 "\n"
8099 "layout (location = 1) out vec2 oMotionVec;\n"
8100 "\n"
8101 "in vec3 aMotionVec0;\n"
8102 "in vec3 aMotionVec1;\n"
8103 "\n"
8104 "void compute_motion_vectors()\n"
8105 "{\n"
8106 " // Write motion vectors\n"
8107 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
8108 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
8109 "\n"
8110 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
8111 "}\n"
8112 "\n"
8113 "#line 15 0 \n"
8114 "\n"
8115 "void main()\n"
8116 "{\n"
8117 " compute_motion_vectors();\n"
8118 "\n"
8119 " vec3 rd = normalize(aNorm);\n"
8120 "\n"
8121 " float fmove = g_time * 5.0;\n"
8122 " vec2 cloudplane = (rd.xz / (rd.y*sign(rd.y))) * 0.025;\n"
8123 " vec4 clouds1 = texture( uTexGarbage, cloudplane + vec2(0.1,0.4)*fmove*2.0 );\n"
8124 " vec4 clouds2 = texture( uTexGarbage, cloudplane*2.0 + vec2(0.3,0.1)*fmove );\n"
8125 "\n"
8126 " float cloud_d = max(clouds1.b*clouds2.r -0.2 - clouds2.g*0.4,0.0);\n"
8127 " float cloud_e = pow(cloud_d,1.5)*pow(abs(rd.y),0.3)*2.0;\n"
8128 "\n"
8129 " oColour = vec4( clearskies_sky( -rd ) ,1.0);\n"
8130 "\n"
8131 " vec3 cloud_colour = mix( mix(g_nightsky_colour.rgb,vec3(1.0),g_day_phase), \n"
8132 " g_sunset_colour.rgb, g_sunset_phase );\n"
8133 "\n"
8134 " oColour.rgb = mix( oColour.rgb, cloud_colour, cloud_e );\n"
8135 "}\n"
8136 ""},
8137 };
8138
8139 GLuint _uniform_model_sky_uMdl;
8140 GLuint _uniform_model_sky_uPv;
8141 GLuint _uniform_model_sky_uPvmPrev;
8142 GLuint _uniform_model_sky_uTexGarbage;
8143 GLuint _uniform_model_sky_g_world_depth;
8144 GLuint _uniform_model_sky_uLightsArray;
8145 GLuint _uniform_model_sky_uLightsIndex;
8146 #include "shaders/model_sky_space.h"
8147 struct vg_shader _shader_model_sky_space = {
8148 .name = "model_sky_space",
8149 .vs =
8150 {
8151 .orig_file = "shaders/model.vs",
8152 .static_src =
8153 "layout (location=0) in vec3 a_co;\n"
8154 "layout (location=1) in vec3 a_norm;\n"
8155 "layout (location=2) in vec2 a_uv;\n"
8156 "layout (location=3) in vec4 a_colour;\n"
8157 "layout (location=4) in vec4 a_weights;\n"
8158 "layout (location=5) in ivec4 a_groups;\n"
8159 "\n"
8160 "#line 1 1 \n"
8161 "const float k_motion_lerp_amount = 0.01;\n"
8162 "\n"
8163 "#line 2 0 \n"
8164 "\n"
8165 "out vec3 aMotionVec0;\n"
8166 "out vec3 aMotionVec1;\n"
8167 "\n"
8168 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
8169 "{\n"
8170 " // This magically solves some artifacting errors!\n"
8171 " //\n"
8172 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
8173 "\n"
8174 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
8175 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
8176 "}\n"
8177 "\n"
8178 "#line 9 0 \n"
8179 "\n"
8180 "uniform mat4x3 uMdl;\n"
8181 "uniform mat4 uPv;\n"
8182 "uniform mat4 uPvmPrev;\n"
8183 "\n"
8184 "out vec4 aColour;\n"
8185 "out vec2 aUv;\n"
8186 "out vec3 aNorm;\n"
8187 "out vec3 aCo;\n"
8188 "out vec3 aWorldCo;\n"
8189 "\n"
8190 "void main()\n"
8191 "{\n"
8192 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
8193 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
8194 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
8195 "\n"
8196 " vs_motion_out( vproj0, vproj1 );\n"
8197 "\n"
8198 " gl_Position = vproj0;\n"
8199 " aWorldCo = world_pos0;\n"
8200 " aColour = a_colour;\n"
8201 " aUv = a_uv;\n"
8202 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
8203 " aCo = a_co;\n"
8204 "}\n"
8205 ""},
8206 .fs =
8207 {
8208 .orig_file = "shaders/model_sky_space.fs",
8209 .static_src =
8210 "uniform sampler2D uTexGarbage;\n"
8211 "\n"
8212 "in vec4 aColour;\n"
8213 "in vec2 aUv;\n"
8214 "in vec3 aNorm;\n"
8215 "in vec3 aCo;\n"
8216 "in vec3 aWorldCo;\n"
8217 "\n"
8218 "// Spooky!\n"
8219 "const vec3 uCamera = vec3(0.0);\n"
8220 "\n"
8221 "#line 1 1 \n"
8222 "// :D\n"
8223 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
8224 "\n"
8225 "#line 13 0 \n"
8226 "#line 1 2 \n"
8227 "layout (location = 0) out vec4 oColour;\n"
8228 "\n"
8229 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
8230 "layout (std140) uniform ub_world_lighting\n"
8231 "{\n"
8232 " vec4 g_cube_min;\n"
8233 " vec4 g_cube_inv_range;\n"
8234 "\n"
8235 " vec4 g_water_plane;\n"
8236 " vec4 g_depth_bounds;\n"
8237 "\n"
8238 " vec4 g_daysky_colour;\n"
8239 " vec4 g_nightsky_colour;\n"
8240 " vec4 g_sunset_colour;\n"
8241 " vec4 g_ambient_colour;\n"
8242 " vec4 g_sunset_ambient;\n"
8243 " vec4 g_sun_colour;\n"
8244 " vec4 g_sun_dir;\n"
8245 " vec4 g_board_0;\n"
8246 " vec4 g_board_1;\n"
8247 "\n"
8248 " float g_water_fog;\n"
8249 " float g_time;\n"
8250 " float g_realtime;\n"
8251 " float g_shadow_length;\n"
8252 " float g_shadow_spread;\n"
8253 "\n"
8254 " float g_time_of_day;\n"
8255 " float g_day_phase;\n"
8256 " float g_sunset_phase;\n"
8257 "\n"
8258 " int g_light_preview;\n"
8259 " int g_shadow_samples;\n"
8260 "\n"
8261 " int g_debug_indices;\n"
8262 " int g_debug_complexity;\n"
8263 "};\n"
8264 "\n"
8265 "uniform sampler2D g_world_depth;\n"
8266 "uniform samplerBuffer uLightsArray;\n"
8267 "uniform usampler3D uLightsIndex;\n"
8268 "\n"
8269 "#line 1 1 \n"
8270 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
8271 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
8272 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
8273 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
8274 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
8275 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
8276 "\n"
8277 "const float SUN_ANGLE = 0.0001;\n"
8278 "const float PI = 3.14159265358979323846264;\n"
8279 "\n"
8280 "//struct world_info\n"
8281 "//{\n"
8282 "// float time,\n"
8283 "// time_of_day,\n"
8284 "// day_phase,\n"
8285 "// sunset_phase;\n"
8286 "// \n"
8287 "// vec3 sun_dir;\n"
8288 "//};\n"
8289 "\n"
8290 "vec3 rand33(vec3 p3)\n"
8291 "{\n"
8292 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
8293 " p3 += dot(p3, p3.yxz+33.33);\n"
8294 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
8295 "}\n"
8296 "\n"
8297 "float stars( vec3 rd, float rr, float size ){\n"
8298 " vec3 co = rd * rr;\n"
8299 "\n"
8300 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
8301 "\n"
8302 " float spaces = 1.0 / rr;\n"
8303 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
8304 " a -= mod(a, spaces) - spaces * 0.5;\n"
8305 "\n"
8306 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
8307 " \n"
8308 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
8309 " plane = plane - mod(plane, PI / count);\n"
8310 "\n"
8311 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
8312 "\n"
8313 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
8314 " float ydist = sqrt(rr * rr - level * level);\n"
8315 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
8316 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
8317 " float star = smoothstep(size, 0.0, distance(center, co));\n"
8318 " return star;\n"
8319 "}\n"
8320 "\n"
8321 "float luminance( vec3 v )\n"
8322 "{\n"
8323 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
8324 "}\n"
8325 "\n"
8326 "vec3 clearskies_ambient( vec3 dir )\n"
8327 "{\n"
8328 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
8329 " float sky_gradient = dir.y;\n"
8330 " \n"
8331 " /* Blend phase colours */\n"
8332 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
8333 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
8334 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
8335 " \n"
8336 " /* Add gradient */\n"
8337 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
8338 " \n"
8339 " return ambient;\n"
8340 "}\n"
8341 "\n"
8342 "vec3 clearskies_sky( vec3 ray_dir )\n"
8343 "{\n"
8344 " ray_dir.y = abs( ray_dir.y );\n"
8345 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
8346 " \n"
8347 " /* Sun */\n"
8348 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
8349 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
8350 " float sun_shape = pow( sun_size, 2000.0 );\n"
8351 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8352 " \n"
8353 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8354 " sun_colour *= sun_shape;\n"
8355 "\n"
8356 " \n"
8357 " float star = 0.0;\n"
8358 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
8359 "\n"
8360 " if( star_blend > 0.001 ){\n"
8361 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
8362 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
8363 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
8364 " }\n"
8365 " }\n"
8366 " \n"
8367 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
8368 " return composite;\n"
8369 "}\n"
8370 "\n"
8371 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
8372 "{\n"
8373 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
8374 "\n"
8375 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
8376 " g_sunset_phase );\n"
8377 "\n"
8378 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
8379 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
8380 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
8381 " ) * g_sun_colour.rgb * g_day_phase;\n"
8382 "\n"
8383 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
8384 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
8385 " g_sunset_phase );\n"
8386 "\n"
8387 " return ambient + (light_sun + sky_reflection) * shadow;\n"
8388 "}\n"
8389 "\n"
8390 "#line 44 0 \n"
8391 "\n"
8392 "float world_depth_sample( vec3 pos )\n"
8393 "{\n"
8394 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
8395 " return texture( g_world_depth, depth_coord ).r;\n"
8396 "}\n"
8397 "\n"
8398 "float world_water_depth( vec3 pos )\n"
8399 "{\n"
8400 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
8401 " return world_depth_sample( pos ) - ref_depth;\n"
8402 "}\n"
8403 "\n"
8404 "float shadow_sample( vec3 co ){\n"
8405 " float height_sample = world_depth_sample( co );\n"
8406 "\n"
8407 " float fdelta = height_sample - co.y;\n"
8408 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
8409 "}\n"
8410 "\n"
8411 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
8412 " if( g_shadow_samples == 0 ){\n"
8413 " return 1.0;\n"
8414 " }\n"
8415 "\n"
8416 " float fspread = g_shadow_spread;\n"
8417 " float flength = g_shadow_length;\n"
8418 "\n"
8419 " float famt = 0.0;\n"
8420 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
8421 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
8422 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
8423 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
8424 "\n"
8425 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
8426 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
8427 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
8428 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
8429 "\n"
8430 " return 1.0 - famt;\n"
8431 "}\n"
8432 "\n"
8433 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
8434 "{\n"
8435 " vec3 specdir = reflect( -dir, wnormal );\n"
8436 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
8437 "}\n"
8438 "\n"
8439 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
8440 " float dist = pow(fdist*0.0010,0.78);\n"
8441 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
8442 "}\n"
8443 "\n"
8444 "vec3 scene_calculate_light( int light_index, \n"
8445 " vec3 halfview, vec3 co, vec3 normal )\n"
8446 "{\n"
8447 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
8448 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
8449 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
8450 "\n"
8451 " vec3 light_delta = light_co.xyz-co;\n"
8452 " float dist2 = dot(light_delta,light_delta);\n"
8453 "\n"
8454 " light_delta = normalize( light_delta );\n"
8455 "\n"
8456 " float quadratic = dist2*100.0;\n"
8457 " float attenuation = 1.0/( 1.0 + quadratic );\n"
8458 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
8459 "\n"
8460 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
8461 "\n"
8462 " if( light_dir.w < 0.999999 ){\n"
8463 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
8464 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
8465 " }\n"
8466 "\n"
8467 " return light_colour.rgb * attenuation * falloff \n"
8468 " * step( g_day_phase, light_colour.w );\n"
8469 "}\n"
8470 "\n"
8471 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
8472 " vec3 halfview, vec3 co, vec3 normal )\n"
8473 "{\n"
8474 " uint light_count = packed_index & 0x3u;\n"
8475 "\n"
8476 " vec3 l = vec3(0.0);\n"
8477 "\n"
8478 " if( light_count >= 1u ){\n"
8479 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
8480 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
8481 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
8482 "\n"
8483 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
8484 "\n"
8485 " if( light_count >= 2u ){\n"
8486 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
8487 "\n"
8488 " if( light_count >= 3u ){\n"
8489 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
8490 " }\n"
8491 " }\n"
8492 " }\n"
8493 "\n"
8494 " return l;\n"
8495 "}\n"
8496 "\n"
8497 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
8498 " float light_mask )\n"
8499 "{\n"
8500 " if( g_light_preview == 1 )\n"
8501 " diffuse = vec3(0.75);\n"
8502 "\n"
8503 " // Lighting\n"
8504 " vec3 halfview = uCamera - co;\n"
8505 " float fdist = length(halfview);\n"
8506 " halfview /= fdist;\n"
8507 "\n"
8508 " float world_shadow = newlight_compute_sun_shadow( \n"
8509 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
8510 "\n"
8511 " vec3 total_light = clearskies_lighting( \n"
8512 " normal, min( light_mask, world_shadow ), halfview );\n"
8513 "\n"
8514 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
8515 " cube_coord = floor( cube_coord );\n"
8516 "\n"
8517 " if( g_debug_indices == 1 )\n"
8518 " {\n"
8519 " return rand33(cube_coord);\n"
8520 " }\n"
8521 "\n"
8522 " if( g_debug_complexity == 1 )\n"
8523 " {\n"
8524 " ivec3 coord = ivec3( cube_coord );\n"
8525 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8526 "\n"
8527 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
8528 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
8529 " }\n"
8530 "\n"
8531 " // FIXME: this coord should absolutely must be clamped!\n"
8532 " \n"
8533 " ivec3 coord = ivec3( cube_coord );\n"
8534 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
8535 "\n"
8536 " total_light += \n"
8537 " scene_calculate_packed_light_patch( index_sample.x,\n"
8538 " halfview, co, normal ) \n"
8539 " * light_mask;\n"
8540 " total_light += \n"
8541 " scene_calculate_packed_light_patch( index_sample.y,\n"
8542 " halfview, co, normal )\n"
8543 " * light_mask;\n"
8544 "\n"
8545 " // Take a section of the sky function to give us a matching fog colour\n"
8546 "\n"
8547 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
8548 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
8549 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
8550 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8551 " \n"
8552 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8553 " sun_colour *= sun_shape;\n"
8554 "\n"
8555 " fog_colour += sun_colour;\n"
8556 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
8557 "}\n"
8558 "\n"
8559 "#line 14 0 \n"
8560 "#line 1 3 \n"
8561 "const float k_motion_lerp_amount = 0.01;\n"
8562 "\n"
8563 "#line 2 0 \n"
8564 "\n"
8565 "layout (location = 1) out vec2 oMotionVec;\n"
8566 "\n"
8567 "in vec3 aMotionVec0;\n"
8568 "in vec3 aMotionVec1;\n"
8569 "\n"
8570 "void compute_motion_vectors()\n"
8571 "{\n"
8572 " // Write motion vectors\n"
8573 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
8574 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
8575 "\n"
8576 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
8577 "}\n"
8578 "\n"
8579 "#line 15 0 \n"
8580 "\n"
8581 "float stars1( vec3 rd, float rr, float size ){\n"
8582 " vec3 co = rd * rr;\n"
8583 "\n"
8584 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
8585 "\n"
8586 " float spaces = 1.0 / rr;\n"
8587 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
8588 " a -= mod(a, spaces) - spaces * 0.5;\n"
8589 "\n"
8590 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
8591 " \n"
8592 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
8593 " plane = plane - mod(plane, PI / count);\n"
8594 "\n"
8595 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
8596 "\n"
8597 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
8598 " float ydist = sqrt(rr * rr - level * level);\n"
8599 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
8600 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
8601 " float star = smoothstep(size, 0.0, distance(center, co));\n"
8602 " return star;\n"
8603 "}\n"
8604 "\n"
8605 "void main(){\n"
8606 " compute_motion_vectors();\n"
8607 "\n"
8608 " vec3 rd = -normalize(aNorm);\n"
8609 "\n"
8610 " float star = 0.0;\n"
8611 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
8612 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
8613 " star += stars( rd, 1.94 * pow( 1.64, j ), m ) * (1.0 / pow(4.0, j));\n"
8614 " }\n"
8615 "\n"
8616 " oColour = vec4( vec3(star*20.0), 1.0);\n"
8617 "}\n"
8618 ""},
8619 };
8620
8621 GLuint _uniform_model_sky_space_uMdl;
8622 GLuint _uniform_model_sky_space_uPv;
8623 GLuint _uniform_model_sky_space_uPvmPrev;
8624 GLuint _uniform_model_sky_space_uTexGarbage;
8625 GLuint _uniform_model_sky_space_g_world_depth;
8626 GLuint _uniform_model_sky_space_uLightsArray;
8627 GLuint _uniform_model_sky_space_uLightsIndex;
8628 #include "shaders/model_menu.h"
8629 struct vg_shader _shader_model_menu = {
8630 .name = "model_menu",
8631 .vs =
8632 {
8633 .orig_file = "shaders/model.vs",
8634 .static_src =
8635 "layout (location=0) in vec3 a_co;\n"
8636 "layout (location=1) in vec3 a_norm;\n"
8637 "layout (location=2) in vec2 a_uv;\n"
8638 "layout (location=3) in vec4 a_colour;\n"
8639 "layout (location=4) in vec4 a_weights;\n"
8640 "layout (location=5) in ivec4 a_groups;\n"
8641 "\n"
8642 "#line 1 1 \n"
8643 "const float k_motion_lerp_amount = 0.01;\n"
8644 "\n"
8645 "#line 2 0 \n"
8646 "\n"
8647 "out vec3 aMotionVec0;\n"
8648 "out vec3 aMotionVec1;\n"
8649 "\n"
8650 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
8651 "{\n"
8652 " // This magically solves some artifacting errors!\n"
8653 " //\n"
8654 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
8655 "\n"
8656 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
8657 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
8658 "}\n"
8659 "\n"
8660 "#line 9 0 \n"
8661 "\n"
8662 "uniform mat4x3 uMdl;\n"
8663 "uniform mat4 uPv;\n"
8664 "uniform mat4 uPvmPrev;\n"
8665 "\n"
8666 "out vec4 aColour;\n"
8667 "out vec2 aUv;\n"
8668 "out vec3 aNorm;\n"
8669 "out vec3 aCo;\n"
8670 "out vec3 aWorldCo;\n"
8671 "\n"
8672 "void main()\n"
8673 "{\n"
8674 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
8675 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
8676 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
8677 "\n"
8678 " vs_motion_out( vproj0, vproj1 );\n"
8679 "\n"
8680 " gl_Position = vproj0;\n"
8681 " aWorldCo = world_pos0;\n"
8682 " aColour = a_colour;\n"
8683 " aUv = a_uv;\n"
8684 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
8685 " aCo = a_co;\n"
8686 "}\n"
8687 ""},
8688 .fs =
8689 {
8690 .orig_file = "shaders/model_menu.fs",
8691 .static_src =
8692 "out vec4 FragColor;\n"
8693 "\n"
8694 "uniform sampler2D uTexMain;\n"
8695 "uniform vec4 uColour;\n"
8696 "\n"
8697 "in vec4 aColour;\n"
8698 "in vec2 aUv;\n"
8699 "in vec3 aNorm;\n"
8700 "in vec3 aCo;\n"
8701 "\n"
8702 "void main()\n"
8703 "{\n"
8704 " vec4 diffuse = texture( uTexMain, aUv );\n"
8705 "\n"
8706 " if( diffuse.a < 0.5 )\n"
8707 " discard;\n"
8708 "\n"
8709 " FragColor = vec4( diffuse.rgb, 1.0 ) * uColour;\n"
8710 "}\n"
8711 ""},
8712 };
8713
8714 GLuint _uniform_model_menu_uMdl;
8715 GLuint _uniform_model_menu_uPv;
8716 GLuint _uniform_model_menu_uPvmPrev;
8717 GLuint _uniform_model_menu_uTexMain;
8718 GLuint _uniform_model_menu_uColour;
8719 #include "shaders/model_character_view.h"
8720 struct vg_shader _shader_model_character_view = {
8721 .name = "model_character_view",
8722 .vs =
8723 {
8724 .orig_file = "shaders/model_skinned.vs",
8725 .static_src =
8726 "layout (location=0) in vec3 a_co;\n"
8727 "layout (location=1) in vec3 a_norm;\n"
8728 "layout (location=2) in vec2 a_uv;\n"
8729 "layout (location=3) in vec4 a_colour;\n"
8730 "layout (location=4) in vec4 a_weights;\n"
8731 "layout (location=5) in ivec4 a_groups;\n"
8732 "\n"
8733 "#line 1 1 \n"
8734 "const float k_motion_lerp_amount = 0.01;\n"
8735 "\n"
8736 "#line 2 0 \n"
8737 "\n"
8738 "out vec3 aMotionVec0;\n"
8739 "out vec3 aMotionVec1;\n"
8740 "\n"
8741 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
8742 "{\n"
8743 " // This magically solves some artifacting errors!\n"
8744 " //\n"
8745 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
8746 "\n"
8747 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
8748 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
8749 "}\n"
8750 "\n"
8751 "#line 9 0 \n"
8752 "\n"
8753 "uniform mat4 uPv;\n"
8754 "uniform mat4x3 uTransforms[32];\n"
8755 "\n"
8756 "out vec4 aColour;\n"
8757 "out vec2 aUv;\n"
8758 "out vec3 aNorm;\n"
8759 "out vec3 aCo;\n"
8760 "out vec3 aWorldCo;\n"
8761 "\n"
8762 "void main()\n"
8763 "{\n"
8764 " vec4 co_local = vec4( a_co, 1.0 );\n"
8765 " vec3 co0 = uTransforms[ a_groups[0] ] * co_local;\n"
8766 " vec3 co1 = uTransforms[ a_groups[1] ] * co_local;\n"
8767 " vec3 co2 = uTransforms[ a_groups[2] ] * co_local;\n"
8768 " vec3 n0 = mat3(uTransforms[ a_groups[0] ]) * a_norm;\n"
8769 " vec3 n1 = mat3(uTransforms[ a_groups[1] ]) * a_norm;\n"
8770 " vec3 n2 = mat3(uTransforms[ a_groups[2] ]) * a_norm;\n"
8771 "\n"
8772 " vec3 world_pos = co0*a_weights[0] + co1*a_weights[1] + co2*a_weights[2];\n"
8773 " vec3 world_normal = n0*a_weights[0] + n1*a_weights[1] + n2*a_weights[2];\n"
8774 " \n"
8775 " gl_Position = uPv * vec4( world_pos, 1.0 );\n"
8776 " aColour = a_colour;\n"
8777 " aUv = a_uv;\n"
8778 " aNorm = world_normal;\n"
8779 " aCo = a_co;\n"
8780 " aWorldCo = world_pos;\n"
8781 "\n"
8782 " // TODO: motion vectors\n"
8783 " aMotionVec0 = vec3(1.0);\n"
8784 " aMotionVec1 = vec3(1.0);\n"
8785 "}\n"
8786 ""},
8787 .fs =
8788 {
8789 .orig_file = "shaders/model_character_view.fs",
8790 .static_src =
8791 "uniform sampler2D uTexMain;\n"
8792 "uniform vec3 uCamera;\n"
8793 "\n"
8794 "in vec4 aColour;\n"
8795 "in vec2 aUv;\n"
8796 "in vec3 aNorm;\n"
8797 "in vec3 aCo;\n"
8798 "in vec3 aWorldCo;\n"
8799 "\n"
8800 "#line 1 1 \n"
8801 "// :D\n"
8802 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
8803 "\n"
8804 "#line 11 0 \n"
8805 "#line 1 2 \n"
8806 "layout (location = 0) out vec4 oColour;\n"
8807 "\n"
8808 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
8809 "layout (std140) uniform ub_world_lighting\n"
8810 "{\n"
8811 " vec4 g_cube_min;\n"
8812 " vec4 g_cube_inv_range;\n"
8813 "\n"
8814 " vec4 g_water_plane;\n"
8815 " vec4 g_depth_bounds;\n"
8816 "\n"
8817 " vec4 g_daysky_colour;\n"
8818 " vec4 g_nightsky_colour;\n"
8819 " vec4 g_sunset_colour;\n"
8820 " vec4 g_ambient_colour;\n"
8821 " vec4 g_sunset_ambient;\n"
8822 " vec4 g_sun_colour;\n"
8823 " vec4 g_sun_dir;\n"
8824 " vec4 g_board_0;\n"
8825 " vec4 g_board_1;\n"
8826 "\n"
8827 " float g_water_fog;\n"
8828 " float g_time;\n"
8829 " float g_realtime;\n"
8830 " float g_shadow_length;\n"
8831 " float g_shadow_spread;\n"
8832 "\n"
8833 " float g_time_of_day;\n"
8834 " float g_day_phase;\n"
8835 " float g_sunset_phase;\n"
8836 "\n"
8837 " int g_light_preview;\n"
8838 " int g_shadow_samples;\n"
8839 "\n"
8840 " int g_debug_indices;\n"
8841 " int g_debug_complexity;\n"
8842 "};\n"
8843 "\n"
8844 "uniform sampler2D g_world_depth;\n"
8845 "uniform samplerBuffer uLightsArray;\n"
8846 "uniform usampler3D uLightsIndex;\n"
8847 "\n"
8848 "#line 1 1 \n"
8849 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
8850 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
8851 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
8852 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
8853 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
8854 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
8855 "\n"
8856 "const float SUN_ANGLE = 0.0001;\n"
8857 "const float PI = 3.14159265358979323846264;\n"
8858 "\n"
8859 "//struct world_info\n"
8860 "//{\n"
8861 "// float time,\n"
8862 "// time_of_day,\n"
8863 "// day_phase,\n"
8864 "// sunset_phase;\n"
8865 "// \n"
8866 "// vec3 sun_dir;\n"
8867 "//};\n"
8868 "\n"
8869 "vec3 rand33(vec3 p3)\n"
8870 "{\n"
8871 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
8872 " p3 += dot(p3, p3.yxz+33.33);\n"
8873 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
8874 "}\n"
8875 "\n"
8876 "float stars( vec3 rd, float rr, float size ){\n"
8877 " vec3 co = rd * rr;\n"
8878 "\n"
8879 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
8880 "\n"
8881 " float spaces = 1.0 / rr;\n"
8882 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
8883 " a -= mod(a, spaces) - spaces * 0.5;\n"
8884 "\n"
8885 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
8886 " \n"
8887 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
8888 " plane = plane - mod(plane, PI / count);\n"
8889 "\n"
8890 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
8891 "\n"
8892 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
8893 " float ydist = sqrt(rr * rr - level * level);\n"
8894 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
8895 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
8896 " float star = smoothstep(size, 0.0, distance(center, co));\n"
8897 " return star;\n"
8898 "}\n"
8899 "\n"
8900 "float luminance( vec3 v )\n"
8901 "{\n"
8902 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
8903 "}\n"
8904 "\n"
8905 "vec3 clearskies_ambient( vec3 dir )\n"
8906 "{\n"
8907 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
8908 " float sky_gradient = dir.y;\n"
8909 " \n"
8910 " /* Blend phase colours */\n"
8911 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
8912 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
8913 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
8914 " \n"
8915 " /* Add gradient */\n"
8916 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
8917 " \n"
8918 " return ambient;\n"
8919 "}\n"
8920 "\n"
8921 "vec3 clearskies_sky( vec3 ray_dir )\n"
8922 "{\n"
8923 " ray_dir.y = abs( ray_dir.y );\n"
8924 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
8925 " \n"
8926 " /* Sun */\n"
8927 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
8928 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
8929 " float sun_shape = pow( sun_size, 2000.0 );\n"
8930 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
8931 " \n"
8932 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
8933 " sun_colour *= sun_shape;\n"
8934 "\n"
8935 " \n"
8936 " float star = 0.0;\n"
8937 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
8938 "\n"
8939 " if( star_blend > 0.001 ){\n"
8940 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
8941 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
8942 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
8943 " }\n"
8944 " }\n"
8945 " \n"
8946 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
8947 " return composite;\n"
8948 "}\n"
8949 "\n"
8950 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
8951 "{\n"
8952 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
8953 "\n"
8954 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
8955 " g_sunset_phase );\n"
8956 "\n"
8957 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
8958 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
8959 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
8960 " ) * g_sun_colour.rgb * g_day_phase;\n"
8961 "\n"
8962 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
8963 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
8964 " g_sunset_phase );\n"
8965 "\n"
8966 " return ambient + (light_sun + sky_reflection) * shadow;\n"
8967 "}\n"
8968 "\n"
8969 "#line 44 0 \n"
8970 "\n"
8971 "float world_depth_sample( vec3 pos )\n"
8972 "{\n"
8973 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
8974 " return texture( g_world_depth, depth_coord ).r;\n"
8975 "}\n"
8976 "\n"
8977 "float world_water_depth( vec3 pos )\n"
8978 "{\n"
8979 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
8980 " return world_depth_sample( pos ) - ref_depth;\n"
8981 "}\n"
8982 "\n"
8983 "float shadow_sample( vec3 co ){\n"
8984 " float height_sample = world_depth_sample( co );\n"
8985 "\n"
8986 " float fdelta = height_sample - co.y;\n"
8987 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
8988 "}\n"
8989 "\n"
8990 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
8991 " if( g_shadow_samples == 0 ){\n"
8992 " return 1.0;\n"
8993 " }\n"
8994 "\n"
8995 " float fspread = g_shadow_spread;\n"
8996 " float flength = g_shadow_length;\n"
8997 "\n"
8998 " float famt = 0.0;\n"
8999 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
9000 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
9001 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
9002 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
9003 "\n"
9004 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
9005 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
9006 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
9007 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
9008 "\n"
9009 " return 1.0 - famt;\n"
9010 "}\n"
9011 "\n"
9012 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
9013 "{\n"
9014 " vec3 specdir = reflect( -dir, wnormal );\n"
9015 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
9016 "}\n"
9017 "\n"
9018 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
9019 " float dist = pow(fdist*0.0010,0.78);\n"
9020 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
9021 "}\n"
9022 "\n"
9023 "vec3 scene_calculate_light( int light_index, \n"
9024 " vec3 halfview, vec3 co, vec3 normal )\n"
9025 "{\n"
9026 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
9027 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
9028 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
9029 "\n"
9030 " vec3 light_delta = light_co.xyz-co;\n"
9031 " float dist2 = dot(light_delta,light_delta);\n"
9032 "\n"
9033 " light_delta = normalize( light_delta );\n"
9034 "\n"
9035 " float quadratic = dist2*100.0;\n"
9036 " float attenuation = 1.0/( 1.0 + quadratic );\n"
9037 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
9038 "\n"
9039 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
9040 "\n"
9041 " if( light_dir.w < 0.999999 ){\n"
9042 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
9043 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
9044 " }\n"
9045 "\n"
9046 " return light_colour.rgb * attenuation * falloff \n"
9047 " * step( g_day_phase, light_colour.w );\n"
9048 "}\n"
9049 "\n"
9050 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
9051 " vec3 halfview, vec3 co, vec3 normal )\n"
9052 "{\n"
9053 " uint light_count = packed_index & 0x3u;\n"
9054 "\n"
9055 " vec3 l = vec3(0.0);\n"
9056 "\n"
9057 " if( light_count >= 1u ){\n"
9058 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
9059 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
9060 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
9061 "\n"
9062 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
9063 "\n"
9064 " if( light_count >= 2u ){\n"
9065 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
9066 "\n"
9067 " if( light_count >= 3u ){\n"
9068 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
9069 " }\n"
9070 " }\n"
9071 " }\n"
9072 "\n"
9073 " return l;\n"
9074 "}\n"
9075 "\n"
9076 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9077 " float light_mask )\n"
9078 "{\n"
9079 " if( g_light_preview == 1 )\n"
9080 " diffuse = vec3(0.75);\n"
9081 "\n"
9082 " // Lighting\n"
9083 " vec3 halfview = uCamera - co;\n"
9084 " float fdist = length(halfview);\n"
9085 " halfview /= fdist;\n"
9086 "\n"
9087 " float world_shadow = newlight_compute_sun_shadow( \n"
9088 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9089 "\n"
9090 " vec3 total_light = clearskies_lighting( \n"
9091 " normal, min( light_mask, world_shadow ), halfview );\n"
9092 "\n"
9093 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9094 " cube_coord = floor( cube_coord );\n"
9095 "\n"
9096 " if( g_debug_indices == 1 )\n"
9097 " {\n"
9098 " return rand33(cube_coord);\n"
9099 " }\n"
9100 "\n"
9101 " if( g_debug_complexity == 1 )\n"
9102 " {\n"
9103 " ivec3 coord = ivec3( cube_coord );\n"
9104 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9105 "\n"
9106 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9107 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9108 " }\n"
9109 "\n"
9110 " // FIXME: this coord should absolutely must be clamped!\n"
9111 " \n"
9112 " ivec3 coord = ivec3( cube_coord );\n"
9113 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9114 "\n"
9115 " total_light += \n"
9116 " scene_calculate_packed_light_patch( index_sample.x,\n"
9117 " halfview, co, normal ) \n"
9118 " * light_mask;\n"
9119 " total_light += \n"
9120 " scene_calculate_packed_light_patch( index_sample.y,\n"
9121 " halfview, co, normal )\n"
9122 " * light_mask;\n"
9123 "\n"
9124 " // Take a section of the sky function to give us a matching fog colour\n"
9125 "\n"
9126 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9127 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9128 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9129 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9130 " \n"
9131 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9132 " sun_colour *= sun_shape;\n"
9133 "\n"
9134 " fog_colour += sun_colour;\n"
9135 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9136 "}\n"
9137 "\n"
9138 "#line 12 0 \n"
9139 "#line 1 3 \n"
9140 "const float k_motion_lerp_amount = 0.01;\n"
9141 "\n"
9142 "#line 2 0 \n"
9143 "\n"
9144 "layout (location = 1) out vec2 oMotionVec;\n"
9145 "\n"
9146 "in vec3 aMotionVec0;\n"
9147 "in vec3 aMotionVec1;\n"
9148 "\n"
9149 "void compute_motion_vectors()\n"
9150 "{\n"
9151 " // Write motion vectors\n"
9152 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
9153 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
9154 "\n"
9155 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
9156 "}\n"
9157 "\n"
9158 "#line 13 0 \n"
9159 "#line 1 4 \n"
9160 "uniform sampler2D uTexSceneDepth;\n"
9161 "uniform vec3 uInverseRatioDepth;\n"
9162 "uniform vec3 uInverseRatioMain;\n"
9163 "uniform int uDepthMode;\n"
9164 "uniform float uDitherCutoff;\n"
9165 "\n"
9166 "float linear_depth( float depth, float near, float far ) {\n"
9167 " float z = depth * 2.0 - 1.0;\n"
9168 " return (2.0 * near * far) / (far + near - z * (far - near)); \n"
9169 "}\n"
9170 "\n"
9171 "void depth_compare_dither()\n"
9172 "{\n"
9173 " if( uDepthMode == 1 )\n"
9174 " {\n"
9175 " vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
9176 " * uInverseRatioDepth.xy;\n"
9177 " float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
9178 " float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
9179 "\n"
9180 " back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
9181 " float diff = back_depth - front_depth;\n"
9182 "\n"
9183 " vec2 ssuv = gl_FragCoord.xy;\n"
9184 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9185 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
9186 "\n"
9187 " if( step(0.0,diff)+dither<0.3 )\n"
9188 " discard;\n"
9189 " }\n"
9190 "\n"
9191 " if( uDepthMode == 2 )\n"
9192 " {\n"
9193 " vec2 ssuv = gl_FragCoord.xy;\n"
9194 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9195 " float dither = fract( vDither.g / 71.0 );\n"
9196 " if( dither<uDitherCutoff ) discard;\n"
9197 " }\n"
9198 "}\n"
9199 "\n"
9200 "#line 14 0 \n"
9201 "\n"
9202 "vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
9203 "{\n"
9204 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
9205 "\n"
9206 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
9207 " g_sunset_phase );\n"
9208 "\n"
9209 "\n"
9210 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
9211 " vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
9212 " * g_sun_colour.rgb * g_day_phase;\n"
9213 "\n"
9214 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
9215 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
9216 " g_sunset_phase );\n"
9217 "\n"
9218 " return ambient + (light_sun + sky_reflection) * shadow;\n"
9219 "}\n"
9220 "\n"
9221 "vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9222 " float light_mask )\n"
9223 "{\n"
9224 " if( g_light_preview == 1 )\n"
9225 " diffuse = vec3(0.75);\n"
9226 "\n"
9227 " // Lighting\n"
9228 " vec3 halfview = uCamera - co;\n"
9229 " float fdist = length(halfview);\n"
9230 " halfview /= fdist;\n"
9231 "\n"
9232 " float world_shadow = newlight_compute_sun_shadow( \n"
9233 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9234 "\n"
9235 " vec3 total_light = character_clearskies_lighting( \n"
9236 " normal, min( light_mask, world_shadow ), halfview );\n"
9237 "\n"
9238 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9239 " cube_coord = floor( cube_coord );\n"
9240 "\n"
9241 " if( g_debug_indices == 1 )\n"
9242 " {\n"
9243 " return rand33(cube_coord);\n"
9244 " }\n"
9245 "\n"
9246 " if( g_debug_complexity == 1 )\n"
9247 " {\n"
9248 " ivec3 coord = ivec3( cube_coord );\n"
9249 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9250 "\n"
9251 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9252 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9253 " }\n"
9254 "\n"
9255 " // FIXME: this coord should absolutely must be clamped!\n"
9256 " \n"
9257 " ivec3 coord = ivec3( cube_coord );\n"
9258 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9259 "\n"
9260 " total_light += \n"
9261 " scene_calculate_packed_light_patch( index_sample.x,\n"
9262 " halfview, co, normal ) \n"
9263 " * light_mask;\n"
9264 " total_light += \n"
9265 " scene_calculate_packed_light_patch( index_sample.y,\n"
9266 " halfview, co, normal )\n"
9267 " * light_mask;\n"
9268 "\n"
9269 " // Take a section of the sky function to give us a matching fog colour\n"
9270 "\n"
9271 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9272 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9273 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9274 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9275 " \n"
9276 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9277 " sun_colour *= sun_shape;\n"
9278 "\n"
9279 " fog_colour += sun_colour;\n"
9280 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9281 "}\n"
9282 "\n"
9283 "void main(){\n"
9284 " depth_compare_dither();\n"
9285 " compute_motion_vectors();\n"
9286 "\n"
9287 " vec3 qnorm = aNorm;\n"
9288 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
9289 " vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
9290 "\n"
9291 " float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
9292 " float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
9293 "\n"
9294 " oColour = vec4( composite, opacity );\n"
9295 "}\n"
9296 ""},
9297 };
9298
9299 GLuint _uniform_model_character_view_uPv;
9300 GLuint _uniform_model_character_view_uTransforms;
9301 GLuint _uniform_model_character_view_uTexMain;
9302 GLuint _uniform_model_character_view_uCamera;
9303 GLuint _uniform_model_character_view_g_world_depth;
9304 GLuint _uniform_model_character_view_uLightsArray;
9305 GLuint _uniform_model_character_view_uLightsIndex;
9306 GLuint _uniform_model_character_view_uTexSceneDepth;
9307 GLuint _uniform_model_character_view_uInverseRatioDepth;
9308 GLuint _uniform_model_character_view_uInverseRatioMain;
9309 GLuint _uniform_model_character_view_uDepthMode;
9310 GLuint _uniform_model_character_view_uDitherCutoff;
9311 #include "shaders/model_board_view.h"
9312 struct vg_shader _shader_model_board_view = {
9313 .name = "model_board_view",
9314 .vs =
9315 {
9316 .orig_file = "shaders/model.vs",
9317 .static_src =
9318 "layout (location=0) in vec3 a_co;\n"
9319 "layout (location=1) in vec3 a_norm;\n"
9320 "layout (location=2) in vec2 a_uv;\n"
9321 "layout (location=3) in vec4 a_colour;\n"
9322 "layout (location=4) in vec4 a_weights;\n"
9323 "layout (location=5) in ivec4 a_groups;\n"
9324 "\n"
9325 "#line 1 1 \n"
9326 "const float k_motion_lerp_amount = 0.01;\n"
9327 "\n"
9328 "#line 2 0 \n"
9329 "\n"
9330 "out vec3 aMotionVec0;\n"
9331 "out vec3 aMotionVec1;\n"
9332 "\n"
9333 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
9334 "{\n"
9335 " // This magically solves some artifacting errors!\n"
9336 " //\n"
9337 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
9338 "\n"
9339 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
9340 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
9341 "}\n"
9342 "\n"
9343 "#line 9 0 \n"
9344 "\n"
9345 "uniform mat4x3 uMdl;\n"
9346 "uniform mat4 uPv;\n"
9347 "uniform mat4 uPvmPrev;\n"
9348 "\n"
9349 "out vec4 aColour;\n"
9350 "out vec2 aUv;\n"
9351 "out vec3 aNorm;\n"
9352 "out vec3 aCo;\n"
9353 "out vec3 aWorldCo;\n"
9354 "\n"
9355 "void main()\n"
9356 "{\n"
9357 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
9358 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
9359 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
9360 "\n"
9361 " vs_motion_out( vproj0, vproj1 );\n"
9362 "\n"
9363 " gl_Position = vproj0;\n"
9364 " aWorldCo = world_pos0;\n"
9365 " aColour = a_colour;\n"
9366 " aUv = a_uv;\n"
9367 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
9368 " aCo = a_co;\n"
9369 "}\n"
9370 ""},
9371 .fs =
9372 {
9373 .orig_file = "shaders/model_character_view.fs",
9374 .static_src =
9375 "uniform sampler2D uTexMain;\n"
9376 "uniform vec3 uCamera;\n"
9377 "\n"
9378 "in vec4 aColour;\n"
9379 "in vec2 aUv;\n"
9380 "in vec3 aNorm;\n"
9381 "in vec3 aCo;\n"
9382 "in vec3 aWorldCo;\n"
9383 "\n"
9384 "#line 1 1 \n"
9385 "// :D\n"
9386 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
9387 "\n"
9388 "#line 11 0 \n"
9389 "#line 1 2 \n"
9390 "layout (location = 0) out vec4 oColour;\n"
9391 "\n"
9392 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
9393 "layout (std140) uniform ub_world_lighting\n"
9394 "{\n"
9395 " vec4 g_cube_min;\n"
9396 " vec4 g_cube_inv_range;\n"
9397 "\n"
9398 " vec4 g_water_plane;\n"
9399 " vec4 g_depth_bounds;\n"
9400 "\n"
9401 " vec4 g_daysky_colour;\n"
9402 " vec4 g_nightsky_colour;\n"
9403 " vec4 g_sunset_colour;\n"
9404 " vec4 g_ambient_colour;\n"
9405 " vec4 g_sunset_ambient;\n"
9406 " vec4 g_sun_colour;\n"
9407 " vec4 g_sun_dir;\n"
9408 " vec4 g_board_0;\n"
9409 " vec4 g_board_1;\n"
9410 "\n"
9411 " float g_water_fog;\n"
9412 " float g_time;\n"
9413 " float g_realtime;\n"
9414 " float g_shadow_length;\n"
9415 " float g_shadow_spread;\n"
9416 "\n"
9417 " float g_time_of_day;\n"
9418 " float g_day_phase;\n"
9419 " float g_sunset_phase;\n"
9420 "\n"
9421 " int g_light_preview;\n"
9422 " int g_shadow_samples;\n"
9423 "\n"
9424 " int g_debug_indices;\n"
9425 " int g_debug_complexity;\n"
9426 "};\n"
9427 "\n"
9428 "uniform sampler2D g_world_depth;\n"
9429 "uniform samplerBuffer uLightsArray;\n"
9430 "uniform usampler3D uLightsIndex;\n"
9431 "\n"
9432 "#line 1 1 \n"
9433 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
9434 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
9435 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
9436 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
9437 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
9438 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
9439 "\n"
9440 "const float SUN_ANGLE = 0.0001;\n"
9441 "const float PI = 3.14159265358979323846264;\n"
9442 "\n"
9443 "//struct world_info\n"
9444 "//{\n"
9445 "// float time,\n"
9446 "// time_of_day,\n"
9447 "// day_phase,\n"
9448 "// sunset_phase;\n"
9449 "// \n"
9450 "// vec3 sun_dir;\n"
9451 "//};\n"
9452 "\n"
9453 "vec3 rand33(vec3 p3)\n"
9454 "{\n"
9455 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
9456 " p3 += dot(p3, p3.yxz+33.33);\n"
9457 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
9458 "}\n"
9459 "\n"
9460 "float stars( vec3 rd, float rr, float size ){\n"
9461 " vec3 co = rd * rr;\n"
9462 "\n"
9463 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
9464 "\n"
9465 " float spaces = 1.0 / rr;\n"
9466 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
9467 " a -= mod(a, spaces) - spaces * 0.5;\n"
9468 "\n"
9469 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
9470 " \n"
9471 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
9472 " plane = plane - mod(plane, PI / count);\n"
9473 "\n"
9474 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
9475 "\n"
9476 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
9477 " float ydist = sqrt(rr * rr - level * level);\n"
9478 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
9479 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
9480 " float star = smoothstep(size, 0.0, distance(center, co));\n"
9481 " return star;\n"
9482 "}\n"
9483 "\n"
9484 "float luminance( vec3 v )\n"
9485 "{\n"
9486 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
9487 "}\n"
9488 "\n"
9489 "vec3 clearskies_ambient( vec3 dir )\n"
9490 "{\n"
9491 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
9492 " float sky_gradient = dir.y;\n"
9493 " \n"
9494 " /* Blend phase colours */\n"
9495 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
9496 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
9497 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
9498 " \n"
9499 " /* Add gradient */\n"
9500 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
9501 " \n"
9502 " return ambient;\n"
9503 "}\n"
9504 "\n"
9505 "vec3 clearskies_sky( vec3 ray_dir )\n"
9506 "{\n"
9507 " ray_dir.y = abs( ray_dir.y );\n"
9508 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
9509 " \n"
9510 " /* Sun */\n"
9511 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
9512 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
9513 " float sun_shape = pow( sun_size, 2000.0 );\n"
9514 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9515 " \n"
9516 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9517 " sun_colour *= sun_shape;\n"
9518 "\n"
9519 " \n"
9520 " float star = 0.0;\n"
9521 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
9522 "\n"
9523 " if( star_blend > 0.001 ){\n"
9524 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
9525 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
9526 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
9527 " }\n"
9528 " }\n"
9529 " \n"
9530 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
9531 " return composite;\n"
9532 "}\n"
9533 "\n"
9534 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
9535 "{\n"
9536 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
9537 "\n"
9538 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
9539 " g_sunset_phase );\n"
9540 "\n"
9541 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
9542 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
9543 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
9544 " ) * g_sun_colour.rgb * g_day_phase;\n"
9545 "\n"
9546 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
9547 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
9548 " g_sunset_phase );\n"
9549 "\n"
9550 " return ambient + (light_sun + sky_reflection) * shadow;\n"
9551 "}\n"
9552 "\n"
9553 "#line 44 0 \n"
9554 "\n"
9555 "float world_depth_sample( vec3 pos )\n"
9556 "{\n"
9557 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
9558 " return texture( g_world_depth, depth_coord ).r;\n"
9559 "}\n"
9560 "\n"
9561 "float world_water_depth( vec3 pos )\n"
9562 "{\n"
9563 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
9564 " return world_depth_sample( pos ) - ref_depth;\n"
9565 "}\n"
9566 "\n"
9567 "float shadow_sample( vec3 co ){\n"
9568 " float height_sample = world_depth_sample( co );\n"
9569 "\n"
9570 " float fdelta = height_sample - co.y;\n"
9571 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
9572 "}\n"
9573 "\n"
9574 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
9575 " if( g_shadow_samples == 0 ){\n"
9576 " return 1.0;\n"
9577 " }\n"
9578 "\n"
9579 " float fspread = g_shadow_spread;\n"
9580 " float flength = g_shadow_length;\n"
9581 "\n"
9582 " float famt = 0.0;\n"
9583 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
9584 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
9585 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
9586 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
9587 "\n"
9588 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
9589 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
9590 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
9591 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
9592 "\n"
9593 " return 1.0 - famt;\n"
9594 "}\n"
9595 "\n"
9596 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
9597 "{\n"
9598 " vec3 specdir = reflect( -dir, wnormal );\n"
9599 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
9600 "}\n"
9601 "\n"
9602 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
9603 " float dist = pow(fdist*0.0010,0.78);\n"
9604 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
9605 "}\n"
9606 "\n"
9607 "vec3 scene_calculate_light( int light_index, \n"
9608 " vec3 halfview, vec3 co, vec3 normal )\n"
9609 "{\n"
9610 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
9611 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
9612 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
9613 "\n"
9614 " vec3 light_delta = light_co.xyz-co;\n"
9615 " float dist2 = dot(light_delta,light_delta);\n"
9616 "\n"
9617 " light_delta = normalize( light_delta );\n"
9618 "\n"
9619 " float quadratic = dist2*100.0;\n"
9620 " float attenuation = 1.0/( 1.0 + quadratic );\n"
9621 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
9622 "\n"
9623 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
9624 "\n"
9625 " if( light_dir.w < 0.999999 ){\n"
9626 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
9627 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
9628 " }\n"
9629 "\n"
9630 " return light_colour.rgb * attenuation * falloff \n"
9631 " * step( g_day_phase, light_colour.w );\n"
9632 "}\n"
9633 "\n"
9634 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
9635 " vec3 halfview, vec3 co, vec3 normal )\n"
9636 "{\n"
9637 " uint light_count = packed_index & 0x3u;\n"
9638 "\n"
9639 " vec3 l = vec3(0.0);\n"
9640 "\n"
9641 " if( light_count >= 1u ){\n"
9642 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
9643 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
9644 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
9645 "\n"
9646 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
9647 "\n"
9648 " if( light_count >= 2u ){\n"
9649 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
9650 "\n"
9651 " if( light_count >= 3u ){\n"
9652 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
9653 " }\n"
9654 " }\n"
9655 " }\n"
9656 "\n"
9657 " return l;\n"
9658 "}\n"
9659 "\n"
9660 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9661 " float light_mask )\n"
9662 "{\n"
9663 " if( g_light_preview == 1 )\n"
9664 " diffuse = vec3(0.75);\n"
9665 "\n"
9666 " // Lighting\n"
9667 " vec3 halfview = uCamera - co;\n"
9668 " float fdist = length(halfview);\n"
9669 " halfview /= fdist;\n"
9670 "\n"
9671 " float world_shadow = newlight_compute_sun_shadow( \n"
9672 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9673 "\n"
9674 " vec3 total_light = clearskies_lighting( \n"
9675 " normal, min( light_mask, world_shadow ), halfview );\n"
9676 "\n"
9677 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9678 " cube_coord = floor( cube_coord );\n"
9679 "\n"
9680 " if( g_debug_indices == 1 )\n"
9681 " {\n"
9682 " return rand33(cube_coord);\n"
9683 " }\n"
9684 "\n"
9685 " if( g_debug_complexity == 1 )\n"
9686 " {\n"
9687 " ivec3 coord = ivec3( cube_coord );\n"
9688 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9689 "\n"
9690 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9691 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9692 " }\n"
9693 "\n"
9694 " // FIXME: this coord should absolutely must be clamped!\n"
9695 " \n"
9696 " ivec3 coord = ivec3( cube_coord );\n"
9697 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9698 "\n"
9699 " total_light += \n"
9700 " scene_calculate_packed_light_patch( index_sample.x,\n"
9701 " halfview, co, normal ) \n"
9702 " * light_mask;\n"
9703 " total_light += \n"
9704 " scene_calculate_packed_light_patch( index_sample.y,\n"
9705 " halfview, co, normal )\n"
9706 " * light_mask;\n"
9707 "\n"
9708 " // Take a section of the sky function to give us a matching fog colour\n"
9709 "\n"
9710 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9711 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9712 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9713 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9714 " \n"
9715 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9716 " sun_colour *= sun_shape;\n"
9717 "\n"
9718 " fog_colour += sun_colour;\n"
9719 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9720 "}\n"
9721 "\n"
9722 "#line 12 0 \n"
9723 "#line 1 3 \n"
9724 "const float k_motion_lerp_amount = 0.01;\n"
9725 "\n"
9726 "#line 2 0 \n"
9727 "\n"
9728 "layout (location = 1) out vec2 oMotionVec;\n"
9729 "\n"
9730 "in vec3 aMotionVec0;\n"
9731 "in vec3 aMotionVec1;\n"
9732 "\n"
9733 "void compute_motion_vectors()\n"
9734 "{\n"
9735 " // Write motion vectors\n"
9736 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
9737 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
9738 "\n"
9739 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
9740 "}\n"
9741 "\n"
9742 "#line 13 0 \n"
9743 "#line 1 4 \n"
9744 "uniform sampler2D uTexSceneDepth;\n"
9745 "uniform vec3 uInverseRatioDepth;\n"
9746 "uniform vec3 uInverseRatioMain;\n"
9747 "uniform int uDepthMode;\n"
9748 "uniform float uDitherCutoff;\n"
9749 "\n"
9750 "float linear_depth( float depth, float near, float far ) {\n"
9751 " float z = depth * 2.0 - 1.0;\n"
9752 " return (2.0 * near * far) / (far + near - z * (far - near)); \n"
9753 "}\n"
9754 "\n"
9755 "void depth_compare_dither()\n"
9756 "{\n"
9757 " if( uDepthMode == 1 )\n"
9758 " {\n"
9759 " vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
9760 " * uInverseRatioDepth.xy;\n"
9761 " float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
9762 " float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
9763 "\n"
9764 " back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
9765 " float diff = back_depth - front_depth;\n"
9766 "\n"
9767 " vec2 ssuv = gl_FragCoord.xy;\n"
9768 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9769 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
9770 "\n"
9771 " if( step(0.0,diff)+dither<0.3 )\n"
9772 " discard;\n"
9773 " }\n"
9774 "\n"
9775 " if( uDepthMode == 2 )\n"
9776 " {\n"
9777 " vec2 ssuv = gl_FragCoord.xy;\n"
9778 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
9779 " float dither = fract( vDither.g / 71.0 );\n"
9780 " if( dither<uDitherCutoff ) discard;\n"
9781 " }\n"
9782 "}\n"
9783 "\n"
9784 "#line 14 0 \n"
9785 "\n"
9786 "vec3 character_clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
9787 "{\n"
9788 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
9789 "\n"
9790 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
9791 " g_sunset_phase );\n"
9792 "\n"
9793 "\n"
9794 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
9795 " vec3 light_sun = max(0.0, dot(normal,g_sun_dir.xyz)*0.5+0.5) \n"
9796 " * g_sun_colour.rgb * g_day_phase;\n"
9797 "\n"
9798 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
9799 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
9800 " g_sunset_phase );\n"
9801 "\n"
9802 " return ambient + (light_sun + sky_reflection) * shadow;\n"
9803 "}\n"
9804 "\n"
9805 "vec3 character_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
9806 " float light_mask )\n"
9807 "{\n"
9808 " if( g_light_preview == 1 )\n"
9809 " diffuse = vec3(0.75);\n"
9810 "\n"
9811 " // Lighting\n"
9812 " vec3 halfview = uCamera - co;\n"
9813 " float fdist = length(halfview);\n"
9814 " halfview /= fdist;\n"
9815 "\n"
9816 " float world_shadow = newlight_compute_sun_shadow( \n"
9817 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
9818 "\n"
9819 " vec3 total_light = character_clearskies_lighting( \n"
9820 " normal, min( light_mask, world_shadow ), halfview );\n"
9821 "\n"
9822 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
9823 " cube_coord = floor( cube_coord );\n"
9824 "\n"
9825 " if( g_debug_indices == 1 )\n"
9826 " {\n"
9827 " return rand33(cube_coord);\n"
9828 " }\n"
9829 "\n"
9830 " if( g_debug_complexity == 1 )\n"
9831 " {\n"
9832 " ivec3 coord = ivec3( cube_coord );\n"
9833 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9834 "\n"
9835 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
9836 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
9837 " }\n"
9838 "\n"
9839 " // FIXME: this coord should absolutely must be clamped!\n"
9840 " \n"
9841 " ivec3 coord = ivec3( cube_coord );\n"
9842 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
9843 "\n"
9844 " total_light += \n"
9845 " scene_calculate_packed_light_patch( index_sample.x,\n"
9846 " halfview, co, normal ) \n"
9847 " * light_mask;\n"
9848 " total_light += \n"
9849 " scene_calculate_packed_light_patch( index_sample.y,\n"
9850 " halfview, co, normal )\n"
9851 " * light_mask;\n"
9852 "\n"
9853 " // Take a section of the sky function to give us a matching fog colour\n"
9854 "\n"
9855 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
9856 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
9857 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
9858 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
9859 " \n"
9860 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
9861 " sun_colour *= sun_shape;\n"
9862 "\n"
9863 " fog_colour += sun_colour;\n"
9864 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
9865 "}\n"
9866 "\n"
9867 "void main(){\n"
9868 " depth_compare_dither();\n"
9869 " compute_motion_vectors();\n"
9870 "\n"
9871 " vec3 qnorm = aNorm;\n"
9872 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
9873 " vec3 composite = character_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
9874 "\n"
9875 " float dist = distance( aWorldCo, uCamera ) - 0.08;\n"
9876 " float opacity = clamp( dist*dist, 0.0, 1.0 );\n"
9877 "\n"
9878 " oColour = vec4( composite, opacity );\n"
9879 "}\n"
9880 ""},
9881 };
9882
9883 GLuint _uniform_model_board_view_uMdl;
9884 GLuint _uniform_model_board_view_uPv;
9885 GLuint _uniform_model_board_view_uPvmPrev;
9886 GLuint _uniform_model_board_view_uTexMain;
9887 GLuint _uniform_model_board_view_uCamera;
9888 GLuint _uniform_model_board_view_g_world_depth;
9889 GLuint _uniform_model_board_view_uLightsArray;
9890 GLuint _uniform_model_board_view_uLightsIndex;
9891 GLuint _uniform_model_board_view_uTexSceneDepth;
9892 GLuint _uniform_model_board_view_uInverseRatioDepth;
9893 GLuint _uniform_model_board_view_uInverseRatioMain;
9894 GLuint _uniform_model_board_view_uDepthMode;
9895 GLuint _uniform_model_board_view_uDitherCutoff;
9896 #include "shaders/model_entity.h"
9897 struct vg_shader _shader_model_entity = {
9898 .name = "model_entity",
9899 .vs =
9900 {
9901 .orig_file = "shaders/model.vs",
9902 .static_src =
9903 "layout (location=0) in vec3 a_co;\n"
9904 "layout (location=1) in vec3 a_norm;\n"
9905 "layout (location=2) in vec2 a_uv;\n"
9906 "layout (location=3) in vec4 a_colour;\n"
9907 "layout (location=4) in vec4 a_weights;\n"
9908 "layout (location=5) in ivec4 a_groups;\n"
9909 "\n"
9910 "#line 1 1 \n"
9911 "const float k_motion_lerp_amount = 0.01;\n"
9912 "\n"
9913 "#line 2 0 \n"
9914 "\n"
9915 "out vec3 aMotionVec0;\n"
9916 "out vec3 aMotionVec1;\n"
9917 "\n"
9918 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
9919 "{\n"
9920 " // This magically solves some artifacting errors!\n"
9921 " //\n"
9922 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
9923 "\n"
9924 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
9925 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
9926 "}\n"
9927 "\n"
9928 "#line 9 0 \n"
9929 "\n"
9930 "uniform mat4x3 uMdl;\n"
9931 "uniform mat4 uPv;\n"
9932 "uniform mat4 uPvmPrev;\n"
9933 "\n"
9934 "out vec4 aColour;\n"
9935 "out vec2 aUv;\n"
9936 "out vec3 aNorm;\n"
9937 "out vec3 aCo;\n"
9938 "out vec3 aWorldCo;\n"
9939 "\n"
9940 "void main()\n"
9941 "{\n"
9942 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
9943 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
9944 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
9945 "\n"
9946 " vs_motion_out( vproj0, vproj1 );\n"
9947 "\n"
9948 " gl_Position = vproj0;\n"
9949 " aWorldCo = world_pos0;\n"
9950 " aColour = a_colour;\n"
9951 " aUv = a_uv;\n"
9952 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
9953 " aCo = a_co;\n"
9954 "}\n"
9955 ""},
9956 .fs =
9957 {
9958 .orig_file = "shaders/model_entity.fs",
9959 .static_src =
9960 "uniform sampler2D uTexMain;\n"
9961 "uniform vec3 uCamera;\n"
9962 "\n"
9963 "in vec4 aColour;\n"
9964 "in vec2 aUv;\n"
9965 "in vec3 aNorm;\n"
9966 "in vec3 aCo;\n"
9967 "in vec3 aWorldCo;\n"
9968 "\n"
9969 "#line 1 1 \n"
9970 "// :D\n"
9971 "const float CLEARSKIES_LIGHT_DOT_MIN = 0.0;\n"
9972 "\n"
9973 "#line 11 0 \n"
9974 "#line 1 2 \n"
9975 "layout (location = 0) out vec4 oColour;\n"
9976 "\n"
9977 "// OpenGL wiki: Recommends do not use vec3 because of drivers. hence the v4s...\n"
9978 "layout (std140) uniform ub_world_lighting\n"
9979 "{\n"
9980 " vec4 g_cube_min;\n"
9981 " vec4 g_cube_inv_range;\n"
9982 "\n"
9983 " vec4 g_water_plane;\n"
9984 " vec4 g_depth_bounds;\n"
9985 "\n"
9986 " vec4 g_daysky_colour;\n"
9987 " vec4 g_nightsky_colour;\n"
9988 " vec4 g_sunset_colour;\n"
9989 " vec4 g_ambient_colour;\n"
9990 " vec4 g_sunset_ambient;\n"
9991 " vec4 g_sun_colour;\n"
9992 " vec4 g_sun_dir;\n"
9993 " vec4 g_board_0;\n"
9994 " vec4 g_board_1;\n"
9995 "\n"
9996 " float g_water_fog;\n"
9997 " float g_time;\n"
9998 " float g_realtime;\n"
9999 " float g_shadow_length;\n"
10000 " float g_shadow_spread;\n"
10001 "\n"
10002 " float g_time_of_day;\n"
10003 " float g_day_phase;\n"
10004 " float g_sunset_phase;\n"
10005 "\n"
10006 " int g_light_preview;\n"
10007 " int g_shadow_samples;\n"
10008 "\n"
10009 " int g_debug_indices;\n"
10010 " int g_debug_complexity;\n"
10011 "};\n"
10012 "\n"
10013 "uniform sampler2D g_world_depth;\n"
10014 "uniform samplerBuffer uLightsArray;\n"
10015 "uniform usampler3D uLightsIndex;\n"
10016 "\n"
10017 "#line 1 1 \n"
10018 "//const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
10019 "//const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
10020 "//const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
10021 "//const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
10022 "//const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
10023 "//const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 );\n"
10024 "\n"
10025 "const float SUN_ANGLE = 0.0001;\n"
10026 "const float PI = 3.14159265358979323846264;\n"
10027 "\n"
10028 "//struct world_info\n"
10029 "//{\n"
10030 "// float time,\n"
10031 "// time_of_day,\n"
10032 "// day_phase,\n"
10033 "// sunset_phase;\n"
10034 "// \n"
10035 "// vec3 sun_dir;\n"
10036 "//};\n"
10037 "\n"
10038 "vec3 rand33(vec3 p3)\n"
10039 "{\n"
10040 " p3 = fract(p3 * vec3(.1031, .1030, .0973));\n"
10041 " p3 += dot(p3, p3.yxz+33.33);\n"
10042 " return fract((p3.xxy + p3.yxx)*p3.zyx);\n"
10043 "}\n"
10044 "\n"
10045 "float stars( vec3 rd, float rr, float size ){\n"
10046 " vec3 co = rd * rr;\n"
10047 "\n"
10048 " float a = atan(co.y, length(co.xz)) + 4.0 * PI;\n"
10049 "\n"
10050 " float spaces = 1.0 / rr;\n"
10051 " size = (rr * 0.0015) * fwidth(a) * 1000.0 * size;\n"
10052 " a -= mod(a, spaces) - spaces * 0.5;\n"
10053 "\n"
10054 " float count = floor(sqrt(pow(rr, 2.0) * (1.0 - pow(sin(a), 2.0))) * 3.0);\n"
10055 " \n"
10056 " float plane = atan(co.z, co.x) + 4.0 * PI;\n"
10057 " plane = plane - mod(plane, PI / count);\n"
10058 "\n"
10059 " vec2 delta = rand33(vec3(plane, a, 0.0)).xy;\n"
10060 "\n"
10061 " float level = sin(a + spaces * (delta.y - 0.5) * (1.0 - size)) * rr;\n"
10062 " float ydist = sqrt(rr * rr - level * level);\n"
10063 " float angle = plane + (PI * (delta.x * (1.0-size) + size * 0.5) / count);\n"
10064 " vec3 center = vec3(cos(angle) * ydist, level, sin(angle) * ydist);\n"
10065 " float star = smoothstep(size, 0.0, distance(center, co));\n"
10066 " return star;\n"
10067 "}\n"
10068 "\n"
10069 "float luminance( vec3 v )\n"
10070 "{\n"
10071 " return dot( v, vec3(0.2126, 0.7052, 0.0722) );\n"
10072 "}\n"
10073 "\n"
10074 "vec3 clearskies_ambient( vec3 dir )\n"
10075 "{\n"
10076 " float sun_azimuth = g_sunset_phase * (dot( dir.xz, g_sun_dir.xz )*0.4+0.6);\n"
10077 " float sky_gradient = dir.y;\n"
10078 " \n"
10079 " /* Blend phase colours */\n"
10080 " vec3 ambient = g_daysky_colour.rgb * (g_day_phase-g_sunset_phase*0.1);\n"
10081 " ambient += g_sunset_colour.rgb * (1.0-dir.y*0.5)*sun_azimuth;\n"
10082 " ambient += g_nightsky_colour.rgb * (1.0-g_day_phase);\n"
10083 " \n"
10084 " /* Add gradient */\n"
10085 " ambient -= sky_gradient * luminance(ambient)*1.6;\n"
10086 " \n"
10087 " return ambient;\n"
10088 "}\n"
10089 "\n"
10090 "vec3 clearskies_sky( vec3 ray_dir )\n"
10091 "{\n"
10092 " ray_dir.y = abs( ray_dir.y );\n"
10093 " vec3 sky_colour = clearskies_ambient( ray_dir );\n"
10094 " \n"
10095 " /* Sun */\n"
10096 " float sun_theta = dot( ray_dir, g_sun_dir.xyz );\n"
10097 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
10098 " float sun_shape = pow( sun_size, 2000.0 );\n"
10099 " sun_shape += sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
10100 " \n"
10101 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
10102 " sun_colour *= sun_shape;\n"
10103 "\n"
10104 " \n"
10105 " float star = 0.0;\n"
10106 " float star_blend = 10.0*max(0.0,(1.0-g_day_phase*2.0));\n"
10107 "\n"
10108 " if( star_blend > 0.001 ){\n"
10109 " for( float j = 1.0; j <= 4.1; j += 1.0 ){\n"
10110 " float m = mix(0.6, 0.9, smoothstep(1.0, 2.0, j));\n"
10111 " star += stars( ray_dir, 1.94 * pow( 1.64, j ), m ) * (1.0/pow(4.0, j));\n"
10112 " }\n"
10113 " }\n"
10114 " \n"
10115 " vec3 composite = sky_colour + sun_colour + star*star_blend;\n"
10116 " return composite;\n"
10117 "}\n"
10118 "\n"
10119 "vec3 clearskies_lighting( vec3 normal, float shadow, vec3 halfview )\n"
10120 "{\n"
10121 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
10122 "\n"
10123 " vec3 reflect_colour = mix( g_daysky_colour.rgb, g_sunset_colour.rgb, \n"
10124 " g_sunset_phase );\n"
10125 "\n"
10126 " vec3 sky_reflection = 0.5 * fresnel * reflect_colour;\n"
10127 " vec3 light_sun = max( CLEARSKIES_LIGHT_DOT_MIN, \n"
10128 " dot(normal,g_sun_dir.xyz)*0.75+0.25\n"
10129 " ) * g_sun_colour.rgb * g_day_phase;\n"
10130 "\n"
10131 " float scaled_shadow = max( shadow, 1.0 - max(g_sun_dir.y,0.0) );\n"
10132 " vec3 ambient = mix( g_ambient_colour.rgb, g_sunset_ambient.rgb, \n"
10133 " g_sunset_phase );\n"
10134 "\n"
10135 " return ambient + (light_sun + sky_reflection) * shadow;\n"
10136 "}\n"
10137 "\n"
10138 "#line 44 0 \n"
10139 "\n"
10140 "float world_depth_sample( vec3 pos )\n"
10141 "{\n"
10142 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
10143 " return texture( g_world_depth, depth_coord ).r;\n"
10144 "}\n"
10145 "\n"
10146 "float world_water_depth( vec3 pos )\n"
10147 "{\n"
10148 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
10149 " return world_depth_sample( pos ) - ref_depth;\n"
10150 "}\n"
10151 "\n"
10152 "float shadow_sample( vec3 co ){\n"
10153 " float height_sample = world_depth_sample( co );\n"
10154 "\n"
10155 " float fdelta = height_sample - co.y;\n"
10156 " return clamp( fdelta, 0.2, 0.4 )-0.2;\n"
10157 "}\n"
10158 "\n"
10159 "float newlight_compute_sun_shadow( vec3 co, vec3 dir ){\n"
10160 " if( g_shadow_samples == 0 ){\n"
10161 " return 1.0;\n"
10162 " }\n"
10163 "\n"
10164 " float fspread = g_shadow_spread;\n"
10165 " float flength = g_shadow_length;\n"
10166 "\n"
10167 " float famt = 0.0;\n"
10168 " famt += shadow_sample(co+(dir+vec3(-0.56,0.55, 0.30)*fspread)*flength*0.1);\n"
10169 " famt += shadow_sample(co+(dir+vec3( 0.80,0.68, 0.34)*fspread)*flength*0.2);\n"
10170 " famt += shadow_sample(co+(dir+vec3( 0.78,0.07,-0.06)*fspread)*flength*0.3);\n"
10171 " famt += shadow_sample(co+(dir+vec3(-0.59,0.07,-0.42)*fspread)*flength*0.4);\n"
10172 "\n"
10173 " //famt+=shadow_sample(co+(dir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
10174 " //famt+=shadow_sample(co+(dir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
10175 " //famt+=shadow_sample(co+(dir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
10176 " //famt+=shadow_sample(co+(dir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
10177 "\n"
10178 " return 1.0 - famt;\n"
10179 "}\n"
10180 "\n"
10181 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
10182 "{\n"
10183 " vec3 specdir = reflect( -dir, wnormal );\n"
10184 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
10185 "}\n"
10186 "\n"
10187 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist ){\n"
10188 " float dist = pow(fdist*0.0010,0.78);\n"
10189 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
10190 "}\n"
10191 "\n"
10192 "vec3 scene_calculate_light( int light_index, \n"
10193 " vec3 halfview, vec3 co, vec3 normal )\n"
10194 "{\n"
10195 " vec4 light_colour = texelFetch( uLightsArray, light_index+0 );\n"
10196 " vec4 light_co = texelFetch( uLightsArray, light_index+1 );\n"
10197 " vec4 light_dir = texelFetch( uLightsArray, light_index+2 );\n"
10198 "\n"
10199 " vec3 light_delta = light_co.xyz-co;\n"
10200 " float dist2 = dot(light_delta,light_delta);\n"
10201 "\n"
10202 " light_delta = normalize( light_delta );\n"
10203 "\n"
10204 " float quadratic = dist2*100.0;\n"
10205 " float attenuation = 1.0/( 1.0 + quadratic );\n"
10206 " attenuation *= max( dot( light_delta, normal ), 0.0 );\n"
10207 "\n"
10208 " float falloff = max( 0.0, 1.0-(dist2*light_co.w) );\n"
10209 "\n"
10210 " if( light_dir.w < 0.999999 ){\n"
10211 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) );\n"
10212 " falloff *= max( 0.0, (spot_theta - light_dir.w) / (1.0-light_dir.w) );\n"
10213 " }\n"
10214 "\n"
10215 " return light_colour.rgb * attenuation * falloff \n"
10216 " * step( g_day_phase, light_colour.w );\n"
10217 "}\n"
10218 "\n"
10219 "vec3 scene_calculate_packed_light_patch( uint packed_index, \n"
10220 " vec3 halfview, vec3 co, vec3 normal )\n"
10221 "{\n"
10222 " uint light_count = packed_index & 0x3u;\n"
10223 "\n"
10224 " vec3 l = vec3(0.0);\n"
10225 "\n"
10226 " if( light_count >= 1u ){\n"
10227 " int index_0 = int( ((packed_index >> 2u) & 0x3ffu) * 3u );\n"
10228 " int index_1 = int( ((packed_index >> 12u) & 0x3ffu) * 3u );\n"
10229 " int index_2 = int( ((packed_index >> 22u) & 0x3ffu) * 3u );\n"
10230 "\n"
10231 " l += scene_calculate_light( index_0, halfview, co, normal );\n"
10232 "\n"
10233 " if( light_count >= 2u ){\n"
10234 " l += scene_calculate_light( index_1, halfview, co, normal );\n"
10235 "\n"
10236 " if( light_count >= 3u ){\n"
10237 " l += scene_calculate_light( index_2, halfview, co, normal );\n"
10238 " }\n"
10239 " }\n"
10240 " }\n"
10241 "\n"
10242 " return l;\n"
10243 "}\n"
10244 "\n"
10245 "vec3 world_compute_lighting( vec3 diffuse, vec3 normal, vec3 co,\n"
10246 " float light_mask )\n"
10247 "{\n"
10248 " if( g_light_preview == 1 )\n"
10249 " diffuse = vec3(0.75);\n"
10250 "\n"
10251 " // Lighting\n"
10252 " vec3 halfview = uCamera - co;\n"
10253 " float fdist = length(halfview);\n"
10254 " halfview /= fdist;\n"
10255 "\n"
10256 " float world_shadow = newlight_compute_sun_shadow( \n"
10257 " co, g_sun_dir.xyz * (1.0/(max(g_sun_dir.y,0.0)+0.2)) );\n"
10258 "\n"
10259 " vec3 total_light = clearskies_lighting( \n"
10260 " normal, min( light_mask, world_shadow ), halfview );\n"
10261 "\n"
10262 " vec3 cube_coord = (co - g_cube_min.xyz) * g_cube_inv_range.xyz;\n"
10263 " cube_coord = floor( cube_coord );\n"
10264 "\n"
10265 " if( g_debug_indices == 1 )\n"
10266 " {\n"
10267 " return rand33(cube_coord);\n"
10268 " }\n"
10269 "\n"
10270 " if( g_debug_complexity == 1 )\n"
10271 " {\n"
10272 " ivec3 coord = ivec3( cube_coord );\n"
10273 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
10274 "\n"
10275 " uint light_count = (index_sample.x & 0x3u) + (index_sample.y & 0x3u);\n"
10276 " return vec3( float(light_count)*(1.0/6.0), 0.0, 0.5 );\n"
10277 " }\n"
10278 "\n"
10279 " // FIXME: this coord should absolutely must be clamped!\n"
10280 " \n"
10281 " ivec3 coord = ivec3( cube_coord );\n"
10282 " uvec4 index_sample = texelFetch( uLightsIndex, coord, 0 );\n"
10283 "\n"
10284 " total_light += \n"
10285 " scene_calculate_packed_light_patch( index_sample.x,\n"
10286 " halfview, co, normal ) \n"
10287 " * light_mask;\n"
10288 " total_light += \n"
10289 " scene_calculate_packed_light_patch( index_sample.y,\n"
10290 " halfview, co, normal )\n"
10291 " * light_mask;\n"
10292 "\n"
10293 " // Take a section of the sky function to give us a matching fog colour\n"
10294 "\n"
10295 " vec3 fog_colour = clearskies_ambient( -halfview );\n"
10296 " float sun_theta = dot( -halfview, g_sun_dir.xyz );\n"
10297 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 );\n"
10298 " float sun_shape = sun_size * max(g_sun_dir.y,0.0) * 0.5;\n"
10299 " \n"
10300 " vec3 sun_colour = mix( vec3(1.0), g_sunset_colour.rgb, g_sunset_phase*0.5 );\n"
10301 " sun_colour *= sun_shape;\n"
10302 "\n"
10303 " fog_colour += sun_colour;\n"
10304 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
10305 "}\n"
10306 "\n"
10307 "#line 12 0 \n"
10308 "#line 1 3 \n"
10309 "const float k_motion_lerp_amount = 0.01;\n"
10310 "\n"
10311 "#line 2 0 \n"
10312 "\n"
10313 "layout (location = 1) out vec2 oMotionVec;\n"
10314 "\n"
10315 "in vec3 aMotionVec0;\n"
10316 "in vec3 aMotionVec1;\n"
10317 "\n"
10318 "void compute_motion_vectors()\n"
10319 "{\n"
10320 " // Write motion vectors\n"
10321 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10322 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10323 "\n"
10324 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10325 "}\n"
10326 "\n"
10327 "#line 13 0 \n"
10328 "\n"
10329 "void main()\n"
10330 "{\n"
10331 " compute_motion_vectors();\n"
10332 "\n"
10333 " vec3 qnorm = normalize(floor(aNorm*2.0)*0.5) + vec3(0.001,0.0,0.0);\n"
10334 " vec3 diffuse = texture( uTexMain, aUv ).rgb;\n"
10335 " vec3 composite = world_compute_lighting( diffuse, qnorm, aWorldCo, 1.0 );\n"
10336 "\n"
10337 " oColour = vec4( composite, 1.0 );\n"
10338 "}\n"
10339 ""},
10340 };
10341
10342 GLuint _uniform_model_entity_uMdl;
10343 GLuint _uniform_model_entity_uPv;
10344 GLuint _uniform_model_entity_uPvmPrev;
10345 GLuint _uniform_model_entity_uTexMain;
10346 GLuint _uniform_model_entity_uCamera;
10347 GLuint _uniform_model_entity_g_world_depth;
10348 GLuint _uniform_model_entity_uLightsArray;
10349 GLuint _uniform_model_entity_uLightsIndex;
10350 #include "shaders/model_gate.h"
10351 struct vg_shader _shader_model_gate = {
10352 .name = "model_gate",
10353 .vs =
10354 {
10355 .orig_file = "shaders/model.vs",
10356 .static_src =
10357 "layout (location=0) in vec3 a_co;\n"
10358 "layout (location=1) in vec3 a_norm;\n"
10359 "layout (location=2) in vec2 a_uv;\n"
10360 "layout (location=3) in vec4 a_colour;\n"
10361 "layout (location=4) in vec4 a_weights;\n"
10362 "layout (location=5) in ivec4 a_groups;\n"
10363 "\n"
10364 "#line 1 1 \n"
10365 "const float k_motion_lerp_amount = 0.01;\n"
10366 "\n"
10367 "#line 2 0 \n"
10368 "\n"
10369 "out vec3 aMotionVec0;\n"
10370 "out vec3 aMotionVec1;\n"
10371 "\n"
10372 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10373 "{\n"
10374 " // This magically solves some artifacting errors!\n"
10375 " //\n"
10376 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10377 "\n"
10378 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10379 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10380 "}\n"
10381 "\n"
10382 "#line 9 0 \n"
10383 "\n"
10384 "uniform mat4x3 uMdl;\n"
10385 "uniform mat4 uPv;\n"
10386 "uniform mat4 uPvmPrev;\n"
10387 "\n"
10388 "out vec4 aColour;\n"
10389 "out vec2 aUv;\n"
10390 "out vec3 aNorm;\n"
10391 "out vec3 aCo;\n"
10392 "out vec3 aWorldCo;\n"
10393 "\n"
10394 "void main()\n"
10395 "{\n"
10396 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
10397 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
10398 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
10399 "\n"
10400 " vs_motion_out( vproj0, vproj1 );\n"
10401 "\n"
10402 " gl_Position = vproj0;\n"
10403 " aWorldCo = world_pos0;\n"
10404 " aColour = a_colour;\n"
10405 " aUv = a_uv;\n"
10406 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
10407 " aCo = a_co;\n"
10408 "}\n"
10409 ""},
10410 .fs =
10411 {
10412 .orig_file = "shaders/model_gate_lq.fs",
10413 .static_src =
10414 "out vec4 FragColor;\n"
10415 "\n"
10416 "uniform float uTime;\n"
10417 "uniform vec3 uCam;\n"
10418 "uniform vec2 uInvRes;\n"
10419 "uniform vec4 uColour;\n"
10420 "\n"
10421 "in vec3 aNorm;\n"
10422 "in vec2 aUv;\n"
10423 "in vec3 aCo;\n"
10424 "\n"
10425 "void main()\n"
10426 "{\n"
10427 " vec2 ssuv = gl_FragCoord.xy;\n"
10428 " float opacity = 1.0-smoothstep(0.0,1.0,aUv.y+uColour.a);\n"
10429 " \n"
10430 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10431 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10432 "\n"
10433 " if( opacity+dither<0.5 )\n"
10434 " discard;\n"
10435 "\n"
10436 " FragColor = uColour;\n"
10437 "}\n"
10438 ""},
10439 };
10440
10441 GLuint _uniform_model_gate_uMdl;
10442 GLuint _uniform_model_gate_uPv;
10443 GLuint _uniform_model_gate_uPvmPrev;
10444 GLuint _uniform_model_gate_uTime;
10445 GLuint _uniform_model_gate_uCam;
10446 GLuint _uniform_model_gate_uInvRes;
10447 GLuint _uniform_model_gate_uColour;
10448 #include "shaders/model_gate_unlinked.h"
10449 struct vg_shader _shader_model_gate_unlinked = {
10450 .name = "model_gate_unlinked",
10451 .vs =
10452 {
10453 .orig_file = "shaders/model.vs",
10454 .static_src =
10455 "layout (location=0) in vec3 a_co;\n"
10456 "layout (location=1) in vec3 a_norm;\n"
10457 "layout (location=2) in vec2 a_uv;\n"
10458 "layout (location=3) in vec4 a_colour;\n"
10459 "layout (location=4) in vec4 a_weights;\n"
10460 "layout (location=5) in ivec4 a_groups;\n"
10461 "\n"
10462 "#line 1 1 \n"
10463 "const float k_motion_lerp_amount = 0.01;\n"
10464 "\n"
10465 "#line 2 0 \n"
10466 "\n"
10467 "out vec3 aMotionVec0;\n"
10468 "out vec3 aMotionVec1;\n"
10469 "\n"
10470 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10471 "{\n"
10472 " // This magically solves some artifacting errors!\n"
10473 " //\n"
10474 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10475 "\n"
10476 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10477 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10478 "}\n"
10479 "\n"
10480 "#line 9 0 \n"
10481 "\n"
10482 "uniform mat4x3 uMdl;\n"
10483 "uniform mat4 uPv;\n"
10484 "uniform mat4 uPvmPrev;\n"
10485 "\n"
10486 "out vec4 aColour;\n"
10487 "out vec2 aUv;\n"
10488 "out vec3 aNorm;\n"
10489 "out vec3 aCo;\n"
10490 "out vec3 aWorldCo;\n"
10491 "\n"
10492 "void main()\n"
10493 "{\n"
10494 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
10495 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
10496 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
10497 "\n"
10498 " vs_motion_out( vproj0, vproj1 );\n"
10499 "\n"
10500 " gl_Position = vproj0;\n"
10501 " aWorldCo = world_pos0;\n"
10502 " aColour = a_colour;\n"
10503 " aUv = a_uv;\n"
10504 " aNorm = normalize( mat3(uMdl) * a_norm );\n"
10505 " aCo = a_co;\n"
10506 "}\n"
10507 ""},
10508 .fs =
10509 {
10510 .orig_file = "shaders/model_gate_unlinked.fs",
10511 .static_src =
10512 "out vec4 FragColor;\n"
10513 "\n"
10514 "uniform float uTime;\n"
10515 "uniform vec3 uCam;\n"
10516 "uniform vec4 uColour;\n"
10517 "\n"
10518 "in vec3 aNorm;\n"
10519 "in vec2 aUv;\n"
10520 "in vec3 aCo;\n"
10521 "\n"
10522 "#line 1 1 \n"
10523 "const float k_motion_lerp_amount = 0.01;\n"
10524 "\n"
10525 "#line 2 0 \n"
10526 "\n"
10527 "layout (location = 1) out vec2 oMotionVec;\n"
10528 "\n"
10529 "in vec3 aMotionVec0;\n"
10530 "in vec3 aMotionVec1;\n"
10531 "\n"
10532 "void compute_motion_vectors()\n"
10533 "{\n"
10534 " // Write motion vectors\n"
10535 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10536 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10537 "\n"
10538 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10539 "}\n"
10540 "\n"
10541 "#line 12 0 \n"
10542 "\n"
10543 "const int NOISE_LOOP = 3;\n"
10544 "vec3 digital_noise( uvec3 iuv ){\n"
10545 " iuv *=uvec3(8,2524,7552);\n"
10546 " for( int i=0; i<NOISE_LOOP; i++ )\n"
10547 " iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
10548 " return vec3(iuv)*(1.0/float(0xffffffffU));\n"
10549 "}\n"
10550 "\n"
10551 "vec2 rand_hash22( vec2 p ){\n"
10552 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
10553 " p3 += dot(p3, p3.yzx+19.19);\n"
10554 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
10555 "}\n"
10556 "\n"
10557 "void main(){\n"
10558 " compute_motion_vectors();\n"
10559 "\n"
10560 " vec2 ssuv = gl_FragCoord.xy;\n"
10561 " float grad = 1.0-aUv.y*0.1;\n"
10562 " float opacity = rand_hash22( vec2(floor(aUv.y*100.0),floor(aCo.z*10.0+uTime*40.0)) ).r*grad;\n"
10563 " \n"
10564 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10565 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10566 "\n"
10567 " if( opacity<0.9 )\n"
10568 " discard;\n"
10569 "\n"
10570 " FragColor = vec4(0.7,0.5,0.5,1.0);\n"
10571 "}\n"
10572 ""},
10573 };
10574
10575 GLuint _uniform_model_gate_unlinked_uMdl;
10576 GLuint _uniform_model_gate_unlinked_uPv;
10577 GLuint _uniform_model_gate_unlinked_uPvmPrev;
10578 GLuint _uniform_model_gate_unlinked_uTime;
10579 GLuint _uniform_model_gate_unlinked_uCam;
10580 GLuint _uniform_model_gate_unlinked_uColour;
10581 #include "shaders/model_font.h"
10582 struct vg_shader _shader_model_font = {
10583 .name = "model_font",
10584 .vs =
10585 {
10586 .orig_file = "shaders/model_font.vs",
10587 .static_src =
10588 "layout (location=0) in vec3 a_co;\n"
10589 "layout (location=1) in vec3 a_norm;\n"
10590 "layout (location=2) in vec2 a_uv;\n"
10591 "\n"
10592 "#line 1 1 \n"
10593 "const float k_motion_lerp_amount = 0.01;\n"
10594 "\n"
10595 "#line 2 0 \n"
10596 "\n"
10597 "out vec3 aMotionVec0;\n"
10598 "out vec3 aMotionVec1;\n"
10599 "\n"
10600 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10601 "{\n"
10602 " // This magically solves some artifacting errors!\n"
10603 " //\n"
10604 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10605 "\n"
10606 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10607 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10608 "}\n"
10609 "\n"
10610 "#line 6 0 \n"
10611 "\n"
10612 "uniform mat4x3 uMdl;\n"
10613 "uniform mat4 uPv;\n"
10614 "uniform mat4 uPvmPrev;\n"
10615 "uniform vec4 uOffset;\n"
10616 "\n"
10617 "out vec2 aUv;\n"
10618 "out vec4 aNorm;\n"
10619 "out vec3 aCo;\n"
10620 "out vec3 aWorldCo;\n"
10621 "\n"
10622 "void main()\n"
10623 "{\n"
10624 " vec3 co = a_co*uOffset.w+uOffset.xyz;\n"
10625 " vec3 world_pos0 = uMdl * vec4( co, 1.0 );\n"
10626 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
10627 " vec4 vproj1 = uPvmPrev * vec4( co, 1.0 );\n"
10628 "\n"
10629 " vs_motion_out( vproj0, vproj1 );\n"
10630 "\n"
10631 " gl_Position = vproj0;\n"
10632 "\n"
10633 " aUv = a_uv;\n"
10634 " aNorm = vec4( mat3(uMdl) * a_norm, 0.0 );\n"
10635 " aCo = co;\n"
10636 " aWorldCo = world_pos0;\n"
10637 "}\n"
10638 ""},
10639 .fs =
10640 {
10641 .orig_file = "shaders/model_font.fs",
10642 .static_src =
10643 "layout (location = 0) out vec4 oColour;\n"
10644 "\n"
10645 "uniform sampler2D uTexMain;\n"
10646 "uniform vec4 uColour;\n"
10647 "\n"
10648 "in vec2 aUv;\n"
10649 "in vec4 aNorm;\n"
10650 "in vec3 aCo;\n"
10651 "\n"
10652 "#line 1 1 \n"
10653 "const float k_motion_lerp_amount = 0.01;\n"
10654 "\n"
10655 "#line 2 0 \n"
10656 "\n"
10657 "layout (location = 1) out vec2 oMotionVec;\n"
10658 "\n"
10659 "in vec3 aMotionVec0;\n"
10660 "in vec3 aMotionVec1;\n"
10661 "\n"
10662 "void compute_motion_vectors()\n"
10663 "{\n"
10664 " // Write motion vectors\n"
10665 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10666 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10667 "\n"
10668 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10669 "}\n"
10670 "\n"
10671 "#line 11 0 \n"
10672 "#line 1 2 \n"
10673 "uniform sampler2D uTexSceneDepth;\n"
10674 "uniform vec3 uInverseRatioDepth;\n"
10675 "uniform vec3 uInverseRatioMain;\n"
10676 "uniform int uDepthMode;\n"
10677 "uniform float uDitherCutoff;\n"
10678 "\n"
10679 "float linear_depth( float depth, float near, float far ) {\n"
10680 " float z = depth * 2.0 - 1.0;\n"
10681 " return (2.0 * near * far) / (far + near - z * (far - near)); \n"
10682 "}\n"
10683 "\n"
10684 "void depth_compare_dither()\n"
10685 "{\n"
10686 " if( uDepthMode == 1 )\n"
10687 " {\n"
10688 " vec2 back_coord = gl_FragCoord.xy * uInverseRatioMain.xy \n"
10689 " * uInverseRatioDepth.xy;\n"
10690 " float back_depth = texture( uTexSceneDepth, back_coord ).r;\n"
10691 " float front_depth = gl_FragCoord.z/gl_FragCoord.w;\n"
10692 "\n"
10693 " back_depth = linear_depth( back_depth, 0.1, 2100.0 );\n"
10694 " float diff = back_depth - front_depth;\n"
10695 "\n"
10696 " vec2 ssuv = gl_FragCoord.xy;\n"
10697 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10698 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10699 "\n"
10700 " if( step(0.0,diff)+dither<0.3 )\n"
10701 " discard;\n"
10702 " }\n"
10703 "\n"
10704 " if( uDepthMode == 2 )\n"
10705 " {\n"
10706 " vec2 ssuv = gl_FragCoord.xy;\n"
10707 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10708 " float dither = fract( vDither.g / 71.0 );\n"
10709 " if( dither<uDitherCutoff ) discard;\n"
10710 " }\n"
10711 "}\n"
10712 "\n"
10713 "#line 12 0 \n"
10714 "\n"
10715 "void main(){\n"
10716 " depth_compare_dither();\n"
10717 " compute_motion_vectors();\n"
10718 " oColour = texture( uTexMain, aUv ) * uColour;\n"
10719 "}\n"
10720 ""},
10721 };
10722
10723 GLuint _uniform_model_font_uMdl;
10724 GLuint _uniform_model_font_uPv;
10725 GLuint _uniform_model_font_uPvmPrev;
10726 GLuint _uniform_model_font_uOffset;
10727 GLuint _uniform_model_font_uTexMain;
10728 GLuint _uniform_model_font_uColour;
10729 GLuint _uniform_model_font_uTexSceneDepth;
10730 GLuint _uniform_model_font_uInverseRatioDepth;
10731 GLuint _uniform_model_font_uInverseRatioMain;
10732 GLuint _uniform_model_font_uDepthMode;
10733 GLuint _uniform_model_font_uDitherCutoff;
10734 #include "shaders/particle.h"
10735 struct vg_shader _shader_particle = {
10736 .name = "particle",
10737 .vs =
10738 {
10739 .orig_file = "shaders/particle.vs",
10740 .static_src =
10741 "layout (location=0) in vec3 a_co;\n"
10742 "layout (location=1) in vec4 a_colour;\n"
10743 "\n"
10744 "#line 1 1 \n"
10745 "const float k_motion_lerp_amount = 0.01;\n"
10746 "\n"
10747 "#line 2 0 \n"
10748 "\n"
10749 "out vec3 aMotionVec0;\n"
10750 "out vec3 aMotionVec1;\n"
10751 "\n"
10752 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10753 "{\n"
10754 " // This magically solves some artifacting errors!\n"
10755 " //\n"
10756 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10757 "\n"
10758 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10759 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10760 "}\n"
10761 "\n"
10762 "#line 5 0 \n"
10763 "\n"
10764 "uniform mat4 uPv;\n"
10765 "uniform mat4 uPvPrev;\n"
10766 "\n"
10767 "out vec4 aColour;\n"
10768 "\n"
10769 "void main(){\n"
10770 " vec4 vproj0 = uPv * vec4( a_co, 1.0 );\n"
10771 " vec4 vproj1 = uPvPrev * vec4( a_co, 1.0 );\n"
10772 " vs_motion_out( vproj0, vproj1 );\n"
10773 "\n"
10774 " gl_Position = vproj0;\n"
10775 " aColour = a_colour;\n"
10776 "}\n"
10777 ""},
10778 .fs =
10779 {
10780 .orig_file = "shaders/particle.fs",
10781 .static_src =
10782 "layout (location = 0) out vec4 oColour;\n"
10783 "in vec4 aColour;\n"
10784 "\n"
10785 "#line 1 1 \n"
10786 "const float k_motion_lerp_amount = 0.01;\n"
10787 "\n"
10788 "#line 2 0 \n"
10789 "\n"
10790 "layout (location = 1) out vec2 oMotionVec;\n"
10791 "\n"
10792 "in vec3 aMotionVec0;\n"
10793 "in vec3 aMotionVec1;\n"
10794 "\n"
10795 "void compute_motion_vectors()\n"
10796 "{\n"
10797 " // Write motion vectors\n"
10798 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10799 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10800 "\n"
10801 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10802 "}\n"
10803 "\n"
10804 "#line 5 0 \n"
10805 "\n"
10806 "void main(){\n"
10807 " compute_motion_vectors();\n"
10808 "\n"
10809 " //vec2 ssuv = gl_FragCoord.xy;\n"
10810 " //vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10811 " //float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10812 "\n"
10813 " //if( vsamplemain.a+dither<0.5 )\n"
10814 " // discard;\n"
10815 "\n"
10816 " oColour = aColour;\n"
10817 "}\n"
10818 ""},
10819 };
10820
10821 GLuint _uniform_particle_uPv;
10822 GLuint _uniform_particle_uPvPrev;
10823 #include "shaders/trail.h"
10824 struct vg_shader _shader_trail = {
10825 .name = "trail",
10826 .vs =
10827 {
10828 .orig_file = "shaders/trail.vs",
10829 .static_src =
10830 "layout (location=0) in vec4 a_co;\n"
10831 "\n"
10832 "#line 1 1 \n"
10833 "const float k_motion_lerp_amount = 0.01;\n"
10834 "\n"
10835 "#line 2 0 \n"
10836 "\n"
10837 "out vec3 aMotionVec0;\n"
10838 "out vec3 aMotionVec1;\n"
10839 "\n"
10840 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
10841 "{\n"
10842 " // This magically solves some artifacting errors!\n"
10843 " //\n"
10844 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
10845 "\n"
10846 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
10847 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
10848 "}\n"
10849 "\n"
10850 "#line 4 0 \n"
10851 "\n"
10852 "uniform mat4 uPv;\n"
10853 "uniform mat4 uPvPrev;\n"
10854 "\n"
10855 "out float aAlpha;\n"
10856 "\n"
10857 "void main(){\n"
10858 " vec4 vproj0 = uPv * vec4( a_co.xyz, 1.0 );\n"
10859 " vec4 vproj1 = uPvPrev * vec4( a_co.xyz, 1.0 );\n"
10860 " vs_motion_out( vproj0, vproj1 );\n"
10861 "\n"
10862 " gl_Position = vproj0;\n"
10863 " aAlpha = a_co.w;\n"
10864 "}\n"
10865 ""},
10866 .fs =
10867 {
10868 .orig_file = "shaders/trail.fs",
10869 .static_src =
10870 "layout (location = 0) out vec4 oColour;\n"
10871 "in float aAlpha;\n"
10872 "uniform vec4 uColour;\n"
10873 "\n"
10874 "#line 1 1 \n"
10875 "const float k_motion_lerp_amount = 0.01;\n"
10876 "\n"
10877 "#line 2 0 \n"
10878 "\n"
10879 "layout (location = 1) out vec2 oMotionVec;\n"
10880 "\n"
10881 "in vec3 aMotionVec0;\n"
10882 "in vec3 aMotionVec1;\n"
10883 "\n"
10884 "void compute_motion_vectors()\n"
10885 "{\n"
10886 " // Write motion vectors\n"
10887 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
10888 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
10889 "\n"
10890 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
10891 "}\n"
10892 "\n"
10893 "#line 6 0 \n"
10894 "\n"
10895 "void main(){\n"
10896 " compute_motion_vectors();\n"
10897 "\n"
10898 " vec2 ssuv = gl_FragCoord.xy;\n"
10899 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), ssuv) );\n"
10900 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
10901 "\n"
10902 " if( aAlpha+dither<0.5 )\n"
10903 " discard;\n"
10904 "\n"
10905 " oColour = vec4( uColour.rgb, uColour.a * aAlpha );\n"
10906 "}\n"
10907 ""},
10908 };
10909
10910 GLuint _uniform_trail_uPv;
10911 GLuint _uniform_trail_uPvPrev;
10912 GLuint _uniform_trail_uColour;
10913 #include "shaders/blit.h"
10914 struct vg_shader _shader_blit = {
10915 .name = "blit",
10916 .vs =
10917 {
10918 .orig_file = "shaders/blit.vs",
10919 .static_src =
10920 "layout (location=0) in vec2 a_co;\n"
10921 "out vec2 aUv;\n"
10922 "\n"
10923 "uniform vec2 uInverseRatio;\n"
10924 "\n"
10925 "void main()\n"
10926 "{\n"
10927 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
10928 " aUv = a_co * uInverseRatio;\n"
10929 "}\n"
10930 ""},
10931 .fs =
10932 {
10933 .orig_file = "shaders/blit.fs",
10934 .static_src =
10935 "out vec4 FragColor;\n"
10936 "uniform sampler2D uTexMain;\n"
10937 "\n"
10938 "in vec2 aUv;\n"
10939 "\n"
10940 "float kPi = 3.14159265358979;\n"
10941 "\n"
10942 "vec2 fisheye_distort(vec2 xy)\n"
10943 "{\n"
10944 " float aperture = 1350.0;\n"
10945 " float apertureHalf = 0.5 * aperture * (kPi / 180.0);\n"
10946 " float maxFactor = sin(apertureHalf);\n"
10947 "\n"
10948 " vec2 uv;\n"
10949 " float d = length(xy);\n"
10950 " if(d < (2.0-maxFactor))\n"
10951 " {\n"
10952 " d = length(xy * maxFactor);\n"
10953 " float z = sqrt(1.0 - d * d);\n"
10954 " float r = atan(d, z) / kPi;\n"
10955 " float phi = atan(xy.y, xy.x);\n"
10956 "\n"
10957 " uv.x = r * cos(phi) + 0.5;\n"
10958 " uv.y = r * sin(phi) + 0.5;\n"
10959 " }\n"
10960 " else\n"
10961 " {\n"
10962 " uv = 0.5*xy + 0.5;\n"
10963 " }\n"
10964 " \n"
10965 " return uv;\n"
10966 "}\n"
10967 "\n"
10968 "\n"
10969 "void main()\n"
10970 "{\n"
10971 " vec2 vwarp = 2.0*aUv - 1.0;\n"
10972 " vwarp = fisheye_distort( vwarp );\n"
10973 "\n"
10974 " FragColor = texture( uTexMain, aUv );\n"
10975 "}\n"
10976 ""},
10977 };
10978
10979 GLuint _uniform_blit_uInverseRatio;
10980 GLuint _uniform_blit_uTexMain;
10981 #include "shaders/blitblur.h"
10982 struct vg_shader _shader_blitblur = {
10983 .name = "blitblur",
10984 .vs =
10985 {
10986 .orig_file = "shaders/blit.vs",
10987 .static_src =
10988 "layout (location=0) in vec2 a_co;\n"
10989 "out vec2 aUv;\n"
10990 "\n"
10991 "uniform vec2 uInverseRatio;\n"
10992 "\n"
10993 "void main()\n"
10994 "{\n"
10995 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
10996 " aUv = a_co * uInverseRatio;\n"
10997 "}\n"
10998 ""},
10999 .fs =
11000 {
11001 .orig_file = "shaders/blitblur.fs",
11002 .static_src =
11003 "out vec4 FragColor;\n"
11004 "uniform sampler2D uTexMain;\n"
11005 "uniform sampler2D uTexMotion;\n"
11006 "uniform float uBlurStrength;\n"
11007 "uniform vec2 uOverrideDir;\n"
11008 "uniform float uTime;\n"
11009 "uniform float uGlitchStrength;\n"
11010 "uniform vec2 uClampUv;\n"
11011 "\n"
11012 "in vec2 aUv;\n"
11013 "\n"
11014 "vec2 rand_hash22( vec2 p ){\n"
11015 " vec3 p3 = fract(vec3(p.xyx) * 213.8976123);\n"
11016 " p3 += dot(p3, p3.yzx+19.19);\n"
11017 " return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y));\n"
11018 "}\n"
11019 "\n"
11020 "const int NOISE_LOOP = 3;\n"
11021 "vec3 digital_noise( uvec3 iuv ){\n"
11022 " iuv *=uvec3(8,2524,7552);\n"
11023 " for( int i=0; i<NOISE_LOOP; i++ )\n"
11024 " iuv += (iuv.yzx<<2) ^ (iuv.yxz)+iuv.z;\n"
11025 " return vec3(iuv)*(1.0/float(0xffffffffU));\n"
11026 "}\n"
11027 "\n"
11028 "void main(){\n"
11029 " vec2 vuv = aUv; \n"
11030 "\n"
11031 " //if( uGlitchStrength > 0.0 ){\n"
11032 " // uvec3 p = uvec3( gl_FragCoord.xy, uint(uTime*30.0) );\n"
11033 " // vec2 g = digital_noise(p).xy;\n"
11034 " // vuv = aUv + g.xy*uGlitchStrength - uGlitchStrength*0.5;\n"
11035 " //}\n"
11036 "\n"
11037 " vec2 vrand = rand_hash22( vuv ) * 2.0 - vec2(1.0);\n"
11038 " vec2 vrand1 = rand_hash22( vrand ) * 2.0 - vec2(1.0);\n"
11039 " \n"
11040 " vec2 vdir = texture( uTexMotion, vuv ).xy * uBlurStrength + uOverrideDir;\n"
11041 "\n"
11042 " vec4 vcolour0 = texture( uTexMain, min(vuv + vdir*vrand.x,uClampUv) );\n"
11043 " vec4 vcolour1 = texture( uTexMain, min(vuv + vdir*vrand.y,uClampUv) );\n"
11044 " vec4 vcolour2 = texture( uTexMain, min(vuv + vdir*vrand1.x,uClampUv) );\n"
11045 " vec4 vcolour3 = texture( uTexMain, min(vuv + vdir*vrand1.y,uClampUv) );\n"
11046 "\n"
11047 " FragColor = ( vcolour0 + vcolour1 + vcolour2 + vcolour3 ) * 0.25;\n"
11048 "}\n"
11049 ""},
11050 };
11051
11052 GLuint _uniform_blitblur_uInverseRatio;
11053 GLuint _uniform_blitblur_uTexMain;
11054 GLuint _uniform_blitblur_uTexMotion;
11055 GLuint _uniform_blitblur_uBlurStrength;
11056 GLuint _uniform_blitblur_uOverrideDir;
11057 GLuint _uniform_blitblur_uTime;
11058 GLuint _uniform_blitblur_uGlitchStrength;
11059 GLuint _uniform_blitblur_uClampUv;
11060 #include "shaders/blitcolour.h"
11061 struct vg_shader _shader_blitcolour = {
11062 .name = "blitcolour",
11063 .vs =
11064 {
11065 .orig_file = "shaders/blit.vs",
11066 .static_src =
11067 "layout (location=0) in vec2 a_co;\n"
11068 "out vec2 aUv;\n"
11069 "\n"
11070 "uniform vec2 uInverseRatio;\n"
11071 "\n"
11072 "void main()\n"
11073 "{\n"
11074 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
11075 " aUv = a_co * uInverseRatio;\n"
11076 "}\n"
11077 ""},
11078 .fs =
11079 {
11080 .orig_file = "shaders/colour.fs",
11081 .static_src =
11082 "out vec4 FragColor;\n"
11083 "uniform vec4 uColour;\n"
11084 "\n"
11085 "in vec2 aUv;\n"
11086 "\n"
11087 "void main()\n"
11088 "{\n"
11089 " FragColor = uColour;\n"
11090 "}\n"
11091 ""},
11092 };
11093
11094 GLuint _uniform_blitcolour_uInverseRatio;
11095 GLuint _uniform_blitcolour_uColour;
11096 #include "shaders/blit_transition.h"
11097 struct vg_shader _shader_blit_transition = {
11098 .name = "blit_transition",
11099 .vs =
11100 {
11101 .orig_file = "shaders/blit.vs",
11102 .static_src =
11103 "layout (location=0) in vec2 a_co;\n"
11104 "out vec2 aUv;\n"
11105 "\n"
11106 "uniform vec2 uInverseRatio;\n"
11107 "\n"
11108 "void main()\n"
11109 "{\n"
11110 " gl_Position = vec4(a_co*2.0-1.0,0.0,1.0);\n"
11111 " aUv = a_co * uInverseRatio;\n"
11112 "}\n"
11113 ""},
11114 .fs =
11115 {
11116 .orig_file = "shaders/blit_transition.fs",
11117 .static_src =
11118 "out vec4 FragColor;\n"
11119 "in vec2 aUv;\n"
11120 "uniform float uT;\n"
11121 "\n"
11122 "void main(){\n"
11123 " float d = uT + distance( aUv, vec2(0.5,0.5) );\n"
11124 "\n"
11125 " vec3 vDither = vec3( dot( vec2( 171.0, 231.0 ), gl_FragCoord.xy) );\n"
11126 " float dither = fract( vDither.g / 71.0 ) - 0.5;\n"
11127 "\n"
11128 " if( d+dither < -0.5 )\n"
11129 " discard;\n"
11130 "\n"
11131 " FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n"
11132 "}\n"
11133 ""},
11134 };
11135
11136 GLuint _uniform_blit_transition_uInverseRatio;
11137 GLuint _uniform_blit_transition_uT;
11138 #include "shaders/routeui.h"
11139 struct vg_shader _shader_routeui = {
11140 .name = "routeui",
11141 .vs =
11142 {
11143 .orig_file = "shaders/routeui.vs",
11144 .static_src =
11145 "layout (location=0) in vec2 a_co;\n"
11146 "\n"
11147 "uniform vec4 uOffset;\n"
11148 "\n"
11149 "void main()\n"
11150 "{\n"
11151 " vec2 vpos = a_co * uOffset.zw + uOffset.xy;\n"
11152 " gl_Position = vec4(vpos,0.0,1.0);\n"
11153 "}\n"
11154 ""},
11155 .fs =
11156 {
11157 .orig_file = "shaders/routeui.fs",
11158 .static_src =
11159 "out vec4 FragColor;\n"
11160 "\n"
11161 "uniform vec4 uColour;\n"
11162 "\n"
11163 "void main()\n"
11164 "{\n"
11165 " FragColor = uColour;\n"
11166 "}\n"
11167 ""},
11168 };
11169
11170 GLuint _uniform_routeui_uOffset;
11171 GLuint _uniform_routeui_uColour;
11172
11173
11174 void vg_auto_shader_link(void)
11175 {
11176 _uniform_scene_standard_uMdl = glGetUniformLocation( _shader_scene_standard.id, "uMdl" );
11177 _uniform_scene_standard_uPv = glGetUniformLocation( _shader_scene_standard.id, "uPv" );
11178 _uniform_scene_standard_uPvmPrev = glGetUniformLocation( _shader_scene_standard.id, "uPvmPrev" );
11179 _uniform_scene_standard_uTexGarbage = glGetUniformLocation( _shader_scene_standard.id, "uTexGarbage" );
11180 _uniform_scene_standard_uTexMain = glGetUniformLocation( _shader_scene_standard.id, "uTexMain" );
11181 _uniform_scene_standard_uCamera = glGetUniformLocation( _shader_scene_standard.id, "uCamera" );
11182 _uniform_scene_standard_uPlane = glGetUniformLocation( _shader_scene_standard.id, "uPlane" );
11183 _uniform_scene_standard_g_world_depth = glGetUniformLocation( _shader_scene_standard.id, "g_world_depth" );
11184 _uniform_scene_standard_uLightsArray = glGetUniformLocation( _shader_scene_standard.id, "uLightsArray" );
11185 _uniform_scene_standard_uLightsIndex = glGetUniformLocation( _shader_scene_standard.id, "uLightsIndex" );
11186 _uniform_scene_standard_alphatest_uMdl = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uMdl" );
11187 _uniform_scene_standard_alphatest_uPv = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPv" );
11188 _uniform_scene_standard_alphatest_uPvmPrev = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPvmPrev" );
11189 _uniform_scene_standard_alphatest_uTexGarbage = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uTexGarbage" );
11190 _uniform_scene_standard_alphatest_uTexMain = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uTexMain" );
11191 _uniform_scene_standard_alphatest_uCamera = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uCamera" );
11192 _uniform_scene_standard_alphatest_uPlane = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uPlane" );
11193 _uniform_scene_standard_alphatest_g_world_depth = glGetUniformLocation( _shader_scene_standard_alphatest.id, "g_world_depth" );
11194 _uniform_scene_standard_alphatest_uLightsArray = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uLightsArray" );
11195 _uniform_scene_standard_alphatest_uLightsIndex = glGetUniformLocation( _shader_scene_standard_alphatest.id, "uLightsIndex" );
11196 _uniform_scene_foliage_uMdl = glGetUniformLocation( _shader_scene_foliage.id, "uMdl" );
11197 _uniform_scene_foliage_uPv = glGetUniformLocation( _shader_scene_foliage.id, "uPv" );
11198 _uniform_scene_foliage_uPvmPrev = glGetUniformLocation( _shader_scene_foliage.id, "uPvmPrev" );
11199 _uniform_scene_foliage_uTime = glGetUniformLocation( _shader_scene_foliage.id, "uTime" );
11200 _uniform_scene_foliage_uTexGarbage = glGetUniformLocation( _shader_scene_foliage.id, "uTexGarbage" );
11201 _uniform_scene_foliage_uTexMain = glGetUniformLocation( _shader_scene_foliage.id, "uTexMain" );
11202 _uniform_scene_foliage_uCamera = glGetUniformLocation( _shader_scene_foliage.id, "uCamera" );
11203 _uniform_scene_foliage_uPlane = glGetUniformLocation( _shader_scene_foliage.id, "uPlane" );
11204 _uniform_scene_foliage_g_world_depth = glGetUniformLocation( _shader_scene_foliage.id, "g_world_depth" );
11205 _uniform_scene_foliage_uLightsArray = glGetUniformLocation( _shader_scene_foliage.id, "uLightsArray" );
11206 _uniform_scene_foliage_uLightsIndex = glGetUniformLocation( _shader_scene_foliage.id, "uLightsIndex" );
11207 _uniform_scene_override_uMdl = glGetUniformLocation( _shader_scene_override.id, "uMdl" );
11208 _uniform_scene_override_uPv = glGetUniformLocation( _shader_scene_override.id, "uPv" );
11209 _uniform_scene_override_uPvmPrev = glGetUniformLocation( _shader_scene_override.id, "uPvmPrev" );
11210 _uniform_scene_override_uNormalMtx = glGetUniformLocation( _shader_scene_override.id, "uNormalMtx" );
11211 _uniform_scene_override_uTexGarbage = glGetUniformLocation( _shader_scene_override.id, "uTexGarbage" );
11212 _uniform_scene_override_uTexMain = glGetUniformLocation( _shader_scene_override.id, "uTexMain" );
11213 _uniform_scene_override_uCamera = glGetUniformLocation( _shader_scene_override.id, "uCamera" );
11214 _uniform_scene_override_uPlane = glGetUniformLocation( _shader_scene_override.id, "uPlane" );
11215 _uniform_scene_override_uPlayerPos = glGetUniformLocation( _shader_scene_override.id, "uPlayerPos" );
11216 _uniform_scene_override_uSpawnPos = glGetUniformLocation( _shader_scene_override.id, "uSpawnPos" );
11217 _uniform_scene_override_uAlphatest = glGetUniformLocation( _shader_scene_override.id, "uAlphatest" );
11218 _uniform_scene_override_uMapInfo = glGetUniformLocation( _shader_scene_override.id, "uMapInfo" );
11219 _uniform_scene_override_g_world_depth = glGetUniformLocation( _shader_scene_override.id, "g_world_depth" );
11220 _uniform_scene_override_uLightsArray = glGetUniformLocation( _shader_scene_override.id, "uLightsArray" );
11221 _uniform_scene_override_uLightsIndex = glGetUniformLocation( _shader_scene_override.id, "uLightsIndex" );
11222 _uniform_scene_fxglow_uMdl = glGetUniformLocation( _shader_scene_fxglow.id, "uMdl" );
11223 _uniform_scene_fxglow_uPv = glGetUniformLocation( _shader_scene_fxglow.id, "uPv" );
11224 _uniform_scene_fxglow_uPvmPrev = glGetUniformLocation( _shader_scene_fxglow.id, "uPvmPrev" );
11225 _uniform_scene_fxglow_uUvOffset = glGetUniformLocation( _shader_scene_fxglow.id, "uUvOffset" );
11226 _uniform_scene_fxglow_uTexMain = glGetUniformLocation( _shader_scene_fxglow.id, "uTexMain" );
11227 _uniform_scene_fxglow_uCamera = glGetUniformLocation( _shader_scene_fxglow.id, "uCamera" );
11228 _uniform_scene_fxglow_g_world_depth = glGetUniformLocation( _shader_scene_fxglow.id, "g_world_depth" );
11229 _uniform_scene_fxglow_uLightsArray = glGetUniformLocation( _shader_scene_fxglow.id, "uLightsArray" );
11230 _uniform_scene_fxglow_uLightsIndex = glGetUniformLocation( _shader_scene_fxglow.id, "uLightsIndex" );
11231 _uniform_scene_vertex_blend_uMdl = glGetUniformLocation( _shader_scene_vertex_blend.id, "uMdl" );
11232 _uniform_scene_vertex_blend_uPv = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPv" );
11233 _uniform_scene_vertex_blend_uPvmPrev = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPvmPrev" );
11234 _uniform_scene_vertex_blend_uTexGarbage = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGarbage" );
11235 _uniform_scene_vertex_blend_uTexGradients = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGradients" );
11236 _uniform_scene_vertex_blend_uCamera = glGetUniformLocation( _shader_scene_vertex_blend.id, "uCamera" );
11237 _uniform_scene_vertex_blend_g_world_depth = glGetUniformLocation( _shader_scene_vertex_blend.id, "g_world_depth" );
11238 _uniform_scene_vertex_blend_uLightsArray = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsArray" );
11239 _uniform_scene_vertex_blend_uLightsIndex = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsIndex" );
11240 _uniform_scene_terrain_uMdl = glGetUniformLocation( _shader_scene_terrain.id, "uMdl" );
11241 _uniform_scene_terrain_uPv = glGetUniformLocation( _shader_scene_terrain.id, "uPv" );
11242 _uniform_scene_terrain_uPvmPrev = glGetUniformLocation( _shader_scene_terrain.id, "uPvmPrev" );
11243 _uniform_scene_terrain_uTexGarbage = glGetUniformLocation( _shader_scene_terrain.id, "uTexGarbage" );
11244 _uniform_scene_terrain_uTexGradients = glGetUniformLocation( _shader_scene_terrain.id, "uTexGradients" );
11245 _uniform_scene_terrain_uCamera = glGetUniformLocation( _shader_scene_terrain.id, "uCamera" );
11246 _uniform_scene_terrain_uSandColour = glGetUniformLocation( _shader_scene_terrain.id, "uSandColour" );
11247 _uniform_scene_terrain_uBlendOffset = glGetUniformLocation( _shader_scene_terrain.id, "uBlendOffset" );
11248 _uniform_scene_terrain_g_world_depth = glGetUniformLocation( _shader_scene_terrain.id, "g_world_depth" );
11249 _uniform_scene_terrain_uLightsArray = glGetUniformLocation( _shader_scene_terrain.id, "uLightsArray" );
11250 _uniform_scene_terrain_uLightsIndex = glGetUniformLocation( _shader_scene_terrain.id, "uLightsIndex" );
11251 _uniform_scene_route_uMdl = glGetUniformLocation( _shader_scene_route.id, "uMdl" );
11252 _uniform_scene_route_uPv = glGetUniformLocation( _shader_scene_route.id, "uPv" );
11253 _uniform_scene_route_uPvmPrev = glGetUniformLocation( _shader_scene_route.id, "uPvmPrev" );
11254 _uniform_scene_route_uNormalMtx = glGetUniformLocation( _shader_scene_route.id, "uNormalMtx" );
11255 _uniform_scene_route_uTexGarbage = glGetUniformLocation( _shader_scene_route.id, "uTexGarbage" );
11256 _uniform_scene_route_uTexGradients = glGetUniformLocation( _shader_scene_route.id, "uTexGradients" );
11257 _uniform_scene_route_uCamera = glGetUniformLocation( _shader_scene_route.id, "uCamera" );
11258 _uniform_scene_route_uColour = glGetUniformLocation( _shader_scene_route.id, "uColour" );
11259 _uniform_scene_route_g_world_depth = glGetUniformLocation( _shader_scene_route.id, "g_world_depth" );
11260 _uniform_scene_route_uLightsArray = glGetUniformLocation( _shader_scene_route.id, "uLightsArray" );
11261 _uniform_scene_route_uLightsIndex = glGetUniformLocation( _shader_scene_route.id, "uLightsIndex" );
11262 _uniform_scene_depth_uMdl = glGetUniformLocation( _shader_scene_depth.id, "uMdl" );
11263 _uniform_scene_depth_uPv = glGetUniformLocation( _shader_scene_depth.id, "uPv" );
11264 _uniform_scene_depth_uPvmPrev = glGetUniformLocation( _shader_scene_depth.id, "uPvmPrev" );
11265 _uniform_scene_depth_uCamera = glGetUniformLocation( _shader_scene_depth.id, "uCamera" );
11266 _uniform_scene_depth_uBoard0 = glGetUniformLocation( _shader_scene_depth.id, "uBoard0" );
11267 _uniform_scene_depth_uBoard1 = glGetUniformLocation( _shader_scene_depth.id, "uBoard1" );
11268 _uniform_scene_depth_g_world_depth = glGetUniformLocation( _shader_scene_depth.id, "g_world_depth" );
11269 _uniform_scene_depth_uLightsArray = glGetUniformLocation( _shader_scene_depth.id, "uLightsArray" );
11270 _uniform_scene_depth_uLightsIndex = glGetUniformLocation( _shader_scene_depth.id, "uLightsIndex" );
11271 _uniform_scene_position_uMdl = glGetUniformLocation( _shader_scene_position.id, "uMdl" );
11272 _uniform_scene_position_uPv = glGetUniformLocation( _shader_scene_position.id, "uPv" );
11273 _uniform_scene_position_uPvmPrev = glGetUniformLocation( _shader_scene_position.id, "uPvmPrev" );
11274 _uniform_scene_position_uCamera = glGetUniformLocation( _shader_scene_position.id, "uCamera" );
11275 _uniform_scene_position_uBoard0 = glGetUniformLocation( _shader_scene_position.id, "uBoard0" );
11276 _uniform_scene_position_uBoard1 = glGetUniformLocation( _shader_scene_position.id, "uBoard1" );
11277 _uniform_scene_position_g_world_depth = glGetUniformLocation( _shader_scene_position.id, "g_world_depth" );
11278 _uniform_scene_position_uLightsArray = glGetUniformLocation( _shader_scene_position.id, "uLightsArray" );
11279 _uniform_scene_position_uLightsIndex = glGetUniformLocation( _shader_scene_position.id, "uLightsIndex" );
11280 _uniform_scene_cubemapped_uMdl = glGetUniformLocation( _shader_scene_cubemapped.id, "uMdl" );
11281 _uniform_scene_cubemapped_uPv = glGetUniformLocation( _shader_scene_cubemapped.id, "uPv" );
11282 _uniform_scene_cubemapped_uPvmPrev = glGetUniformLocation( _shader_scene_cubemapped.id, "uPvmPrev" );
11283 _uniform_scene_cubemapped_uTexGarbage = glGetUniformLocation( _shader_scene_cubemapped.id, "uTexGarbage" );
11284 _uniform_scene_cubemapped_uTexMain = glGetUniformLocation( _shader_scene_cubemapped.id, "uTexMain" );
11285 _uniform_scene_cubemapped_uTexCubemap = glGetUniformLocation( _shader_scene_cubemapped.id, "uTexCubemap" );
11286 _uniform_scene_cubemapped_uCamera = glGetUniformLocation( _shader_scene_cubemapped.id, "uCamera" );
11287 _uniform_scene_cubemapped_uPlane = glGetUniformLocation( _shader_scene_cubemapped.id, "uPlane" );
11288 _uniform_scene_cubemapped_uColour = glGetUniformLocation( _shader_scene_cubemapped.id, "uColour" );
11289 _uniform_scene_cubemapped_g_world_depth = glGetUniformLocation( _shader_scene_cubemapped.id, "g_world_depth" );
11290 _uniform_scene_cubemapped_uLightsArray = glGetUniformLocation( _shader_scene_cubemapped.id, "uLightsArray" );
11291 _uniform_scene_cubemapped_uLightsIndex = glGetUniformLocation( _shader_scene_cubemapped.id, "uLightsIndex" );
11292 _uniform_scene_water_uMdl = glGetUniformLocation( _shader_scene_water.id, "uMdl" );
11293 _uniform_scene_water_uPv = glGetUniformLocation( _shader_scene_water.id, "uPv" );
11294 _uniform_scene_water_uPvmPrev = glGetUniformLocation( _shader_scene_water.id, "uPvmPrev" );
11295 _uniform_scene_water_uTexMain = glGetUniformLocation( _shader_scene_water.id, "uTexMain" );
11296 _uniform_scene_water_uTexDudv = glGetUniformLocation( _shader_scene_water.id, "uTexDudv" );
11297 _uniform_scene_water_uTexBack = glGetUniformLocation( _shader_scene_water.id, "uTexBack" );
11298 _uniform_scene_water_uInvRes = glGetUniformLocation( _shader_scene_water.id, "uInvRes" );
11299 _uniform_scene_water_uTime = glGetUniformLocation( _shader_scene_water.id, "uTime" );
11300 _uniform_scene_water_uCamera = glGetUniformLocation( _shader_scene_water.id, "uCamera" );
11301 _uniform_scene_water_uSurfaceY = glGetUniformLocation( _shader_scene_water.id, "uSurfaceY" );
11302 _uniform_scene_water_uBoard0 = glGetUniformLocation( _shader_scene_water.id, "uBoard0" );
11303 _uniform_scene_water_uBoard1 = glGetUniformLocation( _shader_scene_water.id, "uBoard1" );
11304 _uniform_scene_water_uShoreColour = glGetUniformLocation( _shader_scene_water.id, "uShoreColour" );
11305 _uniform_scene_water_uOceanColour = glGetUniformLocation( _shader_scene_water.id, "uOceanColour" );
11306 _uniform_scene_water_uFresnel = glGetUniformLocation( _shader_scene_water.id, "uFresnel" );
11307 _uniform_scene_water_uWaterScale = glGetUniformLocation( _shader_scene_water.id, "uWaterScale" );
11308 _uniform_scene_water_uWaveSpeed = glGetUniformLocation( _shader_scene_water.id, "uWaveSpeed" );
11309 _uniform_scene_water_g_world_depth = glGetUniformLocation( _shader_scene_water.id, "g_world_depth" );
11310 _uniform_scene_water_uLightsArray = glGetUniformLocation( _shader_scene_water.id, "uLightsArray" );
11311 _uniform_scene_water_uLightsIndex = glGetUniformLocation( _shader_scene_water.id, "uLightsIndex" );
11312 _uniform_scene_water_fast_uMdl = glGetUniformLocation( _shader_scene_water_fast.id, "uMdl" );
11313 _uniform_scene_water_fast_uPv = glGetUniformLocation( _shader_scene_water_fast.id, "uPv" );
11314 _uniform_scene_water_fast_uPvmPrev = glGetUniformLocation( _shader_scene_water_fast.id, "uPvmPrev" );
11315 _uniform_scene_water_fast_uTexDudv = glGetUniformLocation( _shader_scene_water_fast.id, "uTexDudv" );
11316 _uniform_scene_water_fast_uTime = glGetUniformLocation( _shader_scene_water_fast.id, "uTime" );
11317 _uniform_scene_water_fast_uCamera = glGetUniformLocation( _shader_scene_water_fast.id, "uCamera" );
11318 _uniform_scene_water_fast_uSurfaceY = glGetUniformLocation( _shader_scene_water_fast.id, "uSurfaceY" );
11319 _uniform_scene_water_fast_uBoard0 = glGetUniformLocation( _shader_scene_water_fast.id, "uBoard0" );
11320 _uniform_scene_water_fast_uBoard1 = glGetUniformLocation( _shader_scene_water_fast.id, "uBoard1" );
11321 _uniform_scene_water_fast_uShoreColour = glGetUniformLocation( _shader_scene_water_fast.id, "uShoreColour" );
11322 _uniform_scene_water_fast_uOceanColour = glGetUniformLocation( _shader_scene_water_fast.id, "uOceanColour" );
11323 _uniform_scene_water_fast_g_world_depth = glGetUniformLocation( _shader_scene_water_fast.id, "g_world_depth" );
11324 _uniform_scene_water_fast_uLightsArray = glGetUniformLocation( _shader_scene_water_fast.id, "uLightsArray" );
11325 _uniform_scene_water_fast_uLightsIndex = glGetUniformLocation( _shader_scene_water_fast.id, "uLightsIndex" );
11326 _uniform_scene_scoretext_uMdl = glGetUniformLocation( _shader_scene_scoretext.id, "uMdl" );
11327 _uniform_scene_scoretext_uPv = glGetUniformLocation( _shader_scene_scoretext.id, "uPv" );
11328 _uniform_scene_scoretext_uPvmPrev = glGetUniformLocation( _shader_scene_scoretext.id, "uPvmPrev" );
11329 _uniform_scene_scoretext_uInfo = glGetUniformLocation( _shader_scene_scoretext.id, "uInfo" );
11330 _uniform_scene_scoretext_uTexGarbage = glGetUniformLocation( _shader_scene_scoretext.id, "uTexGarbage" );
11331 _uniform_scene_scoretext_uTexMain = glGetUniformLocation( _shader_scene_scoretext.id, "uTexMain" );
11332 _uniform_scene_scoretext_uCamera = glGetUniformLocation( _shader_scene_scoretext.id, "uCamera" );
11333 _uniform_scene_scoretext_uPlane = glGetUniformLocation( _shader_scene_scoretext.id, "uPlane" );
11334 _uniform_scene_scoretext_g_world_depth = glGetUniformLocation( _shader_scene_scoretext.id, "g_world_depth" );
11335 _uniform_scene_scoretext_uLightsArray = glGetUniformLocation( _shader_scene_scoretext.id, "uLightsArray" );
11336 _uniform_scene_scoretext_uLightsIndex = glGetUniformLocation( _shader_scene_scoretext.id, "uLightsIndex" );
11337 _uniform_scene_font_uMdl = glGetUniformLocation( _shader_scene_font.id, "uMdl" );
11338 _uniform_scene_font_uPv = glGetUniformLocation( _shader_scene_font.id, "uPv" );
11339 _uniform_scene_font_uPvmPrev = glGetUniformLocation( _shader_scene_font.id, "uPvmPrev" );
11340 _uniform_scene_font_uOffset = glGetUniformLocation( _shader_scene_font.id, "uOffset" );
11341 _uniform_scene_font_uTexGarbage = glGetUniformLocation( _shader_scene_font.id, "uTexGarbage" );
11342 _uniform_scene_font_uTexMain = glGetUniformLocation( _shader_scene_font.id, "uTexMain" );
11343 _uniform_scene_font_uCamera = glGetUniformLocation( _shader_scene_font.id, "uCamera" );
11344 _uniform_scene_font_uTime = glGetUniformLocation( _shader_scene_font.id, "uTime" );
11345 _uniform_scene_font_uOpacity = glGetUniformLocation( _shader_scene_font.id, "uOpacity" );
11346 _uniform_scene_font_uColourize = glGetUniformLocation( _shader_scene_font.id, "uColourize" );
11347 _uniform_scene_font_g_world_depth = glGetUniformLocation( _shader_scene_font.id, "g_world_depth" );
11348 _uniform_scene_font_uLightsArray = glGetUniformLocation( _shader_scene_font.id, "uLightsArray" );
11349 _uniform_scene_font_uLightsIndex = glGetUniformLocation( _shader_scene_font.id, "uLightsIndex" );
11350 _uniform_model_sky_uMdl = glGetUniformLocation( _shader_model_sky.id, "uMdl" );
11351 _uniform_model_sky_uPv = glGetUniformLocation( _shader_model_sky.id, "uPv" );
11352 _uniform_model_sky_uPvmPrev = glGetUniformLocation( _shader_model_sky.id, "uPvmPrev" );
11353 _uniform_model_sky_uTexGarbage = glGetUniformLocation( _shader_model_sky.id, "uTexGarbage" );
11354 _uniform_model_sky_g_world_depth = glGetUniformLocation( _shader_model_sky.id, "g_world_depth" );
11355 _uniform_model_sky_uLightsArray = glGetUniformLocation( _shader_model_sky.id, "uLightsArray" );
11356 _uniform_model_sky_uLightsIndex = glGetUniformLocation( _shader_model_sky.id, "uLightsIndex" );
11357 _uniform_model_sky_space_uMdl = glGetUniformLocation( _shader_model_sky_space.id, "uMdl" );
11358 _uniform_model_sky_space_uPv = glGetUniformLocation( _shader_model_sky_space.id, "uPv" );
11359 _uniform_model_sky_space_uPvmPrev = glGetUniformLocation( _shader_model_sky_space.id, "uPvmPrev" );
11360 _uniform_model_sky_space_uTexGarbage = glGetUniformLocation( _shader_model_sky_space.id, "uTexGarbage" );
11361 _uniform_model_sky_space_g_world_depth = glGetUniformLocation( _shader_model_sky_space.id, "g_world_depth" );
11362 _uniform_model_sky_space_uLightsArray = glGetUniformLocation( _shader_model_sky_space.id, "uLightsArray" );
11363 _uniform_model_sky_space_uLightsIndex = glGetUniformLocation( _shader_model_sky_space.id, "uLightsIndex" );
11364 _uniform_model_menu_uMdl = glGetUniformLocation( _shader_model_menu.id, "uMdl" );
11365 _uniform_model_menu_uPv = glGetUniformLocation( _shader_model_menu.id, "uPv" );
11366 _uniform_model_menu_uPvmPrev = glGetUniformLocation( _shader_model_menu.id, "uPvmPrev" );
11367 _uniform_model_menu_uTexMain = glGetUniformLocation( _shader_model_menu.id, "uTexMain" );
11368 _uniform_model_menu_uColour = glGetUniformLocation( _shader_model_menu.id, "uColour" );
11369 _uniform_model_character_view_uPv = glGetUniformLocation( _shader_model_character_view.id, "uPv" );
11370 _uniform_model_character_view_uTransforms = glGetUniformLocation( _shader_model_character_view.id, "uTransforms" );
11371 _uniform_model_character_view_uTexMain = glGetUniformLocation( _shader_model_character_view.id, "uTexMain" );
11372 _uniform_model_character_view_uCamera = glGetUniformLocation( _shader_model_character_view.id, "uCamera" );
11373 _uniform_model_character_view_g_world_depth = glGetUniformLocation( _shader_model_character_view.id, "g_world_depth" );
11374 _uniform_model_character_view_uLightsArray = glGetUniformLocation( _shader_model_character_view.id, "uLightsArray" );
11375 _uniform_model_character_view_uLightsIndex = glGetUniformLocation( _shader_model_character_view.id, "uLightsIndex" );
11376 _uniform_model_character_view_uTexSceneDepth = glGetUniformLocation( _shader_model_character_view.id, "uTexSceneDepth" );
11377 _uniform_model_character_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioDepth" );
11378 _uniform_model_character_view_uInverseRatioMain = glGetUniformLocation( _shader_model_character_view.id, "uInverseRatioMain" );
11379 _uniform_model_character_view_uDepthMode = glGetUniformLocation( _shader_model_character_view.id, "uDepthMode" );
11380 _uniform_model_character_view_uDitherCutoff = glGetUniformLocation( _shader_model_character_view.id, "uDitherCutoff" );
11381 _uniform_model_board_view_uMdl = glGetUniformLocation( _shader_model_board_view.id, "uMdl" );
11382 _uniform_model_board_view_uPv = glGetUniformLocation( _shader_model_board_view.id, "uPv" );
11383 _uniform_model_board_view_uPvmPrev = glGetUniformLocation( _shader_model_board_view.id, "uPvmPrev" );
11384 _uniform_model_board_view_uTexMain = glGetUniformLocation( _shader_model_board_view.id, "uTexMain" );
11385 _uniform_model_board_view_uCamera = glGetUniformLocation( _shader_model_board_view.id, "uCamera" );
11386 _uniform_model_board_view_g_world_depth = glGetUniformLocation( _shader_model_board_view.id, "g_world_depth" );
11387 _uniform_model_board_view_uLightsArray = glGetUniformLocation( _shader_model_board_view.id, "uLightsArray" );
11388 _uniform_model_board_view_uLightsIndex = glGetUniformLocation( _shader_model_board_view.id, "uLightsIndex" );
11389 _uniform_model_board_view_uTexSceneDepth = glGetUniformLocation( _shader_model_board_view.id, "uTexSceneDepth" );
11390 _uniform_model_board_view_uInverseRatioDepth = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioDepth" );
11391 _uniform_model_board_view_uInverseRatioMain = glGetUniformLocation( _shader_model_board_view.id, "uInverseRatioMain" );
11392 _uniform_model_board_view_uDepthMode = glGetUniformLocation( _shader_model_board_view.id, "uDepthMode" );
11393 _uniform_model_board_view_uDitherCutoff = glGetUniformLocation( _shader_model_board_view.id, "uDitherCutoff" );
11394 _uniform_model_entity_uMdl = glGetUniformLocation( _shader_model_entity.id, "uMdl" );
11395 _uniform_model_entity_uPv = glGetUniformLocation( _shader_model_entity.id, "uPv" );
11396 _uniform_model_entity_uPvmPrev = glGetUniformLocation( _shader_model_entity.id, "uPvmPrev" );
11397 _uniform_model_entity_uTexMain = glGetUniformLocation( _shader_model_entity.id, "uTexMain" );
11398 _uniform_model_entity_uCamera = glGetUniformLocation( _shader_model_entity.id, "uCamera" );
11399 _uniform_model_entity_g_world_depth = glGetUniformLocation( _shader_model_entity.id, "g_world_depth" );
11400 _uniform_model_entity_uLightsArray = glGetUniformLocation( _shader_model_entity.id, "uLightsArray" );
11401 _uniform_model_entity_uLightsIndex = glGetUniformLocation( _shader_model_entity.id, "uLightsIndex" );
11402 _uniform_model_gate_uMdl = glGetUniformLocation( _shader_model_gate.id, "uMdl" );
11403 _uniform_model_gate_uPv = glGetUniformLocation( _shader_model_gate.id, "uPv" );
11404 _uniform_model_gate_uPvmPrev = glGetUniformLocation( _shader_model_gate.id, "uPvmPrev" );
11405 _uniform_model_gate_uTime = glGetUniformLocation( _shader_model_gate.id, "uTime" );
11406 _uniform_model_gate_uCam = glGetUniformLocation( _shader_model_gate.id, "uCam" );
11407 _uniform_model_gate_uInvRes = glGetUniformLocation( _shader_model_gate.id, "uInvRes" );
11408 _uniform_model_gate_uColour = glGetUniformLocation( _shader_model_gate.id, "uColour" );
11409 _uniform_model_gate_unlinked_uMdl = glGetUniformLocation( _shader_model_gate_unlinked.id, "uMdl" );
11410 _uniform_model_gate_unlinked_uPv = glGetUniformLocation( _shader_model_gate_unlinked.id, "uPv" );
11411 _uniform_model_gate_unlinked_uPvmPrev = glGetUniformLocation( _shader_model_gate_unlinked.id, "uPvmPrev" );
11412 _uniform_model_gate_unlinked_uTime = glGetUniformLocation( _shader_model_gate_unlinked.id, "uTime" );
11413 _uniform_model_gate_unlinked_uCam = glGetUniformLocation( _shader_model_gate_unlinked.id, "uCam" );
11414 _uniform_model_gate_unlinked_uColour = glGetUniformLocation( _shader_model_gate_unlinked.id, "uColour" );
11415 _uniform_model_font_uMdl = glGetUniformLocation( _shader_model_font.id, "uMdl" );
11416 _uniform_model_font_uPv = glGetUniformLocation( _shader_model_font.id, "uPv" );
11417 _uniform_model_font_uPvmPrev = glGetUniformLocation( _shader_model_font.id, "uPvmPrev" );
11418 _uniform_model_font_uOffset = glGetUniformLocation( _shader_model_font.id, "uOffset" );
11419 _uniform_model_font_uTexMain = glGetUniformLocation( _shader_model_font.id, "uTexMain" );
11420 _uniform_model_font_uColour = glGetUniformLocation( _shader_model_font.id, "uColour" );
11421 _uniform_model_font_uTexSceneDepth = glGetUniformLocation( _shader_model_font.id, "uTexSceneDepth" );
11422 _uniform_model_font_uInverseRatioDepth = glGetUniformLocation( _shader_model_font.id, "uInverseRatioDepth" );
11423 _uniform_model_font_uInverseRatioMain = glGetUniformLocation( _shader_model_font.id, "uInverseRatioMain" );
11424 _uniform_model_font_uDepthMode = glGetUniformLocation( _shader_model_font.id, "uDepthMode" );
11425 _uniform_model_font_uDitherCutoff = glGetUniformLocation( _shader_model_font.id, "uDitherCutoff" );
11426 _uniform_particle_uPv = glGetUniformLocation( _shader_particle.id, "uPv" );
11427 _uniform_particle_uPvPrev = glGetUniformLocation( _shader_particle.id, "uPvPrev" );
11428 _uniform_trail_uPv = glGetUniformLocation( _shader_trail.id, "uPv" );
11429 _uniform_trail_uPvPrev = glGetUniformLocation( _shader_trail.id, "uPvPrev" );
11430 _uniform_trail_uColour = glGetUniformLocation( _shader_trail.id, "uColour" );
11431 _uniform_blit_uInverseRatio = glGetUniformLocation( _shader_blit.id, "uInverseRatio" );
11432 _uniform_blit_uTexMain = glGetUniformLocation( _shader_blit.id, "uTexMain" );
11433 _uniform_blitblur_uInverseRatio = glGetUniformLocation( _shader_blitblur.id, "uInverseRatio" );
11434 _uniform_blitblur_uTexMain = glGetUniformLocation( _shader_blitblur.id, "uTexMain" );
11435 _uniform_blitblur_uTexMotion = glGetUniformLocation( _shader_blitblur.id, "uTexMotion" );
11436 _uniform_blitblur_uBlurStrength = glGetUniformLocation( _shader_blitblur.id, "uBlurStrength" );
11437 _uniform_blitblur_uOverrideDir = glGetUniformLocation( _shader_blitblur.id, "uOverrideDir" );
11438 _uniform_blitblur_uTime = glGetUniformLocation( _shader_blitblur.id, "uTime" );
11439 _uniform_blitblur_uGlitchStrength = glGetUniformLocation( _shader_blitblur.id, "uGlitchStrength" );
11440 _uniform_blitblur_uClampUv = glGetUniformLocation( _shader_blitblur.id, "uClampUv" );
11441 _uniform_blitcolour_uInverseRatio = glGetUniformLocation( _shader_blitcolour.id, "uInverseRatio" );
11442 _uniform_blitcolour_uColour = glGetUniformLocation( _shader_blitcolour.id, "uColour" );
11443 _uniform_blit_transition_uInverseRatio = glGetUniformLocation( _shader_blit_transition.id, "uInverseRatio" );
11444 _uniform_blit_transition_uT = glGetUniformLocation( _shader_blit_transition.id, "uT" );
11445 _uniform_routeui_uOffset = glGetUniformLocation( _shader_routeui.id, "uOffset" );
11446 _uniform_routeui_uColour = glGetUniformLocation( _shader_routeui.id, "uColour" );
11447 }
11448
11449 void vg_auto_shader_register(void)
11450 {
11451 vg_shader_register( &_shader_scene_standard );
11452 vg_shader_register( &_shader_scene_standard_alphatest );
11453 vg_shader_register( &_shader_scene_foliage );
11454 vg_shader_register( &_shader_scene_override );
11455 vg_shader_register( &_shader_scene_fxglow );
11456 vg_shader_register( &_shader_scene_vertex_blend );
11457 vg_shader_register( &_shader_scene_terrain );
11458 vg_shader_register( &_shader_scene_route );
11459 vg_shader_register( &_shader_scene_depth );
11460 vg_shader_register( &_shader_scene_position );
11461 vg_shader_register( &_shader_scene_cubemapped );
11462 vg_shader_register( &_shader_scene_water );
11463 vg_shader_register( &_shader_scene_water_fast );
11464 vg_shader_register( &_shader_scene_scoretext );
11465 vg_shader_register( &_shader_scene_font );
11466 vg_shader_register( &_shader_model_sky );
11467 vg_shader_register( &_shader_model_sky_space );
11468 vg_shader_register( &_shader_model_menu );
11469 vg_shader_register( &_shader_model_character_view );
11470 vg_shader_register( &_shader_model_board_view );
11471 vg_shader_register( &_shader_model_entity );
11472 vg_shader_register( &_shader_model_gate );
11473 vg_shader_register( &_shader_model_gate_unlinked );
11474 vg_shader_register( &_shader_model_font );
11475 vg_shader_register( &_shader_particle );
11476 vg_shader_register( &_shader_trail );
11477 vg_shader_register( &_shader_blit );
11478 vg_shader_register( &_shader_blitblur );
11479 vg_shader_register( &_shader_blitcolour );
11480 vg_shader_register( &_shader_blit_transition );
11481 vg_shader_register( &_shader_routeui );
11482 }
11483