Taylor
Taylor

Reputation: 316

Unity WebcamTexture advanced settings (exposure, focus, zoom)

I have my camera feed working in Unity that uses WebcamTexture. According to https://docs.unity3d.com/ScriptReference/WebCamTexture.html, there are no features for changing the exposure or focus settings.

Just to be clear:

  1. Is there any way to change the exposure of WebcamTexture?
  2. If not, is there any other way to adjust the exposure without using WebcamTexture?
  3. If not, what are some widely used API/tools that I can use in Unity for getting camera feed with these adjustable settings?

Upvotes: 1

Views: 6430

Answers (1)

Programmer
Programmer

Reputation: 125275

Is there any way to change the exposure of WebcamTexture?

No. You can on Android with AndroidJavaObject but that's a hack and can stop working each time there is Unity update. Also, it will only work on Android but not on iOS, Windows, Mac and other platforms.

If not, is there any other way to adjust the exposure without using WebcamTexture?

Again, no. You can't modify the camera settings while using WebcamTexture.

If not, what are some widely used API/tools that I can use in Unity for getting camera feed with these adjustable settings?

The only way to be able to modify the camera settings you mentioned is to create a camera API plugin for each platform. This is not easy to do since you have to know many programming languages to get it working such as Java for Android, Objective-C for iOS and Mac, C++ for Windows and Linux and Javascript for WebGL then use C# to put them together. It's really time-consuming to make this and therefore better to use an existing plugin.

The best one out there is the NatCam plugin. This plugin can control the exposure, focus and zoom of the camera but it's not free. It's worth it.

You can set the exposure and the exposure bias as:

DeviceCamera.RearCamera.ExposureMode = ExposureMode.Locked;
NatCam.Camera.ExposureBias = NatCam.Camera.MinExposureBias;

To set the Focus Mode:

NatCam.Camera.FocusMode = FocusMode.TapToFocus | FocusMode.AutoFocus;

To zoom the camera:

NatCam.Camera.ZoomRatio = 2.0f;

You can find the complete tutorial for NatCam here.

Upvotes: 1

Related Questions