- Home /
Generate Alpha Map Procedurally...
I've downloaded the following Shader which allows you to use a splat map on something other than a Terrain object using two textures and an alpha map.
http://www.unifycommunity.com/wiki/index.php?title=LayerShader
I wish to draw the route across the mesh i'm using at runtime randomly but i'm a little stuck on how I should be setting up the texture in my script...
I've tried the following which should make it all appear with the base texture but it doesn't appear to be working since I just get a blend of the base and path textures on the mesh...
function GenTexture()
{
var width:int = 128;
var height:int = 128;
var texture = new Texture2D (width, height, TextureFormat.Alpha8, false);
for (var i:int = 0; i < width; i++)
{
for (var j:int = 0; j < height; j++)
{
texture.SetPixel(i,j,Color(0, 0, 0, 0));
}
}
// assign the texture to the shader
mat.SetTexture("_PathMask", texture);
// update the renderer with the updated material
GetComponent(MeshRenderer).material = mat;
}
Can anyone see what i'm doing wrong or has any tips to generating alpha maps at runtime?
Huge thanks to anyone who can help! :)
Answer by MSFX · Mar 23, 2012 at 10:47 PM
just suddenly noticed I wasn't using texture.Apply() - my mistake =D
works now!