示例#1
0
    public void RealSimpleFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Vector4 v    = drawingDimensions;
        Vector4 u    = drawingUVs;
        Color32 c    = drawingColor;
        int     size = 0;

        size = verts.size;
        verts.Allocate(verts.size += 4);
        var vertsBuffer = verts.buffer;

        vertsBuffer[size]     = new Vector3(v.x, v.y);
        vertsBuffer[size + 1] = new Vector3(v.x, v.w);
        vertsBuffer[size + 2] = new Vector3(v.z, v.w);
        vertsBuffer[size + 3] = new Vector3(v.z, v.y);

        size = uvs.size;
        uvs.Allocate(uvs.size += 4);
        var uvsBuffer = uvs.buffer;

        uvsBuffer[size]     = new Vector2(u.x, u.y);
        uvsBuffer[size + 1] = new Vector2(u.x, u.w);
        uvsBuffer[size + 2] = new Vector2(u.z, u.w);;
        uvsBuffer[size + 3] = new Vector2(u.z, u.y);

        size = cols.size;
        cols.Allocate(cols.size += 4);
        var colsBuffer = cols.buffer;

        colsBuffer[size]     = c;
        colsBuffer[size + 1] = c;
        colsBuffer[size + 2] = c;
        colsBuffer[size + 3] = c;
    }
示例#2
0
        public LightLoopLightsData lightLoopLightsData;   // = new LightLoopLightsData();

        public void Initilize(PipelineSettings pipelineSettings)
        {
            bool needRebuild = false;

            if (NumMaxLights != pipelineSettings.MaxItemsOnScreen)
            {
                needRebuild = true;
            }
            if (NativeLightsBoundList == null ||
                NativeLightsDataList == null)
            {
                needRebuild = true;
            }

            if (needRebuild)
            {
                Dispose();
                NumMaxLights          = pipelineSettings.MaxItemsOnScreen;
                NativeLightsBoundList = new NativeArray <SFiniteLightBound>(NumMaxLights, Allocator.Persistent);
                LightsSphereList      = new NativeArray <Sphere>(NumMaxLights, Allocator.Persistent);
                NativeLightsDataList  = new NativeArray <LightData>(NumMaxLights, Allocator.Persistent);
                lights.Clear();
                culsterDataGenerator = new CulsterDataGenerator();
                tileAndClusterData   = new TileAndClusterData();
                lightLoopLightsData  = new LightLoopLightsData();
                culsterDataGenerator.Initilize(pipelineSettings);
                tileAndClusterData.Initilize(pipelineSettings.NumClusters, pipelineSettings.MaxItemsPerCluster);
                lightLoopLightsData.Initialize(pipelineSettings.MaxItemsOnScreen);

                LightsDataForShadow.Allocate(NumMaxLights);
            }
        }
示例#3
0
    /// <summary>
    /// Helper function that adds the specified values to the buffers.
    /// </summary>
    static void Fill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols, float v0x, float v1x, float v0y, float v1y, float u0x, float u1x, float u0y, float u1y, Color col)
    {
        int size = verts.size;

        verts.Allocate(verts.size += 4);
        var vertsBuffer = verts.buffer;

        vertsBuffer[size]     = new Vector3(v0x, v0y);
        vertsBuffer[size + 1] = new Vector3(v0x, v1y);
        vertsBuffer[size + 2] = new Vector3(v1x, v1y);
        vertsBuffer[size + 3] = new Vector3(v1x, v0y);

        var uvsBuffer = uvs.buffer;

        size = uvs.size;
        uvs.Allocate(uvs.size += 4);
        uvsBuffer[size]        = new Vector2(u0x, u0y);
        uvsBuffer[size + 1]    = new Vector2(u0x, u1y);
        uvsBuffer[size + 2]    = new Vector2(u1x, u1y);
        uvsBuffer[size + 3]    = new Vector2(u1x, u0y);

        size = cols.size;
        cols.Allocate(cols.size += 4);
        var colsBuffer = cols.buffer;

        colsBuffer[size]     = col;
        colsBuffer[size + 1] = col;
        colsBuffer[size + 2] = col;
        colsBuffer[size + 3] = col;
    }
示例#4
0
    private void WriteNormalBuffers(BetterList <Vector3> v, BetterList <Vector2> u, BetterList <Color32> c)
    {
        if (sRtpVerts != null)
        {
            int vertexCount = verts.size;
            sRtpVerts.Clear();
            sRtpVerts.Allocate(vertexCount);
            var   sRtpVertsbuffer = sRtpVerts.buffer;
            float tempX, tempY, tempZ;

            BetterList <Vector3> localverts = verts;
            for (int i = 0; i < vertexCount; ++i)
            {
                tempX = localverts[i].x;
                tempY = localverts[i].y;
                tempZ = localverts[i].z;
                ++sRtpVerts.size;
                // 不调用MultiplyVector,而是直接做矩阵运算,能减少函数调用开销,以及去掉不必要的z坐标计算
                sRtpVertsbuffer[i].x = mRtMatrix.m00 * tempX + mRtMatrix.m01 * tempY + mRtMatrix.m02 * tempZ + mRtMatrix.m03;
                sRtpVertsbuffer[i].y = mRtMatrix.m10 * tempX + mRtMatrix.m11 * tempY + mRtMatrix.m12 * tempZ + mRtMatrix.m13;
                sRtpVertsbuffer[i].z = mRtMatrix.m20 * tempX + mRtMatrix.m21 * tempY + mRtMatrix.m22 * tempZ + mRtMatrix.m23;
            }

            var sRtpVertssize = sRtpVerts.size;
            v.Allocate(v.size + sRtpVertssize);
            u.Allocate(u.size + sRtpVertssize);
            c.Allocate(c.size + sRtpVertssize);

            var vBuffer    = sRtpVerts.buffer;
            var uvsBuffer  = uvs.buffer;
            var colsBuffer = cols.buffer;
            for (int i = 0; i < sRtpVertssize; ++i)
            {
                v.buffer[v.size++] = vBuffer[i];
                u.buffer[u.size++] = uvsBuffer[i];
                c.buffer[c.size++] = colsBuffer[i];
            }
            if (onCustomWrite != null)
            {
                onCustomWrite(v, u, c);
            }
            sRtpVerts.Clear();
        }
    }
示例#5
0
    /// <summary>
    /// Step 2: Transform the vertices by the provided matrix.
    /// </summary>

    public void ApplyTransform(ref Matrix4x4 widgetToPanel)
    {
#if (OPTIMISE_GC_SY_20190426)
        int vertexCount = (m_vertexnum > 0)?m_vertexnum:verts.size;
#else
        int vertexCount = verts.size;
#endif

        if (vertexCount > 0)
        {
#if (OPTIMISE_GC_SY_20190426)
            mRtMatrix = widgetToPanel;
#else
            mRtpVerts.size = 0;
            mRtpVerts.Allocate(vertexCount);
            var   mRtpVertsbuffer = mRtpVerts.buffer;
            float tempX, tempY, tempZ;

            for (int i = 0; i < vertexCount; ++i)
            {
                tempX = verts[i].x;
                tempY = verts[i].y;
                tempZ = verts[i].z;
                ++mRtpVerts.size;
                // 不调用MultiplyVector,而是直接做矩阵运算,能减少函数调用开销,以及去掉不必要的z坐标计算
                mRtpVertsbuffer[i].x = widgetToPanel.m00 * tempX + widgetToPanel.m01 * tempY + widgetToPanel.m02 * tempZ + widgetToPanel.m03;
                mRtpVertsbuffer[i].y = widgetToPanel.m10 * tempX + widgetToPanel.m11 * tempY + widgetToPanel.m12 * tempZ + widgetToPanel.m13;
                mRtpVertsbuffer[i].z = widgetToPanel.m20 * tempX + widgetToPanel.m21 * tempY + widgetToPanel.m22 * tempZ + widgetToPanel.m23;
                //      mRtpVerts.Add(widgetToPanel.MultiplyPoint3x4(verts[i]));
            }
#endif
        }
        else
        {
            //mRtpVerts.Clear();
#if (OPTIMISE_GC_SY_20190426)
            mRtMatrix = Matrix4x4.identity;
#else
            mRtpVerts.size = 0;
#endif
        }
    }
示例#6
0
    /// <summary>
    /// Step 3: Fill the specified buffer using the transformed values.
    /// </summary>
    public void WriteToBuffers(BetterList <Vector3> v, BetterList <Vector2> u, BetterList <Color32> c)
    {
#if (OPTIMISE_GC_SY_20190426)
        if (true)
        {
            if (m_pUIWidget != null)
            {
                if (m_vertexnum > 0)
                {
                    tmpV3.Clear();
                    tmpV2.Clear();
                    tmpC3.Clear();

                    bool bNormalVertexBuffer = false;
                    if (m_pUIWidget.GetType() == typeof(UILabel))
                    {
                        UILabel ulb = m_pUIWidget as UILabel;
                        ulb.WriteDrawCallBuffer(tmpV3, tmpV2, tmpC3);
                    }
                    else
                    {
                        UIBasicSprite ubs = m_pUIWidget as UIBasicSprite;
                        if (ubs.type == UIBasicSprite.Type.Simple)
                        {
                            ubs.RealSimpleFill(tmpV3, tmpV2, tmpC3);
                        }
                        else if (ubs.type == UIBasicSprite.Type.Sliced)
                        {
                            ubs.RealSlicedFill(tmpV3, tmpV2, tmpC3);
                        }
                        else if (ubs.type == UIBasicSprite.Type.Filled)
                        {
                            ubs.RealFilledFill(tmpV3, tmpV2, tmpC3);
                        }
                        else
                        {
                            bNormalVertexBuffer = true;
                            WriteNormalBuffers(v, u, c);
                        }
                    }

                    if (bNormalVertexBuffer == false)
                    {
                        int vertexCount = tmpV3.size;
                        tmpTransedV3.Clear();
                        tmpTransedV3.Allocate(vertexCount);
                        var   tmpTransedV3buffer = tmpTransedV3.buffer;
                        float tempX, tempY, tempZ;

                        for (int i = 0; i < vertexCount; ++i)
                        {
                            tempX = tmpV3[i].x;
                            tempY = tmpV3[i].y;
                            tempZ = tmpV3[i].z;
                            ++tmpTransedV3.size;
                            // 不调用MultiplyVector,而是直接做矩阵运算,能减少函数调用开销,以及去掉不必要的z坐标计算
                            tmpTransedV3buffer[i].x = mRtMatrix.m00 * tempX + mRtMatrix.m01 * tempY + mRtMatrix.m02 * tempZ + mRtMatrix.m03;
                            tmpTransedV3buffer[i].y = mRtMatrix.m10 * tempX + mRtMatrix.m11 * tempY + mRtMatrix.m12 * tempZ + mRtMatrix.m13;
                            tmpTransedV3buffer[i].z = mRtMatrix.m20 * tempX + mRtMatrix.m21 * tempY + mRtMatrix.m22 * tempZ + mRtMatrix.m23;
                        }

                        v.Allocate(v.size + tmpTransedV3.size);
                        u.Allocate(u.size + tmpTransedV3.size);
                        c.Allocate(c.size + tmpTransedV3.size);

                        var vBuffer = tmpTransedV3.buffer;
                        var uvsBuffer  = tmpV2.buffer;
                        var colsBuffer = tmpC3.buffer;

                        for (int i = 0; i < tmpTransedV3.size; ++i)
                        {
                            v.buffer[v.size++] = vBuffer[i];
                            u.buffer[u.size++] = uvsBuffer[i];
                            c.buffer[c.size++] = colsBuffer[i];
                        }

                        tmpV3.Clear();
                        tmpV2.Clear();
                        tmpC3.Clear();
                        tmpTransedV3.Clear();

                        if (onCustomWrite != null)
                        {
                            onCustomWrite(v, u, c);
                        }
                    }
                }
                else
                {
                    WriteNormalBuffers(v, u, c);
                }
            }
            else
            {
                WriteNormalBuffers(v, u, c);
            }
        }
#else
        if (mRtpVerts != null && mRtpVerts.size > 0)
        {
            var mRtpVertssize = mRtpVerts.size;
            v.Allocate(v.size + mRtpVertssize);
            u.Allocate(u.size + mRtpVertssize);
            c.Allocate(c.size + mRtpVertssize);

            var vBuffer    = mRtpVerts.buffer;
            var uvsBuffer  = uvs.buffer;
            var colsBuffer = cols.buffer;

            for (int i = 0; i < mRtpVertssize; ++i)
            {
                v.buffer[v.size++] = vBuffer[i];
                u.buffer[u.size++] = uvsBuffer[i];
                c.buffer[c.size++] = colsBuffer[i];
            }
            if (onCustomWrite != null)
            {
                onCustomWrite(v, u, c);
            }
        }
#endif
    }
示例#7
0
    public void RealSlicedFill(BetterList <Vector3> verts, BetterList <Vector2> uvs, BetterList <Color32> cols)
    {
        Vector4 br = border * pixelSize;

        Color32 c = drawingColor;
        Vector4 v = drawingDimensions;

        mTempPos[0].x = v.x;
        mTempPos[0].y = v.y;
        mTempPos[3].x = v.z;
        mTempPos[3].y = v.w;

        if (mFlip == Flip.Horizontally || mFlip == Flip.Both)
        {
            mTempPos[1].x = mTempPos[0].x + br.z;
            mTempPos[2].x = mTempPos[3].x - br.x;

            mTempUVs[3].x = mOuterUV.xMin;
            mTempUVs[2].x = mInnerUV.xMin;
            mTempUVs[1].x = mInnerUV.xMax;
            mTempUVs[0].x = mOuterUV.xMax;
        }
        else
        {
            mTempPos[1].x = mTempPos[0].x + br.x;
            mTempPos[2].x = mTempPos[3].x - br.z;

            mTempUVs[0].x = mOuterUV.xMin;
            mTempUVs[1].x = mInnerUV.xMin;
            mTempUVs[2].x = mInnerUV.xMax;
            mTempUVs[3].x = mOuterUV.xMax;
        }

        if (mFlip == Flip.Vertically || mFlip == Flip.Both)
        {
            mTempPos[1].y = mTempPos[0].y + br.w;
            mTempPos[2].y = mTempPos[3].y - br.y;

            mTempUVs[3].y = mOuterUV.yMin;
            mTempUVs[2].y = mInnerUV.yMin;
            mTempUVs[1].y = mInnerUV.yMax;
            mTempUVs[0].y = mOuterUV.yMax;
        }
        else
        {
            mTempPos[1].y = mTempPos[0].y + br.y;
            mTempPos[2].y = mTempPos[3].y - br.w;

            mTempUVs[0].y = mOuterUV.yMin;
            mTempUVs[1].y = mInnerUV.yMin;
            mTempUVs[2].y = mInnerUV.yMax;
            mTempUVs[3].y = mOuterUV.yMax;
        }

        /*
         * for (int x = 0; x < 3; ++x)
         *  {
         *      int x2 = x + 1;
         *
         *      for (int y = 0; y < 3; ++y)
         *      {
         *          if (centerType == AdvancedType.Invisible && x == 1 && y == 1) continue;
         *          size += 4;
         *
         */
        // 直接算出size,减少(9-1)x3次调用Allocate
        var size = 0;

        size += centerType == AdvancedType.Invisible ? 32 : 36;

        verts.Allocate(verts.size + size);
        uvs.Allocate(uvs.size + size);
        cols.Allocate(cols.size + size);

        for (int x = 0; x < 3; ++x)
        {
            int x2 = x + 1;

            for (int y = 0; y < 3; ++y)
            {
                if (centerType == AdvancedType.Invisible && x == 1 && y == 1)
                {
                    continue;
                }

                int y2 = y + 1;

                size        = verts.size;
                verts.size += 4;
                var vertsBuffer = verts.buffer;
                vertsBuffer[size].x = mTempPos[x].x;
                vertsBuffer[size].y = mTempPos[y].y;
                vertsBuffer[size].z = 1.0f;

                vertsBuffer[size + 1].x = mTempPos[x].x;
                vertsBuffer[size + 1].y = mTempPos[y2].y;
                vertsBuffer[size + 1].z = 1.0f;

                vertsBuffer[size + 2].x = mTempPos[x2].x;
                vertsBuffer[size + 2].y = mTempPos[y2].y;
                vertsBuffer[size + 2].z = 1.0f;

                vertsBuffer[size + 3].x = mTempPos[x2].x;
                vertsBuffer[size + 3].y = mTempPos[y].y;
                vertsBuffer[size + 3].z = 1.0f;

                size      = uvs.size;
                uvs.size += 4;
                var uvsBuffer = uvs.buffer;
                uvsBuffer[size].x = mTempUVs[x].x;
                uvsBuffer[size].y = mTempUVs[y].y;

                uvsBuffer[size + 1].x = mTempUVs[x].x;
                uvsBuffer[size + 1].y = mTempUVs[y2].y;

                uvsBuffer[size + 2].x = mTempUVs[x2].x;
                uvsBuffer[size + 2].y = mTempUVs[y2].y;

                uvsBuffer[size + 3].x = mTempUVs[x2].x;
                uvsBuffer[size + 3].y = mTempUVs[y].y;

                size       = cols.size;
                cols.size += 4;
                var colsBuffer = cols.buffer;
                colsBuffer[size]     = c;
                colsBuffer[size + 1] = c;
                colsBuffer[size + 2] = c;
                colsBuffer[size + 3] = c;
            }
        }
    }