Created
June 5, 2018 08:51
-
-
Save Frooxius/bfdab668a82accbe20f8ea275d836059 to your computer and use it in GitHub Desktop.
Procedural Noise Texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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