Realistic water scene node

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi.

I've read a little more of your code. I removed the "FRESNEL effect". I don't have the effect anymore. But the refraction is good now.

The refraction was hidden from the X angle of the camera and I don't understand why. From your code, there is no X axis implied in the Fresnel effect.

The only thing i'm 100% sure now. That the problem I have is in this calculation of the fresnel.

Code: Select all

// previous code was:
//float4 combinedColor = refractiveColor*fresnelTerm + reflectiveColor*(1-fresnelTerm);
// disabling fresnel like this:
        float4 combinedColor = refractiveColor + reflectiveColor/4;
Can you check on your side to see what I mean?

After some tweaking, here are some picture of the water of my demo:
Image
Image
Image
Image

This is the new source that you sent last time. I've started implementing with the first source you produced.

If you see now in theses pictures, we clearly see the refraction (the dark parts in the water are the Asphalt and the clearer part are the cement.)

Now it's working like I like. I've also changed a little the water color (too blue for my taste)

I've found a strange problem with my distribution of Irrlicht 1.3.1. The function

Code: Select all

CurrentCamera->GetFOV();
cause a crash. I had to put a valud instead of using GetFOV;

Some questions here:
- Is there a way to get a global value of my main() there?

- Is there a bounding box function that could render the water if the camera enter the zone of the bounding box? I've had to put very ugly code to (if ... if... if...) to do this and get good FPS until we get near of the water...

- Is there some kind of replacement for the clipping planes function that I had to comment out?
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Did you have to do something with the Camera Position too christian?

It seems when I change that code it gives me an error in my Irrlicht debug saying that it couldnt find the value for camera position.

Code: Select all

HLSL Variable to set not found: 'CameraPosition'. Available variables are:
  'ColorBlendFactor' Registers:[begin:2, count:1]
  'ReflectionMap' Registers:[begin:2, count:1]
  'RefractionMap' Registers:[begin:1, count:1]
  'WaterBump' Registers:[begin:0, count:1]
  'WaterColor' Registers:[begin:1, count:1]
  'WaveHeight' Registers:[begin:0, count:1]
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Yes. :)

I commented out that line in RealisticWater.cpp

Code: Select all

//services->setPixelShaderConstant("CameraPosition", &CameraPosition.X, 3);
This line sent a parameter for the calculation of the Fresnel. Since I've disabled it. I commented that out. The output is clean now.

I've modified the pixel shader program to do not account for the Fresnel effect because there is a problem here with it (It's affected by the heading of the camera and shoulnt. The Fresnel effect should only affect surfaces from the pitch of the camera)

If you comment it. I suggest that you try this in the shader program file:
Water_ps.hlsl

Code: Select all

//Previous code by Elvman
//float4 combinedColor = refractiveColor*fresnelTerm + reflectiveColor*(1-fresnelTerm);
//Modified code by Christian Clavet (Fresnel effect disabled)
        float4 combinedColor = refractiveColor + reflectiveColor/4;
The parameter is send for the calculation of the fresnel effect. I think there is a problem with it, Elvman could surely find out. (I've just commented out so it's easy to put back in place)

EDIT: Also note that this reflectiveColor/4 is for getting a reflectivity of 25%. For my kind of water it's correct. 100% reflectivity is too much for my taste.
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Ok, I will try to fix all these problems today.
Last edited by elvman on Wed Aug 22, 2007 7:14 am, edited 1 time in total.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

christianclavet wrote: EDIT: Also note that this reflectiveColor/4 is for getting a reflectivity of 25%. For my kind of water it's correct. 100% reflectivity is too much for my taste.
Actually, you are getting 100 percent see through + reflective colour.

May I suggest:

Code: Select all

float4 combinedColor = lerp(refractiveColor,reflectiveColor,0.25);
or it might be

Code: Select all

float4 combinedColor = lerp(refractiveColor,reflectiveColor,0.75);
(I always forget the order in which lerp works...)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Hey Elvman, since you are in a bug fixing mode I wanted to show you the bugs I am facing in hopes that it helps you. [Lots of images]

I will try to describe the errors and show you images of them.

- When I look a little bit higher than straight I can see right through the water and I see the bottom skybox picture.
Image

- When I look almost 45 degrees downward, I see my character's textures (unwrapped) far away in the water for some reason.
Image

- When I try to look at an intermediate angle I see these artifacts in the water.
Image

The code that I am working with is the following:

Code: Select all

RealisticWaterSceneNode* pWater;

pWater = new RealisticWaterSceneNode(irrSceneMan, 2048.0f, 2048.0f, irrDriver->getTexture("data/textures/env/water2.png"),irrDevice->getTimer(),core::dimension2di(512,512));

pWater->setPosition(vector3df(257*4,WATER_HEIGHT,257*4));

pWater->setWindForce(1.0f);

Modifications that I made to the code according to christians info:

Code: Select all

//In the .hlsl file:

//float4 combinedColor = refractiveColor*fresnelTerm + reflectiveColor*(1-fresnelTerm);
	float4 combinedColor = refractiveColor + reflectiveColor/4;
	//float4 combinedColor = lerp(refractiveColor,reflectiveColor,0.25); 

//In the RealisticWater.cpp file:
//services->setPixelShaderConstant("CameraPosition", &CameraPosition.X, 3);

Hope to see these bugs fixed soon! I am simply awed by your work. Thanks a bunch for the scene node!
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

Ok, thanks for your bugreport krama757. Now I have a clue, where these bugs are hidden. I hope I will fix them as soon as possible.
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi!

for the unwrapping I saw the textures (or geometry) of my second object (Subway station tunnel) in the reflection. It shoulnt be in the reflection because the object is underground and I've modeled the bottom of the little lake. So I've put a code to hide the geometry when I was near the water. Then the problem for my demo was fixed.

But this seem similar of the unwrapping of the texture krama757 is experiencing.

krama757 are you using the OPENGL driver or the DIRECTX9.0 driver? The modification I've done only work on DIRECTX at the moment.

BlindSide it's strange that my reflectiveColor/4 faded the amount of reflection the way that I wanted. Anyway tried and saw that my actual code is DIVIDING the light intensity of the reflection (somewhat similar).

Your code is giving about the same result but it's also work:

Code: Select all

float4 combinedColor = lerp(refractiveColor,reflectiveColor,0.25); 
You mean that It could be possible to change the "see through" so the water could be a little more opaque? This could be very interesting if you would like to make "murky" water, like in a swamp. :)

These could be nice parameters to add into the function. (Amount of reflection, opacity value)
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Yep I'm using Direct X too. Everything seems to work terribly in Open GL...lighting models etc. so I'm not using it for now.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

christianclavet wrote: BlindSide it's strange that my reflectiveColor/4 faded the amount of reflection the way that I wanted. Anyway tried and saw that my actual code is DIVIDING the light intensity of the reflection (somewhat similar).
There is a small difference but it is very important. In your code you are doing:

A + B / 4. So if A = 1 and B = 1, then you might get a value of 1.25! This will cause strange colours to appear (Sometimes inverted) or maybe just alot of white space. Also everything will appear bright.

The lerp function is basically just A * (1 - S) + B * S. And here S is 0.25, so it is A * 0.75 + B * 0.25, both can combine to achieve a maximum value of 1, with no strange results.

Offcourse, you can change "S" (0.25) to any number between 0 - 1 to effect the level of reflectivity in the water to your tastes.

Cheers :D
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Thanks for the explanation Blindside! :)

I've used your code. My water is looking very good now. Big Thanks to Elvman this water is incredible!

Image
krama757
Posts: 451
Joined: Sun Nov 06, 2005 12:07 am

Post by krama757 »

Christian, could you post what code you are using? I cant get such nice results :(

What kind of size are you using for the node? Mine is 2048 x 2048...so its quite huge.
koller202
Posts: 143
Joined: Tue May 08, 2007 4:53 am
Location: Thailand

Post by koller202 »

i error in cpp

Code: Select all

VideoDriver->setClipPlane(0,refractionClipPlane,true);

Code: Select all

VideoDriver->enableClipPlane(0,false);

error message

Code: Select all

c:\documents and settings\numxyz\desktop\irrlicht-1.3.1\irrlicht-1.3.1\examples\07.collision\realisticwater.cpp(83) : error C2039: 'setClipPlane' : is not a member of 'IVideoDriver'
        c:\documents and settings\numxyz\desktop\irrlicht-1.3.1\irrlicht-1.3.1\include\ivideodriver.h(75) : see declaration of 'IVideoDriver'
c:\documents and settings\numxyz\desktop\irrlicht-1.3.1\irrlicht-1.3.1\examples\07.collision\realisticwater.cpp(87) : error C2039: 'enableClipPlane' : is not a member of 'IVideoDriver'
        c:\documents and settings\numxyz\desktop\irrlicht-1.3.1\irrlicht-1.3.1\include\ivideodriver.h(75) : see declaration of 'IVideoDriver'
Error executing cl.exe.

and if i comment in line i can compile it and work cool in direct x 9

opengl can t

only in direct x 9 ?
________
Motorcycle tires
Last edited by koller202 on Thu Feb 17, 2011 1:15 am, edited 1 time in total.
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

You can comment out these lines, because clip planes are supported in upcoming Irrlicht 1.4 only. OpenGL support is under development.
elvman
Posts: 253
Joined: Sun Sep 17, 2006 9:37 am
Location: Riga, Latvia
Contact:

Post by elvman »

TO krama757: try setting the RealisticWaterSceneNode's height to 0. I will fix the bug with water height soon.
Post Reply