Hi. The new WaterFilter post processor in jme3 renders some pretty damn nice water effects. However, since the current API only exposes methods for setting wave height and frequency in general, it cannot be used to recreate a realistic (meaning statistically simulated) sea state for “open ocean” type simulations.
A solution to this problem exists in the form of a port of the ProjectedGrid from jme2 to jme3, along with a custom WaterProcessor implementation that is heavily based on the basic SimpleWater functionality. This allows us to construct a three dimensional grid to project the SimpleWater effects on, based on a height map that is calculated from the statistically simulated sea state.
However, SimpleWater does not allow for any of the visually appealing effects of the jme3 WaterFilter - foaming, light reflections, more realistic underwater environment, and so on. We would really like to try to recreate a realistic sea state with these effects included. We’re prepared to put some resources into this, but have no expertise on hand to be able to gleam how hard it would be to actually achieve it using jme3.
The WaterFilter API exposes functions to set wave height and frequency, yes, but what we need is to show the entire sea state at any given time, which means we must be able to calculate the height of any point in the water plane, and apply water textures and post processing to this height map. This is what is achieved using ProjectedGrid and a custom WaterProcessor at the moment.
Has anybody been looking at this before? Would it be possible to somehow implement support for a ProjectedGrid using the WaterFilter visual effects, or am I just salivating over something that is too technologically complex to be realistic here?
The WaterFilter has no geometry, so it’s very difficult to manage an accurate simulation or buoyancy for example.
All the WaterFilter magic occurs in the shader, it is probably possible to adapt or crerate a new shader that would use the same set of features that would be applied to the water geometry.
I know @ceiphren made some attempts to make a grid based water too, and we talked about adapting the waterfilter for it.
I looked into it once but realized it was less straight forward than I had imagined and i didn’t have the time to get back to it since.
The major difficulty is to compute the water depth (as in real life water depth) for each pixel that is used to compute the water color and the foam appearance. It’s easy in the Filter because we have the depth of the scene so we can compute it with some math.
In the case of a geometry we don’t have that information.
One way to do it would be to pre compute the depth for each vertex store it in a buffer in the mesh so that it can be passed to the shader as an attribute and then passed as a varrying to the frag shader.
I guess some raycasting would be involved, and then the depth could be updated as the position of the vertex is updated.
Actually that’s totally manageable idk why I didn’t think about it before…
This would be pretty cool, the water filter has some bad draw backs that are painful (like it can’t receive shadows), that are due to the fact there is no geometry.
It’s ok when you just want some pretty water and as long as there is not much interaction with it.
@nehon: That’s basically what I thought without having looked at the source code. When it comes to water depth; maybe I’m jumping to conclusions here, but if you have (as in our case) the computed height of the water, compared to the water plane 0-level, for all vertices in the height map, couldn’t the total water depth just be that + some constant? I see that you still have to compute the water depth for the pixels that lie “inbetween” though - which is most of them - but couldn’t some kind of interpolation method be used for that? We have a time simulation of the entire sea state which basically feeds height values for every point in the mesh implemented already.
@ceiphren: Thanks for the information. That C++ implementation looks like it might have some interesting aspects to it. We already have our statistical wave model, so “all” that is necessary is to implement “water effects” onto the three-dimensional height map provided by the wave model. As I mentioned we already achieved this using an adaption of SimpleWaterProcessor, but we would like to investigate if we can have all the visually appealing post-processor effects of the WaterFilter in our simulation as well.
Our challenge is that we don’t really have any skilled graphics / engine programmers on hand. We have programmers, but none with a knowledge at this level when it comes to advanced visual effects. Any literature, like those two links, is appreciated!
@nehon: That's basically what I thought without having looked at the source code. When it comes to water depth; maybe I'm jumping to conclusions here, but if you have (as in our case) the computed height of the water, compared to the water plane 0-level, for all vertices in the height map, couldn't the total water depth just be that + some constant?
The thing is, the depth of the water is not the "height" of the water because the sea bottom is uneven and not necessarily 0.
Also the water filter create foam around objects that are half submerged and this data is a bit difficult to extract.
you’d need a control that would update the data inside the water mesh according to floating objects position and bounds…which is not as easy as it sound.
Yep, I see that taking varying sea depths into account would be required for a general solution to this problem. Our specific need though is for simulation of open ocean conditions, and in that special case I think we could just have a flat sea bottom with a known large depth to subvert this.
Of course, the foaming around submerged objects would still be an issue. I’ll have a look at the implementation of WaterFilter today and see If I have any ideas.