Skip to content

Instantly share code, notes, and snippets.

@Frooxius
Created June 5, 2018 08:51
Show Gist options
  • Save Frooxius/bfdab668a82accbe20f8ea275d836059 to your computer and use it in GitHub Desktop.
Save Frooxius/bfdab668a82accbe20f8ea275d836059 to your computer and use it in GitHub Desktop.
Procedural Noise Texture
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BaseX;
namespace FrooxEngine
{
[Category("Assets/Procedural Textures")]
public class NoiseTexture : ProceduralTexture
{
public readonly Sync<int> Seed;
public readonly Sync<bool> Monochrome;
protected override IEnumerator<Context> UpdateTexture()
{
yield return Context.ToBackground();
var r = new Random(Seed.Value);
if(Monochrome.Value)
{
for (int y = 0; y < tex2D.Size.y; y++)
for (int x = 0; x < tex2D.Size.x; x++)
{
var value = (float)r.NextDouble();
tex2D.SetPixel(x, y, new color(value, value, value));
}
}
else
r.NextBytes(tex2D.RawData);
}
protected override void OnAttach()
{
base.OnAttach();
Seed.Value = RandomX.Int;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment