1
\$\begingroup\$

Good day everyone,

I'm currently programming a fluid simulation through use of metaballs and I have a very specific problem/question.

The steps I use for metaball simulation: 1. Simulate particles' positions 2. Create billboards that always face the camera with the particles' positions at its center 3. Cast a ray from camera to every fragment/pixel and determine the value of every particles' contribution along the ray.

Currently, I have nice looking metaballs with lighting, however, when you look closely you can see the edges of a billboard that is infront of another metaball because the colors are slightly off. The fragments that fail the raycasting test get discarded, but they are obviously still somehow interfering and I just don't know how or why.

screenshot 1 screenshot 2 screenshot 3 Want I want to know, because I have thought about it and didn't come to a conclusion: since the actual fragments of the billboards where there is no implicit surface are discarded, that means that not the color value of the "obstructing" discarded billboard gets changed, but instead that of the actual goal billboard. where are possible points of conflicts that may create this behaviour?

Thanks in advance!

EDIT: I think I am wrong about my earlier assumption: the raycast used to determine the implicit surface most likely hits a metaball BEHIND the billboard, so it actually doesn't get discarded... it then takes the normal of the actual intersection, but uses the light direction vector that is made by using the fragment's position, not the actual intersection. So, my guess is that I need a better condition to let the raycast know it didn't hit anything instead of continuing and hitting a ball that is a little further away.

\$\endgroup\$
  • \$\begingroup\$ This question belongs on computergraphics.stackexchange.com \$\endgroup\$ – Stephane Hockenhull Feb 11 '17 at 23:32
  • \$\begingroup\$ Oh, I didn't know there were such specific sub-exchanges. I thought water simulation fits here, but thanks for letting me know! \$\endgroup\$ – Grougal Feb 12 '17 at 0:02
2
\$\begingroup\$

I solved it and it was a rather stupid mistake on my part.

I post this though because it might help others using raycasts to create surfaces, even though the answer "should" be obvious: When calculating the vectors used for lighting, I used the billboard fragment's position instead of the intersection point. The mistake is easy to make because you are actually setting the color for the billboard fragment, but you actually do it by "acting" as if you were coloring another fragment. So: unless it's about the raycast itself, always use the intersection point, not the billboard point!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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