097046fe397afbb628d7e7472c27d9a35d6caa04
[carveJwlIkooP6JGAAIwe30JlM.git] / shaders / scene_vertex_blend.h
1 #ifndef SHADER_scene_vertex_blend_H
2 #define SHADER_scene_vertex_blend_H
3 static void shader_scene_vertex_blend_link(void);
4 static void shader_scene_vertex_blend_register(void);
5 static struct vg_shader _shader_scene_vertex_blend = {
6 .name = "scene_vertex_blend",
7 .link = shader_scene_vertex_blend_link,
8 .vs =
9 {
10 .orig_file = "shaders/scene.vs",
11 .static_src =
12 "layout (location=0) in vec3 a_co;\n"
13 "layout (location=1) in vec4 a_norm;\n"
14 "layout (location=2) in vec2 a_uv;\n"
15 "layout (location=3) in ivec4 a_lights;\n"
16 "\n"
17 "#line 1 1 \n"
18 "const float k_motion_lerp_amount = 0.01;\n"
19 "\n"
20 "#line 2 0 \n"
21 "\n"
22 "out vec3 aMotionVec0;\n"
23 "out vec3 aMotionVec1;\n"
24 "\n"
25 "void vs_motion_out( vec4 vproj0, vec4 vproj1 )\n"
26 "{\n"
27 " // This magically solves some artifacting errors!\n"
28 " //\n"
29 " vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount;\n"
30 "\n"
31 " aMotionVec0 = vec3( vproj0.xy, vproj0.w );\n"
32 " aMotionVec1 = vec3( vproj1.xy, vproj1.w );\n"
33 "}\n"
34 "\n"
35 "#line 7 0 \n"
36 "\n"
37 "uniform mat4x3 uMdl;\n"
38 "uniform mat4 uPv;\n"
39 "uniform mat4 uPvmPrev;\n"
40 "\n"
41 "out vec2 aUv;\n"
42 "out vec4 aNorm;\n"
43 "out vec3 aCo;\n"
44 "out vec3 aWorldCo;\n"
45 "\n"
46 "flat out ivec4 light_indices;\n"
47 "\n"
48 "void main()\n"
49 "{\n"
50 " vec3 world_pos0 = uMdl * vec4( a_co, 1.0 );\n"
51 " vec4 vproj0 = uPv * vec4( world_pos0, 1.0 );\n"
52 " vec4 vproj1 = uPvmPrev * vec4( a_co, 1.0 );\n"
53 "\n"
54 " vs_motion_out( vproj0, vproj1 );\n"
55 "\n"
56 " gl_Position = vproj0;\n"
57 "\n"
58 " aUv = a_uv;\n"
59 " aNorm = vec4( mat3(uMdl) * a_norm.xyz, a_norm.w );\n"
60 " aCo = a_co;\n"
61 " aWorldCo = world_pos0;\n"
62 "\n"
63 " light_indices = a_lights;\n"
64 "}\n"
65 ""},
66 .fs =
67 {
68 .orig_file = "shaders/scene_vertex_blend.fs",
69 .static_src =
70 "uniform sampler2D uTexGarbage;\n"
71 "uniform sampler2D uTexGradients;\n"
72 "uniform vec3 uCamera;\n"
73 "uniform vec3 uBoard0;\n"
74 "uniform vec3 uBoard1;\n"
75 "\n"
76 "#line 1 1 \n"
77 "// :D\n"
78 "\n"
79 "in vec2 aUv;\n"
80 "in vec4 aNorm;\n"
81 "in vec3 aCo;\n"
82 "in vec3 aWorldCo;\n"
83 "flat in ivec4 light_indices;\n"
84 "\n"
85 "uniform samplerBuffer uLightsArray;\n"
86 "\n"
87 "#line 1 1 \n"
88 "layout (location = 0) out vec4 oColour;\n"
89 "\n"
90 "layout (std140) uniform ub_world_lighting\n"
91 "{\n"
92 " vec4 g_light_colours[3];\n"
93 " vec4 g_light_directions[3];\n"
94 " vec4 g_ambient_colour;\n"
95 "\n"
96 " vec4 g_water_plane;\n"
97 " vec4 g_depth_bounds;\n"
98 " float g_water_fog;\n"
99 " float g_time;\n"
100 " int g_light_count;\n"
101 " int g_light_preview;\n"
102 " int g_shadow_samples;\n"
103 "\n"
104 " int g_debug_indices;\n"
105 " int g_debug_complexity;\n"
106 "\n"
107 " // g_time ?\n"
108 "\n"
109 " //vec4 g_point_light_positions[32];\n"
110 " //vec4 g_point_light_colours[32];\n"
111 "};\n"
112 "\n"
113 "uniform sampler2D g_world_depth;\n"
114 "\n"
115 "float world_depth_sample( vec3 pos )\n"
116 "{\n"
117 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
118 " return texture( g_world_depth, depth_coord ).r;\n"
119 "}\n"
120 "\n"
121 "float world_water_depth( vec3 pos )\n"
122 "{\n"
123 " vec2 depth_coord = (pos.xz - g_depth_bounds.xy) * g_depth_bounds.zw; \n"
124 " float ref_depth = g_water_plane.y*g_water_plane.w;\n"
125 " return texture( g_world_depth, depth_coord ).g - ref_depth;\n"
126 "}\n"
127 "\n"
128 "float shadow_sample( vec3 vdir )\n"
129 "{\n"
130 " vec3 sample_pos = aWorldCo + vdir;\n"
131 " float height_sample = world_depth_sample( sample_pos );\n"
132 "\n"
133 " float fdelta = height_sample - sample_pos.y;\n"
134 " return clamp( fdelta, 0.1, 0.2 )-0.1;\n"
135 "}\n"
136 "\n"
137 "vec3 apply_fog( vec3 vfrag, float fdist )\n"
138 "{\n"
139 " float dist = pow(fdist*0.0008,1.2);\n"
140 " return mix( vfrag, vec3(0.55,0.76,1.0), min( 1.0, dist ) );\n"
141 "}\n"
142 "\n"
143 "\n"
144 "// New lighting model\n"
145 "\n"
146 "vec3 newlight_compute_ambient()\n"
147 "{\n"
148 " return g_ambient_colour.rgb;\n"
149 "}\n"
150 "\n"
151 "float newlight_compute_sun_shadow( vec3 dir )\n"
152 "{\n"
153 " if( g_shadow_samples == 0 )\n"
154 " {\n"
155 " return 1.0;\n"
156 " }\n"
157 "\n"
158 " float fspread = g_light_colours[0].w;\n"
159 " vec3 vdir = dir;\n"
160 " float flength = g_light_directions[0].w;\n"
161 "\n"
162 " float famt = 0.0;\n"
163 " famt+=shadow_sample((vdir+vec3(-0.563, 0.550, 0.307)*fspread)*flength*0.1);\n"
164 " famt+=shadow_sample((vdir+vec3( 0.808, 0.686, 0.346)*fspread)*flength*0.2);\n"
165 " famt+=shadow_sample((vdir+vec3( 0.787, 0.074,-0.065)*fspread)*flength*0.3);\n"
166 " famt+=shadow_sample((vdir+vec3(-0.593, 0.071,-0.425)*fspread)*flength*0.4);\n"
167 " famt+=shadow_sample((vdir+vec3(-0.790,-0.933,-0.875)*fspread)*flength*0.5);\n"
168 " famt+=shadow_sample((vdir+vec3( 0.807,-0.690, 0.472)*fspread)*flength*0.6);\n"
169 " famt+=shadow_sample((vdir+vec3( 0.522,-0.379, 0.350)*fspread)*flength*0.7);\n"
170 " famt+=shadow_sample((vdir+vec3( 0.483, 0.201, 0.306)*fspread)*flength*0.8);\n"
171 "\n"
172 " return 1.0 - famt;\n"
173 "}\n"
174 "\n"
175 "vec3 newlight_compute_world_diffuse( vec3 wnormal )\n"
176 "{\n"
177 " vec3 vtotal = g_ambient_colour.rgb;\n"
178 "\n"
179 " for( int i=0; i<g_light_count; i++ )\n"
180 " {\n"
181 " vec3 vcolour = g_light_colours[i].rgb;\n"
182 " vec3 vdir = g_light_directions[i].xyz;\n"
183 "\n"
184 " float flight = max(dot( vdir, wnormal )*0.75+0.25,0.0);\n"
185 " vtotal += vcolour*flight;\n"
186 " }\n"
187 "\n"
188 " return vtotal;\n"
189 "}\n"
190 "\n"
191 "vec3 newlight_compute_sun_spec( vec3 wnormal, vec3 halfview, float fintensity )\n"
192 "{\n"
193 " vec3 vcolour = g_light_colours[0].rgb;\n"
194 " vec3 vdir = g_light_directions[0].xyz;\n"
195 "\n"
196 " vec3 specdir = reflect( -vdir, wnormal );\n"
197 " float spec = pow(max(dot( halfview, specdir ), 0.0), 10.0);\n"
198 " return vcolour*spec*fintensity;\n"
199 "}\n"
200 "\n"
201 "float newlight_specular( vec3 wnormal, vec3 dir, vec3 halfview, float exponent )\n"
202 "{\n"
203 " vec3 specdir = reflect( -dir, wnormal );\n"
204 " return pow(max(dot( halfview, specdir ), 0.0), exponent);\n"
205 "}\n"
206 "\n"
207 "vec3 newlight_compute_quadratic( vec3 wnormal, vec3 halfview, \n"
208 " vec3 light_colour, vec3 light_pos )\n"
209 "{\n"
210 " vec3 light_delta = (light_pos-aWorldCo) * 10.0;\n"
211 "\n"
212 " float quadratic = dot(light_delta,light_delta);\n"
213 " float attenuation = 1.0f/( 1.0f + quadratic );\n"
214 " attenuation *= max( 0.0, dot( normalize(light_delta), wnormal ) );\n"
215 "\n"
216 " return light_colour*attenuation;\n"
217 "}\n"
218 "\n"
219 "vec3 newlight_compute_spot( vec3 wnormal, vec3 halfview, \n"
220 " vec3 light_colour, vec3 light_pos,\n"
221 " vec4 light_dir )\n"
222 "{\n"
223 " vec3 light_delta = (light_pos-aWorldCo) * 10.0;\n"
224 "\n"
225 " float quadratic = dot(light_delta,light_delta);\n"
226 " float attenuation = 1.0f/( 1.0f + quadratic );\n"
227 "\n"
228 " light_delta = normalize( light_delta );\n"
229 " attenuation *= max( 0.0, dot( light_delta, wnormal ) );\n"
230 "\n"
231 " float spot_theta = max( 0.0, dot( light_delta, -light_dir.xyz ) ),\n"
232 " falloff = max( 0.0,( spot_theta - light_dir.w ) / (1.0-light_dir.w) );\n"
233 "\n"
234 " return light_colour*attenuation*falloff;\n"
235 "}\n"
236 "\n"
237 "#line 12 0 \n"
238 "#line 1 2 \n"
239 "const vec3 DAYSKY_COLOUR = vec3( 0.37, 0.54, 0.97 );\n"
240 "const vec3 NIGHTSKY_COLOUR = vec3( 0.03, 0.05, 0.20 );\n"
241 "const vec3 SUNSET_COLOUR = vec3( 1.00, 0.32, 0.01 );\n"
242 "const vec3 AMBIENT_COLOUR = vec3( 0.13, 0.17, 0.35 );\n"
243 "const vec3 SUNSET_AMBIENT = vec3( 0.25, 0.17, 0.51 );\n"
244 "const vec3 SUN_COLOUR = vec3( 1.10, 0.89, 0.35 ) * 1.125;\n"
245 "\n"
246 "const float SUN_ANGLE = 0.0001;\n"
247 "const float TIME_RATE = 0.025;\n"
248 "\n"
249 "const float PI = 3.14159265;\n"
250 "\n"
251 "struct world_info\n"
252 "{\n"
253 " float time,\n"
254 " time_of_day,\n"
255 " day_phase,\n"
256 " sunset_phase;\n"
257 " \n"
258 " vec3 sun_dir;\n"
259 "};\n"
260 "\n"
261 "float luminance( vec3 v )\n"
262 "{\n"
263 " return dot( v, vec3(0.2126, 0.7152, 0.0722) );\n"
264 "}\n"
265 "\n"
266 "vec3 scene_ambient( vec3 dir, const world_info w )\n"
267 "{\n"
268 " float sun_azimuth = dot( dir.xz, w.sun_dir.xz ) * 0.4 + 0.6;\n"
269 " float sky_gradient = dir.y;\n"
270 " \n"
271 " /* Blend phase colours */\n"
272 " vec3 ambient = DAYSKY_COLOUR * (w.day_phase-w.sunset_phase*0.1);\n"
273 " ambient += SUNSET_COLOUR * (1.0-dir.y*0.5) * w.sunset_phase * sun_azimuth;\n"
274 " ambient += NIGHTSKY_COLOUR * (1.0-w.day_phase);\n"
275 " \n"
276 " /* Add gradient */\n"
277 " ambient -= sky_gradient * luminance(ambient);\n"
278 " \n"
279 " return ambient;\n"
280 "}\n"
281 "\n"
282 "vec3 scene_sky( vec3 ray_dir, const world_info w )\n"
283 "{\n"
284 " ray_dir.y = abs( ray_dir.y );\n"
285 " vec3 sky_colour = scene_ambient( ray_dir, w );\n"
286 " \n"
287 " /* Sun */\n"
288 " float sun_theta = dot( ray_dir, w.sun_dir );\n"
289 " float sun_size = max( 0.0, sun_theta * 0.5 + 0.5 + SUN_ANGLE );\n"
290 " float sun_shape = pow( sun_size, 2000.0 );\n"
291 " sun_shape += sun_size * max(w.sun_dir.y,0.0) * 0.5;\n"
292 " \n"
293 " vec3 sun_colour = mix( vec3(1.0), SUNSET_COLOUR, w.sunset_phase*0.5 );\n"
294 " sun_colour *= sun_shape;\n"
295 " \n"
296 " vec3 composite = sky_colour + sun_colour;\n"
297 " return composite;\n"
298 "}\n"
299 "\n"
300 "vec3 scene_compute_ambient( vec3 normal, const world_info w )\n"
301 "{\n"
302 " return scene_ambient( (normal * vec3(1.0,-1.0,1.0)) * 0.5 + 0.5, w );\n"
303 "}\n"
304 "\n"
305 "vec3 SR_LIGHT( vec3 normal, vec2 dir, vec3 colour )\n"
306 "{\n"
307 " vec3 dir3 = vec3\n"
308 " (\n"
309 " cos(dir.y) * cos(dir.x),\n"
310 " sin(dir.x),\n"
311 " sin(dir.y) * cos(dir.x)\n"
312 " );\n"
313 "\n"
314 " float flight = max( dot( normal, dir3 ) * 0.75 + 0.25, 0.0 );\n"
315 " \n"
316 " return flight * colour;\n"
317 "}\n"
318 "\n"
319 "vec3 scene_lighting_old( vec3 normal, const world_info w )\n"
320 "{\n"
321 " vec3 SR_COLOUR_SUN = vec3( 1.36, 1.35, 1.01 );\n"
322 " vec3 SR_COLOUR_FILL = vec3( 0.33, 0.56, 0.64 );\n"
323 " vec3 SR_COLOUR_RIM = vec3( 0.05, 0.05, 0.23 );\n"
324 " \n"
325 " return SR_LIGHT( normal, vec2( 0.63, -0.08 ), SR_COLOUR_SUN ) +\n"
326 " SR_LIGHT( normal, vec2( -2.60, -0.13 ), SR_COLOUR_FILL ) + \n"
327 " SR_LIGHT( normal, vec2( 2.60, -0.84 ), SR_COLOUR_RIM ) ;\n"
328 "}\n"
329 "\n"
330 "vec3 scene_lighting( vec3 normal, float shadow, vec3 halfview, const world_info w )\n"
331 "{\n"
332 " float fresnel = 1.0 - abs(dot(normal,halfview));\n"
333 "\n"
334 " vec3 sky_reflection = 0.5 * fresnel * mix( DAYSKY_COLOUR, SUNSET_COLOUR, w.sunset_phase );\n"
335 " vec3 light_sun = max(0.0,dot(normal,w.sun_dir)*0.75+0.25) * SUN_COLOUR \n"
336 " * w.day_phase;\n"
337 "\n"
338 " float scaled_shadow = max( shadow, 1.0 - max(w.sun_dir.y,0.0) );\n"
339 "\n"
340 " vec3 ambient = mix( AMBIENT_COLOUR, SUNSET_AMBIENT, w.sunset_phase );\n"
341 "\n"
342 " return ambient + (light_sun + sky_reflection) * shadow;\n"
343 "\n"
344 "\n"
345 "\n"
346 "\n"
347 "\n"
348 "\n"
349 " float sun_theta = dot( normal, w.sun_dir );\n"
350 "\n"
351 " float softness_min = 0.5;\n"
352 " float softness = softness_min + w.sunset_phase * (1.0-softness_min);\n"
353 " float light_min = 0.0 * w.day_phase;\n"
354 " float light_direct = light_min + smoothstep( -softness, softness, sun_theta ) * (1.0-light_min);\n"
355 " light_direct *= clamp(w.sun_dir.y * 4.0 + 1.0,0.0,1.0) * shadow;\n"
356 " \n"
357 " float light_bounce = 0.5 + 0.5 * dot( -normal, w.sun_dir );\n"
358 " light_bounce *= light_bounce * max( w.sun_dir.y, 0.0 );\n"
359 " \n"
360 " vec3 light_colour = SUN_COLOUR*w.day_phase + (SUNSET_COLOUR*w.sunset_phase + 0.1);\n"
361 " vec3 dark_colour = mix( AMBIENT_COLOUR, SUNSET_AMBIENT, w.sunset_phase );\n"
362 " \n"
363 " float spec = newlight_specular( normal, w.sun_dir, halfview, 2.0 ) \n"
364 " * 0.2 * shadow * w.day_phase;\n"
365 " \n"
366 " return mix(dark_colour, light_colour, light_direct) + \n"
367 " spec +\n"
368 " dark_colour * light_bounce;\n"
369 "}\n"
370 "\n"
371 "void scene_state( float world_time, out world_info w )\n"
372 "{\n"
373 " w.time = world_time;\n"
374 " w.time_of_day = fract( w.time );\n"
375 " w.day_phase = cos( w.time_of_day * PI * 2.0 ) * 0.5 + 0.5;\n"
376 " w.sunset_phase = cos( w.time_of_day * PI * 4.0 + PI ) * 0.5 + 0.5;\n"
377 " w.sunset_phase = pow( w.sunset_phase, 6.0 );\n"
378 " \n"
379 " float a = w.time_of_day * PI * 2.0;\n"
380 " w.sun_dir = normalize( vec3( sin( a ), cos( a ), 0.2) );\n"
381 "}\n"
382 "\n"
383 "\n"
384 "#line 13 0 \n"
385 "\n"
386 "float sdLine( vec3 p, vec3 a, vec3 b )\n"
387 "{\n"
388 " vec3 pa = p - a;\n"
389 " vec3 ba = b - a;\n"
390 "\n"
391 " float h = clamp( dot(pa,ba)/dot(ba,ba), 0.0, 1.0 );\n"
392 " return length( pa - ba*h );\n"
393 "}\n"
394 "\n"
395 "float compute_board_shadow()\n"
396 "{\n"
397 " // player shadow\n"
398 " float dist_to_player = max( 0.0, sdLine( aWorldCo, uBoard0, uBoard1 )-0.1 );\n"
399 " float player_shadow = max( 1.0-dist_to_player*2.7, 0.0 );\n"
400 " player_shadow *= player_shadow*player_shadow*player_shadow;\n"
401 "\n"
402 " return 1.0 - player_shadow*0.8;\n"
403 "}\n"
404 "\n"
405 "vec3 scene_apply_fog( vec3 vfrag, vec3 colour, float fdist )\n"
406 "{\n"
407 " float dist = pow(fdist*0.0010,0.78);\n"
408 " return mix( vfrag, colour, min( 1.0, dist ) );\n"
409 "}\n"
410 "\n"
411 "vec3 scene_do_lighting( vec3 diffuse, vec3 wnormal )\n"
412 "{\n"
413 " world_info world;\n"
414 " scene_state( g_time, world );\n"
415 "\n"
416 " // Lighting\n"
417 " vec3 halfview = uCamera - aWorldCo;\n"
418 " float fdist = length(halfview);\n"
419 " halfview /= fdist;\n"
420 "\n"
421 " vec3 total_light = vec3(0.0);\n"
422 "\n"
423 "\n"
424 " float world_shadow = newlight_compute_sun_shadow( world.sun_dir \n"
425 " * (1.0/(max(world.sun_dir.y,0.0)+0.2)) );\n"
426 " float board_shadow = compute_board_shadow();\n"
427 "\n"
428 " total_light += scene_lighting( wnormal, min( board_shadow, world_shadow ), \n"
429 " halfview, world );\n"
430 "\n"
431 " //total_light += scene_lighting_old( wnormal, world );\n"
432 "\n"
433 " // Compute the other lights that exist in the map, not effected by the sun\n"
434 " // shadow\n"
435 "\n"
436 " // read lights\n"
437 " vec4 light_colour_0 = texelFetch( uLightsArray, light_indices.x*3+0 );\n"
438 " vec4 light_colour_1 = texelFetch( uLightsArray, light_indices.y*3+0 );\n"
439 " vec4 light_colour_2 = texelFetch( uLightsArray, light_indices.z*3+0 );\n"
440 " vec4 light_co_0 = texelFetch( uLightsArray, light_indices.x*3+1 );\n"
441 " vec4 light_co_1 = texelFetch( uLightsArray, light_indices.y*3+1 );\n"
442 " vec4 light_co_2 = texelFetch( uLightsArray, light_indices.z*3+1 );\n"
443 " vec4 light_dir_0 = texelFetch( uLightsArray, light_indices.x*3+2 );\n"
444 " vec4 light_dir_1 = texelFetch( uLightsArray, light_indices.y*3+2 );\n"
445 " vec4 light_dir_2 = texelFetch( uLightsArray, light_indices.z*3+2 );\n"
446 "\n"
447 " if( g_debug_indices == 1 )\n"
448 " {\n"
449 " float rings = min( fract(distance(light_co_0.xyz,aWorldCo)),\n"
450 " min( fract(distance(light_co_1.xyz,aWorldCo)),\n"
451 " fract(distance(light_co_2.xyz,aWorldCo)) ) \n"
452 " );\n"
453 " \n"
454 " return vec3(fract(light_indices.x * 0.125), fract(light_indices.y*0.125),\n"
455 " fract(light_indices.z * 0.125 )) + (rings-0.5) * 0.25;\n"
456 " }\n"
457 "\n"
458 " if( g_debug_complexity == 1 )\n"
459 " {\n"
460 " return vec3(1.0,0.0,0.0) * ( light_indices.w/3.0 );\n"
461 " }\n"
462 "\n"
463 " if( light_indices.w >= 1 )\n"
464 " {\n"
465 " total_light += newlight_compute_spot\n"
466 " ( \n"
467 " wnormal, halfview,\n"
468 " light_colour_0.rgb,\n"
469 " light_co_0.xyz,\n"
470 " light_dir_0\n"
471 " ) * board_shadow \n"
472 " * step( world.day_phase, light_colour_0.w );\n"
473 "\n"
474 " if( light_indices.w >= 2 )\n"
475 " {\n"
476 " total_light += newlight_compute_spot\n"
477 " ( \n"
478 " wnormal, halfview,\n"
479 " light_colour_1.rgb,\n"
480 " light_co_1.xyz,\n"
481 " light_dir_1\n"
482 " ) * board_shadow\n"
483 " * step( world.day_phase, light_colour_1.w );\n"
484 "\n"
485 " if( light_indices.w >= 3 )\n"
486 " {\n"
487 " total_light += newlight_compute_spot\n"
488 " ( \n"
489 " wnormal, halfview,\n"
490 " light_colour_2.rgb,\n"
491 " light_co_2.xyz,\n"
492 " light_dir_2\n"
493 " ) * board_shadow\n"
494 " * step( world.day_phase, light_colour_2.w );\n"
495 " }\n"
496 " }\n"
497 " }\n"
498 "\n"
499 " vec3 fog_colour = scene_sky( -halfview, world );\n"
500 " \n"
501 " return scene_apply_fog( diffuse * total_light, fog_colour, fdist );\n"
502 "}\n"
503 "\n"
504 "#line 8 0 \n"
505 "#line 1 2 \n"
506 "const float k_motion_lerp_amount = 0.01;\n"
507 "\n"
508 "#line 2 0 \n"
509 "\n"
510 "layout (location = 1) out vec2 oMotionVec;\n"
511 "\n"
512 "in vec3 aMotionVec0;\n"
513 "in vec3 aMotionVec1;\n"
514 "\n"
515 "void compute_motion_vectors()\n"
516 "{\n"
517 " // Write motion vectors\n"
518 " vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z;\n"
519 " vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z;\n"
520 "\n"
521 " oMotionVec = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount);\n"
522 "}\n"
523 "\n"
524 "#line 9 0 \n"
525 "\n"
526 "void main()\n"
527 "{\n"
528 " compute_motion_vectors();\n"
529 "\n"
530 " vec3 vfrag = vec3(0.5,0.5,0.5);\n"
531 "\n"
532 " // ws modulation\n"
533 " vec4 wgarbage = vec4(0.5,0.5,0.5,1.0);\n"
534 " \n"
535 " // Creating normal patches\n"
536 " vec3 modnorm = (wgarbage.rgb-0.4) * 1.4;\n"
537 " vec3 qnorm = normalize(floor(aNorm.xyz*4.0+modnorm)*0.25);\n"
538 " qnorm += vec3(0.001,0.0,0.0);\n"
539 "\n"
540 " vec3 tangent0 = normalize(cross(qnorm,vec3(0.0,1.0,0.0)));\n"
541 " vec3 tangent1 = cross(qnorm,tangent0);\n"
542 " vec2 uvdiffuse = vec2( dot(tangent0,aCo), dot(tangent1,aCo) ) * 0.160;\n"
543 " \n"
544 " // Patch local noise\n"
545 " vec4 rgarbage = texture( uTexGarbage, uvdiffuse );\n"
546 "\n"
547 " // Colour blending\n"
548 " float fblendclip = step(0.380,aNorm.w + (rgarbage.r-0.5)*-1.740)*0.320;\n"
549 " vec2 uvgradients = aUv + vec2( fblendclip, 0.0 );\n"
550 "\n"
551 " vfrag = texture( uTexGradients, uvgradients ).rgb;\n"
552 " vfrag -= rgarbage.a*0.04;\n"
553 "\n"
554 " if( g_light_preview == 1 )\n"
555 " {\n"
556 " vfrag = vec3(0.5);\n"
557 " }\n"
558 "\n"
559 " vfrag = scene_do_lighting( vfrag, qnorm );\n"
560 " oColour = vec4(vfrag, 1.0);\n"
561 "}\n"
562 ""},
563 };
564
565 static GLuint _uniform_scene_vertex_blend_uMdl;
566 static GLuint _uniform_scene_vertex_blend_uPv;
567 static GLuint _uniform_scene_vertex_blend_uPvmPrev;
568 static GLuint _uniform_scene_vertex_blend_uTexGarbage;
569 static GLuint _uniform_scene_vertex_blend_uTexGradients;
570 static GLuint _uniform_scene_vertex_blend_uCamera;
571 static GLuint _uniform_scene_vertex_blend_uBoard0;
572 static GLuint _uniform_scene_vertex_blend_uBoard1;
573 static GLuint _uniform_scene_vertex_blend_uLightsArray;
574 static GLuint _uniform_scene_vertex_blend_g_world_depth;
575 static void shader_scene_vertex_blend_uMdl(m4x3f m){
576 glUniformMatrix4x3fv(_uniform_scene_vertex_blend_uMdl,1,GL_FALSE,(float*)m);
577 }
578 static void shader_scene_vertex_blend_uPv(m4x4f m){
579 glUniformMatrix4fv(_uniform_scene_vertex_blend_uPv,1,GL_FALSE,(float*)m);
580 }
581 static void shader_scene_vertex_blend_uPvmPrev(m4x4f m){
582 glUniformMatrix4fv(_uniform_scene_vertex_blend_uPvmPrev,1,GL_FALSE,(float*)m);
583 }
584 static void shader_scene_vertex_blend_uTexGarbage(int i){
585 glUniform1i(_uniform_scene_vertex_blend_uTexGarbage,i);
586 }
587 static void shader_scene_vertex_blend_uTexGradients(int i){
588 glUniform1i(_uniform_scene_vertex_blend_uTexGradients,i);
589 }
590 static void shader_scene_vertex_blend_uCamera(v3f v){
591 glUniform3fv(_uniform_scene_vertex_blend_uCamera,1,v);
592 }
593 static void shader_scene_vertex_blend_uBoard0(v3f v){
594 glUniform3fv(_uniform_scene_vertex_blend_uBoard0,1,v);
595 }
596 static void shader_scene_vertex_blend_uBoard1(v3f v){
597 glUniform3fv(_uniform_scene_vertex_blend_uBoard1,1,v);
598 }
599 static void shader_scene_vertex_blend_g_world_depth(int i){
600 glUniform1i(_uniform_scene_vertex_blend_g_world_depth,i);
601 }
602 static void shader_scene_vertex_blend_register(void){
603 vg_shader_register( &_shader_scene_vertex_blend );
604 }
605 static void shader_scene_vertex_blend_use(void){ glUseProgram(_shader_scene_vertex_blend.id); }
606 static void shader_scene_vertex_blend_link(void){
607 _uniform_scene_vertex_blend_uMdl = glGetUniformLocation( _shader_scene_vertex_blend.id, "uMdl" );
608 _uniform_scene_vertex_blend_uPv = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPv" );
609 _uniform_scene_vertex_blend_uPvmPrev = glGetUniformLocation( _shader_scene_vertex_blend.id, "uPvmPrev" );
610 _uniform_scene_vertex_blend_uTexGarbage = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGarbage" );
611 _uniform_scene_vertex_blend_uTexGradients = glGetUniformLocation( _shader_scene_vertex_blend.id, "uTexGradients" );
612 _uniform_scene_vertex_blend_uCamera = glGetUniformLocation( _shader_scene_vertex_blend.id, "uCamera" );
613 _uniform_scene_vertex_blend_uBoard0 = glGetUniformLocation( _shader_scene_vertex_blend.id, "uBoard0" );
614 _uniform_scene_vertex_blend_uBoard1 = glGetUniformLocation( _shader_scene_vertex_blend.id, "uBoard1" );
615 _uniform_scene_vertex_blend_uLightsArray = glGetUniformLocation( _shader_scene_vertex_blend.id, "uLightsArray" );
616 _uniform_scene_vertex_blend_g_world_depth = glGetUniformLocation( _shader_scene_vertex_blend.id, "g_world_depth" );
617 }
618 #endif /* SHADER_scene_vertex_blend_H */