I want to simulate blobs of water in a 2d game in Unity3d. One possible way of doing it is to use 3d metaballs moving in a 2d plane though this is very processor intensive. Do you think it would be possible to make 2d metaballs, so I end up with a 2d meshes something like in the picture (In this case its 2 metaballs in conjunction) and then apply some kind of shader to make it look like they are bulging out and refracting the texture behind them like drops of water? I ask because I dont have much experience with shaders and am not sure what is possible.
Answer
ilmale's answer is very comprehensive for 3D.
For the 2D case, a trick I've used in the past is to render a bunch of blobs with feathered edges using additive blending. (This example I had kicking around used rounded squares, but any shape works. The soft edges let them merge smoothly together when they get close.)
This creates something like a height field. Then in a second pass you threshold this field to generate your blob contours. You can use finite differences to extract normals from the field for shading & refraction.
This gets the visual effect, but the exact countours live only in the raster data on the GPU side. If you need to know where the boundaries of the metaball surface are for gameplay, you may want to use an analytical approach instead (although the two techniques could also be combined, as long as the implementations agree on where the contour goes).
No comments:
Post a Comment