Author Topic: Reflections in water ?  (Read 7495 times)

Offline AW999

  • int
  • **
  • Posts: 57
    • View Profile
Reflections in water ?
« on: January 21, 2010, 04:15:01 am »
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?   

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Reflections in water ?
« Reply #1 on: January 21, 2010, 05:09:17 pm »
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.

Offline fireside

  • double
  • *****
  • Posts: 605
    • View Profile
Re: Reflections in water ?
« Reply #2 on: January 21, 2010, 10:40:22 pm »
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<-

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Reflections in water ?
« Reply #3 on: January 21, 2010, 10:50:29 pm »
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.

Offline AW999

  • int
  • **
  • Posts: 57
    • View Profile
Re: Reflections in water ?
« Reply #4 on: January 22, 2010, 04:43:48 am »
Do you have any plans to add a water reflection feature?  Don't graphics cards do this automatically?

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Re: Reflections in water ?
« Reply #5 on: January 22, 2010, 05:27:36 am »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Reflections in water ?
« Reply #6 on: January 22, 2010, 07:15:40 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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Reflections in water ?
« Reply #7 on: January 24, 2010, 09:02:41 pm »
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...
« Last Edit: January 24, 2010, 10:28:16 pm by EgonOlsen »

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: Reflections in water ?
« Reply #8 on: January 25, 2010, 01:45:15 am »
Nice!  I've been hoping for a feature like this (mostly because I am too lazy to do the work myself  :P)

Offline .jayderyu

  • long
  • ***
  • Posts: 116
    • View Profile
Re: Reflections in water ?
« Reply #9 on: January 25, 2010, 05:09:07 am »
that looks really nice :) good job.

Offline AGP

  • quad
  • ******
  • Posts: 1518
    • View Profile
Re: Reflections in water ?
« Reply #10 on: February 22, 2010, 03:24:06 am »
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!

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Reflections in water ?
« Reply #11 on: February 23, 2010, 08:47:12 am »
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.

Offline AW999

  • int
  • **
  • Posts: 57
    • View Profile
Re: Reflections in water ?
« Reply #12 on: February 26, 2010, 01:15:05 am »
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? 

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: Reflections in water ?
« Reply #13 on: February 26, 2010, 08:09:48 am »
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

Offline zammbi

  • float
  • ****
  • Posts: 360
    • View Profile
Re: Reflections in water ?
« Reply #14 on: August 17, 2010, 03:35:42 am »
Quote
I'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?