Giter VIP home page Giter VIP logo

unitygpumeshvoxelizerpart5's Introduction

UnityGPUMeshVoxelizer

A GPU mesh voxelizer for Unity. Read the accompanying blog post here.

Example

unitygpumeshvoxelizerpart5's People

Contributors

bzgeb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

unitygpumeshvoxelizerpart5's Issues

Shell kernel misses some plane-aligned triangles and fillvolume kernel produces streaks outside of some meshes

This check-if-intersecting-and-exiting-any-closest-triangle algorithm produces streaks of incorrect voxels in some meshes.
I reduced the issue by checking for multiple ray directions and && them.
It misses some voxels inside the mesh now but at least it doesn't produce incorrect streaks outside the mesh.
Also i had to increase AABB extents in shell generator kernel a bit because it was missing some plane-aligned triangles sometimes.
Now the voxelizer is much more stable. Hopefully this can help somebody else out:

VoxelizeMesh
aabb.extents *= 1.41421356;

FillVolume

float3 rayDirection0 = float3(0, 0, 1);
float3 rayDirection1 = float3(0, 0, -1);
float minDistance0 = 10000000.0;
float minDistance1 = 10000000.0;
float3 minDistanceNormal0;
float3 minDistanceNormal1;
bool didIntersect0 = false;
bool didIntersect1 = false;

for (int i = 0; i < _TriangleCount; i += 3)
{
    Triangle tri;
    tri.a = _MeshVertices[_MeshTriangleIndices[i]];
    tri.b = _MeshVertices[_MeshTriangleIndices[i + 1]];
    tri.c = _MeshVertices[_MeshTriangleIndices[i + 2]];
    
    float3 outNormal0;
    float distance0;
    if (IntersectsRayTriangle(rayOrigin, rayDirection0, tri, distance0, outNormal0))
    {
        if (distance0 < minDistance0)
        {
            minDistance0 = distance0;
            minDistanceNormal0 = outNormal0;
            didIntersect0 = true;
        }
    }
    
    float3 outNormal1;
    float distance1;
    if (IntersectsRayTriangle(rayOrigin, rayDirection1, tri, distance1, outNormal1))
    {
    	if (distance1 < minDistance1)
    	{
    		minDistance1 = distance1;
    		minDistanceNormal1 = outNormal1;
    		didIntersect1 = true;
    	}
    }
}

if ((didIntersect0 && dot(minDistanceNormal0, rayDirection0) > 0.0) && (didIntersect1 && dot(minDistanceNormal1, rayDirection1) > 0.0))
{
	_Voxels[voxelIndex].isSolid = 1.0; //or whatever
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.