Realistic water node

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
rustyk
Posts: 25
Joined: Sat Jan 10, 2015 4:03 pm

Re: Realistic water node

Post by rustyk »

Hey elvman,

I really like your water implementation and I would like to see it in action. Would you mind providing some example like the one (similar setup) in the screenshot?

Thanks.
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Re: Realistic water node

Post by elvman »

I added usage instructions to the repository: https://github.com/elnormous/RealisticWaterSceneNode
Ouzel – 2D game engine
Realistic water node
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

Hi! elvman.. When I compiled and tested your project it worked fine in DX (HLSL) mode,
but when I ran it in GL(GLSL) mode I got strange water artifacts. (funny light blue effect from the normal map)

I changed the code in "ShaderMaterial" as follows:

Code: Select all

 
 
 // Approx line 234 in "ShaderMaterial.cpp"..
 // Set texture names for OpenGL Shaders
 // (this is not necessary for DirectX)
 
 if(userdata == 1)
  {for (u32 i=0; i<video::MATERIAL_MAX_TEXTURES; ++i)
    {if(Material.TextureLayer[i].Texture != NULL)
     // services->setPixelShaderConstant(TextureName[i].c_str(), (f32*) &i, 1);  // -- OLD LINE --
     services->setPixelShaderConstant(TextureName[i].c_str(), (s32*) &i, 1);     // -- NEW LINE --
     // I Changed (f32) to (s32) and it worked fine!
    }
  }
 
 
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

I'm still trying to figure out how to use the existing shaders along with my object shaders.
Fog is a problem as I have to incorporate it into ALL the shaders.
(not serious and will be solved eventually)
Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

This is what happens when you have.

Code: Select all

services->setPixelShaderConstant(TextureName[i].c_str(), (f32*) &i, 1);
instead of

Code: Select all

services->setPixelShaderConstant(TextureName[i].c_str(), (s32*) &i, 1);
(f32) should be (s32)..

Image
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

@elvman.. Thanks for sharing this!
I see you can even COMBINE the shaders rendered to the Rendertarget.

Here is my own "underwater" version..
Image


It combines the shaders like this.

Code: Select all

 
   postProcessManager->render(EPPE_UNDER_WATER);     // Original O.K ..
   postProcessManager->render(EPPE_BLUR);            // GLSL O.K.  HLSL O.K.
   postProcessManager->render(EPPE_RADIAL_BLUR);     // GLSL O.K.  HLSL O.K.
 
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

And the best part of all is the FXAA! Unbelievable considering it uses only the pixels in the buffers!
(not the traditional slow multiple geometry rendering)
Here is a magnification of what it can do after turning All AA methods OFF in my NVIDIA Controll panel!

Image

Really cool stuff! Thanks elvman!
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

Fertile ground..
Image
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: Realistic water node

Post by The_Glitch »

Yeah if I remember correctly there are some lines that have to be changed to s32 instead of f32.
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

I've noticed that the version of this thing I have is not the same as pointed to by the link..
Why is this? Are all those other cool things still available somewhere?
The_Glitch
Competition winner
Posts: 523
Joined: Tue Jan 15, 2013 6:36 pm

Re: Realistic water node

Post by The_Glitch »

I just decided to make my own water that way you can implement it any way you like :P
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

@ elvman..(or the_glitch) Hi! The water reflection version with the terrain node and all the other shaders is
quite complex and will take a while to grasp, so I decided to use your
simplified water scene node..

Very cool, but I get a strange offset in the reflected image and
some artifacts on the left side..
What am i doing wrong?

Image:
Image
I meant Artifacts.. :?
Vectrotek
Competition winner
Posts: 1087
Joined: Sat May 02, 2015 5:05 pm

Re: Realistic water node

Post by Vectrotek »

SOLVED..
In the "Water_ps.glsl" file:

Code: Select all

 
  void main()
  {// Bump Colour..
   vec4 bumpColor = texture2D(WaterBump, bumpMapTexCoord);
 
   //  vec2 perturbation = WaveHeight * (bumpColor.rg - 0.5); // Old line..
    vec2 perturbation = WaveHeight * (bumpColor.rg - 0.25);  //  0.5 replaced by 0.25 
   // rest of code....
 
and in the "Water_ps.hlsl" file:

Code: Select all

 
 PS_OUTPUT main( PS_INPUT input )
{ 
    PS_OUTPUT output;
    
    //bump color
    float4 bumpColor = tex2D(WaterBump, input.bumpMapTexCoord);
    // float2 perturbation = WaveHeight * (bumpColor.rg - 0.5); // Old line..
    float2 perturbation = WaveHeight * (bumpColor.rg - 0.25);  //  0.5 replaced by 0.25 
 
Last edited by Vectrotek on Sat Jun 18, 2016 3:19 pm, edited 1 time in total.
Post Reply