Skip to content
Snippets Groups Projects
Commit d1d5e902 authored by Philip Trettner's avatar Philip Trettner
Browse files

Reduced number of cells visited

parent 6985ed47
Branches
Tags
No related merge requests found
......@@ -101,6 +101,7 @@ void DistanceFieldApp::init()
mGpuTimer = TimerQuery::create();
// bunny
if (!false)
{
std::ifstream file(util::pathOf(__FILE__) + "/../../data/bunny.obj");
......@@ -138,8 +139,10 @@ void DistanceFieldApp::init()
}
}
// mPoints.push_back(glm::vec4(Size / 2));
// data
if (false)
if (!!false)
{
// mPoints.push_back(glm::vec4(Size / 2.0f));
for (auto i = 0; i < 1000; ++i) // DEBUG
......@@ -271,13 +274,14 @@ void DistanceFieldApp::recompute()
fb.begin(GL_POINTS);
vao.draw();
fb.end();
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
mFeedbackQuery->end();
mGpuTimer->end();
auto time = TimerQuery::toSeconds(mGpuTimer->getResult64());
auto pts = mFeedbackQuery->getResult64();
glow::info() << "Seeds: " << pts << " (" << time * 1000 << " ms, " << (time / pts * 1000 * 1000 * 1000) << " ns/pt)";
}
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
// march
{
......@@ -305,8 +309,8 @@ void DistanceFieldApp::recompute()
fb.begin(GL_POINTS);
(outputA ? mVAOQueueB : mVAOQueueA)->bind().drawTransformFeedback(outputA ? mFeedbackB : mFeedbackA);
fb.end();
}
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
}
if (shouldQuery)
{
......@@ -320,8 +324,8 @@ void DistanceFieldApp::recompute()
shouldQuery = true;
auto pts = mFeedbackQuery->getResult64();
auto time = TimerQuery::toSeconds(mGpuTimer->getResult64());
glow::info() << "Got " << pts << " indices at iteration " << nextIteration << " (" << time * 1000 << " ms, "
<< (time / pts * 1000 * 1000 * 1000) << " ns/pt)";
glow::info() << "Got " << pts << " indices at iteration " << nextIteration << " (" << time * 1000
<< " ms, " << (time / pts * 1000 * 1000 * 1000) << " ns/pt)";
forceSync = maxSync;
(void)forceSync;
......@@ -333,9 +337,12 @@ void DistanceFieldApp::recompute()
outputA = !outputA;
if (nextIteration > Size * 4)
{
glow::error() << "Too many iterations, aborting.";
break; // DEBUG
}
}
}
mGpuTimerEnd->saveTimestamp();
mGeneratedQuery->end();
mFragmentsQuery->end();
......
......@@ -10,6 +10,18 @@ void notifyNeighbor(int x, int y, int z, int w, int h)
EmitVertex();
}
void notifyNeighbor(ivec3 ip, ivec3 is)
{
if (any(lessThan(ip, ivec3(0))) || any(greaterThanEqual(ip, is)))
return; // out of bounds
if (imageAtomicMax(uTexIteration, ip, uNextIteration) == uNextIteration)
return; // already emitted
gPosition = (ip.z * is.y + ip.y) * is.x + ip.x;
EmitVertex();
}
void notifyNeighbors(ivec3 ip)
{
ivec3 is = imageSize(uTexNearestPoint);
......
......@@ -10,7 +10,17 @@ layout(points, max_vertices = 6) out;
in uint vPosition[1];
ivec3 is = imageSize(uTexNearestPoint);
const ivec3 is = imageSize(uTexNearestPoint);
const float maxDistance = is.x + is.y + is.z;
const ivec3 dirs[6] = ivec3[6](
ivec3(-1, 0, 0),
ivec3(+1, 0, 0),
ivec3(0, -1, 0),
ivec3(0, +1, 0),
ivec3(0, 0, -1),
ivec3(0, 0, +1)
);
void checkNeighbor(ivec3 ip, int dx, int dy, int dz, inout float refDis, inout uint ptIdx)
{
......@@ -40,31 +50,51 @@ void main()
idx / (is.x * is.y)
);
//if (imageLoad(uTexDistanceField, ip).r != dis)
// return; // wrong distance
uint ptIdx = imageLoad(uTexNearestPoint, ip).r;
uint origIdx = ptIdx;
float dis = is.x + is.y + is.z;
float refDis = maxDistance;
vec3 refP = vec3(0);
// collect candidates
float nDistances[6];
// initial dis
if (origIdx < points.length())
{
vec3 currP = points[ptIdx].xyz;
dis = primitiveDistance(ip, currP);
refP = points[ptIdx].xyz;
refDis = primitiveDistance(ip, refP);
}
// check neighbors
for (int i = 0; i < 6; ++i)
{
ivec3 np = ip + dirs[i];
uint nIdx = imageLoad(uTexNearestPoint, np).x;
// no change possible
if (nIdx == INVALID_POINT)
{
nDistances[i] = maxDistance;
}
else
{
vec3 nPos = points[nIdx].xyz;
float nDis = primitiveDistance(ip, nPos); // distance to ip!
nDistances[i] = primitiveDistance(np, nPos); // distance to np!
// check nearest
checkNeighbor(ip, +1, 0, 0, dis, ptIdx);
checkNeighbor(ip, -1, 0, 0, dis, ptIdx);
checkNeighbor(ip, 0, +1, 0, dis, ptIdx);
checkNeighbor(ip, 0, -1, 0, dis, ptIdx);
checkNeighbor(ip, 0, 0, +1, dis, ptIdx);
checkNeighbor(ip, 0, 0, -1, dis, ptIdx);
if (nDis < refDis) // update
{
refDis = nDis;
refP = nPos;
ptIdx = nIdx;
}
}
}
// crust
if (dis > uCrustSize)
if (refDis > uCrustSize)
return;
// notify neighbors if changed
......@@ -74,6 +104,14 @@ void main()
imageStore(uTexNearestPoint, ip, uvec4(ptIdx));
// notify
notifyNeighbors(ip);
for (int i = 0; i < 6; ++i)
{
ivec3 np = ip + dirs[i];
// only if update expected
float newDis = primitiveDistance(np, refP);
if (newDis < nDistances[i])
notifyNeighbor(np, is);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment