Normals to metaballs

ok. my metaballs works. even fast. but i am doing flat shading, so i can see each and every triangle. that is pretty ugly. do u know how to calculate the normals per vertex?
i thought of computing the normals per vertex per marching cube, so i wont have to store all the triangles before rendering them, the resollt wont be perfect, but still it might work. any ideas?
thnx.

You could just make a normal mesh and then calculate the normals, like normal

But if you used 1/dist for the strength then this can be used:

normal+=VectorFromMetaballCenterToVertex/LengthOfTheVector.

This way, the metaballs that have little impact on the vertex also have little impact on the vector.

To approximate the normal for any given point on an implicit surface, you can do the following:

// n = normal vector
// p = point in the iso surface (the vertex you want the normal for)
// S(x, y, z) is the field strength at point {x,y,z} (the iso value you calculate)
n.x = S(p.x-0.01f, p.y, p.z) - S(p.x+0.01f, p.y, p.z);
n.y = S(p.x, p.y-0.0f, p.z) - S(p.x, p.y+0.01f, p.z);
n.z = S(p.x, p.y, p.z-0.01f) - S(p.x, p.y, p.z+0.01f);

And don’t forget to normalize n too.
The S-function is the function where you collect the sample from each metaball. I’m pretty sure (but not completely) that you have to calculate the fieldstrength in the 1/dist-way to get this method to work properly.
You will get more or less proper normals anywhere on the surface. Even in the space where two or more balls melts together.

If this wasn’t understandable, I can try to explain it again, just tell me

thats ok, i understand. ill try it.

Silly question. What are Metaballs? Thanks!

If you know blobs in POV-Ray -> Thats the same. Otherwise, imagine balls in space with
different sizes and different gravities. If a ball gets near enough to an other ball, they are melting together (dependent on the gravity).

Yep I know them. Never thought that could be accomplished in realtime. Sounds complicated. Do these metaballs intersect in your realtime calculations?
Thanks!

Oh, to add: Maybe you check the distance of a vertex of a ball to the center of another ball and move it toward it when it’s near enough. Oh, it’s not likely… But if it can be done really fast, that’s a cool rain effect! Because, you could precalculate the meshes for a fixed number of distances, and simply rotate them to the according (blob)direction. At least, it would still look cool, I think.

[This message has been edited by Michael Steinberg (edited 11-23-2000).]

Well, metaballs is indeed doable in realtime, and the intersection part is “for free”. Managing thousads of metaballs includint their intersections is as easy as managin one single metaball (though thousands of them will surely kill performance, but still it’s no harder). In general, all you do is calculating the sum of the distance to all metaballs (the center of them), for each point in a 3 dimensional grid.

In pseodicode:

sample = 0;
for( i=each metaball )
{
sample += 1/distance_to_metaball[i] //intersection is automatically performed here
}

This is how you calculate the iso-value at each point in the grid, where you draw the balls later on. As you can see, adding more balls wont’ do anything to your calculations excetp looping one more time.

Could anyone be so nice and drop me an image or a little demo, just to see how it’ll look like at the end? Thanks!

htttp://scene.swix.ch/quixoft/marko/metagl.zip

[This message has been edited by Blaze (edited 11-26-2000).]

my demo of metaballs is on glvelocity site, give me your email and ill send it to you, or dl it from the site if you want.
you need a geforce to see it, because the metaballs are cubed mapped.
but i can send you the none cubed mapped version too.

My email is th-steinberg@t-online.de
It’s saved on the board anyway, look into my preferences. Oh, I apreciate that very much!

Oh, don’t have a GeForce yet. Waiting for that damn NV20 !!!

Oh, thanks blaze! Seems to be not very realtime friendly, I think. Aren’t there any good aproximations? How about simply moving the vertices nearer to another ball if they are near enough? Didn’T test it yet, should be really ugly… For instance, I’d need no physics, just a cool graphical effect.

This technique is very “realtime friendly.”
With metagl.exe’s default settings I got 250 fps on my old workstation.
The polygon per second count is about ~600 Ê. Not bad. Metaballs
can be easily optimized with streaming extensions. Memory requirements
is not very high (scene mesh can be divided into NxNxN 3d “tiles”).
I think, 2-3M triangles per second can be achieved with strong optimization.
Also metaballs are very LOD friendly.

PLease excuse my English

Well, didn’t think that my father’s graphics card is so slow. Something of ATI, but I think that my TNT won’t do it much faster than 4X, and that would be 9 fps for some “blobs”. For my purposes, that would be too much, might be that my dad’s compi is all crazy… Gonna check that in a bit. Thnx.

Marko is pretty proud of his metaballs, they should be pretty fast, he took a recursive approach so it’s a minimum of cells that have to be calculated.

As you can see there isn’t many triangles and metaballs are very dependant on cpu power.

With the default settings i get 100-130fps.

Oh, by the way he uses the same method for calculating the normals as i suggested in my first comment.

Oh, what processor do you have blaze?

p3 500