- Home /
Is it possible to round a perlin noise value to 1 or 0?
Is it possible to round a perlin noise value to 1 or 0? What I mean is, if perlin noise floats between 0 and 1, how can I round the values bigger than 0.50 to 1 and the values smaller than 0.50 to 0. I'm making a texture and I already have perlin noise generating it, but what I'm looking for is a 0 or 1 system.
Even though no one is answering I'm still gonna give updates. I've made a new script, but with basic noise, not with perlin noise.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SimplexNoise : $$anonymous$$onoBehaviour {
float xCoord, yCoord;
public int width, height;
public GameObject rockTile;
float noise;
Vector3 pos;
// Use this for initialization
void Start () {
GenerateTerrain ();
}
void GenerateTerrain()
{
for (xCoord = 0; xCoord < width; xCoord++) {
for (yCoord = 0; yCoord < height; yCoord++) {
noise = Random.value;
pos = new Vector3 (xCoord, yCoord, 0);
if(noise < 0.5f)
{
noise = 0;
}
else{
noise = 1;
Instantiate (rockTile, pos, Quaternion.identity);
}
}
}
}
}
Basically it does what I want, but I'm ending with a basic white noise "texture".
Note: If you try this start with the width and height at 10, then increase it accordingly to your machine, because it will crash unity.
Answer by Eno-Khaon · Apr 03, 2018 at 12:21 AM
Unity's Perlin Noise function takes a Vector2 as input and returns a float value, so I don't see any reason why you wouldn't be able to simply Round the result of it.
float totalWidth = 50.0f; // example Width
float totalHeight = 50.0f; // example Height
for(int y = 0; y < totalHeight; y++)
{
float fy = y / totalHeight;
for(int x = 0; x < totalWidth; x++)
{
float fx = x / totalWidth;
float sample = Mathf.PerlinNoise(fx, fy);
sample = Mathf.Round(sample);
}
}
Your answer
Follow this Question
Related Questions
3d Perlin Noise? 3 Answers
Unity Crashing when this function is called. 1 Answer
Huge C# Procedural Generation Errors. Why? 1 Answer
generate procedural floating island 1 Answer
Procedural Generated Galaxy 2 Answers