- Home /
Creating random planet textures
Hi Everyone,
I feel I may be out of my depth here but I'm wondering if someone can explain to me how to random planet textures? No meshes, just a simple, randomised texture that makes every planet unique.
I want to avoid having to spend hours using planetGen and bulking up projects with thousands of textures, I've heard of Perlin Noise, but everywhere I look creates meshes and deforms it to create raised terrain as well which I don't require, I'm just looking for something simple to create a texture based on snow, mountains, hills, sand, grass and water, randomise the lot and create a single texture that will wrap around a sphere and as the player will not be able to land on planets and will instead burn up in the atmosphere if they get too close (think the X-Series of games, though that's not what i'm trying to create) I don't require raised terrain and all that malarky.
Cheers,
Supershandy
Answer by Jessespike · May 26, 2015 at 06:40 PM
Perlin noise is just an algorithm, so it can applied to almost anything. The Unity documentation has an example for textures: http://docs.unity3d.com/ScriptReference/Mathf.PerlinNoise.html
using UnityEngine;
public class GeneratePerlinTexture : MonoBehaviour {
public int pixWidth = 1024;
public int pixHeight = 1024;
public float xOrg;
public float yOrg;
public float scale = 20.0F;
private Texture2D noiseTex;
private Color[] pix;
private Renderer rend;
void Start() {
rend = GetComponent<Renderer>();
noiseTex = new Texture2D(pixWidth, pixHeight);
pix = new Color[noiseTex.width * noiseTex.height];
rend.material.mainTexture = noiseTex;
}
void CalcNoise() {
int y = 0;
while (y < noiseTex.height) {
int x = 0;
while (x < noiseTex.width) {
float xCoord = xOrg + (float)x / noiseTex.width * scale;
float yCoord = yOrg + (float)y / noiseTex.height * scale;
float sample = Mathf.PerlinNoise(xCoord, yCoord);
pix[y * noiseTex.width + x] = new Color(sample, sample, sample);
x++;
}
y++;
}
noiseTex.SetPixels(pix);
noiseTex.Apply();
}
void Update() {
CalcNoise();
}
}
Ok that makes sense, so how would you go about doing the different gradients? I understand you can use Texture2D to apply the sand, water, grass textures etc, but how do you layer them so it looks more like a planet?
I know this was years ago, but check this out.
http://www.jgallant.com/procedurally-generating-wrapping-world-maps-in-unity-csharp-part-1/#intro
Answer by Warcel · May 26, 2015 at 07:41 PM
Hello, you can try to adapt one of these tutorials...
http://catlikecoding.com/unity/tutorials/
they are very well explained, i like this site a lot
Answer by AMU4u · May 26, 2015 at 09:55 PM
Hey, superhans! Love you in peepshow!
One way that I instantly come to would be creating objects out of terrain identifying objects, if that makes sense. So you would have a large set of differently drawn cliffs, lakes, trees, and different settings. You would then be able to arrange them according to their boimes, and then have those biomes randomly selected as well as their contents inside. So your generator would be given a variable needing to be filled (a planet) with 4 different biomes all containing a certain amount of biome elements.
This would drastically remove the overhead of actually creating meshes randomly.
Defining how the elements of the biome would be placed would require (I ASSUME, someone might have a better idea) some kind of either drawn or randomly computer drawn bitmap with empty spaces vs spaces containing biome elements. That is beyond me, sadly, but I have seen it done before and know it also severely reduces overhead vs storing thousands of possible biomes or settings, etc.
Your answer
Follow this Question
Related Questions
Procedual Terrain 1 Answer
Unity changes pixel colors 2 Answers
Texture Compression format for UWP,Texture 0 Answers
Blending two Texture2D 1 Answer
EncodetoPNG and all other file types leaves the image in the wrong color space 0 Answers