Water Reflections

Hello everyone,

I'm coding a little terrain engine in Java3D and was wondering if anyone could give me a few pointers with some questions I have. I'm aware of course that this is a forum for jME, but my questions are fairly general and (hopefully) not too API specific. Besides that, this community seems to be extremely active, welcoming and helpful!

How is the effect of water reflection acheived? I'm vaguely aware of the following approach…

    - Render the relevant aspects of the current scene to a texture (terrain and sky)

    - Pass that texture down to your shader

    - Perform the necessary operations with your noise texture and the rendered scene texture to create the appearance of a reflection.

The last part isn't much of a problem, because I've got quite a number of good examples of water shaders and they are simple enough to understand.

Where I am running into difficulty is the initial step of rendering to texture. I don't really understand how I can produce a texture from my current scene which is appropriate as a reflection. Off the top of my head, I suppose that it should be something along the lines of…

  • Invert the appropriate aspects along the vertical axis
  • When in the shader, have the reflection texture be projected onto the surface from the camera's point of view.

    The most immediate problem, and perhaps one which is of least relevance to the jME forum, is that, as far as I can tell, Java3D does not actually have a render-to-texture function! Does anyone know if this is the case, and if so, are water reflections in Java3D a total dead-end? Are there any possible work-arounds to acheive this effect myself?

    I suppose I'll leave it at that for now. If anyone has any useful information at all regarding this problem, I would be greatly appreciative. I have seen the work of Mr.Coder with the projected grid implementation and was extremely impressed. I'm only hoping to have a simple reflective quad stretched across my scene, so I hope someone can give a bit of insight!


Well, jME has a pretty nice water effect, you could always look at what that does… uses RTT though.

Or just switch to jME, and use that effect, of course :wink:

Heh, I'd love to switch to jME at this point, Java3D has a relatively inactive community around it, and trying to find examples of how effects like this have been acheived is a nightmare.

Unfortunately I don't have the time available to start from scratch with a new API (this is part of my dissertation for my degree, and needs to be completed within the next 6-8 weeks). At this point, I'm not too fussed about the water looking fantastic, I'd just be happy with a relatively simple looking reflection effect. I'm experimenting with an example of rendering scenes to an off-screen canvas at the moment, hopefully it can function in something approaching real-time!

You might find that it takes you less time to switch than you thought.  In addition, the fact that we've got built-in water support in jME already will give you a massive jump-start toward your ultimate goal.  Or, if you're determined to write it yourself at least a working example that you can see the source code for how it works.