Skip to content
Snippets Groups Projects
Commit e6a5d4b1 authored by DarkGod's avatar DarkGod
Browse files

When in underwater levels the screen will very slightly .. hum .. wooble

parent e78cd320
No related branches found
No related tags found
No related merge requests found
......@@ -405,6 +405,11 @@ function _M:updateMainShader()
elseif game.level and game.level.data and game.level.data.motionblur then game.fbo_shader:setUniform("motionblur", game.level.data.motionblur)
else game.fbo_shader:setUniform("motionblur", 0) -- Disable
end
-- Underwater shader
if game.level and game.level.data and game.level.data.underwater then game.fbo_shader:setUniform("underwater", 1)
else game.fbo_shader:setUniform("underwater", 0) -- Disable
end
end
end
......
......@@ -3,6 +3,7 @@ uniform float air_warning;
uniform float death_warning;
uniform float solipsism_warning;
uniform float motionblur;
uniform float underwater;
uniform float blur;
uniform float tick;
uniform sampler2D noisevol;
......@@ -11,6 +12,61 @@ uniform sampler2D tex;
uniform vec4 colorize;
uniform vec4 intensify;
// Simple Water shader. (c) Victor Korsun, bitekas@gmail.com; 2012.
//
// Attribution-ShareAlike CC License.
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 mapCoord;
const float PI = 3.1415926535897932;
// play with these parameters to custimize the effect
// ===================================================
//speed
const float speed = 0.05;
const float speed_x = 0.3;
const float speed_y = 0.3;
// refraction
const float emboss = 0.05;
const float intensity = 0.4;
const int steps = 6;
const float frequency = 100.0;
const int angle = 7; // better when a prime
// reflection
const float delta = 60.;
const float intence = 700.;
const float reflectionCutOff = 0.012;
const float reflectionIntence = 200000.;
// ===================================================
float time = tick / 30000.0;
float col(vec2 coord)
{
float delta_theta = 2.0 * PI / float(angle);
float col = 0.0;
float theta = 0.0;
for (int i = 0; i < steps; i++)
{
vec2 adjc = coord;
theta = delta_theta*float(i);
adjc.x += cos(theta)*time*speed + time * speed_x;
adjc.y -= sin(theta)*time*speed - time * speed_y;
col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity;
}
return cos(col);
}
void main(void)
{
gl_FragColor = texture2D(tex, gl_TexCoord[0].xy);
......@@ -96,6 +152,30 @@ void main(void)
sample /= (blur*2.0) * (blur*2.0);
gl_FragColor = sample;
}
else if (underwater > 0.0)
{
vec2 p = (vec2(gl_FragCoord.x - mapCoord.x, texSize.y - gl_FragCoord.y - mapCoord.y)) / texSize.xy, c1 = p, c2 = p;
float cc1 = col(c1);
c2.x += texSize.x/delta;
float dx = emboss*(cc1-col(c2))/delta;
c2.x = p.x;
c2.y += texSize.y/delta;
float dy = emboss*(cc1-col(c2))/delta;
c1.x += dx*2.;
c1.y = -(c1.y+dy*2.);
float alpha = 1.+dot(dx,dy)*intence;
float ddx = dx - reflectionCutOff;
float ddy = dy - reflectionCutOff;
if (ddx > 0. && ddy > 0.) alpha = pow(alpha, ddx*ddy*reflectionIntence);
vec4 col = texture2D(tex,c1)*(alpha);
gl_FragColor = col;
}
if (colorize.r > 0.0 || colorize.g > 0.0 || colorize.b > 0.0)
{
......
......@@ -27,6 +27,7 @@ return {
width = 70, height = 70,
-- all_remembered = true,
all_lited = true,
underwater = true,
persistent = "zone",
ambient_music = "Inside a dream.ogg",
-- Apply a bluish tint to all the map
......
......@@ -84,6 +84,7 @@ return {
},
},
[2] = {
underwater = true,
generator = {
actor = {
filters = {{special_rarity="water_rarity"}},
......@@ -91,6 +92,7 @@ return {
},
},
[3] = {
underwater = is_flooded,
generator = is_flooded and {
map = {
down = "SHERTUL_FORTRESS",
......
......@@ -26,6 +26,7 @@ return {
width = 70, height = 70,
-- all_remembered = true,
-- all_lited = true,
underwater = true,
persistent = "zone",
ambient_music = "Inside a dream.ogg",
-- Apply a bluish tint to all the map
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment