Somthing Weird! Creating filled circle with gradient(alpha) texture
Look the final drawing Effect . the Angle step count is 4 .why every corner has sharp line.
the texture used by shader is 4X4 size. top 2 pixels alpha == 0
int count = 4;//Mathf.Max(40, Mathf.RoundToInt(cicle.outter_radius * 0.1f));
float step = 360 / count;
float outter = cicle.outter_radius;
float inner = (cicle.outter_radius - cicle.outter_soft);
Quaternion target = Quaternion.identity;
Vector3 dir = Vector3.zero;
//Vector3 from = Quaternion.Euler(0, 0, (180 % count == 0) && (count % 2 == 0) ? 180 / count: 0) *Vector3.up;
//from.Normalize();
Vector3 from = Vector3.up;
/*outter*/
if (cicle.outter_soft > 0)
{
v1 = cicle.center + from * inner;
v2 = cicle.center + from * outter;
for (int i = 1; i < count + 1; i++)
{
target = Quaternion.Euler(0, 0, -step * i);
dir = target * from;
dir.Normalize();
v3 = cicle.center + dir * outter;
v4 = cicle.center + dir * inner;
FillVerts(cicle.geometry, v1, v2, v3, v4);
FillTopUVColor(cicle.geometry, cicle.color, false);
v1 = v4;
v2 = v3;
}
}
if (cicle.inner_radius < cicle.outter_radius)
{
outter = cicle.outter_radius - cicle.outter_soft;
inner = cicle.inner_radius + cicle.inner_soft;
v1 = cicle.center + from * inner;
v2 = cicle.center + from * outter;
/*mider*/
for (int i = 1; i < count + 1; i++)
{
target = Quaternion.Euler(0, 0, -step * i);
dir = target * from;
v3 = cicle.center + dir * outter;
v4 = cicle.center + dir * inner;
FillVerts(cicle.geometry, v1, v2, v3, v4);
FillSolidUVColor(cicle.geometry, cicle.color);
v1 = v4;
v2 = v3;
}
}
if (cicle.inner_soft > 0)
{
outter = cicle.inner_radius + cicle.inner_soft;
inner = cicle.inner_radius;
v1 = cicle.center + from * inner;
v2 = cicle.center + from * outter;
/*inner*/
for (int i = 1; i < count + 1; i++)
{
target = Quaternion.Euler(0, 0, -step * i);
dir = target * from;
v3 = cicle.center + dir * outter;
v4 = cicle.center + dir * inner;
FillVerts(cicle.geometry, v1, v2, v3, v4);
FillBottomUV(cicle.geometry, cicle.color);
v1 = v4;
v2 = v3;
}
}
void FillTopUVColor(UIGeometry geometry, Color color, bool solid = false)
{
if (solid)
{
geometry.uvs.Add(new Vector2(0, 0.4f));
geometry.uvs.Add(new Vector2(0, 0.6f));
geometry.uvs.Add(new Vector2(1, 0.6f));
geometry.uvs.Add(new Vector2(1, 0.4f));
}
else
{
geometry.uvs.Add(new Vector2(0, 0.5f));
geometry.uvs.Add(new Vector2(0, 1));
geometry.uvs.Add(new Vector2(1, 1));
geometry.uvs.Add(new Vector2(1, 0.5f));
}
geometry.cols.Append(color, 4);
}
Sample Texture is:![alt text][2]
[2]: /storage/temp/72109-hline.png
inner_soft means inner soft border. by controlling the texture coord. this demo inner_soft is 0
params is below: Circle circle = new Circle(new Vector3(400, -400,0),200,300,Color.blue); circle.outter_soft = 200; circle.inner_soft = 0; test_canvas.DrawCircle(circle);
Circle Declare is : public class Circle : Shape { public Circle(Vector3 center, float radius,Color color) { this.center = center; this.color = color; inner_radius = 0; outter_radius = radius; } public Circle(Vector3 center, float radius_o, float radius_i, Color color) { this.center = center; this.color = color; inner_radius = radius_i; outter_radius = radius_o; } public Vector3 center; public Color color; public float outter_radius; public float inner_radius; public float outter_soft; public float inner_soft; }
Drawing Soft Rect. Drawing Result is:
Code is:
caller :
FRect rect = new FRect(new Rect(0,0, 1200, 1200), Color.black);
rect.left_soft = 600;
rect.right_soft = 600;
rect.top_soft = 600;
rect.bottom_soft = 600;
test_canvas.DrawRect(rect);