I cant give you the code (no screenshot also because the game is not ready for release yet) but may be some hints and suggestion for optimizing the Water surface and its reflection rendering I did for my implementation:
1- My ski slide on the water surface which made by curve just like a racing road. The surface it also move up and down by sin wave (just like one in JME). End of it are water buoyancy affect back to the ski… So you can see it’s very arbirary and dynamic.
2- The reflection “should” contain few things… I said “should” be cause the things are choosed to be appear in the reflection. Remember that another phase of rendering are trigger on the water surface. So I just have a filter over the geometry list, which geometry is important for player brain, which geometry are in a reflected frustum with limited view range… In my implemetation, the ski and the player ride it should be contained in the reflection, some very close obstable and building are also included. Everything else every except the skybox are excluded.
3- After consider 2 things above. The final things is to render the surface out. The area of water surface which near the player it render it higher resolution. The area far from view render with lower resoltion, and the over 40 meter area has no reflection at all.
4- The soap border effect, at the area near border of water surface are also implemented. But because I don’t have appropriate Z-Buffer as the normal effect (my pool have similar deep every where). The depth value is calculate easily by the distance for the center of the path to that border.
5- First i experiment with the Defered rendering method and I’m currently ported the game to DR. As you can imagine, the problem is quite easier in DR… The concept are the same but quite computation saved because it just render what should be rendered! Then I put lightprobe and refectionprobe along my racing path.
You polygon approach is also quite interesting indeed. It may also help me to solve my soap border problem but not much in optimize the rendered surface… Hope this also help you back.
Hi Rémy! Well, the 3 shapes the original filter was offering are: 1) Infinite XZ plane, 2) square, 3) circle. It does not account for more complex shapes. Why is the polygon shape useful? Because if you have a big river shaped like a “S” and you have lower parts of your terrain on the sides of the “S” or near the curves, you only want the water to appear in the “S” shape river, not on the side of the terrain. There may be tons of applications where this could be useful and where circle wouldn’t cut it. I really think combining multiple polygon shapes in the same shader instance would be a nice add-on, I just don’t have time right now to do that, but at some point I will have to do this myself if nobody does it.
Hi @atomix, polygon shaped water filter does NOT save fps over other water shapes and as a matter of fact, it is more GPU consuming (by a very low factor tough) because it has to do bounds checking on the polygon’s vertices every frame, so depending on how many bounds you have (6?..100?..1000?..) it’s prone to be slower than circle or infinite plane shapes. I like your point #2 it makes sense for fps optimization, good idea.
It’s easy to get carried away and try to implement stuff like this and end up realizing it’s not optimal and draws too many fps on older hardware. Like I’ve read here somewhere last month, game programming is most of the time trickery. It’s not about if the geometry is logically correct. It’s more about if the user thinks it is. It’s all about faking stuff. That’s why I understand perfectly why you would want people to stick with the simpler circle or square shapes, but it’s just not always possible. I mean, in some situations, I could cover this by making sure the land is always above the water level but not ALL the time.
It's easy to get carried away and try to implement stuff like this and end up realizing it's not optimal and draws too many fps on older hardware. Like I've read here somewhere last month, game programming is most of the time trickery. It's not about if the geometry is logically correct. It's more about if the user thinks it is. It's all about faking stuff. That's why I understand perfectly why you would want people to stick with the simpler circle or square shapes, but it's just not always possible. I mean, in some situations, I could cover this by making sure the land is always above the water level but not ALL the time.
I agree, really. You made a point with your previous post. the S shaped water and the uneven ground convinced me ;)
This should clearly be added to the actual jme postwater!
Edit: I’ve tried to make it work, but there is some part of the file that seem to be different from yours… It only make a circle shape lake.
I will have to stick with the square lake for now. But thank you for the help anyway!
Hi, thx. Make sure that after the place you’re doing: WaterFilter water_filter = new WaterFilter()… you’re also configuring it like this:
ArrayList<Vector2f> list_vector2f_vertices = new ArrayList<>();
list_vector2f_vertices.add(new Vector2f(20f, 30f)); // your lake bound vertices go here...
list_vector2f_vertices.add(new Vector2f(35f, 54f)); // your lake bound vertices go here...
....... add your lake bound vertices here.....
OK let me create a new project and do all of this. Then you can copy all the files in your own project OK? BTW, just to make sure you know, this technique will become VERY SLOW if you put more than like 4-5-6 lakes on the same scene. It’s not optimized enough for putting a lot of lakes.
OK, they updated the WaterFilter and my tweak wouldn’t work anymore, so I just fixed it so that it works again. It had to do with variables they renamed in the shader. Here it is working again, feel free to download the zipped project file so that you can exactly see a fully working example and copy from it what you want. AGAIN, this needs to be optimized, it’s very slow and probably would not be usable in a game as it sits.