Exemplo 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;
                    }
                }
            }
        }
        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);
                }
            }
        }
Exemplo n.º 3
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);
                }
            }
        }