float AngleTo(float2 v1, float2 v2, bool clockWise)
 {
     int sign = clockWise ? -1 : 1;
     float a1 = atan2(v1.y, v1.x) * sign;
     float a2 = atan2(v2.y, v2.x) * sign;
     float a = a2 - a1;
     if (a < 0)
     {
         return 2 * Pi + a; ;
     }
     return a;
 }
        public void AngularGradientTest(float4 inputSampler, float2 uv, float2 centerPoint, float startAngle, float arcLength, float4 startColor, float4 endColor, float4 expected)
        {
            this.inputSampler = inputSampler;
            this.CenterPoint = centerPoint;
            this.StartAngle = startAngle;
            this.ArcLength = arcLength;

            this.StartColor = startColor;
            this.EndColor = endColor;
            float4 c = main(uv);
            if (distance(expected, c) < 0.01)
            {
                Assert.Pass();
            }
            else
            {
                Assert.AreEqual(expected, c);
            }
        }
示例#3
0
 protected static float4 tex2D(float4 inputSampler, float2 uv)
 {
     return inputSampler;
 }
示例#4
0
 protected static float2 normalize(float2 x)
 {
     return new float2(x.Normalize(2.0));
 }
示例#5
0
 protected static float2 mul(float2 v, float2x2 m)
 {
     return new float2(m.Multiply(v));
 }
示例#6
0
 protected static float2 mul(float f, float2 v)
 {
     return new float2(v.Multiply(f));
 }
 float4 main(float2 uv)
 {
     float4 src = tex2D(inputSampler, uv);
     if (src.a < 0.01 || abs(ArcLength) < 0.01)
     {
         return transparent;
     }
     float2 v = uv - CenterPoint;
     float2 vs = mul(float2(1, 0), RotationMatrix(radians(StartAngle)));
     float a = degrees(AngleTo( vs,v, ArcLength < 0));
     float f = abs(a) < 0.1 ? 0 : a / abs(ArcLength);
     if (f < 0 || f > 1)
     {
         return transparent;
     }
     float3 rgb = lerp(StartColor.rgb, EndColor.rgb, f);
     return float4(rgb, src.a);
 }