Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

please excuse terrible drawing!

share|improve this question
2  
Since the question is asking whether it is possible or not - I'll tell you. Yes it's possible to do it with shaders - and the droi - I mean shader you are looking for is a fragment shader. –  Grey Jan 23 at 18:29
    
Furthermore I'd say you'll need Unity Pro, because you'll need to grab the framebuffer as a texture to apply some effect on it. –  Pedro Boechat Jan 23 at 20:53
add comment

2 Answers

up vote 2 down vote accepted

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

First render pass

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.

Second render pass

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

share|improve this answer
add comment

If you want to draw 2d drop of water a solution is to draw sphere normals and then blur the normal buffer. Then use the buffer to calculate the refraction.

This technique is briefly explained here (in 3d):

http://developer.download.nvidia.com/presentations/2010/gdc/Direct3D_Effects.pdf

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.