Reflections in water ?

Started by AW999, January 21, 2010, 04:15:01 AM

Previous topic - Next topic

AW999

I haven't been able to find any information on this, so I'm posting a question.
What's the best way of rendering water so that it reflects the landscape?   

EgonOlsen

No real idea...the basic idea is to render the scene once into a texture and somehow project and perturb it onto the water's surface. While the first step (render into the texture) is pretty easy, i've no idea how to do the second step properly. I've found some examples based on shaders, but i think that it should be possible without them. I've once tried to use a projective texture for it, but the effect didn't really look great.
Another way is to render the scene upside down and use a stencil buffer to cut out the water when rendering it normally. But i don't think that this is what people are doing nowadays.

fireside

I'm still working on a project in another language, but isn't it like environmental mapping like the shiny gun thing in the fps? 
click here->Fireside 7 Games<-

EgonOlsen

Not exactly. That's spherical environment mapping. I think you can do something with cubic environment mapping (currently not supported), but i'm not sure if you have to.

AW999

Do you have any plans to add a water reflection feature?  Don't graphics cards do this automatically?

.jayderyu

sigh

I'm interested in this too. At some point. I was working on trying to get some water rendering working, but my math skills were far lacking in understanding complex numbers for Fast Fourouir Transforms to understand it or how to translate it to code. So i'm taking a break and weak by weak pick up my math skills.

In the mean time. I would suggest "Planar mirrors for local reflections" @ (http://www.gamedev.net/reference/articles/article2138.asp).

It has lot's of discussion on how to do water. And no water reflection is not a default feature of graphics cards. It is however becoming a more accessible middle ware for C++/DX/OLG. Java is a bit behind.

JME does have a water demo that your looking for however. http://www.youtube.com/watch?v=UVbKNUaYuBk
The video shows landscape reflection. They also have a few water features.

EgonOlsen

Quote from: .jayderyu on January 22, 2010, 05:27:36 AM
In the mean time. I would suggest "Planar mirrors for local reflections" @ (http://www.gamedev.net/reference/articles/article2138.asp).
That is basically what i tried to do (i.e. render from the camera's view into a texture, use projective texturing to project it onto the water surface...)...it somehow didn't worked out. I'll give it another shot, when i find the time...

EgonOlsen

#7
It works now. It was a problem with my the transformation code from jPCT's into OpenGL's coordinate system that only occured when using a combined transformation matrix, which jPCT by itself doesn't, which is why i never noticed it before. This is how it looks like (note that there's no distortion (i.e. the water is a planar mirror), because i'm not using shaders for this):



It cuts framerate almost in half, because you render the scene two times. One for the normal view and one for the reflection map. One may use a cheaper scene for the reflection map (like replace the trees with billboards and such), but i didn't want to take this demo too far. It even runs on a shitty i945G Intel integrated graphics...but very slow (not that this thing would be fast otherwise...).

I'll release a version for download when i've cleaned everything up, which may take a while...

paulscode

Nice!  I've been hoping for a feature like this (mostly because I am too lazy to do the work myself  :P)

.jayderyu

that looks really nice :) good job.

AGP

Egon, so what exactly did you do? Did you add another camera somewhere or just use the original one with which to paint the texture? And what was the method you used to create the texture (did you paint an Image then pass it to the texture?)? Show us the code!

EgonOlsen

It's a combination of projective texture mapping and render-to-texture. The scene is rendered into a texture using a tweaked camera matrix and then that texture is projected onto the plane. This happens each frame, which is why the frame rate is almost cut in half.
I'm currently creating a helper class to ease this. I'll post the sources of that class and the modified terrain demo, when it's done. I'm still quite busy ATM, which is why this takes a little longer than usual.

AW999

I've been hoping for a feature like this, since it adds a lot of realism.

BTW, since you said you were busy, I assume that means you aren't able to devote full time to JPCT? 

EgonOlsen

It never was a full time job anyway... ;D It's just that we still have a lot of work to do in our new home plus i have several jPCT related thing to work on like improving the reflection stuff, finishing (maybe...) the Android port and in addition, i'm using it for a small project at work right now, which requires some changes too...and don't forget that a bunch of interesting games comes out within the next weeks... ;D

zammbi

QuoteI'll release a version for download when i've cleaned everything up, which may take a while...
Was this ever added? I don't remember reading about it. If not could you share the code?