PDA

View Full Version : Normals to metaballs

okapota
11-22-2000, 09:42 AM
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.

Blaze
11-22-2000, 11:11 AM
You could just make a normal mesh and then calculate the normals, like normal http://www.opengl.org/discussion_boards/ubb/smile.gif

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.

Bob
11-22-2000, 01:07 PM
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 http://www.opengl.org/discussion_boards/ubb/smile.gif

okapota
11-23-2000, 04:41 AM
thats ok, i understand. ill try it.

Michael Steinberg
11-23-2000, 08:18 AM
Silly question. What are Metaballs? Thanks!

Kilam Malik
11-23-2000, 08:56 AM
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).

Michael Steinberg
11-23-2000, 09:49 AM
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).]

Bob
11-25-2000, 02:54 AM
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.

Michael Steinberg
11-25-2000, 04:01 AM
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!

Blaze
11-26-2000, 06:20 AM
htttp://scene.swix.ch/quixoft/marko/metagl.zip (http://scene.swix.ch/quixoft/marko/metagl.zip)

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

okapota
11-26-2000, 06:47 AM
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.

Michael Steinberg
11-27-2000, 06:23 AM
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!

Michael Steinberg
11-27-2000, 06:26 AM
Oh, don't have a GeForce yet. Waiting for that damn NV20 !!!

Michael Steinberg
11-27-2000, 06:29 AM
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.

IronPeter
11-27-2000, 12:07 PM
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

Michael Steinberg
11-27-2000, 12:40 PM
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.

Blaze
11-27-2000, 02:23 PM
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.

Michael Steinberg
11-29-2000, 08:40 AM
Oh, what processor do you have blaze?

Blaze
11-30-2000, 03:45 AM
p3 500