コード例 #1
0
        protected override void ThreadMission_Pixel(int i, int j)
        {
            base.ThreadMission_Pixel(i, j);
            Vector2 uv = SWTextureProcess.TexUV(texWidth, texHeight, i, j);

            for (int k = 0; k < info.pts.Count - 1; k++)
            {
                var   p0  = info.pts [SWTextureProcess.LoopID(k - 1, info.pts.Count)];
                var   p1  = info.pts [SWTextureProcess.LoopID(k, info.pts.Count)];
                var   p2  = info.pts [SWTextureProcess.LoopID(k + 1, info.pts.Count)];
                float pcg = SWTextureProcess.PointOnSegPcgSign(uv, p1.uv, p2.uv);
                pcg = p1.pcg + (p2.pcg - p1.pcg) * pcg;
                float disSeg      = SWTextureProcess.Point2SegDis(uv, p1.uv, p2.uv);
                float disLineSign = SWTextureProcess.Point2LineDisSign(uv, p1.uv, p2.uv);
                disLineSign = -disLineSign;
                float g = (disLineSign / size + 1) * 0.5f;
                float b = 0;
                float a = GreenToAlpha(g);
                //first seg cap
                if (k == 0)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p2.pre, p1.uv - p2.pre) >= 0)
                        {
                            texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                        }
                    }
                }
                //last seg cap
                else if (k == info.pts.Count - 2)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p1.after, p2.uv - p1.after) >= 0)
                        {
                            texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                        }
                    }
                }
                else
                {
                    if (SWTextureProcess.PointInSeg(uv, p1.after, p2.pre, size))
                    {
                        texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(pcg, g, b, a);
                    }
                }

                if (k == 0)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p1.uv, p2.uv - p1.uv) <= 0)
                        {
                            float disCenter = (uv - p1.uv).magnitude;
                            if (disCenter / size > 1 - threhold * 2)
                            {
                                a = 1 - (disCenter / size - (1 - threhold * 2)) / (threhold * 2);
                                texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].r,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].g,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].b,
                                    a
                                    );
                            }
                        }
                    }
                }
                if (k == info.pts.Count - 2 || info.pts.Count == 2)
                {
                    if (disSeg <= size)
                    {
                        if (Vector2.Dot(uv - p2.uv, p1.uv - p2.uv) <= 0)
                        {
                            float disCenter = (uv - p2.uv).magnitude;
                            if (disCenter / size > 1 - threhold * 2)
                            {
                                a = 1 - (disCenter / size - (1 - threhold * 2)) / (threhold * 2);
                                texColorBuffer [(texHeight - j - 1) * texWidth + i] = new Color(
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].r,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].g,
                                    texColorBuffer [(texHeight - j - 1) * texWidth + i].b,
                                    a
                                    );
                            }
                        }
                    }
                }
            }
        }