Exemplo n.º 1
0
 public Ray2F(Vector2F origin, Vector2F direction)
 {
     this.Origin    = origin;
     this.Direction = direction;
 }
        ///// <summary>
        ///// The number of UV tiles per unit of the world.
        ///// </summary>
        //[DefaultValue( "1 1" )]
        //public Reference<Vector2> TilesPerUnit
        //{
        //	get { if( tilesPerUnit.BeginGet() ) TilesPerUnit = tilesPerUnit.Get( this ); return tilesPerUnit.value; }
        //	set
        //	{
        //		if( tilesPerUnit.BeginSet( ref value ) )
        //		{
        //			try
        //			{
        //				TilesPerUnitChanged?.Invoke( this );
        //				ShouldRecompileMesh();
        //			}
        //			finally { tilesPerUnit.EndSet(); }
        //		}
        //	}
        //}
        ///// <summary>Occurs when the <see cref="TilesPerUnit"/> property value changes.</summary>
        //public event Action<Component_MeshModifier_BoxUV> TilesPerUnitChanged;
        //ReferenceField<Vector2> tilesPerUnit = Vector2.One;

        ///// <summary>
        ///// Increases the value of object dimensions that is used to calculate UV.
        ///// </summary>
        //[DefaultValue( "0 0 0" )]
        //public Reference<Vector3> ExtendBounds
        //{
        //	get { if( _extendBounds.BeginGet() ) ExtendBounds = _extendBounds.Get( this ); return _extendBounds.value; }
        //	set
        //	{
        //		if( _extendBounds.BeginSet( ref value ) )
        //		{
        //			try
        //			{
        //				ExtendBoundsChanged?.Invoke( this );
        //				ShouldRecompileMesh();
        //			}
        //			finally { _extendBounds.EndSet(); }
        //		}
        //	}
        //}
        ///// <summary>Occurs when the <see cref="ExtendBounds"/> property value changes.</summary>
        //public event Action<Component_MeshModifier_BoxUV> ExtendBoundsChanged;
        //ReferenceField<Vector3> _extendBounds = Vector3.Zero;

        /////////////////////////////////////////

        void ProcessVertex(ref Vector3 tiles, ref Bounds bounds, ref Vector3F position, ref Vector3F normal, out Vector2F result)
        {
            var side = Vector3I.Zero;
            {
                float max = -1;
                //if( Math.Abs( normal.X ) > max )
                {
                    max  = Math.Abs(normal.X);
                    side = new Vector3I(normal.X >= 0 ? 1 : -1, 0, 0);
                }
                if (Math.Abs(normal.Y) > max)
                {
                    max  = Math.Abs(normal.Y);
                    side = new Vector3I(0, normal.Y >= 0 ? 1 : -1, 0);
                }
                if (Math.Abs(normal.Z) > max)
                {
                    max  = Math.Abs(normal.Z);
                    side = new Vector3I(0, 0, normal.Z >= 0 ? 1 : -1);
                }
            }

            int  axis0  = 0;
            int  axis1  = 0;
            bool invert = false;
            {
                if (side.X != 0)
                {
                    axis0  = 1;
                    axis1  = 2;
                    invert = side.X < 0;
                }
                else if (side.Y != 0)
                {
                    axis0  = 0;
                    axis1  = 2;
                    invert = side.Y < 0;
                }
                else if (side.Z != 0)
                {
                    axis0  = 0;
                    axis1  = 1;
                    invert = side.Z < 0;
                }
            }

            {
                double s0 = 0;
                {
                    var d = bounds.Maximum[axis0] - bounds.Minimum[axis0];
                    if (d != 0)
                    {
                        s0 = (position[axis0] - bounds.Minimum[axis0]) / d;
                    }
                }

                double s1 = 0;
                {
                    var d = bounds.Maximum[axis1] - bounds.Minimum[axis1];
                    if (d != 0)
                    {
                        s1 = (position[axis1] - bounds.Minimum[axis1]) / d;
                    }
                }

                var v = new Vector2(s0 * tiles[axis0], -s1 * tiles[axis1]);

                if (side.X != 0)
                {
                    if (invert)
                    {
                        v.X = -v.X;
                    }
                }
                else if (side.Y != 0)
                {
                    if (!invert)
                    {
                        v.X = -v.X;
                    }
                }
                else if (side.Z != 0)
                {
                    if (invert)
                    {
                        v.X = -v.X;
                    }
                }

                result = v.ToVector2F();
            }
        }
Exemplo n.º 3
0
 public Line2F(Vector2F start, Vector2F end)
 {
     this.Start = start;
     this.End   = end;
 }
Exemplo n.º 4
0
        //

        static SimpleTypes()
        {
            //string
            RegisterType(typeof(string), delegate(string value)
            {
                if (value == null)
                {
                    return("");
                    //throw new Exception( "GetSimpleTypeValue: string type, value = null" );
                }
                return(value);
            }, "");

            //bool
            RegisterType(typeof(bool), delegate(string value)
            {
                string lower = value.ToLower();
                if (value == "1" || lower == "yes" || lower == "true")
                {
                    return(true);
                }
                else if (value == "0" || lower == "no" || lower == "false")
                {
                    return(false);
                }
                else
                {
                    return(bool.Parse(value));
                }
            }, false);

            //sbyte
            RegisterType(typeof(sbyte), delegate(string value) { return(sbyte.Parse(value)); }, 0);

            //byte
            RegisterType(typeof(byte), delegate(string value) { return(byte.Parse(value)); }, 0);

            //char
            RegisterType(typeof(char), delegate(string value) { return(char.Parse(value)); }, 0);

            //short
            RegisterType(typeof(short), delegate(string value) { return(short.Parse(value)); }, 0);

            //ushort
            RegisterType(typeof(ushort), delegate(string value) { return(ushort.Parse(value)); }, 0);

            //int
            RegisterType(typeof(int), delegate(string value) { return(int.Parse(value)); }, 0);

            //uint
            RegisterType(typeof(uint), delegate(string value) { return(uint.Parse(value)); }, (uint)0);

            //long
            RegisterType(typeof(long), delegate(string value) { return(long.Parse(value)); }, (long)0);

            //ulong
            RegisterType(typeof(ulong), delegate(string value) { return(ulong.Parse(value)); }, (ulong)0);

            //float
            RegisterType(typeof(float), delegate(string value) { return(float.Parse(value)); }, 0.0f);

            //double
            RegisterType(typeof(double), delegate(string value) { return(double.Parse(value)); }, 0.0);

            //decimal
            RegisterType(typeof(decimal), delegate(string value) { return(decimal.Parse(value)); }, (decimal)0.0);

            //Vec2
            RegisterType(typeof(Vector2F), delegate(string value) { return(Vector2F.Parse(value)); }, Vector2F.Zero);

            //Range
            RegisterType(typeof(RangeF), delegate(string value) { return(RangeF.Parse(value)); }, RangeF.Zero);

            //Vec3
            RegisterType(typeof(Vector3F), delegate(string value) { return(Vector3F.Parse(value)); }, Vector3F.Zero);

            //Vec4
            RegisterType(typeof(Vector4F), delegate(string value) { return(Vector4F.Parse(value)); }, Vector4F.Zero);

            //Bounds
            RegisterType(typeof(BoundsF), delegate(string value) { return(BoundsF.Parse(value)); }, BoundsF.Zero);

            //Quat
            RegisterType(typeof(QuaternionF), delegate(string value) { return(QuaternionF.Parse(value)); }, QuaternionF.Identity);

            //ColorValue
            RegisterType(typeof(ColorValue), delegate(string value) { return(ColorValue.Parse(value)); }, ColorValue.Zero);

            //ColorValuePowered
            RegisterType(typeof(ColorValuePowered), delegate(string value) { return(ColorValuePowered.Parse(value)); }, ColorValuePowered.Zero);

            //ColorPacked
            RegisterType(typeof(ColorByte), delegate(string value) { return(ColorByte.Parse(value)); }, ColorByte.Zero);

            //SphereDir
            RegisterType(typeof(SphericalDirectionF), delegate(string value) { return(SphericalDirectionF.Parse(value)); }, SphericalDirectionF.Zero);

            //Vec2I
            RegisterType(typeof(Vector2I), delegate(string value) { return(Vector2I.Parse(value)); }, Vector2I.Zero);

            //Vec3I
            RegisterType(typeof(Vector3I), delegate(string value) { return(Vector3I.Parse(value)); }, Vector3I.Zero);

            //Vec4I
            RegisterType(typeof(Vector4I), delegate(string value) { return(Vector4I.Parse(value)); }, Vector4I.Zero);

            //Rect
            RegisterType(typeof(RectangleF), delegate(string value) { return(RectangleF.Parse(value)); }, RectangleF.Zero);

            //RectI
            RegisterType(typeof(RectangleI), delegate(string value) { return(RectangleI.Parse(value)); }, RectangleI.Zero);

            //Degree
            RegisterType(typeof(DegreeF), delegate(string value) { return(DegreeF.Parse(value)); }, DegreeF.Zero);

            //Radian
            RegisterType(typeof(RadianF), delegate(string value) { return(RadianF.Parse(value)); }, RadianF.Zero);

            //Vec2D
            RegisterType(typeof(Vector2), delegate(string value) { return(Vector2.Parse(value)); }, Vector2.Zero);

            //RangeD
            RegisterType(typeof(Range), delegate(string value) { return(Range.Parse(value)); }, Range.Zero);

            //RangeI
            RegisterType(typeof(RangeI), delegate(string value) { return(RangeI.Parse(value)); }, RangeI.Zero);

            //Vec3D
            RegisterType(typeof(Vector3), delegate(string value) { return(Vector3.Parse(value)); }, Vector3.Zero);

            //Vec4D
            RegisterType(typeof(Vector4), delegate(string value) { return(Vector4.Parse(value)); }, Vector4.Zero);

            //BoundsD
            RegisterType(typeof(Bounds), delegate(string value) { return(Bounds.Parse(value)); }, Bounds.Zero);

            //QuatD
            RegisterType(typeof(Quaternion), delegate(string value) { return(Quaternion.Parse(value)); }, Quaternion.Identity);

            //SphereDirD
            RegisterType(typeof(SphericalDirection), delegate(string value) { return(SphericalDirection.Parse(value)); }, SphericalDirection.Zero);

            //RectD
            RegisterType(typeof(Rectangle), delegate(string value) { return(Rectangle.Parse(value)); }, Rectangle.Zero);

            //DegreeD
            RegisterType(typeof(Degree), delegate(string value) { return(Degree.Parse(value)); }, Degree.Zero);

            //RadianD
            RegisterType(typeof(Radian), delegate(string value) { return(Radian.Parse(value)); }, Radian.Zero);

            //Angles
            RegisterType(typeof(AnglesF), delegate(string value) { return(AnglesF.Parse(value)); }, AnglesF.Zero);

            //AnglesD
            RegisterType(typeof(Angles), delegate(string value) { return(Angles.Parse(value)); }, Angles.Zero);

            //Mat2F
            RegisterType(typeof(Matrix2F), delegate(string value) { return(Matrix2F.Parse(value)); }, Matrix2F.Zero);

            //Mat2D
            RegisterType(typeof(Matrix2), delegate(string value) { return(Matrix2.Parse(value)); }, Matrix2.Zero);

            //Mat3F
            RegisterType(typeof(Matrix3F), delegate(string value) { return(Matrix3F.Parse(value)); }, Matrix3F.Zero);

            //Mat3D
            RegisterType(typeof(Matrix3), delegate(string value) { return(Matrix3.Parse(value)); }, Matrix3.Zero);

            //Mat4F
            RegisterType(typeof(Matrix4F), delegate(string value) { return(Matrix4F.Parse(value)); }, Matrix4F.Zero);

            //Mat4D
            RegisterType(typeof(Matrix4), delegate(string value) { return(Matrix4.Parse(value)); }, Matrix4.Zero);

            //PlaneF
            RegisterType(typeof(PlaneF), delegate(string value) { return(PlaneF.Parse(value)); }, PlaneF.Zero);

            //PlaneD
            RegisterType(typeof(Plane), delegate(string value) { return(Plane.Parse(value)); }, Plane.Zero);

            //Transform
            RegisterType(typeof(Transform), delegate(string value) { return(Transform.Parse(value)); }, Transform.Identity);

            //UIMeasureValueDouble
            RegisterType(typeof(UIMeasureValueDouble), delegate(string value) { return(UIMeasureValueDouble.Parse(value)); }, new UIMeasureValueDouble());

            //UIMeasureValueVec2
            RegisterType(typeof(UIMeasureValueVector2), delegate(string value) { return(UIMeasureValueVector2.Parse(value)); }, new UIMeasureValueVector2());

            //UIMeasureValueRect
            RegisterType(typeof(UIMeasureValueRectangle), delegate(string value) { return(UIMeasureValueRectangle.Parse(value)); }, new UIMeasureValueRectangle());

            RegisterType(typeof(RangeVector3F), delegate(string value) { return(RangeVector3F.Parse(value)); }, RangeVector3F.Zero);
            RegisterType(typeof(RangeColorValue), delegate(string value) { return(RangeColorValue.Parse(value)); }, RangeColorValue.Zero);

            //no Parse methods. This is complex structures. This is not simple types? or just can't parse?
            //Box
            //Capsule
            //Cone
            //Line3
            //Line2
            //Ray
            //Frustum?

            RegisterConvertDoubleToFloatTypes();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Constructs a matrix with the specified <see cref="Vector2F"/> elements,
 /// which are the corresponding rows of the matrix.
 /// </summary>
 /// <param name="x">The vector which is the first row.</param>
 /// <param name="y">The vector which is the second row.</param>
 public Matrix2F(Vector2F x, Vector2F y)
 {
     Item0 = x;
     Item1 = y;
 }
Exemplo n.º 6
0
        void RenderBackRectangle(ViewportRenderingContext context, Rectangle rectangle, ColorValue color)
        {
            var renderer = context.Owner.CanvasRenderer;

            switch (BackStyle.Value)
            {
            case BackStyleEnum.Rectangle:
                renderer.AddQuad(rectangle, color);
                break;

            case BackStyleEnum.RoundedRectangle:
            {
                var rect2     = rectangle.ToRectangleF();
                var fontSize  = GetFontSizeScreen(context);
                var roundSize = new Vector2F(renderer.AspectRatioInv, 1) * (float)fontSize * 0.4f;

                int steps = 16;

                var list = new List <Vector2F>(steps * 4);

                for (int n = 0; n < steps; n++)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.LeftTop + new Vector2F(1.0f - MathEx.Cos(angle), 1.0f - MathEx.Sin(angle)) * roundSize);
                }

                for (int n = steps - 1; n >= 0; n--)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.RightTop + new Vector2F(MathEx.Cos(angle) - 1.0f, 1.0f - MathEx.Sin(angle)) * roundSize);
                }

                for (int n = 0; n < steps; n++)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.RightBottom + new Vector2F(MathEx.Cos(angle) - 1.0f, MathEx.Sin(angle) - 1.0f) * roundSize);
                }

                for (int n = steps - 1; n >= 0; n--)
                {
                    var v     = (float)n / (float)(steps - 1);
                    var angle = v * MathEx.PI / 2;
                    list.Add(rect2.LeftBottom + new Vector2F(1.0f - MathEx.Cos(angle), MathEx.Sin(angle) - 1.0f) * roundSize);
                }

                var vertices = new List <CanvasRenderer.TriangleVertex>(1 + list.Count);
                var indices  = new List <int>(list.Count * 3);

                vertices.Add(new CanvasRenderer.TriangleVertex(rect2.GetCenter(), color));
                foreach (var v in list)
                {
                    vertices.Add(new CanvasRenderer.TriangleVertex(v, color));
                }

                for (int n = 0; n < list.Count; n++)
                {
                    indices.Add(0);
                    indices.Add(1 + n);
                    indices.Add(1 + (n + 1) % list.Count);
                }

                renderer.AddTriangles(vertices, indices);
            }
            break;
            }
        }
Exemplo n.º 7
0
 public TriangleVertex(Vector2F position, ColorValue color)
 {
     this.position = position;
     this.color    = color;
     this.texCoord = Vector2F.Zero;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Multiplies a matrix by a given <see cref="Vector2F"/> structure.
 /// </summary>
 /// <param name="m">The matrix to multiply.</param>
 /// <param name="v">The vector by which to multiply.</param>
 /// <param name="result">When the method completes, contains the result of the multiplication.</param>
 public static void Multiply(ref Matrix2F m, ref Vector2F v, out Vector2F result)
 {
     result.X = m.Item0.X * v.X + m.Item1.X * v.Y;
     result.Y = m.Item0.Y * v.X + m.Item1.Y * v.Y;
 }
Exemplo n.º 9
0
 public void GetCenter(out Vector2F result)
 {
     Vector2F.Add(ref Point1, ref Point2, out result);
     result.X *= .5f;
     result.Y *= .5f;
 }
Exemplo n.º 10
0
        public static void PerformRenderUI()
        {
            CanvasRenderer renderer = MainViewport.CanvasRenderer;

            if (transparency == 0.0f)
            {
                return;
            }

            //load backgrouund texture and font
            if (texture != null && texture.Disposed)
            {
                needLoadTextureAndFont = true;
            }
            if (needLoadTextureAndFont)
            {
                texture = ResourceManager.LoadResource <Component_Image>("Base\\UI\\Images\\Console.png");
                //texture = ResourceManager.LoadResource<Component_Image>( "Base\\UI\\Images\\Console.jpg" );

                font = renderer.DefaultFont;
                //font = EngineFontManager.Instance.LoadFont( "Default", .025f );
                needLoadTextureAndFont = false;
            }

            if (font == null)
            {
                return;
            }

            Vector2F viewportSize = renderer.ViewportForScreenCanvasRenderer.SizeInPixels.ToVector2F();
            Vector2F shadowOffset = new Vector2F(1, 1) / viewportSize;

            //draw background
            var textureRect = new Rectangle(0, 0, 10 * renderer.AspectRatio, 10 / 2);

            textureRect -= textureOffset;
            renderer.AddQuad(new Rectangle(0, 0, 1, .5f), textureRect, texture, new ColorValue(1, 1, 1, transparency), false);

            //var textureRect = new Rectangle( 0, 1.0 - renderer.AspectRatioInv, 1, 1 );
            //renderer.AddQuad( new Rectangle( 0, 0, 1, .5f ), textureRect, texture, new ColorValue( 0.7, 0.7, 0.7, transparency ), false );

            //draw border line
            renderer.AddQuad(new Rectangle(0, .5f, 1, .508f), new ColorValue(0.29f, 0.6f, 0.86f, 0.9f * transparency));

            //draw background info
            string staticText = "Press \"~\" or \"F12\" to hide console\r\nPress \"Ctrl + ~\" to hide and disable auto opening";

            renderer.AddTextWordWrap(staticText, new RectangleF(0, 0, .995f, .495f), EHorizontalAlignment.Right, false, EVerticalAlignment.Bottom, 0,
                                     new ColorValue(0.8, 0.8, 0.8, transparency));

            float fontheight = (float)fontSize;            // font.Height;

            float x = .01f;

            float y = .5f - fontheight;

            string str;

            if (stringDownPosition != strings.Count - 1)
            {
                str = "- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -" +
                      " - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -";
            }
            else
            {
                str = currentString + "_";
            }

            renderer.PushClipRectangle(new RectangleF(0, 0, .975f, 1));
            renderer.AddText(font, fontSize, str, new Vector2F(x, y) + shadowOffset, EHorizontalAlignment.Left,
                             EVerticalAlignment.Center, new ColorValue(0, 0, 0, transparency / 2));
            renderer.AddText(font, fontSize, str, new Vector2F(x, y), EHorizontalAlignment.Left,
                             EVerticalAlignment.Center, new ColorValue(1, 1, 1, transparency));
            renderer.PopClipRectangle();

            y -= fontheight + fontheight * .5f;

            int startpos = stringDownPosition;

            if (startpos > strings.Count - 1)
            {
                startpos = strings.Count - 1;
            }
            for (int n = startpos; n >= 0 && y - fontheight > 0; n--)
            {
                var text      = strings[n].text;
                int lineCount = text.Count(f => f == '\n') + 1;

                float y2 = y - fontheight * (lineCount - 1) / 2;

                renderer.AddText(font, fontSize, text, new Vector2F(x, y2) + shadowOffset, EHorizontalAlignment.Left,
                                 EVerticalAlignment.Center, strings[n].color * new ColorValue(0, 0, 0, transparency / 2));
                renderer.AddText(font, fontSize, text, new Vector2F(x, y2), EHorizontalAlignment.Left,
                                 EVerticalAlignment.Center, strings[n].color * new ColorValue(1, 1, 1, transparency));
                y -= fontheight * lineCount;
            }
        }
Exemplo n.º 11
0
 public Capsule2F(Vector2F point1, Vector2F point2, float radius)
 {
     this.Point1 = point1;
     this.Point2 = point2;
     this.Radius = radius;
 }
Exemplo n.º 12
0
 public Capsule2F(Capsule2F source)
 {
     Point1 = source.Point1;
     Point2 = source.Point2;
     Radius = source.Radius;
 }
Exemplo n.º 13
0
 public void GetDirection(out Vector2F result)
 {
     Vector2F.Subtract(ref Point2, ref Point1, out result);
     result.Normalize();
 }
Exemplo n.º 14
0
            //!!!!можно его сделать развитым. в юнити normal, tangent, uv0, uv1
            //!!!!!еще про смешивание. хотя вероятно это надо обуздать что максимум можно извлечь из шейдеров. + еще всякие размытия

            //

            public TriangleVertex(Vector2F position, ColorValue color, Vector2F texCoord)
            {
                this.position = position;
                this.color    = color;
                this.texCoord = texCoord;
            }
Exemplo n.º 15
0
 public LineItem(Vector2F start, Vector2F end, ColorValue color)
 {
     this.start = start;
     this.end   = end;
     this.color = color;
 }
Exemplo n.º 16
0
 /// <summary>
 /// Constructs a vector with a given <see cref="Vector2F"/> and a scalar.
 /// </summary>
 /// <param name="xy">The given <see cref="Vector2F"/>.</param>
 /// <param name="z">The scalar value.</param>
 public Vector3F(Vector2F xy, float z)
 {
     this.X = xy.X;
     this.Y = xy.Y;
     this.Z = z;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Adds text to rendering queue.
 /// </summary>
 /// <param name="font">The text font.</param>
 /// <param name="text">The text.</param>
 /// <param name="position">The text position.</param>
 /// <param name="horizontalAlign">The text horizontal align.</param>
 /// <param name="verticalAlign">The text vertical align.</param>
 /// <param name="color">The text color.</param>
 public abstract void AddText(Component_Font font, double fontSize, string text, Vector2F position, EHorizontalAlignment horizontalAlign, EVerticalAlignment verticalAlign, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign);
Exemplo n.º 18
0
 /// <summary>
 /// Constructs a matrix with the given individual elements.
 /// </summary>
 /// <param name="xx">Value at row 1 column 1 of the matrix.</param>
 /// <param name="xy">Value at row 1 column 2 of the matrix.</param>
 /// <param name="yx">Value at row 2 column 1 of the matrix.</param>
 /// <param name="yy">Value at row 2 column 2 of the matrix.</param>
 public Matrix2F(float xx, float xy, float yx, float yy)
 {
     Item0 = new Vector2F(xx, xy);
     Item1 = new Vector2F(yx, yy);
 }
Exemplo n.º 19
0
 /// <summary>
 /// Adds text to rendering queue.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="position">The text position.</param>
 /// <param name="horizontalAlign">The text horizontal align.</param>
 /// <param name="verticalAlign">The text vertical align.</param>
 /// <param name="color">The text color.</param>
 public void AddText(string text, Vector2F position, EHorizontalAlignment horizontalAlign, EVerticalAlignment verticalAlign, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign)
 {
     AddText(null, DefaultFontSize, text, position, horizontalAlign, verticalAlign, color, options);
 }
Exemplo n.º 20
0
 /// <summary>
 /// Constructs a matrix with another specified <see cref="Matrix2F"/> object.
 /// </summary>
 /// <param name="m">A specified matrix.</param>
 public Matrix2F(Matrix2F m)
 {
     Item0 = m.Item0;
     Item1 = m.Item1;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Adds text to rendering queue.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="position">The text position.</param>
 public void AddText(string text, Vector2F position)
 {
     AddText(null, DefaultFontSize, text, position, EHorizontalAlignment.Left, EVerticalAlignment.Top, new ColorValue(1, 1, 1));
 }
Exemplo n.º 22
0
 public Line2F(Line2F source)
 {
     Start = source.Start;
     End   = source.End;
 }
Exemplo n.º 23
0
        /////////////////////////////////////////

        /// <summary>
        /// Adds text lines to rendering queue.
        /// </summary>
        /// <param name="font">The font.</param>
        /// <param name="lines">The text lines.</param>
        /// <param name="pos">The text position.</param>
        /// <param name="horizontalAlign">The text horizontal align.</param>
        /// <param name="verticalAlign">The text vertical align.</param>
        /// <param name="textVerticalIndention">The vertical intention between lines.</param>
        /// <param name="color">The text color.</param>
        public abstract void AddTextLines(Component_Font font, double fontSize, IList <string> lines, Vector2F pos, EHorizontalAlignment horizontalAlign,
                                          EVerticalAlignment verticalAlign, float textVerticalIndention, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign);
Exemplo n.º 24
0
        unsafe protected override void OnRender(ViewportRenderingContext context, Component_RenderingPipeline.IFrameData frameData, ref Component_Image actualTexture)
        {
            base.OnRender(context, frameData, ref actualTexture);

            //is not supported
            if (!context.RenderingPipeline.GetUseMultiRenderTargets())
            {
                return;
            }

            //downscale for SSAA
            var actualTextureSource = actualTexture;

            if (actualTexture.Result.ResultSize != context.Owner.SizeInPixels)
            {
                actualTexture = context.RenderTarget2D_Alloc(context.Owner.SizeInPixels, actualTextureSource.Result.ResultFormat);

                //copy to scene texture with downscale
                context.SetViewport(actualTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\Downscale2_fs.sc";

                shader.Parameters.Set("sourceSizeInv", new Vector2F(1, 1) / actualTextureSource.Result.ResultSize.ToVector2F());

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0 /*"sourceTexture"*/,
                                                                                   actualTextureSource, TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));

                context.RenderQuadToCurrentViewport(shader);
            }

            // Setup Constants:

            Vector2F viewportPixelSize        = new Vector2F(1.0f / (float)actualTexture.Result.ResultSize.X, 1.0f / (float)actualTexture.Result.ResultSize.Y);
            Vector2F halfViewportPixelSize    = new Vector2F(1.0f / ((float)actualTexture.Result.ResultSize.X * 0.5f), 1.0f / ((float)actualTexture.Result.ResultSize.Y * 0.5f));
            Vector4F quarterViewportPixelSize = new Vector4F(1.0f / ((float)actualTexture.Result.ResultSize.X * 0.25f), 1.0f / ((float)actualTexture.Result.ResultSize.Y * 0.25f), (float)((actualTexture.Result.ResultSize.X / 4) * (actualTexture.Result.ResultSize.Y / 4)), 0.0f);
            Vector2F viewport2xPixelSize      = new Vector2F(viewportPixelSize.X * 2.0f, viewportPixelSize.Y * 2.0f);

            Matrix4F projectionMatrix = context.Owner.CameraSettings.ProjectionMatrix.ToMatrix4F();

            float depthLinearizeMul = -projectionMatrix[3][2];
            float depthLinearizeAdd = projectionMatrix[2][2];

            if (depthLinearizeMul * depthLinearizeAdd < 0.0f)
            {
                depthLinearizeAdd = -depthLinearizeAdd;
            }

            Vector2F depthUnpackConsts = new Vector2F(depthLinearizeMul, depthLinearizeAdd);

            float tanHalfFOVY = 1.0f / projectionMatrix[1][1];
            float tanHalfFOVX = 1.0F / projectionMatrix[0][0];

            Vector2F cameraTanHalfFOV = new Vector2F(tanHalfFOVX, tanHalfFOVY);

            Vector2F NDCToViewMul = new Vector2F(cameraTanHalfFOV.X * 2.0f, cameraTanHalfFOV.Y * -2.0f);
            Vector2F NDCToViewAdd = new Vector2F(cameraTanHalfFOV.X * -1.0f, cameraTanHalfFOV.Y * 1.0f);

            Matrix4F itViewMatrix = (context.Owner.CameraSettings.ViewMatrix.GetInverse().ToMatrix4F()).GetTranspose();

            // Effect Params:

            float effectSamplingRadiusNearLimit = (float)Radius * 1.2f;

            if (Quality.Value == QualityEnum.Low)
            {
                effectSamplingRadiusNearLimit *= 1.50f;
            }

            effectSamplingRadiusNearLimit /= tanHalfFOVY;

            float effectSamplingRadiusNearLimitRec = 1.0f / effectSamplingRadiusNearLimit;

            Vector4F effectRadiusParams = new Vector4F((float)Radius, -1.0f / (float)Radius, effectSamplingRadiusNearLimitRec, 0.0f);

            float effectFadeOutMul = -1.0f / ((float)FadeOutTo - (float)FadeOutFrom);
            float effectFadeOutAdd = (float)FadeOutFrom / ((float)FadeOutTo - (float)FadeOutFrom) + 1.0f;

            float detailAOStrength     = (float)DetailStrength;
            float effectShadowStrength = (float)Multiplier;
            float effectShadowClamp    = 1.0f;
            float effectShadowPow      = (float)Power;

            float invSharpness = 1.0f - (float)Sharpness;

            if (invSharpness < 0.0f)
            {
                invSharpness = 0.0f;
            }
            if (invSharpness > 1.0f)
            {
                invSharpness = 1.0f;
            }

            // First Pass: Prepare 4 Depth half-Buffers:

            Component_Image[] halfDepths = new Component_Image[4];
            for (int i = 0; i < 4; i++)
            {
                halfDepths[i] = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 2, PixelFormat.Float16R);
            }

            var fourDepthsMRT = context.MultiRenderTarget_Create(new[] {
                new MultiRenderTarget.Item(halfDepths[0]),
                new MultiRenderTarget.Item(halfDepths[1]),
                new MultiRenderTarget.Item(halfDepths[2]),
                new MultiRenderTarget.Item(halfDepths[3])
            });

            {
                context.SetViewport(fourDepthsMRT.Viewports[0], Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\PrepareDepths_fs.sc";

                context.objectsDuringUpdate.namedTextures.TryGetValue("depthTexture", out Component_Image depthTexture);

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, depthTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                shader.Parameters.Set("depthUnpackConsts", depthUnpackConsts);
                //!!!!use actualTextureSource size?
                shader.Parameters.Set("viewportPixelSize", viewportPixelSize);

                context.RenderQuadToCurrentViewport(shader);
            }

            // Second Pass: prepare 4 Mip-Maps for each Half-Depth-Map:

            Component_Image[,] depthMipMaps = null;

            if (Quality.Value > QualityEnum.Medium)
            {
                Vector2I[] mipMapSizes = new Vector2I[4];                   // Setup Mip-Map sizes:

                mipMapSizes[0] = new Vector2I(actualTexture.Result.ResultSize / 2);
                for (int m = 1; m < 4; m++)
                {
                    mipMapSizes[m] = new Vector2I(mipMapSizes[m - 1] / 2);
                }

                // Prepare MipMaps textures:

                depthMipMaps = new Component_Image[4, 4];

                for (int d = 0; d < 4; d++)
                {
                    depthMipMaps[d, 0] = halfDepths[d];                         // MipMaps 0 is original halfDepthMaps
                    for (int m = 1; m < 4; m++)
                    {
                        depthMipMaps[d, m] = context.RenderTarget2D_Alloc(mipMapSizes[m], PixelFormat.Float16R);
                    }
                }

                for (int m = 1; m < 4; m++)                  // Mip-Maps loop
                {
                    var fourDepthsMipsMRT = context.MultiRenderTarget_Create(new[] {
                        new MultiRenderTarget.Item(depthMipMaps[0, m]),
                        new MultiRenderTarget.Item(depthMipMaps[1, m]),
                        new MultiRenderTarget.Item(depthMipMaps[2, m]),
                        new MultiRenderTarget.Item(depthMipMaps[3, m])
                    });

                    context.SetViewport(fourDepthsMipsMRT.Viewports[0], Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\PrepareDepthMips_fs.sc";

                    // For current Mip-Map generation using previous Mip-Map:

                    float    prevMipLevel  = (float)(m - 1);
                    var      prevMipSize   = mipMapSizes[m - 1];
                    Vector4F prevMipParams = new Vector4F(1.0f / (float)prevMipSize.X, 1.0f / (float)prevMipSize.Y, prevMipLevel, 0.0f);

                    for (int i = 0; i < 4; i++)
                    {
                        // previous MipMap as input:
                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(i, depthMipMaps[i, m - 1],
                                                                                           TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                    }
                    shader.Parameters.Set("prevMipParams", prevMipParams);
                    shader.Parameters.Set("effectRadiusParams", effectRadiusParams);

                    context.RenderQuadToCurrentViewport(shader);
                }
            }

            Component_Image SSAOTextureArray = new Component_Image();

            Component_Image SSAOBaseTextureArray = null;

            if (Quality.Value == QualityEnum.HighestAdaptive)
            {
                SSAOBaseTextureArray = new Component_Image();
                SSAOBaseTextureArray = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 2, PixelFormat.R8G8_UInt, 0, false, /*0,*/ 4);
            }

            Component_Image importanceMap     = null;
            Component_Image averageImportance = null;

            // Generate Importance Map for Highest/Adaptive Quality mode:
            if (Quality.Value == QualityEnum.HighestAdaptive)
            {
                // 4 SSAO passes:

                for (int pass = 0; pass < 4; pass++)
                {
                    Vector4F[] patternRotScaleMatrices;
                    GeneratePatternRotScaleMatrices(pass, out patternRotScaleMatrices);

                    Vector2F perPassFullResCoordOffset = new Vector2F((float)(pass % 2), (float)(pass / 2));

                    {
                        context.SetViewport(SSAOBaseTextureArray.Result.GetRenderTarget(0, pass).Viewports[0],
                                            Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                        CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                        shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                        shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GenerateSSAO_AdaptiveBase_fs.sc";

                        context.objectsDuringUpdate.namedTextures.TryGetValue("normalTexture", out Component_Image normalTexture);

                        for (int m = 0; m < 4; m++)
                        {
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(m, depthMipMaps[pass, m],
                                                                                               TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                        }

                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(4, halfDepths[pass],
                                                                                           TextureAddressingMode.Mirror, FilterOption.Point, FilterOption.Point, FilterOption.None));

                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(5, normalTexture,
                                                                                           TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                        shader.Parameters.Set("NDCToViewMul", NDCToViewMul);
                        shader.Parameters.Set("NDCToViewAdd", NDCToViewAdd);
                        shader.Parameters.Set("effectRadiusParams", effectRadiusParams);
                        shader.Parameters.Set("viewportPixelSize", viewportPixelSize);
                        shader.Parameters.Set("viewport2xPixelSize", viewport2xPixelSize);
                        shader.Parameters.Set("halfViewportPixelSize", halfViewportPixelSize);
                        shader.Parameters.Set("perPassFullResCoordOffset", perPassFullResCoordOffset);
                        shader.Parameters.Set("patternRotScaleMatrices", patternRotScaleMatrices);
                        shader.Parameters.Set("effectFadeOutMul", effectFadeOutMul);
                        shader.Parameters.Set("effectFadeOutAdd", effectFadeOutAdd);
                        shader.Parameters.Set("effectShadowStrength", effectShadowStrength);
                        shader.Parameters.Set("effectShadowClamp", effectShadowClamp);
                        shader.Parameters.Set("effectShadowPow", effectShadowPow);
                        shader.Parameters.Set("detailAOStrength", detailAOStrength);
                        shader.Parameters.Set("itViewMatrix", itViewMatrix);

                        context.RenderQuadToCurrentViewport(shader);
                    }
                }

                // Importance Map Generation:
                importanceMap = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 4, PixelFormat.L8);
                {
                    context.SetViewport(importanceMap.Result.GetRenderTarget().Viewports[0],
                                        Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GenerateImportanceMap_fs.sc";

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, SSAOBaseTextureArray,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set("halfViewportPixelSize", halfViewportPixelSize);
                    shader.Parameters.Set("effectShadowStrength", effectShadowStrength);
                    shader.Parameters.Set("effectShadowPow", effectShadowPow);

                    context.RenderQuadToCurrentViewport(shader);
                }

                // Importance Map Post-Process A:
                var importanceMapPong = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 4, PixelFormat.L8);
                {
                    context.SetViewport(importanceMapPong.Result.GetRenderTarget().Viewports[0],
                                        Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\PostProcessImportanceMapA_fs.sc";

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, importanceMap,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));

                    shader.Parameters.Set("quarterViewportPixelSize", quarterViewportPixelSize);

                    context.RenderQuadToCurrentViewport(shader);
                }

                // Importance Map Post-Process B:
                {
                    context.SetViewport(importanceMap.Result.GetRenderTarget().Viewports[0],
                                        Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\PostProcessImportanceMapB_fs.sc";

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, importanceMapPong,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));

                    shader.Parameters.Set("quarterViewportPixelSize", quarterViewportPixelSize);

                    context.RenderQuadToCurrentViewport(shader);
                }

                context.DynamicTexture_Free(importanceMapPong);

                // Get Average Importance Pass:
                averageImportance = context.RenderTarget2D_Alloc(new Vector2I(1, 1), PixelFormat.L8);
                {
                    context.SetViewport(averageImportance.Result.GetRenderTarget().Viewports[0],
                                        Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GetAverageImportance_fs.sc";

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, importanceMap,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set("quarterViewportPixelSize", quarterViewportPixelSize);

                    context.RenderQuadToCurrentViewport(shader);
                }
            }

            // Third Pass: Generate 4 SSAO buffers:

            Component_Image blurPingTexture = null, blurPongTexture = null;

            if (BlurAmount.Value > 0)
            {
                blurPingTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 2, PixelFormat.R8G8_UInt);
                blurPongTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 2, PixelFormat.R8G8_UInt);
            }

            SSAOTextureArray = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize / 2, PixelFormat.R8G8_UInt, 0, false, /*0,*/ 4);

            for (int pass = 0; pass < 4; pass++)
            {
                Vector4F[] patternRotScaleMatrices;
                GeneratePatternRotScaleMatrices(pass, out patternRotScaleMatrices);

                Vector2F perPassFullResCoordOffset = new Vector2F((float)(pass % 2), (float)(pass / 2));

                {
                    if (BlurAmount.Value == 0)
                    {
                        context.SetViewport(SSAOTextureArray.Result.GetRenderTarget(0, pass).Viewports[0],
                                            Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);
                    }
                    else
                    {
                        context.SetViewport(blurPingTexture.Result.GetRenderTarget().Viewports[0],
                                            Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);
                    }

                    CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                    shader.VertexProgramFileName = @"Base\Shaders\EffectsCommon_vs.sc";

                    if (Quality.Value == QualityEnum.Low)
                    {
                        shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GenerateSSAO_LQ_fs.sc";
                    }
                    else if (Quality.Value == QualityEnum.Medium)
                    {
                        shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GenerateSSAO_MQ_fs.sc";
                    }
                    else if (Quality.Value == QualityEnum.High)
                    {
                        shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GenerateSSAO_HQ_fs.sc";
                    }
                    else if (Quality.Value == QualityEnum.HighestAdaptive)
                    {
                        shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\GenerateSSAO_HAQ_fs.sc";
                    }

                    context.objectsDuringUpdate.namedTextures.TryGetValue("normalTexture", out Component_Image normalTexture);

                    if (Quality.Value > QualityEnum.Medium)
                    {
                        for (int m = 0; m < 4; m++)
                        {
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(m, depthMipMaps[pass, m],
                                                                                               TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                        }

                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(4, halfDepths[pass],
                                                                                           TextureAddressingMode.Mirror, FilterOption.Point, FilterOption.Point, FilterOption.None));

                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(5, normalTexture,
                                                                                           TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                        if (Quality.Value == QualityEnum.HighestAdaptive)
                        {
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(6, importanceMap,
                                                                                               TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(7, averageImportance,
                                                                                               TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(8, SSAOBaseTextureArray,
                                                                                               TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                        }
                    }
                    else
                    {
                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, halfDepths[pass],
                                                                                           TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1, halfDepths[pass],
                                                                                           TextureAddressingMode.Mirror, FilterOption.Point, FilterOption.Point, FilterOption.None));

                        shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(2, normalTexture,
                                                                                           TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));
                    }

                    shader.Parameters.Set("NDCToViewMul", NDCToViewMul);
                    shader.Parameters.Set("NDCToViewAdd", NDCToViewAdd);
                    shader.Parameters.Set("effectRadiusParams", effectRadiusParams);
                    shader.Parameters.Set("viewportPixelSize", viewportPixelSize);
                    shader.Parameters.Set("viewport2xPixelSize", viewport2xPixelSize);
                    shader.Parameters.Set("halfViewportPixelSize", halfViewportPixelSize);
                    shader.Parameters.Set("perPassFullResCoordOffset", perPassFullResCoordOffset);
                    shader.Parameters.Set("patternRotScaleMatrices", patternRotScaleMatrices);
                    shader.Parameters.Set("effectFadeOutMul", effectFadeOutMul);
                    shader.Parameters.Set("effectFadeOutAdd", effectFadeOutAdd);
                    shader.Parameters.Set("effectShadowStrength", effectShadowStrength);
                    shader.Parameters.Set("effectShadowClamp", effectShadowClamp);
                    shader.Parameters.Set("effectShadowPow", effectShadowPow);
                    shader.Parameters.Set("detailAOStrength", detailAOStrength);
                    shader.Parameters.Set("itViewMatrix", itViewMatrix);

                    if (Quality.Value == QualityEnum.HighestAdaptive)
                    {
                        shader.Parameters.Set("adaptiveSampleCountLimit", (float)AdaptiveQualityLimit);
                        shader.Parameters.Set("passNumber", (float)pass);
                    }

                    context.RenderQuadToCurrentViewport(shader);
                }

                if (Quality.Value > QualityEnum.Medium)
                {
                    // Free Mip-Maps Targets for this Pass:
                    for (int m = 0; m < 4; m++)
                    {
                        context.DynamicTexture_Free(depthMipMaps[pass, m]);
                    }
                }
                else
                {
                    context.DynamicTexture_Free(halfDepths[pass]);
                }

                // Blur SSAO Texture:

                if (BlurAmount.Value > 0)
                {
                    int wideBlursRemaining = Math.Max(0, BlurAmount.Value - 2);

                    for (int i = 0; i < BlurAmount.Value; i++)
                    {
                        if (i == (BlurAmount.Value - 1))
                        {
                            context.SetViewport(SSAOTextureArray.Result.GetRenderTarget(0, pass).Viewports[0],
                                                Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);
                        }
                        else
                        {
                            context.SetViewport(blurPongTexture.Result.GetRenderTarget().Viewports[0],
                                                Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);
                        }

                        CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                        shader.VertexProgramFileName = @"Base\Shaders\EffectsCommon_vs.sc";

                        if (Quality.Value > QualityEnum.Low)
                        {
                            if (wideBlursRemaining > 0)
                            {
                                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\SmartBlurWide_fs.sc";
                                wideBlursRemaining--;
                            }
                            else
                            {
                                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\SmartBlur_fs.sc";
                            }
                        }
                        else
                        {
                            shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\NonSmartBlur_fs.sc";
                        }

                        if (Quality.Value > QualityEnum.Low)
                        {
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, blurPingTexture,
                                                                                               TextureAddressingMode.Mirror, FilterOption.Point, FilterOption.Point, FilterOption.None));
                            shader.Parameters.Set("invSharpness", invSharpness);
                        }
                        else
                        {
                            shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, blurPingTexture,
                                                                                               TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));
                        }

                        shader.Parameters.Set("halfViewportPixelSize", halfViewportPixelSize);

                        context.RenderQuadToCurrentViewport(shader);

                        // Swap Ping-Pong Blur textures:
                        var tmp_tex = blurPingTexture;
                        blurPingTexture = blurPongTexture;
                        blurPongTexture = tmp_tex;
                    }
                }
            }

            if (Quality.Value == QualityEnum.HighestAdaptive)
            {
                context.DynamicTexture_Free(SSAOBaseTextureArray);
            }

            if (Quality.Value == QualityEnum.HighestAdaptive)
            {
                context.DynamicTexture_Free(importanceMap);
                context.DynamicTexture_Free(averageImportance);
            }

            if (BlurAmount.Value > 0)
            {
                // Free Blur ping/pong Targets:
                context.DynamicTexture_Free(blurPingTexture);
                context.DynamicTexture_Free(blurPongTexture);
            }

            // 4th Pass: Apply 4 SSAO Textures to Final SSAO Result:

            var FullSSAOTexture = context.RenderTarget2D_Alloc(actualTexture.Result.ResultSize, PixelFormat.R8G8_UInt);

            {
                context.SetViewport(FullSSAOTexture.Result.GetRenderTarget().Viewports[0],
                                    Matrix4F.Identity, Matrix4F.Identity, FrameBufferTypes.All, ColorValue.Zero);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName = @"Base\Shaders\EffectsCommon_vs.sc";

                if (Quality.Value > QualityEnum.Low)
                {
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\Apply_fs.sc";
                }
                else
                {
                    shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\Apply_noSmart_fs.sc";
                }

                if (Quality.Value > QualityEnum.Low)
                {
                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, SSAOTextureArray,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1, SSAOTextureArray,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));
                }
                else
                {
                    shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, SSAOTextureArray,
                                                                                       TextureAddressingMode.Clamp, FilterOption.Linear, FilterOption.Linear, FilterOption.None));
                }

                if (Quality.Value > QualityEnum.Low)
                {
                    shader.Parameters.Set("invSharpness", invSharpness);
                    shader.Parameters.Set("halfViewportPixelSize", halfViewportPixelSize);
                }

                context.RenderQuadToCurrentViewport(shader);
            }

            // Free SSAO Texture Array Target:
            context.DynamicTexture_Free(SSAOTextureArray);

            // 5th Final Pass:
            var finalTexture = context.RenderTarget2D_Alloc(actualTextureSource.Result.ResultSize, actualTextureSource.Result.ResultFormat);

            {
                context.SetViewport(finalTexture.Result.GetRenderTarget().Viewports[0]);

                CanvasRenderer.ShaderItem shader = new CanvasRenderer.ShaderItem();
                shader.VertexProgramFileName   = @"Base\Shaders\EffectsCommon_vs.sc";
                shader.FragmentProgramFileName = @"Base\Shaders\Effects\ASSAO\Final_fs.sc";

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(0, actualTextureSource,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                shader.Parameters.Set(new ViewportRenderingContext.BindTextureData(1, FullSSAOTexture,
                                                                                   TextureAddressingMode.Clamp, FilterOption.Point, FilterOption.Point, FilterOption.None));

                shader.Parameters.Set("intensity", (float)Intensity);
                shader.Parameters.Set("showAO", ShowAO ? 1.0f : -1.0f);

                context.RenderQuadToCurrentViewport(shader);
            }

            // Free Targets:
            context.DynamicTexture_Free(actualTexture);
            if (actualTextureSource != actualTexture)
            {
                context.DynamicTexture_Free(actualTextureSource);
            }
            context.DynamicTexture_Free(FullSSAOTexture);

            // Update actual Texture:
            actualTexture = finalTexture;
        }
Exemplo n.º 25
0
 /// <summary>
 /// Adds text lines to rendering queue.
 /// </summary>
 /// <param name="lines">The text lines.</param>
 /// <param name="pos">The text position.</param>
 /// <param name="textVerticalIndention">The vertical intention between lines.</param>
 /// <param name="horizontalAlign">The text horizontal align.</param>
 /// <param name="verticalAlign">The text vertical align.</param>
 /// <param name="color">The text color.</param>
 public void AddTextLines(IList <string> lines, Vector2F pos, EHorizontalAlignment horizontalAlign,
                          EVerticalAlignment verticalAlign, float textVerticalIndention, ColorValue color, AddTextOptions options = AddTextOptions.PixelAlign)
 {
     AddTextLines(null, DefaultFontSize, lines, pos, horizontalAlign, verticalAlign, textVerticalIndention, color, options);
 }
Exemplo n.º 26
0
 public Ray2F(Ray2F source)
 {
     Origin    = source.Origin;
     Direction = source.Direction;
 }
Exemplo n.º 27
0
        /////////////////////////////////////////

        /// <summary>
        /// Adds line to rendering queue.
        /// </summary>
        /// <param name="start">The line start position.</param>
        /// <param name="end">The line end position.</param>
        /// <param name="color">The text color.</param>
        public abstract void AddLine(Vector2F start, Vector2F end, ColorValue color);
Exemplo n.º 28
0
 public void GetPointOnRay(float t, out Vector2F result)
 {
     result.X = Origin.X + Direction.X * t;
     result.Y = Origin.Y + Direction.Y * t;
 }
        protected override void OnBakeIntoMesh(DocumentInstance document, UndoMultiAction undoMultiAction)
        {
            base.OnBakeIntoMesh(document, undoMultiAction);

            var mesh       = (Component_Mesh)Parent;
            var geometries = mesh.GetComponents <Component_MeshGeometry>();

            var bounds = Bounds.Cleared;
            {
                foreach (var geometry in geometries)
                {
                    var positions = geometry.VerticesExtractChannel <Vector3F>(VertexElementSemantic.Position);
                    if (positions != null)
                    {
                        foreach (var p in positions)
                        {
                            bounds.Add(p);
                        }
                    }
                }
                //bounds.Expand( ExtendBounds );
            }

            var tiles = Tiles.Value;

            foreach (var geometry in geometries)
            {
                var positions = geometry.VerticesExtractChannel <Vector3F>(VertexElementSemantic.Position);
                var normals   = geometry.VerticesExtractChannel <Vector3F>(VertexElementSemantic.Normal);
                if (positions != null && normals != null)
                {
                    var vertexStructure = geometry.VertexStructure.Value;
                    vertexStructure.GetInfo(out var vertexSize, out _);

                    var oldValue    = geometry.Vertices;
                    var vertices    = geometry.Vertices.Value;
                    var vertexCount = vertices.Length / vertexSize;

                    var newTexCoords = new Vector2F[vertexCount];
                    for (int n = 0; n < vertexCount; n++)
                    {
                        ProcessVertex(ref tiles, ref bounds, ref positions[n], ref normals[n], out newTexCoords[n]);
                    }

                    var newVertices = (byte[])vertices.Clone();
                    if (geometry.VerticesWriteChannel(VertexElementSemantic.TextureCoordinate0, newTexCoords, newVertices))
                    {
                        //update property
                        geometry.Vertices = newVertices;

                        //undo
                        if (undoMultiAction != null)
                        {
                            var property   = (Metadata.Property)geometry.MetadataGetMemberBySignature("property:Vertices");
                            var undoAction = new UndoActionPropertiesChange(new UndoActionPropertiesChange.Item(geometry, property, oldValue));
                            undoMultiAction.AddAction(undoAction);
                        }
                    }
                }
            }
        }