Author Topic: Rubbish blobby thing  (Read 3830 times)

0 Members and 1 Guest are viewing this topic.

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Rubbish blobby thing
« on: January 27, 2012 »
Needs a LOT of work but it's a start.

Source and exe

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: Rubbish blobby thing
« Reply #1 on: January 27, 2012 »
A good start! :)
raizor

Challenge Trophies Won:

Offline Kirl

  • Senior Member
  • Pentium
  • ********
  • Posts: 1215
  • Karma: 230
    • View Profile
    • Homepage
Re: Rubbish blobby thing
« Reply #2 on: January 27, 2012 »
Awesome metablobs, good show!  :clap:
Some sort of surface normal shading would be sweet to really show off the curves.

This ran fine on me laptop, my own 2d metaballs were uselessly slow!  :-\
« Last Edit: January 27, 2012 by Kirl »
www.kirl.nl
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Rubbish blobby thing
« Reply #3 on: January 27, 2012 »
Thanks.

I'm going to add some decent shading but atm it's just using a single cube being repositioned so I can't share the verts yet. Trying to think of ways not to have to loop through every position in the 3d grid too.

Offline ttemper

  • Amiga 1200
  • ****
  • Posts: 261
  • Karma: 7
    • View Profile
Re: Rubbish blobby thing
« Reply #4 on: January 28, 2012 »
Very nice!

Looks good, thanks for sharing the code too, a lil' bit past my coding knowledge at the moment, but it will help me learn.  :) 2 months of coding and I'm slowly getting the hang of the 'oldskool' demo feel. OpenGL will be a while away yet.

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1292
  • Karma: 466
    • View Profile
    • my stuff
Re: Rubbish blobby thing
« Reply #5 on: January 28, 2012 »
atm it's just using a single cube being repositioned so I can't share the verts yet.
Trying to think of ways not to have to loop through every position in the 3d grid too.
It's much faster to fill only the relevant parts of the volume-grid using a bounding box for each sphere.
The box just needs to be big enough to make 1/distance insignificant to the test-threshold.
Since the boxes will overlap you have to make sure to visit every sub-cube only once when extracting the surface.

You can even use an "inner" bounding box for all distances which are definately bigger than the test-threshold. This area doesn't need any distance calculation (there can't be any surface anyway) and can be fill with a constant value instead (I never tried this, though and maybe it's more hassle than advantage).

There are also several approximations for 1/sqr which are sufficiently precise for this task, the most prominent is probably this one and SSE's RSQRTPS can even calculate 4 in parallel.
As you've already calculated 1/sqr of (x-cx)^2 + (y-cy)^2 + (z-cz)^2 for the previous voxel, you can use that as a pretty good approximation for (x-cx+1)^2 + (y-cy)^2 + (z-cz)^2 and just do one newton-iteration for refinement (this is not very precise near 0 but that area isn't very interesting anyway).

With your 2x2x2 appraoch you're now doing 8x the work.
When parsing the sub-cubes along the x-axis, you can always reuse the 4 left test-flags and just shift them to another position in the bitmask.
If you save the flags of the previous row you only need to update two flags.
And if you also save the flags of the last slice you only need to update a single flag.
Try to add some early-out-test if the flags signal a complete full (all bits set) or empty (all bits zero) sub-cube as it's nothing to do then.

You don't need face-connectivity information to calculate the normals.
You can get the normal-vector at each grid-point from the gradient of the volume field:
Code: [Select]
normal(x,y,z)= normalize(
  grid(x+1, y,   z  ) - grid(x-1, y,   z  ),
  grid(x,   y+1, z  ) - grid(x,   y-1, z  ),
  grid(x,   y,   z+1) - grid(x,   y,   z-1)
);
The normals can then be interpolated like the vertex-positions.
« Last Edit: January 28, 2012 by hellfire »
Challenge Trophies Won:

Offline Stonemonkey

  • Pentium
  • *****
  • Posts: 1315
  • Karma: 96
    • View Profile
Re: Rubbish blobby thing
« Reply #6 on: January 28, 2012 »
Thanks hellfire, cool stuff there to work on. I had been thinking along the lines of hollowed out bounding boxes, and making a list of active cubes each frame for when it comes to the drawing and using some sort of flag so only to calc each cube once. I had been considering making a big 3d grid array of cubes but it looks like that's not necessary.
I've posted something about approx. 1/sqr somewhere here in the past so I'll have a look at that too and I'll look into that shading.

Cheers
Fryer