SetPixel : Writing to 2nd UV

Hi, this is one of Eric’s scripts:

var splat : Texture2D;
var blank : Texture2D;
private var tex : Texture2D;
private var splatTexArray : Color[];

// Work off a copy of the texture, since we'll be writing to it
function Start () {
    tex = Instantiate(blank);
    GetComponent(Projector).material.SetTexture("_ShadowTex", tex);
    splatTexArray = splat.GetPixels();
}

function OnApplicationQuit() {
    GetComponent(Projector).material.SetTexture("_ShadowTex", blank);
}

function ScorchMark (hitX : float, hitZ : float) {
    // Limit hit area to size of projector
    var projectorSize = GetComponent(Projector).orthoGraphicSize;
    hitX = Mathf.Clamp(hitX, -projectorSize, projectorSize);
    hitZ = Mathf.Clamp(hitZ, -projectorSize, projectorSize);
    // Get texture drawing coordinates from hit point
    var uvX : int = Mathf.InverseLerp(-projectorSize, projectorSize, hitX) * tex.width;
    var uvY : int = Mathf.InverseLerp(-projectorSize, projectorSize, hitZ) * tex.height;
    
    var dir = 1;
    // Half the time, overlay the splat texture upside-down  backwards just for variety
    if (Random.value > .5) {
        uvX -= splat.width/2;
        uvY -= splat.height/2;
    }
    else {
        dir = -1;
        uvX += splat.width/2;
        uvY += splat.height/2;
    }
    // Copy the splat texture to an area around the hit point
    var startX = uvX;
    for (y = 0; y < splat.height; y++) {
        uvX = startX;
        for (x = 0; x < splat.width; x++) {
            var splatAlpha : float = splatTexArray[x + (y*splat.width)].a;
            // If there's something in the splat texture at this point,
            // and the splat texture at this point is lighter
            // (prevents ugly light anti-aliased pixels being drawn over dark areas) 
            if ( (splatAlpha != 1)  (tex.GetPixel(uvX, uvY).a > splatAlpha) ) {
                tex.SetPixel(uvX, uvY, splatTexArray[x + (y*splat.width)]);
            }
            uvX += dir;
        }
        uvY += dir;
    }
    tex.Apply();
}

I was hoping to find a way to make it write to the second UV set, but I cant even see where hes caching the first. Any ideas?

Thanks
AaronC

writting pixels does not write to a UV at all cause UV is mesh data, it has nothing to do with textures at all (aside of fetching the pixel basing on the UV coordinate from it on the gpu).

if you want to use the texture on the 2nd uv channel, you will need to change the shader to make it do so (see bindchannel and the legacy lightmap shader for example)

Have a look at Erics package here: Bomb_140.zip

http://forum.unity3d.com/threads/5337-Decal-SetPixel

Theres very little other than the above script, and he says to alter the texture rather than the shader.

What do you think?

EDIT: I’m already using the lightmap shaders