So I’m slowly working my way through lots of the manual code snippets and tinkering with them - lots of fun.
In the bit below I took the getPixels/setPixels example to copy an entire source texture at the click point (e.g. bullet hole type thing). Works fine except I am not doing any calculations to see that the source texture will fit at the point clicked.
What I can’t figure out is how to do alphas. My source texture is RGBA.Do I need to do a separate getPixels on the Color.grayscale and apply those to the target texture?
Also, is there any equivalent to imaging lingo (Director) to use ink effect types of blitting? (additive, etc.)
(sorry for this barrage of questions!!)
–Roy
var blobTex: Texture2D;
function Update () {
// Only when we press the mouse
if (!Input.GetMouseButton (0))
return;
// Only if we hit something, do we continue
var hit : RaycastHit;
if (!Physics.Raycast (camera.ScreenPointToRay(Input.mousePosition), hit))
return;
var renderer : Renderer = hit.collider.renderer;
var meshCollider = hit.collider as MeshCollider;
if (renderer == null || renderer.sharedMaterial == null ||
renderer.sharedMaterial.mainTexture == null || meshCollider == null)
return;
var px = blobTex.GetPixels(0,0, blobTex.width, blobTex.height, 0);
var tex : Texture2D = renderer.material.mainTexture;
var pixelUV = hit.textureCoord;
pixelUV.x *= tex.width;
pixelUV.y *= tex.height;
tex.SetPixels (pixelUV.x, pixelUV.y, blobTex.width, blobTex.height, px, 0);
tex.Apply();
}