Webcam Texture into the Emission

I am working to get a Webcam Texture piped into the _EMISSION node of a default shader. I have created a custom material to take the input, but for some reason, it’s not working as expected.

I can get it to pipe into the mainTexture, just not into the Emission. Incidentally, I am using the mainTexture to take advantage of the alpha channel, so I don’t want the main channel as my webcamTexture. I can set all of this up and working using regular single texture maps, just wanting a live image in the Emission.

Here’s the code thus far…

#pragma strict
private var webcamTexture1 : WebCamTexture;
var plane1 : Transform;
var plane1 : Transform;
var myMaterial : Material;
function Start () {
webcamTexture1 = WebCamTexture();
var renderer: Renderer = GetComponent.();
var devices : WebCamDevice[ ] = WebCamTexture.devices;

if(devices.length > 1){
webcamTexture1.deviceName = devices[0].name;
myMaterial.EnableKeyword (“_EMISSION”);
myMaterial.SetTexture(“_EMISSION”, webcamTexture1);
webcamTexture1.Play();
}
}

Any help here is much appreciated.
Cheers!

Which shader are you using? (in standard shader the emission texture is “_EmissionMap”)

I am using a default material, but had not found the reference to “_EmissionMap”. That fixed it! Thank you!! I’ve cleaned up the code to help anyone else that might want to do the same thing. Cheers!

#pragma strict

private var webcamTexture1 : WebCamTexture;

var myMaterial : Material;

function Start () {

     webcamTexture1 = WebCamTexture();

     var devices : WebCamDevice[] = WebCamTexture.devices;
     if(devices.length > 1){
          webcamTexture1.deviceName = devices[0].name;

          myMaterial.EnableKeyword ("_EMISSION");
          myMaterial.SetTexture("_EmissionMap", webcamTexture1);

          webcamTexture1.Play();
     }
}

You can see shader details by right clicking over the shader or that small settings wheel, and do Select Shader
2863224--209639--upload_2016-11-25_9-49-49.png

Then can see these

2 Likes

This is great! Nice tip!
Thank you for that… should save a ton of time!