Ejemplo n.º 1
0
        public void Execute()
        {
            int     startIndex     = 0;
            int     endIndex       = 0;
            int     leftNodeIndex  = 0;
            int     rightNodeIndex = 0;
            bool    mark0          = false;
            bool    mark1          = false;
            bool    mark2          = false;
            bool    mark3          = false;
            bool    mark4          = false;
            bool    mark5          = false;
            Vector2 v12            = Vector2.zero;

            GSubdivNode currentNode;
            GSubdivNode leftNode  = new GSubdivNode();
            GSubdivNode rightNode = new GSubdivNode();

            meshBaseResolution = Mathf.Max(0, meshBaseResolution - lod);

            metadata[GGeometryJobUtilities.METADATA_NEW_VERTEX_CREATED] = 0;
            for (int res = meshBaseResolution; res < meshResolution; ++res)
            {
                startIndex = GGeometryJobUtilities.GetStartIndex(ref res);
                endIndex   = startIndex + GGeometryJobUtilities.GetElementCountForSubdivLevel(ref res) - 1;
                for (int i = startIndex; i <= endIndex; ++i)
                {
                    GGeometryJobUtilities.GetChildrenNodeIndex(ref i, ref leftNodeIndex, ref rightNodeIndex);
                    if (creationState[leftNodeIndex] != GGeometryJobUtilities.STATE_NOT_CREATED ||
                        creationState[rightNodeIndex] != GGeometryJobUtilities.STATE_NOT_CREATED)
                    {
                        continue;
                    }
                    currentNode = nodes[i];
                    mark0       = GGeometryJobUtilities.GetVertexMark(vertexMarker, currentNode.v01);
                    mark1       = GGeometryJobUtilities.GetVertexMark(vertexMarker, currentNode.v12);
                    mark2       = GGeometryJobUtilities.GetVertexMark(vertexMarker, currentNode.v20);
                    mark3       = CheckMarkLOD0(currentNode.v01);
                    mark4       = CheckMarkLOD0(currentNode.v12);
                    mark5       = CheckMarkLOD0(currentNode.v20);

                    if (mark0 || mark1 || mark2 ||
                        mark3 || mark4 || mark5)
                    {
                        currentNode.Split(ref leftNode, ref rightNode);
                        nodes[leftNodeIndex]          = leftNode;
                        nodes[rightNodeIndex]         = rightNode;
                        creationState[leftNodeIndex]  = GGeometryJobUtilities.STATE_CREATED;
                        creationState[rightNodeIndex] = GGeometryJobUtilities.STATE_CREATED;
                        GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref leftNode);
                        GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref rightNode);

                        metadata[GGeometryJobUtilities.METADATA_NEW_VERTEX_CREATED] = 1;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            GSubdivNode n;
            Vector3     v0 = Vector3.zero;
            Vector3     v1 = Vector3.zero;
            Vector3     v2 = Vector3.zero;

            Vector2 uv0 = Vector2.zero;
            Vector2 uv1 = Vector2.zero;
            Vector2 uv2 = Vector2.zero;
            Vector2 uvc = Vector2.zero;

            Vector3 normal = Vector3.zero;
            Color32 color  = new Color32();

            int i0 = 0;
            int i1 = 0;
            int i2 = 0;

            Color hmData0      = Color.black;
            Color hmData1      = Color.black;
            Color hmData2      = Color.black;
            float heightSample = 0;

            meshBaseResolution = Mathf.Max(0, meshBaseResolution - lod);

            int length           = nodes.Length;
            int leafIndex        = 0;
            int startIndex       = GGeometryJobUtilities.GetStartIndex(ref meshBaseResolution);
            int removedLeafCount = 0;

            for (int i = startIndex; i < length; ++i)
            {
                if (creationState[i] != GGeometryJobUtilities.STATE_LEAF)
                {
                    continue;
                }
                n = nodes[i];
                ProcessTriangle(
                    ref n, ref leafIndex,
                    ref uv0, ref uv1, ref uv2, ref uvc,
                    ref v0, ref v1, ref v2,
                    ref i0, ref i1, ref i2,
                    ref normal, ref color,
                    ref hmData0, ref hmData1, ref hmData2,
                    ref heightSample, ref removedLeafCount);
                leafIndex += 1;
            }

            metadata[GGeometryJobUtilities.METADATA_LEAF_REMOVED] = removedLeafCount;
        }
Ejemplo n.º 3
0
        public void Execute()
        {
            int startIndex     = 0;
            int endIndex       = 0;
            int leftNodeIndex  = 0;
            int rightNodeIndex = 0;
            int count          = 0;
            int length         = creationState.Length;

            baseResolution = Mathf.Max(0, baseResolution - lod);

            for (int res = baseResolution; res <= resolution; ++res)
            {
                startIndex = GGeometryJobUtilities.GetStartIndex(ref res);
                endIndex   = startIndex + GGeometryJobUtilities.GetElementCountForSubdivLevel(ref res) - 1;
                for (int i = startIndex; i <= endIndex; ++i)
                {
                    if (creationState[i] != GGeometryJobUtilities.STATE_CREATED)
                    {
                        continue;
                    }
                    GGeometryJobUtilities.GetChildrenNodeIndex(ref i, ref leftNodeIndex, ref rightNodeIndex);
                    if (leftNodeIndex >= length || rightNodeIndex >= length)
                    {
                        creationState[i] = GGeometryJobUtilities.STATE_LEAF;
                        count           += 1;
                        continue;
                    }
                    if (creationState[leftNodeIndex] == GGeometryJobUtilities.STATE_NOT_CREATED ||
                        creationState[rightNodeIndex] == GGeometryJobUtilities.STATE_NOT_CREATED)
                    {
                        creationState[i] = GGeometryJobUtilities.STATE_LEAF;
                        count           += 1;
                        continue;
                    }
                }
            }
            metadata[0] = count;
        }
        public void Execute()
        {
            int startIndex     = 0;
            int endIndex       = 0;
            int leftNodeIndex  = 0;
            int rightNodeIndex = 0;

            GSubdivNode currentNode;
            GSubdivNode leftNode  = new GSubdivNode();
            GSubdivNode rightNode = new GSubdivNode();

            Vector2 uv0 = Vector2.zero;
            Vector2 uv1 = Vector2.zero;
            Vector2 uv2 = Vector2.zero;
            Vector2 uvc = Vector2.zero;

            float r0          = 0;
            float r1          = 0;
            float r2          = 0;
            float rc          = 0;
            float rMax        = 0;
            int   subDivLevel = 0;

            baseResolution = Mathf.Max(0, baseResolution - lod);
            resolution     = Mathf.Max(0, resolution - lod);

            int maxLevel = baseResolution + Mathf.Min(Mathf.FloorToInt(1f / GGeometryJobUtilities.SUB_DIV_STEP), resolution - baseResolution);

            for (int res = baseResolution; res < maxLevel; ++res)
            {
                startIndex = GGeometryJobUtilities.GetStartIndex(ref res);
                endIndex   = startIndex + GGeometryJobUtilities.GetElementCountForSubdivLevel(ref res) - 1;
                for (int i = startIndex; i <= endIndex; ++i)
                {
                    if (creationState[i] != GGeometryJobUtilities.STATE_CREATED)
                    {
                        continue;
                    }
                    currentNode = baseTree[i];
                    GGeometryJobUtilities.NormalizeToPoint(ref uv0, ref uvRect, ref currentNode.v0);
                    GGeometryJobUtilities.NormalizeToPoint(ref uv1, ref uvRect, ref currentNode.v1);
                    GGeometryJobUtilities.NormalizeToPoint(ref uv2, ref uvRect, ref currentNode.v2);
                    uvc = (uv0 + uv1 + uv2) / 3;

                    r0 = GGeometryJobUtilities.GetColorBilinear(subdivMap, ref uv0).r;
                    r1 = GGeometryJobUtilities.GetColorBilinear(subdivMap, ref uv1).r;
                    r2 = GGeometryJobUtilities.GetColorBilinear(subdivMap, ref uv2).r;
                    rc = GGeometryJobUtilities.GetColorBilinear(subdivMap, ref uvc).r;

                    rMax = Mathf.Max(Mathf.Max(r0, r1), Mathf.Max(r2, rc));

                    subDivLevel = baseResolution + (int)(rMax / GGeometryJobUtilities.SUB_DIV_STEP);
                    if (subDivLevel <= res)
                    {
                        continue;
                    }

                    GGeometryJobUtilities.GetChildrenNodeIndex(ref i, ref leftNodeIndex, ref rightNodeIndex);
                    currentNode.Split(ref leftNode, ref rightNode);

                    baseTree[leftNodeIndex]      = leftNode;
                    creationState[leftNodeIndex] = GGeometryJobUtilities.STATE_CREATED;
                    GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref leftNode);

                    baseTree[rightNodeIndex]      = rightNode;
                    creationState[rightNodeIndex] = GGeometryJobUtilities.STATE_CREATED;
                    GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref rightNode);
                }
            }
        }
Ejemplo n.º 5
0
        public void Execute()
        {
            ResetMetadata();
            ResetStates();
            ResetMarker();

            GSubdivNode nodes0 = new GSubdivNode()
            {
                v0 = Vector2.up,
                v1 = Vector2.one,
                v2 = Vector2.zero
            };

            nodes[0]         = nodes0;
            creationState[0] = GGeometryJobUtilities.STATE_CREATED;
            GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref nodes0);

            GSubdivNode nodes1 = new GSubdivNode()
            {
                v0 = Vector2.right,
                v1 = Vector2.zero,
                v2 = Vector2.one
            };

            nodes[1]         = nodes1;
            creationState[1] = GGeometryJobUtilities.STATE_CREATED;
            GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref nodes1);

            int         startIndex     = 0;
            int         endIndex       = 0;
            int         leftNodeIndex  = 0;
            int         rightNodeIndex = 0;
            GSubdivNode currentNode;
            GSubdivNode leftNode  = new GSubdivNode();
            GSubdivNode rightNode = new GSubdivNode();

            for (int res = 0; res < resolution; ++res)
            {
                startIndex = GGeometryJobUtilities.GetStartIndex(ref res);
                endIndex   = startIndex + GGeometryJobUtilities.GetElementCountForSubdivLevel(ref res) - 1;
                for (int i = startIndex; i <= endIndex; ++i)
                {
                    currentNode = nodes[i];
                    currentNode.Split(ref leftNode, ref rightNode);
                    GGeometryJobUtilities.GetChildrenNodeIndex(ref i, ref leftNodeIndex, ref rightNodeIndex);

                    nodes[leftNodeIndex]  = leftNode;
                    nodes[rightNodeIndex] = rightNode;
                }
            }

            baseResolution = Mathf.Max(0, baseResolution - lod);
            for (int res = 0; res <= baseResolution; ++res)
            {
                startIndex = GGeometryJobUtilities.GetStartIndex(ref res);
                endIndex   = startIndex + GGeometryJobUtilities.GetElementCountForSubdivLevel(ref res) - 1;
                for (int i = startIndex; i <= endIndex; ++i)
                {
                    currentNode      = nodes[i];
                    creationState[i] = GGeometryJobUtilities.STATE_CREATED;
                    GGeometryJobUtilities.MarkVertices(ref vertexMarker, ref currentNode);
                }
            }
        }