Commit 8d9821ebb227fc325023f54ae82a8269bd3755cf

Authored by DarkGod
1 parent 5b3285fa

New fullscreen effect for stuns/dazes

... ... @@ -424,6 +424,12 @@ function _M:updateMainShader()
424 424 if game.level and game.level.data and game.level.data.underwater then game.fbo_shader:setUniform("underwater", 1)
425 425 else game.fbo_shader:setUniform("underwater", 0) -- Disable
426 426 end
  427 +
  428 + -- 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
  432 + end
427 433 end
428 434 end
429 435
... ...
... ... @@ -2,6 +2,7 @@ uniform float hp_warning;
2 2 uniform float air_warning;
3 3 uniform float death_warning;
4 4 uniform float solipsism_warning;
  5 +uniform float wobbling;
5 6 uniform float motionblur;
6 7 uniform float underwater;
7 8 uniform float blur;
... ... @@ -67,11 +68,129 @@ float col(vec2 coord)
67 68 return cos(col);
68 69 }
69 70
  71 +vec4 permute( vec4 x ) {
  72 +
  73 + return mod( ( ( x * 34.0 ) + 1.0 ) * x, 289.0 );
  74 +
  75 +}
  76 +
  77 +vec4 taylorInvSqrt( vec4 r ) {
  78 +
  79 + return 1.79284291400159 - 0.85373472095314 * r;
  80 +
  81 +}
  82 +
  83 +float snoise( vec3 v ) {
  84 +
  85 + const vec2 C = vec2( 1.0 / 6.0, 1.0 / 3.0 );
  86 + const vec4 D = vec4( 0.0, 0.5, 1.0, 2.0 );
  87 +
  88 + // First corner
  89 +
  90 + vec3 i = floor( v + dot( v, C.yyy ) );
  91 + vec3 x0 = v - i + dot( i, C.xxx );
  92 +
  93 + // Other corners
  94 +
  95 + vec3 g = step( x0.yzx, x0.xyz );
  96 + vec3 l = 1.0 - g;
  97 + vec3 i1 = min( g.xyz, l.zxy );
  98 + vec3 i2 = max( g.xyz, l.zxy );
  99 +
  100 + vec3 x1 = x0 - i1 + 1.0 * C.xxx;
  101 + vec3 x2 = x0 - i2 + 2.0 * C.xxx;
  102 + vec3 x3 = x0 - 1. + 3.0 * C.xxx;
  103 +
  104 + // Permutations
  105 +
  106 + i = mod( i, 289.0 );
  107 + vec4 p = permute( permute( permute(
  108 + i.z + vec4( 0.0, i1.z, i2.z, 1.0 ) )
  109 + + i.y + vec4( 0.0, i1.y, i2.y, 1.0 ) )
  110 + + i.x + vec4( 0.0, i1.x, i2.x, 1.0 ) );
  111 +
  112 + // Gradients
  113 + // ( N*N points uniformly over a square, mapped onto an octahedron.)
  114 +
  115 + float n_ = 1.0 / 7.0; // N=7
  116 +
  117 + vec3 ns = n_ * D.wyz - D.xzx;
  118 +
  119 + vec4 j = p - 49.0 * floor( p * ns.z *ns.z ); // mod(p,N*N)
  120 +
  121 + vec4 x_ = floor( j * ns.z );
  122 + vec4 y_ = floor( j - 7.0 * x_ ); // mod(j,N)
  123 +
  124 + vec4 x = x_ *ns.x + ns.yyyy;
  125 + vec4 y = y_ *ns.x + ns.yyyy;
  126 + vec4 h = 1.0 - abs( x ) - abs( y );
  127 +
  128 + vec4 b0 = vec4( x.xy, y.xy );
  129 + vec4 b1 = vec4( x.zw, y.zw );
  130 +
  131 +
  132 + vec4 s0 = floor( b0 ) * 2.0 + 1.0;
  133 + vec4 s1 = floor( b1 ) * 2.0 + 1.0;
  134 + vec4 sh = -step( h, vec4( 0.0 ) );
  135 +
  136 + vec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy;
  137 + vec4 a1 = b1.xzyw + s1.xzyw * sh.zzww;
  138 +
  139 + vec3 p0 = vec3( a0.xy, h.x );
  140 + vec3 p1 = vec3( a0.zw, h.y );
  141 + vec3 p2 = vec3( a1.xy, h.z );
  142 + vec3 p3 = vec3( a1.zw, h.w );
  143 +
  144 + // Normalise gradients
  145 +
  146 + vec4 norm = taylorInvSqrt( vec4( dot( p0, p0 ), dot( p1, p1 ), dot( p2, p2 ), dot( p3, p3 ) ) );
  147 + p0 *= norm.x;
  148 + p1 *= norm.y;
  149 + p2 *= norm.z;
  150 + p3 *= norm.w;
  151 +
  152 + // Mix final noise value
  153 +
  154 + vec4 m = max( 0.6 - vec4( dot( x0, x0 ), dot( x1, x1 ), dot( x2, x2 ), dot( x3, x3 ) ), 0.0 );
  155 + m = m * m;
  156 + return 42.0 * dot( m*m, vec4( dot( p0, x0 ), dot( p1, x1 ),
  157 + dot( p2, x2 ), dot( p3, x3 ) ) );
  158 +
  159 +}
  160 +
  161 +
  162 +vec2 snoise2(vec3 pos)
  163 +{
  164 + return vec2(snoise(pos), snoise(pos + vec3(0.0, 0.0, 1.0)));
  165 +}
  166 +
70 167 void main(void)
71 168 {
72 169 gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
73 170
74   - if (motionblur > 0.0)
  171 + /*vec2 offset =
  172 + vec4 offsetColor = texture2D(tex, gl_TexCoord[0].xy);*/
  173 +
  174 + if (wobbling > 0.0)
  175 + {
  176 + float scaledTime = tick / 5000.0;
  177 + vec2 coord = gl_TexCoord[0].xy;
  178 + coord.x *= texSize.x / texSize.y;
  179 + vec2 offset =
  180 + snoise2(vec3(coord / 2.0, scaledTime / 0.25)) * 0.33 * 3.0 +
  181 + snoise2(vec3(coord / 2.0, scaledTime / 2.0)) * 0.0 +
  182 + snoise2(vec3(coord / 4.0, scaledTime / 4.0)) * 0.0;
  183 +
  184 + offset.x *= texSize.x / texSize.y;
  185 +
  186 + 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
  187 + ratio *= (1.0 + snoise2(vec3(coord / 2.0, scaledTime / 0.25 + 10.0))) * 0.5;
  188 +
  189 + gl_FragColor =
  190 + texture2D(tex, gl_TexCoord[0].xy) * (1.0 - ratio) +
  191 + texture2D(tex, gl_TexCoord[0].xy + offset * 0.01 * wobbling) * ratio;
  192 + }
  193 + else if (motionblur > 0.0)
75 194 {
76 195 int blursize = int(motionblur);
77 196 vec2 offset = 0.8/texSize;
... ...