Beispiel #1
0
        internal Number4 DoBlend(int renderTargetIndex, ref Number4 source, ref Number4 destination, ref Number4 blendFactor)
		{
            var blendDescription = _renderTargetBlendDescriptions[renderTargetIndex];
			if (!blendDescription.IsBlendEnabled)
				return source;

            var result = new Number4();

			// RGB blending
			var colorDestinationBlendFactor = GetBlendFactor(blendDescription.DestinationBlend, ref source, ref destination, ref blendFactor);
			var colorSourceBlendFactor = GetBlendFactor(blendDescription.SourceBlend, ref source, ref destination, ref blendFactor);

			var colorDestination = Number4.Multiply(ref destination, ref colorDestinationBlendFactor);
            var colorSource = Number4.Multiply(ref source, ref colorSourceBlendFactor);

			result.R = DoBlendOperation(blendDescription.BlendOperation, colorSource.R, colorDestination.R);
			result.G = DoBlendOperation(blendDescription.BlendOperation, colorSource.G, colorDestination.G);
			result.B = DoBlendOperation(blendDescription.BlendOperation, colorSource.B, colorDestination.B);

			// Alpha blending
			var alphaDestinationBlendFactor = GetBlendFactor(blendDescription.DestinationAlphaBlend, ref source, ref destination, ref blendFactor);
			var alphaSourceBlendFactor = GetBlendFactor(blendDescription.SourceAlphaBlend, ref source, ref destination, ref blendFactor);

			var alphaDestination = destination.A * alphaDestinationBlendFactor.A;
			var alphaSource = source.A * alphaSourceBlendFactor.A;

			result.A = DoBlendOperation(blendDescription.AlphaBlendOperation, alphaSource, alphaDestination);

			return result;
		}
Beispiel #2
0
        private Number4 GetBlendFactor(BlendOption blend, ref Number4 source, ref Number4 destination, ref Number4 blendFactor)
		{
			switch (blend)
			{
				case BlendOption.Zero:
                    return new Number4(0, 0, 0, 0);
				case BlendOption.One:
                    return new Number4(1, 1, 1, 1);
				case BlendOption.SourceColor:
					return source;
				case BlendOption.InverseSourceColor:
                    return Number4.Invert(ref source);
				case BlendOption.SourceAlpha:
                    return new Number4(source.A, source.A, source.A, source.A);
				case BlendOption.InverseSourceAlpha:
                    return Number4.Invert(new Number4(source.A, source.A, source.A, source.A));
				case BlendOption.DestinationAlpha:
                    return new Number4(destination.A, destination.A, destination.A, destination.A);
				case BlendOption.InverseDestinationAlpha:
                    return Number4.Invert(new Number4(destination.A, destination.A, destination.A, destination.A));
				case BlendOption.DestinationColor:
					return destination;
				case BlendOption.InverseDestinationColor:
                    return Number4.Invert(ref destination);
				case BlendOption.SourceAlphaSaturate:
                    return Number4.Saturate(new Number4(source.A, source.A, source.A, source.A));
				case BlendOption.BlendFactor:
					return blendFactor;
				case BlendOption.InverseBlendFactor:
					return Number4.Invert(ref blendFactor);
				default:
					throw new NotSupportedException();
			}
		}
        private static uint CalculateClipCode(ref Number4 position)
        {
            var w = position.W;

            uint result = 0;

            if (position.X < -w)
                result |= 1;
            if (position.X > w)
                result |= 2;

            if (position.Y < -w)
                result |= 4;
            if (position.Y > w)
                result |= 8;

            if (position.Z < 0)
                result |= 16;
            if (position.Z > w)
                result |= 32;

            // TODO: 0 < w ?

            return result;
        }
Beispiel #4
0
 public static Number4 Multiply(ref Number4 left, ref Number4 right)
 {
     return new Number4(
         left.X * right.X,
         left.Y * right.Y,
         left.Z * right.Z,
         left.W * right.W);
 }
Beispiel #5
0
 public static Number4 Multiply(ref Number4 left, ref Number4 right)
 {
     return(new Number4(
                left.X * right.X,
                left.Y * right.Y,
                left.Z * right.Z,
                left.W * right.W));
 }
Beispiel #6
0
 public static Number4 Swizzle(Number4 original, Operand4ComponentName[] swizzles)
 {
     return(new Number4(
                original.GetNumber((int)swizzles[0]),
                original.GetNumber((int)swizzles[1]),
                original.GetNumber((int)swizzles[2]),
                original.GetNumber((int)swizzles[3])));
 }
Beispiel #7
0
 public static Number4 Average(ref Number4 v0, ref Number4 v1, ref Number4 v2, ref Number4 v3)
 {
     return(new Number4(
                (v0.X + v1.X + v2.X + v3.X) / 4.0f,
                (v0.Y + v1.Y + v2.Y + v3.Y) / 4.0f,
                (v0.Z + v1.Z + v2.Z + v3.Z) / 4.0f,
                (v0.W + v1.W + v2.W + v3.W) / 4.0f));
 }
Beispiel #8
0
 public static Number4 Lerp(ref Number4 left, ref Number4 right, float value)
 {
     return new Number4(
         left.X * (1 - value) + right.X * value,
         left.Y * (1 - value) + right.Y * value,
         left.Z * (1 - value) + right.Z * value,
         left.W * (1 - value) + right.W * value);
 }
Beispiel #9
0
 public static Number4 Subtract(ref Number4 left, ref Number4 right)
 {
     return(new Number4(
                Number.FromFloat(left.Number0.Float - right.Number0.Float),
                Number.FromFloat(left.Number1.Float - right.Number1.Float),
                Number.FromFloat(left.Number2.Float - right.Number2.Float),
                Number.FromFloat(left.Number3.Float - right.Number3.Float)));
 }
Beispiel #10
0
 public static Number4 Average(ref Number4 v0, ref Number4 v1, ref Number4 v2, ref Number4 v3)
 {
     return new Number4(
         (v0.X + v1.X + v2.X + v3.X) / 4.0f,
         (v0.Y + v1.Y + v2.Y + v3.Y) / 4.0f,
         (v0.Z + v1.Z + v2.Z + v3.Z) / 4.0f,
         (v0.W + v1.W + v2.W + v3.W) / 4.0f);
 }
Beispiel #11
0
 public static Number4 Lerp(ref Number4 left, ref Number4 right, float value)
 {
     return(new Number4(
                left.X * (1 - value) + right.X * value,
                left.Y * (1 - value) + right.Y * value,
                left.Z * (1 - value) + right.Z * value,
                left.W * (1 - value) + right.W * value));
 }
Beispiel #12
0
		public Pixel(int x, int y)
		{
		    Vertices = null;
			X = x;
			Y = y;
			Color = new Number4();
			Samples = new Samples();
			PrimitiveID = 0;
		    RenderTargetArrayIndex = 0;
		}
Beispiel #13
0
 public static Number4 Saturate(Number4 original)
 {
     return(new Number4
     {
         Number0 = Number.FromFloat(original.Number0.Float, true),
         Number1 = Number.FromFloat(original.Number1.Float, true),
         Number2 = Number.FromFloat(original.Number2.Float, true),
         Number3 = Number.FromFloat(original.Number3.Float, true)
     });
 }
        public static Number4 Linear(float alpha, float beta, float gamma,
            ref Number4 p1, ref Number4 p2, ref Number4 p3)
		{
            return new Number4
			{
				X = Linear(alpha, beta, gamma, p1.X, p2.X, p3.X),
				Y = Linear(alpha, beta, gamma, p1.Y, p2.Y, p3.Y),
				Z = Linear(alpha, beta, gamma, p1.Z, p2.Z, p3.Z),
				W = Linear(alpha, beta, gamma, p1.W, p2.W, p3.W)
			};
		}
		void ISwapChainPresenter.Present(Number4[] colors)
		{
            // TODO: Convert Color4F[] to byte[] in R8G8B8A8 format.
			var bitmapData = _bitmap.LockBits(new Rectangle(0, 0, _width, _height),
				ImageLockMode.WriteOnly, _bitmap.PixelFormat);

			//Marshal.Copy(colors, 0, bitmapData.Scan0, _width * _height * 3);

			_bitmap.UnlockBits(bitmapData);

			_graphics.DrawImage(_bitmap, Point.Empty);
		}
Beispiel #16
0
        public static Box2D CreateBoundingBox(ref Number4 v0, ref Number4 v1, ref Number4 v2)
		{
			float minX = float.MaxValue, minY = float.MaxValue;
			float maxX = float.MinValue, maxY = float.MinValue;

			CheckMinMax(ref v0, ref minX, ref maxX, ref minY, ref maxY);
			CheckMinMax(ref v1, ref minX, ref maxX, ref minY, ref maxY);
			CheckMinMax(ref v2, ref minX, ref maxX, ref minY, ref maxY);

			return new Box2D(
                MathUtility.FloorToInt(minX), MathUtility.FloorToInt(minY),
                MathUtility.CeilingToInt(maxX), MathUtility.CeilingToInt(maxY));
		}
Beispiel #17
0
		public static Number4 Negate(Number4 original, NumberType type)
		{
            switch (type)
			{
				case NumberType.Float:
			        return NegateFloat(original);
                case NumberType.Int:
			        return NegateInt(original);
				case NumberType.Double:
                    return NegateDouble(original);
				default:
                    throw new InvalidOperationException(string.Format("Negate is not a valid operation for number type '{0}'.", type));
			}
		}
Beispiel #18
0
        private static void CheckMinMax(ref Number4 v,
			ref float minX, ref float maxX,
			ref float minY, ref float maxY)
		{
			if (v.X < minX)
				minX = v.X;
			if (v.X > maxX)
				maxX = v.X;

			if (v.Y < minY)
				minY = v.Y;
			if (v.Y > maxY)
				maxY = v.Y;
		}
        public static Number4 Perspective(
			float alpha, float beta, float gamma,
            ref Number4 p1, ref Number4 p2, ref Number4 p3,
			float p1W, float p2W, float p3W,
			float w)
		{
            var result = new Number4
			{
				X = Perspective(alpha, beta, gamma, p1.X, p2.X, p3.X, p1W, p2W, p3W, w),
				Y = Perspective(alpha, beta, gamma, p1.Y, p2.Y, p3.Y, p1W, p2W, p3W, w),
				Z = Perspective(alpha, beta, gamma, p1.Z, p2.Z, p3.Z, p1W, p2W, p3W, w),
				W = Perspective(alpha, beta, gamma, p1.W, p2.W, p3.W, p1W, p2W, p3W, w)
			};
			return result;
		}
Beispiel #20
0
        public static Number4 Negate(Number4 original, NumberType type)
        {
            switch (type)
            {
            case NumberType.Float:
                return(NegateFloat(original));

            case NumberType.Int:
                return(NegateInt(original));

            case NumberType.Double:
                return(NegateDouble(original));

            default:
                throw new InvalidOperationException(string.Format("Negate is not a valid operation for number type '{0}'.", type));
            }
        }
Beispiel #21
0
 public void WriteMaskedValue(Number4 value, ComponentMask mask)
 {
     if (mask.HasFlag(ComponentMask.X))
     {
         Number0 = value.Number0;
     }
     if (mask.HasFlag(ComponentMask.Y))
     {
         Number1 = value.Number1;
     }
     if (mask.HasFlag(ComponentMask.Z))
     {
         Number2 = value.Number2;
     }
     if (mask.HasFlag(ComponentMask.W))
     {
         Number3 = value.Number3;
     }
 }
		void ISwapChainPresenter.Present(Number4[] colors)
		{
            for (var i = 0; i < colors.Length; i++)
            {
                _outputBytes[(i * 4) + 0] = (byte) (colors[i].B * 255.0f);
                _outputBytes[(i * 4) + 1] = (byte) (colors[i].G * 255.0f);
                _outputBytes[(i * 4) + 2] = (byte) (colors[i].R * 255.0f);
                _outputBytes[(i * 4) + 3] = (byte) (colors[i].A * 255.0f);
            }

			_bitmap.Dispatcher.Invoke((Action) (() =>
			{
				_bitmap.Lock();
				_bitmap.WritePixels(
                    new Int32Rect(0, 0, _bitmap.PixelWidth, _bitmap.PixelHeight),
                    _outputBytes, _width * _bitmap.Format.BitsPerPixel / 8, 0);
				_bitmap.Unlock();
			}));
		}
		public void AlphaBlendStateIsValid()
		{
			// Arrange.
			var device = new Device();
			var blendState = new BlendState(device, BlendStateDescription.AlphaBlend);
		    var source = new Number4(1.0f, 0.0f, 0.0f, 0.3f);
		    var destination = new Number4(0.0f, 1.0f, 0.0f, 0.4f);
		    var blendFactor = new Number4();

			// Act.
			var result = blendState.DoBlend(0,
                ref source, ref destination,
                ref blendFactor);

			// Assert.
			Assert.That(result.R, Is.EqualTo(1.0f).Within(0.01f));
			Assert.That(result.G, Is.EqualTo(0.7f).Within(0.01f));
			Assert.That(result.B, Is.EqualTo(0.0f).Within(0.01f));
			Assert.That(result.A, Is.EqualTo(0.3f + (1 - 0.3f) * 0.4f).Within(0.01f));
		}
Beispiel #24
0
		public static Number4 Abs(Number4 original, NumberType type)
		{
            switch (type)
			{
                case NumberType.Float:
                case NumberType.Int:
                case NumberType.UInt:
					return new Number4(
						Number.Abs(original.Number0, type),
                        Number.Abs(original.Number1, type),
                        Number.Abs(original.Number2, type),
                        Number.Abs(original.Number3, type));
				case NumberType.Double:
					return new Number4(
						Math.Abs(original.Double0),
						Math.Abs(original.Double1));
				default:
                    throw new InvalidOperationException(string.Format("Abs is not a valid operation for number type '{0}'.", type));
			}
		}
Beispiel #25
0
 public PixelEventArgs(
     VertexShaderOutput[] vertices, 
     int primitiveID,
     uint renderTargetArrayIndex,
     int x,
     int y,
     ref Number4 pixelShader,
     ref Number4 previous,
     Number4? result,
     PixelExclusionReason exclusionReason)
 {
     _vertices = vertices;
     _primitiveID = primitiveID;
     _renderTargetArrayIndex = renderTargetArrayIndex;
     _x = x;
     _y = y;
     _pixelShader = pixelShader;
     _previous = previous;
     _result = result;
     _exclusionReason = exclusionReason;
 }
Beispiel #26
0
        public static Number4 Abs(Number4 original, NumberType type)
        {
            switch (type)
            {
            case NumberType.Float:
            case NumberType.Int:
            case NumberType.UInt:
                return(new Number4(
                           Number.Abs(original.Number0, type),
                           Number.Abs(original.Number1, type),
                           Number.Abs(original.Number2, type),
                           Number.Abs(original.Number3, type)));

            case NumberType.Double:
                return(new Number4(
                           Math.Abs(original.Double0),
                           Math.Abs(original.Double1)));

            default:
                throw new InvalidOperationException(string.Format("Abs is not a valid operation for number type '{0}'.", type));
            }
        }
Beispiel #27
0
 public void SetData(int x, int y, int z, ref Number4 value)
 {
     Data[((z * Width * Height) + (y * Width) + x)] = value;
 }
Beispiel #28
0
        public ColorViewModel(Number4 color)
		{
			_color = color;
		}
            public override void Clear(ref Number4 color)
			{
			    foreach (var subresource in _subresources)
			        subresource.Clear(ref color);
			}
 public override void SetData(uint arrayIndex, int x, int y, int sampleIndex, ref Number4 value)
 {
     _subresources[arrayIndex].SetData(x, y, ref value);
 }
        private static void PerspectiveDivide(ref Number4 position)
		{
			position.X /= position.W;
			position.Y /= position.W;
			position.Z /= position.W;
		}
 public abstract void Clear(ref Number4 color);
 public abstract void SetData(uint arrayIndex, int x, int y, int sampleIndex, ref Number4 value);
 public override void Clear(float depth)
 {
     var color = new Number4(depth, 0, 0, 0);
     _subresource.Clear(ref color);
 }
Beispiel #35
0
 public void SetData(int x, ref Number4 value)
 {
     Data[x] = value;
 }
Beispiel #36
0
 public static Number4 NegateDouble(Number4 original)
 {
     return(new Number4(-original.Double0, -original.Double1));
 }
Beispiel #37
0
 public static Number4 NegateFloat(Number4 original)
 {
     return(new Number4(-original.Float0, -original.Float1, -original.Float2, -original.Float3));
 }
Beispiel #38
0
 public static Number4 Invert(ref Number4 value)
 {
     return new Number4(1 - value.R, 1 - value.G, 1 - value.B, 1 - value.A);
 }
Beispiel #39
0
 public static Number4 NegateInt(Number4 original)
 {
     return(new Number4(-original.Int0, -original.Int1, -original.Int2, -original.Int3));
 }
 public override void SetData(uint arrayIndex, int x, int y, int sampleIndex, float value)
 {
     var color = new Number4(value, 0, 0, 0);
     _subresource.SetData(x, ref color);
 }
Beispiel #41
0
 public static Number4 NegateDouble(Number4 original)
 {
     return new Number4(-original.Double0, -original.Double1);
 }
        void ISwapChainPresenter.Present(Number4[] colors)
		{
			Data = colors;
		}
Beispiel #43
0
 public static Number4 Invert(ref Number4 value)
 {
     return(new Number4(1 - value.R, 1 - value.G, 1 - value.B, 1 - value.A));
 }