I want to show two different parts of the same WebCamTexture simultaneously on two separate planes (using a specific mainTextureOffset & mainTextureScale for each plane), but I can’t figure out how to make a copy of the WebCamTexture. So anything I do with the offset & scale on one plane always affects the other. I’d guess that it somehow involves GetPixels32 and SetPixels32, but nothing I’ve tried works at all. Any ideas?
You indeed need to copy / paste pixels from webcamtexture to target texture(s), and that is done with GetPixels and SetPixels (or Get/SetPixels32) Check the docs, there is more info and examples. This is how its done with js:
#pragma strict
var webcamTarget1:Transform;
var webcamTarget2:Transform;
private var texture1:Texture2D;
private var texture2:Texture2D;
private var webcamTexture : WebCamTexture;
function Start () {
webcamTexture = WebCamTexture(); //webcamimage holder
webcamTexture.Play(); //start the cam ..img data goes to webcamTexture
texture1 = new Texture2D(webcamTexture.width, webcamTexture.height, TextureFormat.ARGB32, false); //create texture, same size as webcamTexture
texture2 = new Texture2D(webcamTexture.width /2, webcamTexture.height /2, TextureFormat.ARGB32, false); //create halfsize texture
webcamTarget1.renderer.material.mainTexture = texture1; //set texture for whatever your target transform is ..plane, cube
webcamTarget2.renderer.material.mainTexture = texture2; //set texture for another one
}
function Update(){
var pixels1 = webcamTexture.GetPixels(0, 0, texture1.width, texture1.height); //get fullsize
var pixels2 = webcamTexture.GetPixels(texture2.width /2, texture2.height /2, texture2.width, texture2.height); //get halfsize from center
//set pixels to texture, and send texture to gpu
texture1.SetPixels(pixels1);
texture1.Apply();
texture2.SetPixels(pixels2);
texture2.Apply();
}