MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / SampleSDFGrad

Function SampleSDFGrad

extensions/flexExtRigid.cpp:49–65  ·  view source on GitHub ↗

return normal of signed distance field

Source from the content-addressed store, hash-verified

47
48// return normal of signed distance field
49Vec3 SampleSDFGrad(const float* sdf, int dim, int x, int y, int z)
50{
51 int x0 = std::max(x-1, 0);
52 int x1 = std::min(x+1, dim-1);
53
54 int y0 = std::max(y-1, 0);
55 int y1 = std::min(y+1, dim-1);
56
57 int z0 = std::max(z-1, 0);
58 int z1 = std::min(z+1, dim-1);
59
60 float dx = (SampleSDF(sdf, dim, x1, y, z) - SampleSDF(sdf, dim, x0, y, z))*(dim*0.5f);
61 float dy = (SampleSDF(sdf, dim, x, y1, z) - SampleSDF(sdf, dim, x, y0, z))*(dim*0.5f);
62 float dz = (SampleSDF(sdf, dim, x, y, z1) - SampleSDF(sdf, dim, x, y, z0))*(dim*0.5f);
63
64 return Vec3(dx, dy, dz);
65}
66
67} // anonymous namespace
68

Callers 1

Calls 1

SampleSDFFunction · 0.70

Tested by

no test coverage detected