Texture Manipulation - Trivaxy/Libvaxy GitHub Wiki
Libvaxy offers a few tools that let you create and modify textures at runtime. This is done by providing the Texture2D
type with a plethora of new extension methods.
You can view all the methods in this code file with their respective Visual Studio summaries.
Let's try to build a cool-looking texture from scratch:
Texture2D rippleTexture = TextureExtensions.CreateTexture(256, 256); // create a new 256x256 texture
Color textureColor = Color.Violet;
rippleTexture.Fill(textureColor); // let's fill the texture with a violet color (or any color of your choice)
for (int x = 0; x < rippleTexture.Width; x++)
{
for (int y = 0; y < rippleTexture.Height; y++)
{
byte darkenValue = (byte)(127 * Math.Sin(x * y / 50)); // we find the sine of the x * y coordinate, and multiply it by 127.
// this means that the texture in some regions can darken by up to half the max brightness allowed in textures
rippleTexture.SetColor(x, y, new Color(textureColor.R - darkenValue, textureColor.G - darkenValue, textureColor.B - darkenValue));
}
}
Done! The texture will take a while to generate as we need to account for 65536 pixels (256 x 256) (and also partially because SetColor
still needs to be optimized).
Here is the result:
There's other texture methods you can try. Experiment and see what you get.