|
@@ -22,6 +22,7 @@ namespace KairoEngine.NoiseUtilities
|
|
[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), Range(0, 1f), OnValueChanged("OnChange")] public float opacity = 1f;
|
|
[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), Range(0, 1f), OnValueChanged("OnChange")] public float opacity = 1f;
|
|
[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), OnValueChanged("OnChange")] public NoiseBlendingModes blending = NoiseBlendingModes.Blend;
|
|
[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), OnValueChanged("OnChange")] public NoiseBlendingModes blending = NoiseBlendingModes.Blend;
|
|
[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), HideInInspector] public Vector2Int size = new Vector2Int(128, 128);
|
|
[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Config"), LabelWidth(80), HideInInspector] public Vector2Int size = new Vector2Int(128, 128);
|
|
|
|
+ [HideInInspector] public Vector2 randomOffset = new Vector2();
|
|
|
|
|
|
[HideInInspector] public System.Action OnChangeDelegate;
|
|
[HideInInspector] public System.Action OnChangeDelegate;
|
|
|
|
|
|
@@ -36,32 +37,33 @@ namespace KairoEngine.NoiseUtilities
|
|
|
|
|
|
public float SamplePoint(float x, float y)
|
|
public float SamplePoint(float x, float y)
|
|
{
|
|
{
|
|
- float xCoord = (x * scale) + offset.x;
|
|
|
|
- float yCoord = (y * scale) + offset.y;
|
|
|
|
|
|
+ float xCoord = (x * scale) + offset.x + randomOffset.x;
|
|
|
|
+ float yCoord = (y * scale) + offset.y + randomOffset.y;
|
|
return Mathf.PerlinNoise(xCoord, yCoord);
|
|
return Mathf.PerlinNoise(xCoord, yCoord);
|
|
}
|
|
}
|
|
|
|
|
|
public float SamplePixel(int x, int y)
|
|
public float SamplePixel(int x, int y)
|
|
{
|
|
{
|
|
- float xCoord = (((float)x / size.x) * scale) + offset.x;
|
|
|
|
- float yCoord = (((float)y / size.y) * scale) + offset.y;
|
|
|
|
|
|
+ float xCoord = (((float)x / size.x) * scale) + offset.x + randomOffset.x;
|
|
|
|
+ float yCoord = (((float)y / size.y) * scale) + offset.y + randomOffset.y;
|
|
return Mathf.PerlinNoise(xCoord, yCoord);
|
|
return Mathf.PerlinNoise(xCoord, yCoord);
|
|
}
|
|
}
|
|
|
|
|
|
//[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Preview"), Button("Preview")]
|
|
//[HorizontalGroup("Slpit"), VerticalGroup("Slpit/Preview"), Button("Preview")]
|
|
public void GenerateTexture()
|
|
public void GenerateTexture()
|
|
{
|
|
{
|
|
- texture = new Texture2D(size.x, size.y);
|
|
|
|
|
|
+ var newTexture = new Texture2D(size.x, size.y);
|
|
for (int x = 0; x < size.x; x++)
|
|
for (int x = 0; x < size.x; x++)
|
|
{
|
|
{
|
|
for (int y = 0; y < size.y; y++)
|
|
for (int y = 0; y < size.y; y++)
|
|
{
|
|
{
|
|
float sample = SamplePixel(x, y);
|
|
float sample = SamplePixel(x, y);
|
|
Color color = new Color(sample, sample, sample);
|
|
Color color = new Color(sample, sample, sample);
|
|
- texture.SetPixel(x, y, color);
|
|
|
|
|
|
+ newTexture.SetPixel(x, y, color);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- texture.Apply();
|
|
|
|
|
|
+ newTexture.Apply();
|
|
|
|
+ texture = newTexture;
|
|
}
|
|
}
|
|
|
|
|
|
private void OnChange()
|
|
private void OnChange()
|