What are some good underwater/distort 2d Filters?

Hey everyone!
I am putting the finishing touches on a simulator that I am working on. The final piece of the puzzle is some sort of underwater 2d filter. I do have the island demo (though I can’t remember who from). But that seems to be a bit hard to implement. The simulator will be fully underwater, so that means that the filter can be on all of the time. And I think that a “simple” wavy distort filter would do the job nicely. However I have not ever written a 2d-filter, and I’m a bit short on time at the moment. So I was wondering if anybody had a good wavy distort or under-water 2d filter.

Thank you! :yes:

This is a basic filter that just uses Sine and Cosine with a Timer property to distort the screen. You can mess with it if you’d like; it’s fairly simple. Not perfect, be warned; assembled very quickly. Anyway, set this up on an object with a Timer property “timer”.


uniform sampler2D bgl_RenderedTexture;

uniform float timer;

void main()
{
    float amp = 0.1;
    float turb = 10.0;
    float border = 0.9;
    vec2 texCoo = gl_TexCoord[0].st;
    float cooX = gl_TexCoord[0].s-0.5;
    float cooY = gl_TexCoord[0].t-0.5;
    vec2 warp = vec2(cooX*(border+sin(timer+cooX*turb)*amp)+0.5,cooY*(border+cos(timer+cooY*turb)*amp)+0.5);
    vec4 warped = texture2D(bgl_RenderedTexture, (warp));
   
    gl_FragColor = warped;
}

If I were you I’d make some sort of low-level depth blur filter a priority. Looks really nice all-around, and certainly would play well underwater.

Hi! Could you reccomend me a filter that makes a blue fog close to player when player is in water(when filter is activated). I need a good looking uw filter…

Actually, I simply need an underwater shader that looks good, but has good performance. Any ideas?

I don’t see any effect in it… I have the requiered ditort already. I more need the distance bsed blur, a fog effect…

Maybe there is a way to make the mist be located only under 0.0. That way it would look quite good. I just need it to not to be on top of water, but need it to be under it…

Oops sorry I made a mistake.

What mistake exactly?

Inverted fog: I don’t know why but I have to invert fog factor to make it work:

It’s linear fog. I’ll try to make it exponential (more realistic)

I don’t know why, but I get blank screen, with only simple cubes, no shaders on them…:confused:

Hi youle, your shader have some errors on my pc, you are trying to do math operations with int and floats (what is not supported by some cards), here a fixed shader:

uniform sampler2D bgl_RenderedTexture;
uniform sampler2D bgl_DepthTexture;
uniform float timer;

vec2 texcoord = vec2(gl_TexCoord[0]).st;
vec2 cancoord = vec2(gl_TexCoord[3]).st;

float near = 0.0;
float far = 100.0;

float camNear = 0.1; //camera clipping start
float camFar = 100.0; //camera clipping end

float R = 0.4;
float G = 0.5;
float B = 0.6;

float linearize(float depth)
{
    return -camFar * camNear / (depth * (camFar - camNear) - camFar);
}

void main(void)
{
    texcoord.y = texcoord.y + (sin(cancoord.x*4.0+timer*2.0)*0.01);
    texcoord.x = texcoord.x + (cos(cancoord.y*4.0+timer*2.0)*0.01);
    
    float depth = linearize(texture2D(bgl_DepthTexture,texcoord.xy).x);
    
    vec4 fog = vec4(R,G,B,0.0);

    float factor = 1.0/clamp((depth-near)/(far - near), 0.0, 1.0)*0.05;
    
    if (factor>0.99999)
    {
        factor = 0.0; 
    }else{ 
        factor *= 1.0;
    }  

    vec4 tex = texture2D(bgl_RenderedTexture, texcoord);
    

    gl_FragColor = mix(fog, tex, factor);
    
}

Maybe that’s why It does not work with adrian, and why all those cubes have the shader? it is an 2d shader, you just have to use one filter 2d actuator.

Another one: http://www.mediafire.com/download/kjhdh9wo1lofj07/underWaterDistortMist2.blend

(I don’t know if it is mathematically correct… I must retrieve the exp expression…)

EDIT: @Carlo697: Thanks for corrections (I had no error on my computer)

Wow, good shader, except- the objects, which are very close, get solid colored… How do I fix it(how do I make them uneffected by shader at all). Here is screen:


OK! Got it. Inreasing the camNear solves that. Setting float far allows you to regulate the density. However, as you can see, there is a frame around which could be removed…

Try to increase camNear value (You got it)

EDIT: Maybe you can try to replace cancoord by texcoord… (I have not this problem on my computer…)

OK! That all together made me a good underwater shader;)