/// <summary> /// Funciton to generate random noise for the effect. /// </summary> private void GenerateRandomNoise() { int textureSize = 128; object parameter; if ((Parameters.TryGetValue("TextureSize", out parameter)) && (parameter != null)) { var size = (int)parameter; if (size > 16) { textureSize = size; } } using (var image = new GorgonImageData(new GorgonTexture2DSettings { Width = textureSize, Height = textureSize, Format = BufferFormat.R8_UIntNormal, Usage = BufferUsage.Default })) { unsafe { var dataPtr = (byte *)image.Buffers[0].Data.UnsafePointer; // Write perlin noise to the texture. for (int y = 0; y < textureSize; ++y) { for (int x = 0; x < textureSize; ++x) { float simplexNoise = GorgonRandom.SimplexNoise(new Vector2(x * (1.0f / _noiseFrequency), y * (1.0f / _noiseFrequency))); if (simplexNoise < -0.75f) { simplexNoise *= -1; } else { simplexNoise *= 0.95f; } if (simplexNoise < 0.125f) { simplexNoise = 0.0f; } *(dataPtr++) = (byte)(simplexNoise * 255.0f); } } } _randomTexture = Graphics.Textures.CreateTexture <GorgonTexture2D>("Effect.OldFilm.RandomTexture", image); } }