JME3 Water Effect on arbitrary shapes (polygons) / DIY version :D


#3

Hi,

Your idea and implementation is good :slight_smile: I hacked the “water filter” in another direction to create my clone of Riptide GP:

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.


#4

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.


#5

Ok great, just wanted to be sure you were aware of the other way to have smaller bounds for the water.


#6

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.


#7
@.Ben. said: 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 ;)

#8

Afaik if I use very small lakes (from the eye perspective), one could use another approach,

Build a full cubemap (preferable at gamestartup or level editing time) from the middle of the sea, and use this for everything, until the player comes very near.


#9

This should clearly be added to the actual jme postwater! :smiley:

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!


#10

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.....

water_filter.setShapeType(WaterFilter.AreaShape.Polygon);
water_filter.setArrPolygonShapeVertices(list_vector2f_vertices);

#11

Can you provide a complete demo download address


#12

ERHH… I guess I could put it together, omg this new forum messed up my post, wtf…


#13

It’s just that we don’t support [java] tags any longer.


#14

I get it, but I’m not going to reformat all my previous posts…
EDIT: Wait, now it displays perfectly… Erlend, did you just re-enable java tags?


#15

No, I just edited your posts in this thread :stuck_out_tongue: You can click the red pencil icon for a nifty changelog!


#16

Oh! Thanks Erland :smiley:
EDIT: You only forgot about the diamond operators, they’re shown as HTML entities at the moment :stuck_out_tongue: I’ll change them right now to avoid future confusion.


#17
java.lang.NullPointerException
    at com.jme3.util.BufferUtils.setInBuffer(BufferUtils.java:565)
    at com.jme3.shader.Uniform.setValue(Uniform.java:233)
    at com.jme3.material.Technique.updateUniformParam(Technique.java:151)
    at com.jme3.material.MatParam.apply(MatParam.java:147)
    at com.jme3.material.Material.render(Material.java:1088)
    at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:523)
    at com.jme3.post.FilterPostProcessor.renderProcessing(FilterPostProcessor.java:202)
    at com.jme3.post.FilterPostProcessor.renderFilterChain(FilterPostProcessor.java:281)
    at com.jme3.post.FilterPostProcessor.postFrame(FilterPostProcessor.java:294)
    at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:987)
    at com.jme3.renderer.RenderManager.render(RenderManager.java:1029)
    at com.jme3.app.SimpleApplication.update(SimpleApplication.java:252)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
    at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
    at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
    at java.lang.Thread.run(Thread.java:744)

#18

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.


#19

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.

DOWNLOAD: The project ZIP file

PREVIEW:


#20

Thank you for your warm help ! In addition I have one other approach using Geometry to do, wait a moment I attached program


#21

You can use FileDropper to attach a zip file link if you want. http://www.filedropper.com/


#22

Thank you for sharing this awesome idea! But the download link is broken. Can you reupload this?