public void Process(Vector2 uv, float _tolerance) { tasks = new List <PixelCom>(); map = new int[texSrcWidth, texSrcHeight]; tolerance = _tolerance; int index = SWTextureProcess.TexUV2Index(texSrcWidth, texSrcHeight, uv); int x = 0; int y = 0; SWTextureProcess.TexUV2Index(texSrcWidth, texSrcHeight, uv, ref x, ref y); AddTask(x, y, index); while (tasks.Count > 0) { var n = new List <PixelCom> (tasks); tasks.Clear(); foreach (var item in n) { PerPixel(item); } } MissionEnd(); }
public void Process(Vector2 uv, float _tolerance) { int index = SWTextureProcess.TexUV2Index(texSrcWidth, texSrcHeight, uv); colors.Add(texSrcColorBuffer [index]); tolerance = _tolerance; Process(); }
protected override void ThreadMission_Pixel(int i, int j) { base.ThreadMission_Pixel(i, j); Vector2 uv = SWTextureProcess.TexUV(texSrcWidth, texSrcHeight, i, j); Vector2 fromUV = uv - offset; Vector2 dis = fromUV - uv; float alpha = 0; float pcg = 0; Color c = SWTextureProcess.GetColor_UV(texSrcWidth, texSrcHeight, texSrcColorBuffer, uv); Color c2 = SWTextureProcess.GetColor_UV(texSrcWidth, texSrcHeight, texSrcColorBuffer, uv - dis.normalized * 3f / 512f); Vector2 newUV = uv - dis.normalized * pixelBack / 512f; int newI = 0; int newJ = 0; SWTextureProcess.TexUV2Index(texSrcWidth, texSrcHeight, newUV, ref newI, ref newJ); if (!IsImage(c) && !IsImage(c2)) { // int index = 0; while (pcg <= 1) { Vector2 xuv = uv + dis * pcg; Color xColor = SWTextureProcess.GetColor_UV(texSrcWidth, texSrcHeight, texSrcColorBuffer, xuv); Vector2 xpos = uv; xpos -= center; xpos = matrix.MultiplyPoint(xpos); xpos += center; if (xColor.a > 0) { alpha = pcg; float g = alpha; float b = 0; float a = GreenToAlpha(g); texColorBuffer [(texSrcHeight - newJ - 1) * texSrcWidth + newI] = new Color(xpos.x, alpha, b, a); break; } pcg += accuracyUnit; } } }
void ThreadMission_Pixel2(int i, int j) { int index = SWTextureProcess.XYtoIndex(texWidth, texHeight, i, j); Vector2 uv = SWTextureProcess.TexUV(texWidth, texHeight, i, j); Color c = texColorBuffer [index]; float dis = offset.magnitude * threhold; float alpha = -1; for (float v = 0; v < 1; v += 0.01f) { Vector2 newUV = uv + dirHor * v * dis; int newIndex = SWTextureProcess.TexUV2Index(texWidth, texHeight, newUV); Color newC = texColorBuffer[newIndex]; if (newC.a == 0) { alpha = v; break; } newUV = uv - dirHor * v * dis; newIndex = SWTextureProcess.TexUV2Index(texWidth, texHeight, newUV); newC = texColorBuffer[newIndex]; if (newC.a == 0) { alpha = v; break; } } // if (alpha < 0.5f) // alpha = 0; if (alpha >= 0) { texColorBuffer [index] = new Color(c.r, c.g, c.b, c.a * alpha); } }
protected IntRect GetBrushRect(List <Vector2> uvs) { int rectSize = brush.size + extraSize; IntRect rect = new IntRect(); foreach (var uv in uvs) { int centerX = 0; int centerY = 0; SWTextureProcess.TexUV2Index(texWidth, texHeight, uv, ref centerX, ref centerY); int xMin = centerX - rectSize; int xMax = centerX + rectSize; int yMin = centerY - rectSize; int yMax = centerY + rectSize; if (xMin < rect.xMin) { rect.xMin = xMin; } if (yMin < rect.yMin) { rect.yMin = yMin; } if (xMax > rect.xMax) { rect.xMax = xMax; } if (yMax > rect.yMax) { rect.yMax = yMax; } } rect.xMin = Mathf.Clamp(rect.xMin, 0, texWidth); rect.xMax = Mathf.Clamp(rect.xMax, 0, texWidth); rect.yMin = Mathf.Clamp(rect.yMin, 0, texHeight); rect.yMax = Mathf.Clamp(rect.yMax, 0, texHeight); return(rect); }