Skip to content

Instantly share code, notes, and snippets.

@qpfiffer
Created July 27, 2011 16:07
Show Gist options
  • Save qpfiffer/1109704 to your computer and use it in GitHub Desktop.
Save qpfiffer/1109704 to your computer and use it in GitHub Desktop.
Concrete TextureGen
public static void modConcrete(ref Texture2D modify, GraphicsDevice gDevice, Random tRandom)
{
if (modify == null)
throw new Exception("Null texture.");
//float colorFloat = (float)(tRandom.Next(25, 75)) / 255.0f;
//Color bgColor = new Color(colorFloat, colorFloat, colorFloat, 1.0f);
Color setColor;
simplexCarmody simC = new simplexCarmody(tRandom);
double noise = 0;
Color[] texData = new Color[(modify.Width * modify.Height)];
for (int y = 0; y < modify.Height; y++)
{
for (int x = 0; x < modify.Width; x++)
{
// Octave 1: Grain
noise = (simC.noise(x * 2, y * 2, 0) + 1) * 20;
noise = (noise - (int)noise) * 1f;
// Octave 2: Fine noise
noise += simC.noise(x* 200, y*200, 0) * 0.5f;
// Octave 3: Streak
noise += simC.noise(x, y * 100, 0) * 0.7f;
// Adjust range to [0, 1]
noise = (noise + 1) / 2;
int red = (int)(noise * 55);
int green = (int)(noise * 55);
int blue = (int)(noise * 55);
if (red > 255) red = 255;
else if (red < 0) red = 0;
if (green > 255) green = 255;
else if (green < 0) green = 0;
if (blue > 255) blue = 255;
else if (blue < 0) blue = 0;
setColor = new Color(red, green, blue);
texData[y * modify.Width + x] = setColor;
}
}
modify.SetData<Color>(texData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment