Jump to content

[SOLVED] Underwater effect


photo

Recommended Posts

Hi,

In our application, I have to deal with underwater scenes, playing with world expression nodes and blur effect I achieved what you can see in the screenshot:

post-59-0-58343700-1344265536_thumb.jpg

I want to improve the scene adding a post filter like

. I don't have experience with shaders so my starting point are the unigine shaders and your good advices ;)

 

Thanks in advance.

Link to comment

Hi,

In our application, I have to deal with underwater scenes, playing with world expression nodes and blur effect I achieved what you can see in the screenshot:

post-59-0-58343700-1344265536_thumb.jpg

I want to improve the scene adding a post filter like

. I don't have experience with shaders so my starting point are the unigine shaders and your good advices ;)

 

Thanks in advance.

 

Maybe its an idea to use the heat refraction effect and attach that to the player as soon as your underwater

Link to comment

To create a post process effect start by creating a new material library file.

 

<?xml version="1.0" encoding="utf-8"?>
<materials version="1.00">
 <material name="example_post_process" editable="0">
  <!-- shaders -->
<shader pass="post"
vertex="shaders/vertex_post_example.shader"
fragment="shaders/fragment_filter_example.shader"/>
  <!-- textures -->
<texture name="color" pass="post" type="procedural"/>
  <!-- parameters-->
<parameter name="example_param" type="slider" shared="1" min="0.0" max="1.0">0.0</parameter>
 </material>
</materials>

 

Here you define the "post" pass for the effect along with 2 shader files which will need to be written.

The "color" texture, is simply the render of the scene up untill the point of the post process effect (think of it as a screen grab)

You can use other textures such as "deferred_depth" (I'm not sure where the full list buffered textures are, but you can work them out from looking at other material libraries as a reference)

The parameters are list of variables that can be configured in the material editor window. Ensure the shared flag is set so the shader can acccess them. They are declared in xml very similarly to property variables which are better documented so perhaps look at them first.

 

When writing shaders, write for DX9 first and get it working before writing for other drivers, as shaders are notoriously hard to debug. Also all GLSL has been redefined to write like HLSL, which is v. nice on Unigine's behalf :-).

To start, create a vertex shader. Usually for a post process effect they only require some default number juggling and can be as simple as;

 

#elif DIRECT3D9
struct VERTEX_IN {
float4 position : POSITION;
float4 texcoord : TEXCOORD0;
float4 color : COLOR0;
};
struct VERTEX_OUT {
float4 position : POSITION;
float4 texcoord_0 : TEXCOORD0;
};
/*
*/
VERTEX_OUT main(VERTEX_IN IN) {

VERTEX_OUT OUT;

OUT.position = getPosition(IN.position);
OUT.texcoord_0 = IN.texcoord;

return OUT;
}

 

The fragment (or pixel) shader is setup in a similar way, For example you can use the pixel colours of the "color" texture and modulate them in some way, perhaps with a parameter value!

 

#elif DIRECT3D9
float example_parameter; //This is our parameter (remember the shared flag!)
struct FRAGMENT_IN {
float4 texcoord_0 : TEXCOORD0;
};
/*
*/
half4 main(FRAGMENT_IN IN) : COLOR {

half4 colour = tex2D(s_texture_0,IN.texcoord_0.xy); //This is the "color" texture colour at the current texture coord
colour.x += example_param; //this will naievly brighten up the rgb colour values
colour.y += example_param;
colour.z += example_param;
saturate(colour);
return outputColour;
}

 

Hope that helps

Link to comment

Kudos, Carl! A really nice explanation.

 

Ivan, it really looks to me that the effect shown on the video can be achieved with a combination of water Volume + DOF. Or is there something else in it?

Link to comment
  • 3 months later...

Its funny that so many games like to use this warping effect to simulate underwater. The truth is that water does not do that in reality through glass or through bare eyes. The only time I have ever seen water warp like that is when there is a sudden temperature difference, hence varying IOR, and that is not very common.

Link to comment

Steve, yep, fully agreed. This effect has little to do with real life since it does not happen often.

 

But if it's needed to create a proper atmosphere or a feeling of immersion, why not, actually. It's an artist's point of view (let's remember sound, vacuum and star wars).

Link to comment
×
×
  • Create New...