[C++] Reflective Water (conversion from .NET)

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

Here's a [297KB] video showing the problem at water height -

http://irrlicht.spintz.com/movies/WaterShader2.wmv

And here's a longer video [4.75MB] showing the little demo I've put together showing off the water shader. In this demo( towards the end ) you can see some fragments pop up.

http://irrlicht.spintz.com/movies/WaterShader3.wmv

It looks very good and I'm going to press on looking at how to fix the fragments and look at some of the other water info people have posted recently to spice it up some more.
Image
DeusXL
Posts: 114
Joined: Sun Mar 14, 2004 9:37 am
Contact:

Post by DeusXL »

That's pretty weird but I'm really looking forward to see a fix. For now I'll try your new shaders and see the difference (because a video is never enough) and I'll try to fix the GLSL shader.

For the second bug, I fixed it on my scene node by adding a clamp shader. This is a really ugly shader but since Irrlicht does not support clip planes, I had to do that. This bug is due to the fact that nothing under the water height should be drawn on the refraction texture.

EDIT : Okay, I took your HLSL shader and my GLSL shader, the GLSL works perfectly (with no stretching texture bug) and the HLSL works quite better since the only bug there is is this texture stretching bug when you are at the water height.
Here are the shaders :
http://irrlichtnetcp.svn.sourceforge.ne ... iew=markup
Irrlicht .NET complete and Cross Platform Wrapper
The kid on my avatar wrote:A painless lesson is one without any meaning
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

I think i read somewhere that dx has half percision floats and full precision, maybe thats why the glsl isnt buggy. The dx compiler might be deaulting to low aquracy.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

I didn't keep the "clamp shader" when I converted the code (thanks again to DeusXL) as I intended to put in a better solution. I've been kinda sidetracked this week with throwing crates around Quake3 levels and watching them bounce and tumble around (Irrlicht+Newton physics). 8)

What's needed is a clip plane. DeusXL has mentioned this in a separate topic and one reply said Irrlicht didn't support it, which is almost true. It may not be nice, but I was going to use IVideoDriver::getExposedData() to get the driver, set a user clip plane, render the reflected geometry then reset the user clip plane.
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

Clip planes will become part of Irrlicht only after release 1.2 since we do not add any features anymore before the new release. But I'll add this patch later on.
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

omaremad wrote:I think i read somewhere that dx has half percision floats and full precision, maybe thats why the glsl isnt buggy. The dx compiler might be deaulting to low aquracy.
These "half float" precisions are denoted by 'half' while full float precisions are denoted simply by 'float'. We're not using half's anywhere, so don't think that's the problem. The user clip plane I believe could be the problem with the artifacts you see in the larger video I posted. They only appear to be close to the camera maybe because of some screwy Z-ordering, but they are most likely far away on the water plane. I'm going to add user clip planes to IrrSpintz and see if that fixes the problem.
Image
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

I know there is a lack of halves but some vendors cheat and still do stuff in less percision to get more speed.

I think there are certain tricks that can be applied to the shader compilers in the drivers. Nvidia made a driver that made 3dmark process allot less pixels than it should do thus doing it faster and getting fake scores.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

I enabled clip planes. Fixes the artifact problem in OpenGL and DX. However, I'm having a problem with clip planes, in DX.

I'm setting the clip plane to 0,0,0 with a normal of 0,1,0. In DX, this also clips the skybox, which I cant figure out why( clip planes are all new to me ). Anyone have any clue why that would happen? It doesn't happen in OpenGL.
Image
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Maybe clip planes in ogl dont work on things that have depth testing disabled, while in dx they work all the time. Try enabling the clip plane right after the skybox is drawn (cscenemanger.cpp)
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
sio2
Competition winner
Posts: 1003
Joined: Thu Sep 21, 2006 5:33 pm
Location: UK

Post by sio2 »

In DX9 you should specify clip planes in worldspace for the fixed-function pipeline. For shaders you specify clip planes in clipspace (same space as your output vertices).
Spintz
Posts: 1688
Joined: Thu Nov 04, 2004 3:25 pm

Post by Spintz »

sio2 : Yeah, I know that about DX and clip planes, it really sucks.

omaremad : I was thinking that as well. That's probably the only way to do it. I was hoping for a way without doing that. For our purposes it would work, but if you wanted to just set a clip plane and leave it for multiple frames, this would end up being a waste, as you'd have to keep setting/unsetting it constantly.

I've also found a bug with the clip planes in OpenGL I need to fix as well, it's as if the clip plane being transformed by view space or something. I'll get a screenshot/movie of that up sometime this week.
Image
noreg
Posts: 158
Joined: Fri Jun 23, 2006 6:01 pm
Location: continental europe

Post by noreg »

Nice shader, thanks to all who contribute. With pertubation we even had a nice ocean shader, but this on should be already good for indoor pools and very calm lakes. Got the stuff working from page one and packed it with the media file and codeblocks project file into a 7z compressed package.
Works out of the box that way, if you use codeblocks and mingw. This is for all the more "artist" oriented people or those with less time.

Grab it here:
http://fileho.com/download/8f1b09649110/water.7z.html
ca. 3MB, fast server
thefuzion
Posts: 10
Joined: Tue Mar 06, 2007 11:31 am

Post by thefuzion »

Very nice effect ! :D
I think i'll use it a lot
Please, could you specify the licence ? Can we use it as we want ?
lantis
Posts: 64
Joined: Thu Jun 17, 2004 2:46 pm

Post by lantis »

noreg, 0kb file size ;(
Masterhawk
Posts: 299
Joined: Mon Nov 27, 2006 6:52 pm
Location: GERMANY
Contact:

Post by Masterhawk »

Hey Spintz or sio2, I hope you read that....

I've got an issue with the reflective water. The images should explain better than words...

Image

Image

Image

On the last pic you see what I'm supposed to see all the time. But the right reflection only appear when the camera angle is like on the last pic. A little too high(like on pic 1 + 2) and the reflection is gone....
Is there anything I can do?
Last edited by Masterhawk on Fri Jul 20, 2007 8:48 am, edited 1 time in total.
Image
Post Reply