Ejemplo n.º 1
0
        public double this[double x, double y]
        {
            get
            {
                x *= _scaleFactor;
                y *= _scaleFactor;

                double value = 0;

                double x0, x1, y0, y1;

                /* We implement a high-pass filter by subtracting a blurred version of the noise from itself. */

                x0 = Math.Ceiling(x - _blurFactor * CutOffDistance);
                y0 = Math.Ceiling(y - _blurFactor * CutOffDistance);
                x1 = Math.Floor(x + _blurFactor * CutOffDistance);
                y1 = Math.Floor(y + _blurFactor * CutOffDistance);
                for (var xi = x0; xi <= x1; ++xi)
                {
                    var squaredDistanceX = ExtraMath.Square(x - xi);

                    for (var yi = y0; yi <= y1; ++yi)
                    {
                        var squaredDistance = ExtraMath.Square(y - yi) + squaredDistanceX;
                        value -= GetWeight(squaredDistance * _blurNormalizationFactor) * GetValue(_seedHash[xi][yi]);
                    }
                }

                value *= _blurNormalizationFactor;

                /* We implement a low-pass filter by simply only sampling the noise function at certain intervals. */

                x0 = Math.Ceiling(x - CutOffDistance);
                y0 = Math.Ceiling(y - CutOffDistance);
                x1 = Math.Floor(x + CutOffDistance);
                y1 = Math.Floor(y + CutOffDistance);
                for (var xi = x0; xi <= x1; ++xi)
                {
                    var squaredDistanceX = ExtraMath.Square(x - xi);

                    for (var yi = y0; yi <= y1; ++yi)
                    {
                        var squaredDistance = ExtraMath.Square(y - yi) + squaredDistanceX;
                        value += GetWeight(squaredDistance) * GetValue(_seedHash[xi][yi]);
                    }
                }

                return(value);
            }
        }
Ejemplo n.º 2
0
        private void SetUpScreen(RenderInfo renderInfo)
        {
            float diagonalFactor = (float)(_uiDiagonal / Math.Sqrt(ExtraMath.Square(renderInfo.Width) + ExtraMath.Square(renderInfo.Height)));

            Width  = renderInfo.Width * diagonalFactor;
            Height = renderInfo.Height * diagonalFactor;

            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();

            var modelViewMatrix = Matrix4.Zero;

            modelViewMatrix.M11 = 2.0f / Width;
            modelViewMatrix.M41 = -1.0f;
            modelViewMatrix.M22 = -2.0f / Height;
            modelViewMatrix.M42 = 1.0f;
            modelViewMatrix.M33 = 1;
            modelViewMatrix.M44 = 1;

            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadMatrix(ref modelViewMatrix);
        }