Commit 9fd9a6cc4a243543b41408b911607aff7d233241

Authored by DarkGod
1 parent 2be02293

All fullscreen effects can be enabled at once now (underwater, blur, wobbling, ...)

... ... @@ -514,6 +514,13 @@ function _M:createFBOs()
514 514 self.fbo = core.display.newFBO(Map.viewport.width, Map.viewport.height)
515 515 if self.fbo then
516 516 self.fbo_shader = Shader.new("main_fbo")
  517 + self.posteffects = {
  518 + wobbling = Shader.new("main_fbo/wobbling"),
  519 + underwater = Shader.new("main_fbo/underwater"),
  520 + motionblur = Shader.new("main_fbo/motionblur"),
  521 + blur = Shader.new("main_fbo/blur"),
  522 + }
  523 + self.posteffects_use = { self.fbo_shader.shad }
517 524 if not self.fbo_shader.shad then self.fbo = nil self.fbo_shader = nil end
518 525 self.fbo2 = core.display.newFBO(Map.viewport.width, Map.viewport.height)
519 526 end
... ... @@ -1392,7 +1399,7 @@ function _M:displayMap(nb_keyframes)
1392 1399 self.fbo2:use(false, self.full_fbo)
1393 1400
1394 1401 _2DNoise:bind(1, false)
1395   - self.fbo2:toScreen(map.display_x, map.display_y, map.viewport.width, map.viewport.height, self.fbo_shader.shad)
  1402 + self.fbo2:postEffects(self.fbo, self.full_fbo, map.display_x, map.display_y, map.viewport.width, map.viewport.height, unpack(self.posteffects_use))
1396 1403 if self.target then self.target:display(nil, nil, self.full_fbo, nb_keyframes) end
1397 1404
1398 1405 -- Basic display; no FBOs
... ...
... ... @@ -374,6 +374,9 @@ end
374 374 --- Funky shader stuff
375 375 function _M:updateMainShader()
376 376 if game.fbo_shader then
  377 + local effects = {}
  378 + local pf = game.posteffects
  379 +
377 380 -- Set shader HP warning
378 381 if self.life ~= self.shader_old_life then
379 382 if self.life < self.max_life / 2 then game.fbo_shader:setUniform("hp_warning", 1 - (self.life / self.max_life))
... ... @@ -408,28 +411,26 @@ function _M:updateMainShader()
408 411 end
409 412
410 413 -- Blur shader
411   - if self:attr("confused") and self.confused >= 1 then game.fbo_shader:setUniform("blur", 2)
412   --- elseif game:hasDialogUp() then game.fbo_shader:setUniform("blur", 3)
413   - else game.fbo_shader:setUniform("blur", 0) -- Disable
  414 + if self:attr("confused") and self.confused >= 1 then pf.blur.shad:uniBlur(2) effects[pf.blur.shad] = true
414 415 end
415 416
416 417 -- Moving Blur shader
417   - if self:attr("invisible") then game.fbo_shader:setUniform("motionblur", 3)
418   - elseif self:attr("lightning_speed") then game.fbo_shader:setUniform("motionblur", 2)
419   - elseif game.level and game.level.data and game.level.data.motionblur then game.fbo_shader:setUniform("motionblur", game.level.data.motionblur)
420   - else game.fbo_shader:setUniform("motionblur", 0) -- Disable
  418 + if self:attr("invisible") then pf.motionblur.shad:uniMotionblur(3) effects[pf.motionblur.shad] = true
  419 + elseif self:attr("lightning_speed") then pf.motionblur.shad:uniMotionblur(2) effects[pf.motionblur.shad] = true
  420 + elseif game.level and game.level.data and game.level.data.motionblur then pf.motionblur.shad:uniMotionblur(game.level.data.motionblur) effects[pf.motionblur.shad] = true
421 421 end
422 422
423 423 -- Underwater shader
424   - if game.level and game.level.data and game.level.data.underwater then game.fbo_shader:setUniform("underwater", 1)
425   - else game.fbo_shader:setUniform("underwater", 0) -- Disable
  424 + if game.level and game.level.data and game.level.data.underwater then effects[pf.underwater.shad] = true
426 425 end
427 426
428 427 -- Wobbling shader
429   - if self:attr("stunned") and self.stunned >= 1 then game.fbo_shader:setUniform("wobbling", 1)
430   - elseif self:attr("dazed") and self.dazed >= 1 then game.fbo_shader:setUniform("wobbling", 0.7)
431   - else game.fbo_shader:setUniform("wobbling", 0) -- Disable
  428 + if self:attr("stunned") and self.stunned >= 1 then pf.wobbling.shad:uniWobbling(1) effects[pf.wobbling.shad] = true
  429 + elseif self:attr("dazed") and self.dazed >= 1 then pf.wobbling.shad:uniWobbling(0.7) effects[pf.wobbling.shad] = true
432 430 end
  431 +
  432 + game.posteffects_use = table.keys(effects)
  433 + game.posteffects_use[#game.posteffects_use+1] = game.fbo_shader.shad
433 434 end
434 435 end
435 436
... ...
... ... @@ -271,30 +271,6 @@ void main(void)
271 271 sample /= (blur*2.0) * (blur*2.0);
272 272 gl_FragColor = sample;
273 273 }
274   - else if (underwater > 0.0)
275   - {
276   - vec2 p = (vec2(gl_FragCoord.x - mapCoord.x, texSize.y - gl_FragCoord.y - mapCoord.y)) / texSize.xy, c1 = p, c2 = p;
277   - float cc1 = col(c1);
278   -
279   - c2.x += texSize.x/delta;
280   - float dx = emboss*(cc1-col(c2))/delta;
281   -
282   - c2.x = p.x;
283   - c2.y += texSize.y/delta;
284   - float dy = emboss*(cc1-col(c2))/delta;
285   -
286   - c1.x += dx*2.;
287   - c1.y = -(c1.y+dy*2.);
288   -
289   - float alpha = 1.+dot(dx,dy)*intence;
290   -
291   - float ddx = dx - reflectionCutOff;
292   - float ddy = dy - reflectionCutOff;
293   - if (ddx > 0. && ddy > 0.) alpha = pow(alpha, ddx*ddy*reflectionIntence);
294   -
295   - vec4 col = texture2D(tex,c1)*(alpha);
296   - gl_FragColor = col;
297   - }
298 274
299 275 if (colorize.r > 0.0 || colorize.g > 0.0 || colorize.b > 0.0)
300 276 {
... ... @@ -335,67 +311,3 @@ void main(void)
335 311 gl_FragColor = mix(gl_FragColor, solipsism_warning_color, dist);
336 312 }
337 313 }
338   -
339   -/*uniform sampler2D tex;
340   -uniform vec2 texSize;
341   -int blursize = 5;
342   -
343   -void main(void)
344   -{
345   - vec2 offset = 1.0/texSize;
346   -
347   - // Center Pixel
348   - vec4 sample = vec4(0.0,0.0,0.0,0.0);
349   - float factor = ((float(blursize)*2.0)+1.0);
350   - factor = factor*factor;
351   -
352   - for(int i = -blursize; i <= blursize; i++)
353   - {
354   - for(int j = -blursize; j <= blursize; j++)
355   - {
356   - sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
357   - }
358   - }
359   - sample /= float((blursize*2) * (blursize*2));
360   -
361   - float grey = sample.r*0.3+sample.g*0.59+sample.b*0.11;
362   - vec3 color = vec3(1, 0, 0);
363   - gl_FragColor = vec4(vec3(color*grey),1.0);
364   -}
365   -*/
366   -/*
367   -uniform sampler2D tex;
368   -uniform sampler3D noiseVol;
369   -uniform float tick;
370   -float do_blur = 3.0;
371   -uniform vec2 texSize;
372   -
373   -void main(void)
374   -{
375   - if (do_blur > 0.0)
376   - {
377   - vec2 offset = 1.0/texSize;
378   - offset.y += texture3D(noiseVol, vec3(gl_TexCoord[0].xy, tick/100000))/30;
379   -
380   - // Center Pixel
381   - vec4 sample = vec4(0.0,0.0,0.0,0.0);
382   - float factor = ((float(do_blur)*2.0)+1.0);
383   - factor = factor*factor;
384   -
385   - for(int i = -do_blur; i <= do_blur; i++)
386   - {
387   - for(int j = -do_blur; j <= do_blur; j++)
388   - {
389   - sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
390   - }
391   - }
392   - sample /= float((do_blur*2) * (do_blur*2));
393   -
394   - gl_FragColor = sample;
395   - }
396   -
397   - float grey = gl_FragColor.r*0.3+gl_FragColor.g*0.59+gl_FragColor.b*0.11;
398   - vec3 color = vec3(1, 0, 0);
399   - gl_FragColor = vec4(vec3(color*grey),1.0);
400   -}
401   -*/
... ...
  1 +uniform float blur;
  2 +uniform float tick;
  3 +uniform vec2 texSize;
  4 +uniform sampler2D tex;
  5 +
  6 +void main(void)
  7 +{
  8 + int blursize = int(blur);
  9 + vec2 offset = 1.0/texSize;
  10 +
  11 + // Center Pixel
  12 + vec4 sample = vec4(0.0,0.0,0.0,0.0);
  13 + float factor = ((float(blursize)*2.0)+1.0);
  14 + factor = factor*factor;
  15 +
  16 + for(int i = -blursize; i <= blursize; i++)
  17 + {
  18 + for(int j = -blursize; j <= blursize; j++)
  19 + {
  20 + sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
  21 + }
  22 + }
  23 + sample /= (blur*2.0) * (blur*2.0);
  24 + gl_FragColor = sample;
  25 +}
... ...
  1 +-- ToME - Tales of Maj'Eyal
  2 +-- Copyright (C) 2009 - 2014 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +return {
  21 + frag = "main_fbo/blur",
  22 + vert = nil,
  23 + args = {
  24 + tex = { texture = 0 },
  25 + },
  26 + clone = false,
  27 + permanent = true,
  28 +}
... ...
  1 +uniform float motionblur;
  2 +uniform float tick;
  3 +uniform sampler2D noisevol;
  4 +uniform vec2 texSize;
  5 +uniform sampler2D tex;
  6 +uniform vec2 mapCoord;
  7 +
  8 +void main(void)
  9 +{
  10 + gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
  11 +
  12 + int blursize = int(motionblur);
  13 + vec2 offset = 0.8/texSize;
  14 +
  15 + float fTime0_X = tick / 20000.0;
  16 + float coord = gl_TexCoord[0].x + gl_TexCoord[0].y * texSize[0];
  17 + float noisy1 = texture2D(noisevol,vec2(coord,fTime0_X)).r;
  18 + float noisy2 = texture2D(noisevol,vec2(coord/5.0,fTime0_X/1.5)).r;
  19 + float noisy3 = texture2D(noisevol,vec2(coord/7.0,fTime0_X/2.0)).r;
  20 + float noisy = (noisy1+noisy2+noisy3)/3.0;
  21 +
  22 + // Center Pixel
  23 + vec4 sample = vec4(0.0,0.0,0.0,0.0);
  24 + float factor = ((float(blursize)*2.0)+1.0);
  25 + factor = factor*factor;
  26 +
  27 + if (noisy < 0.25)
  28 + {
  29 + for(int i = -blursize; i <= 0; i++)
  30 + {
  31 + for(int j = -blursize; j <= 0; j++)
  32 + {
  33 + sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
  34 + }
  35 + }
  36 + }
  37 + else if (noisy < 0.50)
  38 + {
  39 + for(int i = 0; i <= blursize; i++)
  40 + {
  41 + for(int j = 0; j <= blursize; j++)
  42 + {
  43 + sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
  44 + }
  45 + }
  46 + }
  47 + else if (noisy < 0.75)
  48 + {
  49 + for(int i = 0; i <= blursize; i++)
  50 + {
  51 + for(int j = -blursize; j <= 0; j++)
  52 + {
  53 + sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
  54 + }
  55 + }
  56 + }
  57 + else
  58 + {
  59 + for(int i = -blursize; i <= 0; i++)
  60 + {
  61 + for(int j = 0; j <= blursize; j++)
  62 + {
  63 + sample += texture2D(tex, vec2(gl_TexCoord[0].xy+vec2(float(i)*offset.x, float(j)*offset.y)));
  64 + }
  65 + }
  66 + }
  67 + sample /= float((motionblur*1.5) * (motionblur*0.5));
  68 + gl_FragColor = sample;
  69 +}
... ...
  1 +-- ToME - Tales of Maj'Eyal
  2 +-- Copyright (C) 2009 - 2014 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +return {
  21 + frag = "main_fbo/motionblur",
  22 + vert = nil,
  23 + args = {
  24 + tex = { texture = 0 },
  25 + },
  26 + clone = false,
  27 + permanent = true,
  28 +}
... ...
  1 +uniform float tick;
  2 +uniform vec2 texSize;
  3 +uniform sampler2D tex;
  4 +
  5 +// Simple Water shader. (c) Victor Korsun, bitekas@gmail.com; 2012.
  6 +//
  7 +// Attribution-ShareAlike CC License.
  8 +
  9 +#ifdef GL_ES
  10 +precision highp float;
  11 +#endif
  12 +
  13 +uniform vec2 mapCoord;
  14 +
  15 +const float PI = 3.1415926535897932;
  16 +
  17 +// play with these parameters to custimize the effect
  18 +// ===================================================
  19 +
  20 +//speed
  21 +const float speed = 0.05;
  22 +const float speed_x = 0.3;
  23 +const float speed_y = 0.3;
  24 +
  25 +// refraction
  26 +const float emboss = 0.05;
  27 +const float intensity = 0.4;
  28 +const int steps = 6;
  29 +const float frequency = 100.0;
  30 +const int angle = 7; // better when a prime
  31 +
  32 +// reflection
  33 +const float delta = 60.;
  34 +const float intence = 700.;
  35 +
  36 +const float reflectionCutOff = 0.012;
  37 +const float reflectionIntence = 200000.;
  38 +
  39 +// ===================================================
  40 +
  41 +float time = tick / 30000.0;
  42 +
  43 +float col(vec2 coord)
  44 +{
  45 + float delta_theta = 2.0 * PI / float(angle);
  46 + float col = 0.0;
  47 + float theta = 0.0;
  48 + for (int i = 0; i < steps; i++)
  49 + {
  50 + vec2 adjc = coord;
  51 + theta = delta_theta*float(i);
  52 + adjc.x += cos(theta)*time*speed + time * speed_x;
  53 + adjc.y -= sin(theta)*time*speed - time * speed_y;
  54 + col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity;
  55 + }
  56 +
  57 + return cos(col);
  58 +}
  59 +
  60 +void main(void)
  61 +{
  62 + gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
  63 + vec2 p = (vec2(gl_FragCoord.x - mapCoord.x, texSize.y - gl_FragCoord.y - mapCoord.y)) / texSize.xy, c1 = p, c2 = p;
  64 + float cc1 = col(c1);
  65 +
  66 + c2.x += texSize.x/delta;
  67 + float dx = emboss*(cc1-col(c2))/delta;
  68 +
  69 + c2.x = p.x;
  70 + c2.y += texSize.y/delta;
  71 + float dy = emboss*(cc1-col(c2))/delta;
  72 +
  73 + c1.x += dx*2.;
  74 + c1.y = -(c1.y+dy*2.);
  75 +
  76 + float alpha = 1.+dot(dx,dy)*intence;
  77 +
  78 + float ddx = dx - reflectionCutOff;
  79 + float ddy = dy - reflectionCutOff;
  80 + if (ddx > 0. && ddy > 0.) alpha = pow(alpha, ddx*ddy*reflectionIntence);
  81 +
  82 + vec4 col = texture2D(tex,c1)*(alpha);
  83 + gl_FragColor = col;
  84 +}
... ...
  1 +-- ToME - Tales of Maj'Eyal
  2 +-- Copyright (C) 2009 - 2014 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +return {
  21 + frag = "main_fbo/underwater",
  22 + vert = nil,
  23 + args = {
  24 + tex = { texture = 0 },
  25 + },
  26 + clone = false,
  27 + permanent = true,
  28 +}
... ...
  1 +uniform float wobbling;
  2 +uniform float tick;
  3 +uniform sampler2D noisevol;
  4 +uniform vec2 texSize;
  5 +uniform sampler2D tex;
  6 +uniform vec2 mapCoord;
  7 +
  8 +const float PI = 3.1415926535897932;
  9 +
  10 +// play with these parameters to custimize the effect
  11 +// ===================================================
  12 +
  13 +//speed
  14 +const float speed = 0.05;
  15 +const float speed_x = 0.3;
  16 +const float speed_y = 0.3;
  17 +
  18 +// refraction
  19 +const float emboss = 0.05;
  20 +const float intensity = 0.4;
  21 +const int steps = 6;
  22 +const float frequency = 100.0;
  23 +const int angle = 7; // better when a prime
  24 +
  25 +// reflection
  26 +const float delta = 60.;
  27 +const float intence = 700.;
  28 +
  29 +const float reflectionCutOff = 0.012;
  30 +const float reflectionIntence = 200000.;
  31 +
  32 +float time = tick / 30000.0;
  33 +
  34 +float col(vec2 coord)
  35 +{
  36 + float delta_theta = 2.0 * PI / float(angle);
  37 + float col = 0.0;
  38 + float theta = 0.0;
  39 + for (int i = 0; i < steps; i++)
  40 + {
  41 + vec2 adjc = coord;
  42 + theta = delta_theta*float(i);
  43 + adjc.x += cos(theta)*time*speed + time * speed_x;
  44 + adjc.y -= sin(theta)*time*speed - time * speed_y;
  45 + col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity;
  46 + }
  47 +
  48 + return cos(col);
  49 +}
  50 +
  51 +vec4 permute( vec4 x ) {
  52 +
  53 + return mod( ( ( x * 34.0 ) + 1.0 ) * x, 289.0 );
  54 +
  55 +}
  56 +
  57 +vec4 taylorInvSqrt( vec4 r ) {
  58 +
  59 + return 1.79284291400159 - 0.85373472095314 * r;
  60 +
  61 +}
  62 +
  63 +float snoise( vec3 v ) {
  64 +
  65 + const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );
  66 + const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );
  67 +
  68 + // First corner
  69 +
  70 + vec3 i = floor( v + dot( v, C.yyy ) );
  71 + vec3 x0 = v - i + dot( i, C.xxx );
  72 +
  73 + // Other corners
  74 +
  75 + vec3 g = step( x0.yzx, x0.xyz );
  76 + vec3 l = 1.0 - g;
  77 + vec3 i1 = min( g.xyz, l.zxy );
  78 + vec3 i2 = max( g.xyz, l.zxy );
  79 +
  80 + vec3 x1 = x0 - i1 + 1.0 * C.xxx;
  81 + vec3 x2 = x0 - i2 + 2.0 * C.xxx;
  82 + vec3 x3 = x0 - 1. + 3.0 * C.xxx;
  83 +
  84 + // Permutations
  85 +
  86 + i = mod( i, 289.0 );
  87 + vec4 p = permute( permute( permute(
  88 + i.z + vec4( 0.0, i1.z, i2.z, 1.0 ) )
  89 + + i.y + vec4( 0.0, i1.y, i2.y, 1.0 ) )
  90 + + i.x + vec4( 0.0, i1.x, i2.x, 1.0 ) );
  91 +
  92 + // Gradients
  93 + // ( N*N points uniformly over a square, mapped onto an octahedron.)
  94 +
  95 + float n_ = 1.0 / 7.0; // N=7
  96 +
  97 + vec3 ns = n_ * D.wyz - D.xzx;
  98 +
  99 + vec4 j = p - 49.0 * floor( p * ns.z *ns.z ); // mod(p,N*N)
  100 +
  101 + vec4 x_ = floor( j * ns.z );
  102 + vec4 y_ = floor( j - 7.0 * x_ ); // mod(j,N)
  103 +
  104 + vec4 x = x_ *ns.x + ns.yyyy;
  105 + vec4 y = y_ *ns.x + ns.yyyy;
  106 + vec4 h = 1.0 - abs( x ) - abs( y );
  107 +
  108 + vec4 b0 = vec4( x.xy, y.xy );
  109 + vec4 b1 = vec4( x.zw, y.zw );
  110 +
  111 +
  112 + vec4 s0 = floor( b0 ) * 2.0 + 1.0;
  113 + vec4 s1 = floor( b1 ) * 2.0 + 1.0;
  114 + vec4 sh = -step( h, vec4( 0.0 ) );
  115 +
  116 + vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
  117 + vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
  118 +
  119 + vec3 p0 = vec3( a0.xy, h.x );
  120 + vec3 p1 = vec3( a0.zw, h.y );
  121 + vec3 p2 = vec3( a1.xy, h.z );
  122 + vec3 p3 = vec3( a1.zw, h.w );
  123 +
  124 + // Normalise gradients
  125 +
  126 + vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );
  127 + p0 *= norm.x;
  128 + p1 *= norm.y;
  129 + p2 *= norm.z;
  130 + p3 *= norm.w;
  131 +
  132 + // Mix final noise value
  133 +
  134 + vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );
  135 + m = m * m;
  136 + return 42.0 * dot( m*m, vec4( dot( p0, x0 ), dot( p1, x1 ),
  137 + dot( p2, x2 ), dot( p3, x3 ) ) );
  138 +
  139 +}
  140 +
  141 +
  142 +vec2 snoise2(vec3 pos)
  143 +{
  144 + return vec2(snoise(pos), snoise(pos + vec3(0.0, 0.0, 1.0)));
  145 +}
  146 +
  147 +void main(void)
  148 +{
  149 + float scaledTime = tick / 5000.0;
  150 + vec2 coord = gl_TexCoord[0].xy;
  151 + coord.x *= texSize.x / texSize.y;
  152 + vec2 offset =
  153 + snoise2(vec3(coord / 2.0, scaledTime / 0.25)) * 0.33 * 3.0 +
  154 + snoise2(vec3(coord / 2.0, scaledTime / 2.0)) * 0.0 +
  155 + snoise2(vec3(coord / 4.0, scaledTime / 4.0)) * 0.0;
  156 +
  157 + offset.x *= texSize.x / texSize.y;
  158 +
  159 + float ratio = clamp(1.5 * pow(length(vec2(0.5, 0.5) - gl_TexCoord[0].xy) / (0.7071), 2.0), 0.0, 1.0); //sqrt(2) / 2 = 0.7071
  160 + ratio *= (1.0 + snoise2(vec3(coord / 2.0, scaledTime / 0.25 + 10.0))) * 0.5;
  161 +
  162 + gl_FragColor =
  163 + texture2D(tex, gl_TexCoord[0].xy) * (1.0 - ratio) +
  164 + texture2D(tex, gl_TexCoord[0].xy + offset * 0.01 * wobbling) * ratio;
  165 +}
... ...
  1 +-- ToME - Tales of Maj'Eyal
  2 +-- Copyright (C) 2009 - 2014 Nicolas Casalini
  3 +--
  4 +-- This program is free software: you can redistribute it and/or modify
  5 +-- it under the terms of the GNU General Public License as published by
  6 +-- the Free Software Foundation, either version 3 of the License, or
  7 +-- (at your option) any later version.
  8 +--
  9 +-- This program is distributed in the hope that it will be useful,
  10 +-- but WITHOUT ANY WARRANTY; without even the implied warranty of
  11 +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12 +-- GNU General Public License for more details.
  13 +--
  14 +-- You should have received a copy of the GNU General Public License
  15 +-- along with this program. If not, see <http://www.gnu.org/licenses/>.
  16 +--
  17 +-- Nicolas Casalini "DarkGod"
  18 +-- darkgod@te4.org
  19 +
  20 +return {
  21 + frag = "main_fbo/wobbling",
  22 + vert = nil,
  23 + args = {
  24 + tex = { texture = 0 },
  25 + noisevol = { texture = 1 },
  26 + },
  27 + clone = false,
  28 + permanent = true,
  29 +}
... ...
... ... @@ -2665,6 +2665,95 @@ static int gl_fbo_toscreen(lua_State *L)
2665 2665 return 0;
2666 2666 }
2667 2667
  2668 +static int gl_fbo_posteffects(lua_State *L)
  2669 +{
  2670 + lua_fbo *fbo = (lua_fbo*)auxiliar_checkclass(L, "gl{fbo}", 1);
  2671 + lua_fbo *fbo2 = (lua_fbo*)auxiliar_checkclass(L, "gl{fbo}", 2);
  2672 + lua_fbo *fbo_final = (lua_fbo*)auxiliar_checkclass(L, "gl{fbo}", 3);
  2673 + lua_fbo *tmpfbo;
  2674 + lua_fbo *srcfbo = fbo;
  2675 + lua_fbo *dstfbo = fbo2;
  2676 + int x = luaL_checknumber(L, 4);
  2677 + int y = luaL_checknumber(L, 5);
  2678 + int w = luaL_checknumber(L, 6);
  2679 + int h = luaL_checknumber(L, 7);
  2680 +
  2681 + glDisable(GL_BLEND);
  2682 +
  2683 + GLfloat colors[4*4] = {
  2684 + 1, 1, 1, 1,
  2685 + 1, 1, 1, 1,
  2686 + 1, 1, 1, 1,
  2687 + 1, 1, 1, 1,
  2688 + };
  2689 + glColorPointer(4, GL_FLOAT, 0, colors);
  2690 +
  2691 + GLfloat texcoords[2*4] = {
  2692 + 0, 1,
  2693 + 0, 0,
  2694 + 1, 0,
  2695 + 1, 1,
  2696 + };
  2697 + glTexCoordPointer(2, GL_FLOAT, 0, texcoords);
  2698 +
  2699 + GLfloat vertices[2*4] = {
  2700 + 0, 0,
  2701 + 0, h,
  2702 + w, h,
  2703 + w, 0,
  2704 + };
  2705 + glVertexPointer(2, GL_FLOAT, 0, vertices);
  2706 +
  2707 + // Set the viewport and save the old one
  2708 + glPushAttrib(GL_VIEWPORT_BIT);
  2709 + glViewport(0, 0, fbo->w, fbo->h);
  2710 + glMatrixMode(GL_PROJECTION);
  2711 + glPushMatrix();
  2712 + glLoadIdentity();
  2713 + glOrtho(0, fbo->w, fbo->h, 0, -1001, 1001);
  2714 + glMatrixMode(GL_MODELVIEW);
  2715 + glLoadIdentity();
  2716 +
  2717 + tglClearColor(0, 0, 0, 1);
  2718 +
  2719 + int shad_idx = 8;
  2720 + while (lua_isuserdata(L, shad_idx) && lua_isuserdata(L, shad_idx+1)) {
  2721 + shader_type *s = (shader_type*)lua_touserdata(L, shad_idx);
  2722 + useShader(s, fbo->w, fbo->h, w, h, 1, 1, 1, 1);
  2723 +
  2724 + tglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, dstfbo->fbo);
  2725 + glClear(GL_COLOR_BUFFER_BIT);
  2726 + tglBindTexture(GL_TEXTURE_2D, srcfbo->texture);
  2727 + glDrawArrays(GL_QUADS, 0, 4);
  2728 +
  2729 + shad_idx++;
  2730 + tmpfbo = srcfbo;
  2731 + srcfbo = dstfbo;
  2732 + dstfbo = tmpfbo;
  2733 + }
  2734 +
  2735 + // Bind final fbo (must have bee previously activated)
  2736 + shader_type *s = (shader_type*)lua_touserdata(L, shad_idx);
  2737 + useShader(s, fbo_final->w, fbo_final->h, w, h, 1, 1, 1, 1);
  2738 + glMatrixMode(GL_PROJECTION);
  2739 + glPopMatrix();
  2740 + glMatrixMode(GL_MODELVIEW);
  2741 + glPopAttrib();
  2742 + tglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo_final->fbo);
  2743 + glClear(GL_COLOR_BUFFER_BIT);
  2744 + tglBindTexture(GL_TEXTURE_2D, srcfbo->texture);
  2745 + vertices[0] = x; vertices[1] = y;
  2746 + vertices[2] = x; vertices[3] = y + h;
  2747 + vertices[4] = x + w; vertices[5] = y + h;
  2748 + vertices[6] = x + w; vertices[7] = y;
  2749 + glDrawArrays(GL_QUADS, 0, 4);
  2750 +
  2751 + tglUseProgramObject(0);
  2752 +
  2753 + glEnable(GL_BLEND);
  2754 + return 0;
  2755 +}
  2756 +
2668 2757 static int gl_fbo_is_active(lua_State *L)
2669 2758 {
2670 2759 lua_pushboolean(L, fbo_active);
... ... @@ -3051,6 +3140,7 @@ static const struct luaL_Reg gl_fbo_reg[] =
3051 3140 {
3052 3141 {"__gc", gl_free_fbo},
3053 3142 {"toScreen", gl_fbo_toscreen},
  3143 + {"postEffects", gl_fbo_posteffects},
3054 3144 {"use", gl_fbo_use},
3055 3145 {"png", gl_fbo_to_png},
3056 3146 {NULL, NULL},
... ...