Adding shadow was pain. But was crucial for visuals.
Champagne and lasange. Game is shaping nice.
Going to make something. Not that much time but lot of will and booze.
Maybe some 2.5 tech demo that I camouflauge as game and force it to to theme. Sounds like a plan.
For my Ludum Dare entry Lonely miner I implemented water simulation.
You can see it in action here:
First you need to know how to use box2d or some other fast physic library that can handle circles. Particle simulator would be best but integrating that to game would take some precious time that I didn’t have. So I created a pool and obstacles and hefty amount of small slippery balls with pretty high density. You don’t want any friction, damping and only small amount of restitution. Radius of one ball is about 0.25m when my full screen size is 48m x 32m.
So this is how things look with debug renderer on this stage.
Simulating lots of dynamic bodies that clamp often to one place is really heavy weight operation. This need to be taken consideration. For this reason I used really inaccurate physic settings. I stepped world with only one velocity and position substeps. Also I fixed physic steps to 30/s.(After competition I noticed 20 would be enough) Always when dealing with fixed time step you want to interpolate or extrapolate position when physic are not stepped but rendering is. I choosed extrapolationing. This is simple to pull of.
RenderPos = PhysicalPos + Velocity * TimeAccumulator
Rendering is the part that trick players to believe that water is not just a bunch of tiny balls. My method was to render water drops as metaballs with radius twice the physical size of the object. Fastest way to make metaball was just sprite that is opaque at middle and fully transparent at edges with smooth circular gradient. I mixed some noise and color there to get better look. Water rendering need two pass. First water is rendered to small off-screen buffer and after that it is rendered as full-screen quad to screen with alpha test discarding too transparent pixels. This will give water hard edges, continuous body and vivid look. To get water drips non circular look just never clear the off-screen buffer completely but leave 75% of alpha channel left but discard alpha if its small enough. Every water drip have unique rotation to give little variety for look. I just ignored body rotation because I don’t want to reveal the circular origin of the water drips.
For final touches I added velocity based color change. This will give nice waves if something collides with water. Its’s also important to render water after ground to get best look. Because water was little too chunky I just colored it to green and called it slime. Lighting and shadow give nice feeling too because water is box2d based and I have implemented open source box2dlights library, integration just worked out of the box. http://code.google.com/p/box2dlights/
Performance is a problem after 500 water drips on desktop and 250 on android but this amount is just as much I need.
Thanks for the event.
19:50 < kalle_h> custom fluid simulation, box2d lights, destroyable world,
19:51 < kalle_h> but i dont have a jump
19:51 < kalle_h> or gameplay
Theme is not inspiring but I wanted to do fluid simulator and that I gonna do. Game name should be “alone with fluid simulator” but i dont give up yet maybe there is idea somewhere hiding under technical stuff.
Idea for fluid simulator is use box2d circles and render them as metaballs with alpha test shader. I hope that is gonna work or I am in trouble.
Hardcoded alpha test shader that I use.
Fixed timestep stepper. That I gonna use.
I have set the project. Empty window is launching. Gameloop just need the game.
I am plannign to use:
My own Light library http://code.google.com/p/box2dlights/
Box2d debugrenderer for prototyping.
Maybe I can use physic particles to do something pretty. There is my test to show about 20k particles rendering 60fps while capturing the video. http://www.youtube.com/watch?v=4bNkTgMXXj4
I hope that theme will allow me hack some fluid simulation something like you can see Where is my water.
I also planning to use purely gles2.0 but I have never used it before for anythign really. Maybe shaders aren’t that hard at all.