Previously, I found an useful article that explained how to convert 3d mesh to SDF easily.

I want our artists to be able to easily convert from polygonal data to SDFs with little-to-no effort.


this article is what I want but unfortunately there wasn't simple Implemention.

there is algorithm in this article:

foreach (pixel in texture)
    foreach (triangle in mesh)
         get pixel center as mesh bounds position
         get closest point on triangle
         calculate distance from pixel position to triangle
         keep the smallest distance
         perform a raycast along arbitrary vector against triangle
         if(raycast intersects triangle)
            increment an intersection counter
    if(number of intersections is even)
        pixel value is positive // outside mesh
        pixel value is negative // inside mesh

I like to Implement this article but I can't understand above algorithm and I don't know how can I convert 3D mesh to SDF data and then sotre this data to 3D RenderTexture?

  • \$\begingroup\$ Is there a particular step in the algorithm above that you're stuck on? Or a particular concept you need elaboration about? \$\endgroup\$ – DMGregory Oct 26 '18 at 23:48
  • \$\begingroup\$ @DMGregory My problem is that I don't know where to start Implement above algorithm.I'm confused \$\endgroup\$ – Seyed Morteza Kamali Oct 27 '18 at 8:09
  • \$\begingroup\$ Okay, so it says for each pixel in texture — have you got an outer triple for loop iterating over each cell in the volume grid? Next it says for each triangle, have you got an inner for loop iterating over the triangles? \$\endgroup\$ – DMGregory Oct 27 '18 at 8:23

Your Answer

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

Browse other questions tagged or ask your own question.