Search Unity

Procedural Texture Generation

Discussion in 'Scripting' started by Dr.Pure, Feb 21, 2011.

  1. Dr.Pure

    Dr.Pure

    Joined:
    Sep 20, 2009
    Posts:
    136
  2. HarvesteR

    HarvesteR

    Joined:
    May 22, 2009
    Posts:
    531
    Completely possible. In fact, I myself have made a procedural terrain gen that draws an RGBA blend map texture, to blend between different terrain textures, depending on terrain height and steepness.

    Basically, you create a Texture2D object (it represents a texture), and use it's setPixel() method to define a color for each pixel. Then, you must call the Apply() method, to (I think) commit the pixel changes you've made onto the texture. Later you can assign that texture to a material, so you can see it on a mesh.

    In my generator, I'm using a shader I found online, that will combine 4 different textures based on the color of the corresponding pixel of the blend map... you could use that shader (look up 'unity procedural terrain', there are plenty of examples), or you can write your own... Using Strumpy's Shader Editor, it should be quite straightforward :)

    Hope this helps

    Cheers
     
  3. Dr.Pure

    Dr.Pure

    Joined:
    Sep 20, 2009
    Posts:
    136
    Thanks for the answer!

    So, basically you take this shader http://www.unifycommunity.com/wiki/index.php?title=TerrainFourLayer and generate, depending on the procedural heightmap, the "Mixing Mask" of it with a Texture2D object. But which color or alpha value represents the first, second, third and fourth texture? Or better: How does the shader know where to place the textures?
     
  4. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    In his case he seems to be using world coordinates of a point to generate the texture, but you could also use, for instance, points in UV space.