- Home /
Is it possible to proceduraly generate textures in Unity?
hello everyone, i am attempting to create a space game with a randomly generated solar sisten, i was wodnering if it was possible to generate textures, hopefuly with a normal map for each planet, and if so where could i learn to do it. i pareciate your time and thanks in advanced.
Answer by jongallant · Nov 25, 2014 at 11:19 PM
Here is an example:
Texture2D CreateTexture()
{
int width = 100;
int height = 100;
Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
texture.filterMode = FilterMode.Point;
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
texture.SetPixel(j,height-1-i, Color.red);
}
}
texture.Apply();
return texture;
}
Note if you are doing this frequently then SetPixels is faster then SetPixel.
Yes, thank you. If you are only updating a few pixels, SetPixel may be faster though. I use SetPixel a lot, because I update a thumbnail with few pixels.
wow, thanks a lot. No way i could have came up with this on my own.
SetPixel is indeed faster for a few pixels. I'm not sure exactly what percentage of the texture makes it worth switching methods. Probably worth a benchmark if you are concerned.
$$anonymous$$y application was completely redrawing three 1024*1024 textures every frame. Hence set pixel was not an option.
Your answer
![](https://koobas.hobune.stream/wayback/20220613172429im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Is it possible to round a perlin noise value to 1 or 0? 1 Answer
Procedural Random Walk Dungeon Generator? 2 Answers
Block based map generator 5 Answers
Procedurally Generated Room System... 1 Answer
Random Room Generator 1 Answer