#How to Properly Sample a SDF Bilinearly

1 messages · Page 1 of 1 (latest)

rose ingot
#

i cannot seem to understand how to code sample an sdf. when i sample (0, 0, 0) and (1, 1, 1), they both give .301 red (even though both samples are defo outside of the true sdf volume. points that i know are inside give something close to .07, and ones that are outside, but closer then the edges are also .07 r, and the rest of the color values are 1, 1, 1). for a color of (.07, 1, 1, 1) for both points inside and outside the sdf when sampling the main branch.
heres my code that uses the sdf and samples it(https://paste.ofcode.org/3byc7F7YcQdeJPSTFvNvyXk) thank you guys for any help provided.

reef scarab
reef scarab
rose ingot
# reef scarab Looking at the screenshot it says the format is r16 - just one channel of data.

first off thank you for the help dlich
i baked this sdf using the meshtoSDF VFX bake tool, then taking the data from the gpu and reading it into a 3d Texture then saving it. i can read the data as a sdf in editor, so i dont understand how im misunderstanding it this much. https://paste.ofcode.org/mMXNzhwJNrZ36XxbV8RmXr (heres the code creating and saving it, the reading part is above)
I did assume it was just an r value that if the value was below or equal to .5f it was inside the sdf, or if it was above .5f it was outside, but its defo not that

#

heres a picture of the sdf as a volume

rose ingot
#

heres an updated output, whiich probably means im somehow reading the SDF into a texture wrong.

reef scarab
reef scarab
rose ingot
#

i did and thats how i got this baked texture. i used .5f,

#

i did try 1 and 0, and they made wierd partial edits to the sdf, but they didnt seem to change the value of any of the 3 color uvs i used to test

#

(i know that the thershold should be .5, just tested because i couldnt think of anything else to test).

#

Thank you again for helping.

reef scarab
#

I'd try using the baking and visualizing tools to confirm if the issue is with your baking or visualizing process.

rose ingot
#

im using that, just gotta edit my code to output the meshes as well (havent been saving the mesh)

reef scarab
rose ingot
reef scarab
#

Ah, OK, I guess it compares the actual alpha channel.

reef scarab
rose ingot
#

yes, it compares exactly to the actual mesh shape

#

a little off due to level of detail, but well enoughk

reef scarab
#

Then I'd assume the sdf is correct.
What is the actual use case for that sdf? Is there a problem during that time?

rose ingot
#

yes, i cannot sample it correctly, the values give back .31 to .7, and .7 can be both inside or outside the mesh

#

the use case is for fast runtime checking to see if a point is inside that volume

reef scarab
#

What does it look like with 0.5 used as a threshold in your use case?

rose ingot
#

thats what i have been using as a threshhold this entire time

reef scarab
#

Perhaps what you think is outside is actually inside the mesh?

rose ingot
#

the point at 0 0 0 is defo outside the mesh

#

the point at bottem center is defo inside the mesh

#

the points im check are for branches, and i know for a fact the first 8 are checking points inside the mesh, the 9th is outside the mesh,

reef scarab
#

Is the texture you're sampling, created as cpu readable?

rose ingot
#

yes, it threw an error when i tried to read it after making acidentally making it unreadable

#

the code is all present above if you need to take a look, the original "read" that isnt giving what i want is in the first post. the one that i included with my response has the code for reading the texture to a file, and the code for creating the meshes

reef scarab
rose ingot
#

it says "normilized coordinates are coords between 0-1 in all axis's

#

you can do GetPixel, but im using GetPixelBilinear which takes u v and w, im guessing it coresponds to the same as 2d,, with z repersenting w and the width or length

reef scarab
rose ingot
#

.5, 0, .5f

#

i did also try .5f, .5f, 0f

reef scarab
#

I'd try 0.5,0.5,0.5 just to be sure.

#

It's not impossible that there are some inaccuracies at the edges.

rose ingot
#

.5, .5, .5f is very close to not being inside the mesh

#

but i will try it

reef scarab
#

How close?

#

Oh, you mean physically?

rose ingot
#

yes,

reef scarab
#

I see. I'd suggest testing with simpler shapes that you can confirm more easily. Like a sphere for example.

rose ingot
#

i meant like, i know for a fact that 000 and 111 are both outside

#

and they give .31

#

and if a value is outside but on the edge of a mesh, it should give back values just above .5f, to denote being close to the edge no?

#

thats the values for the first branch test, different from the others, but still not right

#

oh. this is an sdf.

reef scarab
#

Normally, I'd expect values outside to have the min value(0), even very close, but I guess it depends on the algorithm.

rose ingot
#

signed distance field, not a regular one. let me check

#

only part i hate is that it takes 20s to do a new check,

reef scarab
#

Again, sdf can mean many things and generated in many ways. You use sdfs for marching cubes as well, and the values there can be totally different to what you're getting.

rose ingot
#

alright, somethings wrong with my checking algorithm, but the signed distance field is from -1 to 1

reef scarab
rose ingot
#

thank you so much for helping me, i defo feel dumb for not figuring it out sooner

#

.5f

#

im pretty sure the baker takes the .5f to bake a distance field, then remaps to -1 to 1

#

well now im pretty sure lol

#

that, was a really dumb problem i created, and i should of been able to figure it out.