Procedurally combine (merge) two Texture2D

Hello Unity users,

I am currently trying to combine two textures into one, by script.

The main texture is a procedurally generated texture (makes random pixels at random position, some kind of colored perlin noise). I've got another texture, which is a grid (represented by white pixels) on a black background. Let's say they're both 256*256.

  • I through of getting every white pixels coordinate of the grid texture and reassigning them to the main texture, but It would be alot of work repeating 256 times an action, and I would like to chose the texture size as a variable. (maybe we could use "for"? but I really don't know how to use it so I gave up)

Another way I was thinking about was use of alpha maybe?

Could someone please help me? It would be great.

Regards -Alex

Examples:

Perlin Texture: alt text

Grid Texture: alt text

in js:

`
var cols1 = tex1.GetPixels();
var cols2 = tex2.GetPixels();
for(var i = 0; i < cols1.Length; ++i)
{
    cols1 _+= cols2*;*_
_*}*_
_*tex1.SetPixels(cols1);*_
_*tex1.Apply();*_
_*
`

*_ _*

that will do an additive sum of both images (so will be white where the grid is white), then put it back into the first texture

*_ _*

it should be pretty easy to adapt it to any other style you like

*_

Try this :

http://www.aforgenet.com/framework/features/