Procedural Textures in Unity?
Asked Answered
C

1

5

I am mainly a programmer, not very good at drawing, so I decided to make textures at run time in a procedural way and by that I mean to generate something new and fresh every time at the same time it should look believable.How to get Started with this ? Programming in Unity, if that is going to help.

Curcio answered 13/1, 2015 at 19:6 Comment(0)
G
13

You can create Textures in code by doing something like this:

public Texture2D CreateTexture()
{
    int width = 100;
    int height = 100;

    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;
}

You may want to look into Texture2D.SetPixels() if you are looking to optimize, as Texture2D.SetPixel() is much slower.

For the procedural texture generation, that is a very broad topic, with various techniques. Typically, you would use some sort of coherent noise generator to generate your textures, such as Perlin or Simplex.

You can google "Texture Generation Noise", and find a wide range of articles explaining how to do this.

This question is really broad, so hope that helps you get started.

Gladis answered 13/1, 2015 at 19:18 Comment(1)
I meant more like algorithms for generation @JonCurcio

© 2022 - 2024 — McMap. All rights reserved.