Esempio n. 1
0
 /// <summary>
 /// Function to draw a single point to the current target.
 /// </summary>
 /// <param name="position">Position of the point.</param>
 /// <param name="color">Color of the point.</param>
 /// <param name="thickness">Thickness of the point.</param>
 public void DrawPoint(Vector2 position, GorgonColor color, Vector2 thickness)
 {
     SetStates(_point);
     _point.Position       = position;
     _point.PointThickness = thickness;
     _point.Color          = color;
     _point.Draw();
 }
Esempio n. 2
0
        /// <summary>
        /// Function called after a pass has been rendered.
        /// </summary>
        /// <param name="pass">Pass that was rendered.</param>
        protected override void OnAfterPassRender(GorgonEffectPass pass)
        {
            // We must set the pixel shader back to the default here.
            // Otherwise our current shader may not like that we're trying to
            // render lines and points with no textures attached.

            // If this shader is nested with another (e.g. gauss blur), then
            // this situation can throw warnings up in the debug spew.

            // Setting the pixel shader to the proper shader when rendering
            // primitives with no textures is the best way to correct this.
            Gorgon2D.PixelShader.Current = null;

            var blend = Gorgon2D.Drawing.Blending;

            // Render dust and dirt.
            for (int i = 0; i < DirtAmount; ++i)
            {
                float grayDust  = GorgonRandom.RandomSingle(0.1f, 0.25f);
                var   dustColor = new GorgonColor(grayDust, grayDust, grayDust, GorgonRandom.RandomSingle(0.25f, 0.95f));

                // Render dust points.
                _point.Color          = dustColor;
                _point.PointThickness = new Vector2(1);
                _point.Position       = new Vector2(GorgonRandom.RandomSingle(0, _currentTargetSize.X - 1),
                                                    GorgonRandom.RandomSingle(0, _currentTargetSize.Y - 1));
                _point.Draw();

                if (GorgonRandom.RandomInt32(100) >= DirtPercent)
                {
                    continue;
                }

                // Render dirt/hair lines.
                var dirtStart = new Vector2(GorgonRandom.RandomSingle(0, _currentTargetSize.X - 1),
                                            GorgonRandom.RandomSingle(0, _currentTargetSize.Y - 1));

                float dirtWidth      = GorgonRandom.RandomSingle(1.0f, 3.0f);
                bool  isHair         = GorgonRandom.RandomInt32(100) > 50;
                bool  isHairVertical = isHair && GorgonRandom.RandomInt32(100) > 50;

                grayDust  = GorgonRandom.RandomSingle(0.1f, 0.15f);
                dustColor = new GorgonColor(grayDust, grayDust, grayDust, GorgonRandom.RandomSingle(0.25f, 0.95f));

                for (int j = 0; j < GorgonRandom.RandomInt32(4, (int)_currentTargetSize.X / 4); j++)
                {
                    _point.Color          = dustColor;
                    _point.Position       = new Vector2(dirtStart.X, dirtStart.Y);
                    _point.PointThickness = isHair ? new Vector2(1) : new Vector2(dirtWidth, dirtWidth);
                    _point.Draw();

                    if ((!isHair) || (isHairVertical))
                    {
                        if (GorgonRandom.RandomInt32(100) > 50)
                        {
                            dirtStart.X++;
                        }
                        else
                        {
                            dirtStart.X--;
                        }
                    }
                    else
                    {
                        if (grayDust < 0.25f)
                        {
                            dirtStart.X++;
                        }
                        else
                        {
                            dirtStart.X--;
                        }
                    }

                    if ((!isHair) || (!isHairVertical))
                    {
                        if (GorgonRandom.RandomInt32(100) > 50)
                        {
                            dirtStart.Y++;
                        }
                        else
                        {
                            dirtStart.Y--;
                        }
                    }
                    else
                    {
                        if (dirtWidth < 1.5f)
                        {
                            dirtStart.Y++;
                        }
                        else
                        {
                            dirtStart.Y--;
                        }
                    }
                }
            }

            // Restore the previous blend state.
            Gorgon2D.Drawing.Blending = blend;

            base.OnAfterPassRender(pass);
        }