Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would you implement a grid resolution factor? #2

Closed
streunerlein opened this issue Jan 14, 2022 · 4 comments
Closed

How would you implement a grid resolution factor? #2

streunerlein opened this issue Jan 14, 2022 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@streunerlein
Copy link

streunerlein commented Jan 14, 2022

Hello @keijiro !

Thank you for this amazing implementation. One question arose while we've tried it, how would you implement a grid resolution parameter as in Paul Bourke's article to steer the resolution of the mesh? By just increasing sampling distances in the volume?

Greetings

Dominique

PS: Talking about this
image

My first guess would be the increase the sampling in the MeshConstruction shader from:

[numthreads(4, 4, 4)]
void MeshReconstruction(uint3 id : SV_DispatchThreadID)
{
    // Boundary check
    if (any(id + 1 >= Dims.xyz)) return;

    // Voxel samples at each cube vertex
    float4 samples[8];
    for (uint i = 0; i < 8; i++)
        samples[i] = VoxelValueWithGradient(id + CubeVertex(i));

// ...
}

to something like

uint samplingDistance;

[numthreads(4, 4, 4)]
void MeshReconstruction(uint3 id : SV_DispatchThreadID)
{
    id = id * samplingDistance;
    // Boundary check
    if (any(id + 1 >= Dims.xyz)) return;

    // Voxel samples at each cube vertex
    float4 samples[8];
    for (uint i = 0; i < 8; i++)
        samples[i] = VoxelValueWithGradient(id + CubeVertex(i));

// ...
}

and modifying the threadgroups by this samplingDistance:

   int samplingDistance = 1;
    void RunCompute(ComputeBuffer voxels, float target, float scale)
    {
        _counterBuffer.SetCounterValue(0);

        var downSampledGrids = new Vector3Int(_grids.x / samplingDistance, _grids.y / samplingDistance, _grids.z / samplingDistance);

        // Isosurface reconstruction
        _compute.SetInt("samplingDistance", samplingDistance);
        _compute.SetInts("Dims", downSampledGrids );
        _compute.SetInt("MaxTriangle", _triangleBudget);
        _compute.SetFloat("Scale", scale);
        _compute.SetFloat("Isovalue", target);
        _compute.SetBuffer(0, "TriangleTable", _triangleTable);
        _compute.SetBuffer(0, "Voxels", voxels);
        _compute.SetBuffer(0, "VertexBuffer", _vertexBuffer);
        _compute.SetBuffer(0, "IndexBuffer", _indexBuffer);
        _compute.SetBuffer(0, "Counter", _counterBuffer);
        _compute.DispatchThreads(0, downSampledGrids );

        // Clear unused area of the buffers.
        _compute.SetBuffer(1, "VertexBuffer", _vertexBuffer);
        _compute.SetBuffer(1, "IndexBuffer", _indexBuffer);
        _compute.SetBuffer(1, "Counter", _counterBuffer);
        _compute.DispatchThreads(1, 1, 1, 1);

        // Bounding box
        var ext = new Vector3(_grids.x, _grids.y, _grids.z) * scale;
        _mesh.bounds = new Bounds(Vector3.zero, ext);
    }
@keijiro keijiro self-assigned this Jan 14, 2022
@keijiro keijiro added the question Further information is requested label Jan 14, 2022
@keijiro
Copy link
Owner

keijiro commented Jan 14, 2022

Sorry, I can't understand your point. Isn't it just increasing dimensions count?

@streunerlein
Copy link
Author

streunerlein commented Jan 14, 2022

Does this also work for Volumes (instead of noise)? That's our case we are trying to solve right now (VolumeDataVisualizer.cs)

@keijiro
Copy link
Owner

keijiro commented Jan 15, 2022

You should increase the resolution of the volume data (I think that's what the author said in the article).

@keijiro
Copy link
Owner

keijiro commented Jan 21, 2022

I'm closing this issue now. Please reopen it for further problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants