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