Joined: Sun Jun 13, 2010 5:40 am Posts: 1059 Location: I chose my fate, do not pity me.
Re: Dynamic water
I would like to point out that Mehman is the first person to do this after years of people saying it can't be done, hell, there was even a whole thread dedicated to putting people down those few people who dared to dream, but Mehmen made these dreams a (admittedly laggy) reality.
Thu Jan 12, 2012 9:38 am
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Dynamic water
xenoargh wrote:
Took a look at this.
Seems like a really expensive way to do this. There's a lot of math being run each frame for this and it spawns a plethora of managers
False, it spawns only one, you can check this by opening the lua console and counting how many times the initialisation message is displayed(because it is displayed each time a manager is spawned). And there's the minimum amount of math possible for it to behave somewhat realistically.
xenoargh wrote:
But mainly I'm not sure that this is taking on the issues in an efficient way. Water in a 2D world is pretty simple stuff.
Each water pixel should just follow some simple rules:
If velocity < some threshold... If air below, move down a pixel. If air beside, small chance to move sideways. If air beside and water beside, strong chance to move in direction away from water.
That's pretty much what it does.
xenoargh wrote:
Else do nothing, let the physics engine handle the behavior, because somebody just shot it or is swimming or whatever.
Unfortunately that doesn't work properly, so I have to code it too.
xenoargh wrote:
Doing stuff like waves would get really complex, of course, and so would any complex attempts to model fluid dynamics, but none of that is necessary for a reasonable sense of basic water.
Indeed, that would require pressure simulation, that would induce huge amounts of lag.
xenoargh wrote:
If it's vaporized, it should just respawn; if it leaves the map edge, then it's permanently lost.
This already happens.
Fail Flail wrote:
I would like to point out that Mehman is the first person to do this after years of people saying it can't be done, hell, there was even a whole thread dedicated to putting people down those few people who dared to dream, but Mehmen made these dreams a (admittedly laggy) reality.
Thanks!
Thu Jan 12, 2012 12:00 pm
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Dynamic water [V5: optimization update]
Updated to V5: I optimized the code a lot, there should be less lag.
Shakatuko wrote:
You can't make it become particles instead of glows? Because glows are the most laggy thingies in my CC. It doesn't matter how many particles, but glows ruin my game. It doesn't matter how many "lag updates" you make, it always stay laggy.
They already are particles, particles(MOPixels to be exact) with glows. This update should strongly reduce lag, if this isn't enough you can remove the glows by replacing line 2 of Water.rte/Watc2.lua by
Code:
local a = CreateMOPixel("Water","Watern.rte");
but water will be much less visible.
Thu Jan 12, 2012 12:10 pm
xenoargh
Joined: Fri Dec 30, 2011 3:33 am Posts: 276
Re: Dynamic water [V5: optimization update]
TL:DNR version: cool, I'll try it out again- as was pointed out, an imperfect solution is better than none at all. Sorry if my comments seemed overly critical, I was very intrigued by this and thought I'd offer more than "cool, water" for feedback
You're sure about the manager? Seemed like it allowed more than one in the scene, but only one per water group. I did not test that to death, it just seemed like there was a pretty big relationship between each thrown Molotow and lag.
One of the things I thought of was that it might be considerably cheaper to treat each block as an agent without management; the current rules attempt to manage the whole as a system and I'm feeling like perhaps you can save math stages if you just check for water, air and land to the right, left and downwards of each agent, and then apply the rules. I've done stuff like that in shaders and it's generally cheaper than central management of a complex system, because your costs are then linear. It'd also allow for a reasonable cap on total water agents to keep it performing well.
Anyhow, I'll take a look at V5; it'd be awfully nice if this could operate without significant lag for small stuff.
I also really wish it was prettier. One idea might be to cycle glows with a repeating "watery" tile of light and dark but different colors, to create a more "watery" look; the other would be to judge absolute depth and adjust the glows emitted accordingly. Both together would probably make it look considerably better
But the blocky look would remain an issue. To get it really nice with this approach, even if it could run fast, it'd need to have a glow that rendered right after the sky but before the background pixels, so that it could exceed the borders a bit and look full; I doubt if that would be a huge engine change, since it appears to do that rendering order already... but it'd be pretty specific to doing bodies of water and perhaps dynamic weather events like changing the sky.
I tested the engine-side issues, and you're quite right, the engine won't let MOPixels not reach a rest state that doesn't leave them solid, it erases a lot of pixels it shouldn't be erasing, and it's incredibly lag-inducing, to boot. So I can see why that doesn't offer a reasonable solution. My apologies for my ignorance; I really expected that part of the engine to operate very strictly according to its parameters, but like other stuff, it looks like a lot of optimization was necessary to get performance to where it needed to be.
All that said, even if this version is 10X faster, it's still too slow for anything but a minor feature on a map atm; it's not practical to do a waterfall with this, or even a big lake. Ultimately, I think the engine has to address this, with either a special type of MOPixel that's optimized for simple water behavior, or polygonal water bodies if that can't be made fast enough- that would allow for waves at a reasonable cost too. But we don't get any direct access to drawing code or the engine side so that's just pipedream.
Fri Jan 13, 2012 3:45 am
111herbert111
Joined: Fri Jan 07, 2011 12:31 am Posts: 550 Location: error: location not found
Re: Dynamic water [V5: optimization update]
while not perfect, this is nonetheless amazing, I bow to the lua god.
Fri Jan 13, 2012 7:02 am
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Dynamic water [V5: optimization update]
xenoargh wrote:
You're sure about the manager? Seemed like it allowed more than one in the scene, but only one per water group. I did not test that to death, it just seemed like there was a pretty big relationship between each thrown Molotow and lag.
I'm quite sure about that, if there were more than one manager, the initialization message would be displayed multiple times and they would interfere with one another(huge amonts of lag, non uniform refresh rate, actors able to swim at supersonic speeds). The current increased lag per water particle has several causes: _the obvious one: more particles means more glows means more calculations means more lag. _since the water system keeps a constant update frequency for each particle(~10hz), more particles means more overall updates per second, and more lag. _since more water covers more surface, there will be statistically more particles/actors/objects in the water, so once again more calculations and more lag.
xenoargh wrote:
One of the things I thought of was that it might be considerably cheaper to treat each block as an agent without management; the current rules attempt to manage the whole as a system and I'm feeling like perhaps you can save math stages if you just check for water, air and land to the right, left and downwards of each agent, and then apply the rules.
That's what the manager does, plus it allows me easy control of the refresh frequency, that would be difficult with individual particle scripts since they are executed with a frequency of 60hz, I would have to check at every update wether or not to actually update the particle, and make sure that updates on a global scale are distributed evenly over time(eg so that not every particle updates at the same time), and that would be even more laggy, I already tried.
xenoargh wrote:
I've done stuff like that in shaders and it's generally cheaper than central management of a complex system, because your costs are then linear. It'd also allow for a reasonable cap on total water agents to keep it performing well.
Using the current system the costs are directly proportionnal to the number of particles, plus the constant minimal calculation amount necessary to run the water controller. If I controlled each particle individually, it would be too, but the minimal amount of calculations nbecessary would be much higher, and would also be proportionnal to the number of particles. Plus each particle would have to individually check the proximity of every actor/object/particle at every update, instead of the manager just doing it once for the whole water system each update, and that is lots and lots of calculations. Since lua is an interpreted language, it is really slow, that's why doing something as simple as 2d water ends up being so difficule, I wish I had all the power of a GPU to compute this, then I would be able to make pixel sized water particles with an update frequency of 500hz while also computing pressure, elasticity, temperature, visquosity, change of state, dissolution of terrain elements, and steam powered flying molefishs.
xenoargh wrote:
I also really wish it was prettier. One idea might be to cycle glows with a repeating "watery" tile of light and dark but different colors, to create a more "watery" look; the other would be to judge absolute depth and adjust the glows emitted accordingly. Both together would probably make it look considerably better
I'll try that.
xenoargh wrote:
But the blocky look would remain an issue. To get it really nice with this approach, even if it could run fast, it'd need to have a glow that rendered right after the sky but before the background pixels, so that it could exceed the borders a bit and look full; I doubt if that would be a huge engine change, since it appears to do that rendering order already... but it'd be pretty specific to doing bodies of water and perhaps dynamic weather events like changing the sky.
Right, but I don't have access to the game engine.
xenoargh wrote:
All that said, even if this version is 10X faster, it's still too slow for anything but a minor feature on a map atm; it's not practical to do a waterfall with this, or even a big lake. Ultimately, I think the engine has to address this, with either a special type of MOPixel that's optimized for simple water behavior, or polygonal water bodies if that can't be made fast enough- that would allow for waves at a reasonable cost too. But we don't get any direct access to drawing code or the engine side so that's just pipedream.
I'll try to increase performance even more, but I fear optimization has its limits.
Anyway thanks for your constructive criticism.
Fri Jan 13, 2012 3:00 pm
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Dynamic water [V6: optimization/pressure]
Updated to V6: _even more optimization, so less lag _increased water frequency to 12hz _added basic pressure system:explosive can move water creating shockwaves that can move actors...etc(still buggy, I need to work on this) _no steam powered flying molefish yet, sorry.
Fri Jan 13, 2012 4:46 pm
Sims_Doc
Joined: Fri Aug 20, 2010 4:45 am Posts: 911 Location: No Comment.
Re: Dynamic water [V6: optimization/pressure]
Any chance of an updated video?
Mon Jan 16, 2012 10:15 pm
bioemerl
Joined: Sat Dec 18, 2010 6:11 pm Posts: 285
Re: Dynamic water [V6: optimization/pressure]
One thing that feels bad with the dynamic water is how single squares will be floating around at the top. Is there any way for the water to auto-level itself, so it ends up as one flat layer?
Tue Jan 17, 2012 8:55 pm
nicolasx
Joined: Sun Mar 13, 2011 6:17 pm Posts: 646
Re: Dynamic water [V6: optimization/pressure]
I think i'm having a map wrapping glitch on Mountains 2, the water seems to work on one side and on the other it just is like a wall.
Tue Jan 17, 2012 9:37 pm
unwoundpath
Joined: Sun Mar 07, 2010 7:19 am Posts: 1279 Location: Places. And things.
Re: Dynamic water [V6: optimization/pressure]
nicolasx wrote:
I think i'm having a map wrapping glitch on Mountains 2, the water seems to work on one side and on the other it just is like a wall.
Is it possibly the map loop boundary? That thing is always glitchy.
Tue Jan 17, 2012 10:38 pm
CrimsonCloud
Joined: Thu Dec 22, 2011 5:12 pm Posts: 24 Location: South Africa
Re: Dynamic water [V6: optimization/pressure]
Okay seriously -__- why haven't datarealms hired you or something cause your a modding god. Awesome mod btw
Wed Jan 18, 2012 9:55 am
Sims_Doc
Joined: Fri Aug 20, 2010 4:45 am Posts: 911 Location: No Comment.
Re: Dynamic water [V6: optimization/pressure]
CrimsonCloud wrote:
Okay seriously -__- why haven't datarealms hired you or something cause your a modding god. Awesome mod btw
We all know that won't happen since Cortex Command is a 12 year project and were only in build 26, So i expect we will be build 46 in 2022, I mite place bets on that.
Wed Jan 25, 2012 5:14 pm
Duh102
happy carebear mom
Joined: Tue Mar 04, 2008 1:40 am Posts: 7096 Location: b8bbd5
Re: Dynamic water [V6: optimization/pressure]
Actually, Data periodically hires a modder or two to help with content, so it would be entirely possible he would hire Mehman. Unlikely though, last I knew, he had a pretty good team of content devs as-is.
Wed Jan 25, 2012 8:12 pm
Dylanhutch
Joined: Sun Apr 25, 2010 12:04 am Posts: 303 Location: Australia
Re: Dynamic water [V6: optimization/pressure]
Would it not be possible to make the priority lower than the ground materials and make them overlap? I'm guessing the answer is no, but try it, if it's possible.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum