• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by saline13 · Feb 25, 2012 at 03:11 AM · iostexture

WebCamTexture flipped and rotated when applied to texture iOS

I have script that applies a webcam texture to a guitexture.

The video texture is applied and updates fi e but the image is flipped and rotated 90 degrees.

Even if I rotate the game object -90 or 90 the video image is still flipped and rotated the same.

The image is fine in the editor preview.

Is there something I am missing or a setting for iPhone camera I am missing?

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Aizee · Mar 21, 2012 at 12:19 AM 0
Share

Bump

I'm having the same issue on the new iPad. The pixels are co$$anonymous$$g in mirrored and rotated -90. Here's the code:

var cameraOutput : GUITexture; var plane : GameObject;

private var webcamTexture : WebCamTexture; private var devices : WebCamDevice[];

function Start () { devices = WebCamTexture.devices; webcamTexture = WebCamTexture(); if(devices.length > 0){ webcamTexture.deviceName = devices[0].name; webcamTexture.requestedWidth = Screen.width; webcamTexture.requestedHeight = Screen.height; var width = webcamTexture.requestedWidth; var height = webcamTexture.requestedHeight;
cameraOutput.pixelInset = Rect (width/2*(-1), height/2*(-1), width, height); cameraOutput.texture = webcamTexture; webcamTexture.Play(); } }

function OnGUI () { if (WebCamDevice == null){ GUI.Label(Rect(10,10,65,25),"NO ACTIVE CA$$anonymous$$ERA"); }

for( var i = 0 ; i < devices.length ; i++ ){ if(GUI.Button(Rect(150,i*100,350,100),devices[i].name)){ webcamTexture.Stop(); webcamTexture.deviceName = devices[i].name; webcamTexture.requestedWidth = Screen.width; webcamTexture.requestedHeight = Screen.height; webcamTexture.Play(); } } }

Any help appreciated.

avatar image Maverick · Sep 10, 2012 at 07:54 PM 0
Share

Have same problem. Will file a bug report.

8 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Iamdain · Jul 24, 2012 at 08:58 AM

Guys the solution I used was to apply a transform matrix which is processed in the shader.

Just use what you need from here:

http://docs.unity3d.com/Documentation/ScriptReference/Material.SetMatrix.html

You can just add "matrix [_Rotation]" to your shader pass in your existing shader if you don't want to build your own shader at run-time as they did in this example.

The full transformation matrix is built for you so you don't need to understand how the 4x4 Matrix works internally, just plug in your offset, scale and rotation values. http://docs.unity3d.com/Documentation/ScriptReference/Matrix4x4.TRS.html?from=Material

The real problem I have at the moment is HOW DO YOU DETECT THE RESOLUTION OF THE CAMERA???? You can't scale the resulting image to give the correct aspect ratio without knowing this making the feature fairly useless. Is there something I missed here? I need to build for iOS and Android, have only just hit this problem so will post back if I find a solution.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by salIne13 · Mar 22, 2012 at 02:46 AM

It is interesting that no one else is commenting on this issue. It makes me think I am just plain doing something wrong.

I posted a bug with unity but have not heard anything back from them.

I asked for help from unity and they said it would be something I was doing wrong but they would send the solution in a day or 2 that was a week ago:)

I would think that the expected behaviour of this feature is to be the same across devices.

In the mean time I am manually manipulating the pixel data to flip and rotate the data from the camera on iOS.

Unfortunately this is quite a lot of processing on something that is repeated pretty much every update. ,It is interesting that th

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by ferretnt · Apr 04, 2012 at 06:48 PM

I'm seeing exactly the same thing. However, if you're simply rendering with the texture, don't manually manipulate the pixel data, instead construct your own orthographic camera, and a custom plane mesh with different UVs on the various platforms.

However, I agree with your general observation that handling of webcams isn't quite as cross-platform as you might like.

Code attached below which I'm currently using to generate a 2D plane with identical positions but different UVs which works on iOS and Mac (haven't yet tested windows or android):

     videoPlaneMesh = new Mesh ();
     
     videoPlaneMesh.vertices = new Vector3[] { new Vector3 (-1, -1, 0), new Vector3 (1, -1, 0), new Vector3 (-1, 1, 0), new Vector3 (1, 1, 0) };
     
     //
     // We have to use different UVs for OpenCV versus unity Webcam, because the y-axes of the image we get from the camera
     // are opposite.
     //
     if (useUnityWebcam)
     {
 #if UNITY_IPHONE && !UNITY_EDITOR
         // This version is for iPad, and seems to permute X and Z
         videoPlaneMesh.uv = new Vector2[] { new Vector2 (1, 1), new Vector2 (1, 0), new Vector2 (0, 1), new Vector2 (0, 0) };
 #else
         videoPlaneMesh.uv = new Vector2[] { new Vector2 (0, 0), new Vector2 (1, 0), new Vector2 (0, 1), new Vector2 (1, 1) };
 #endif //UNITY_IPHONE
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hitori · Jun 06, 2014 at 03:05 AM 0
Share

hi, can you attach the whole script here? thanks! :)

avatar image
0

Answer by Iamdain · Jul 24, 2012 at 08:58 AM

The solution I used was to apply a transform matrix which is processed in the shader.

Just use what you need from here:

http://docs.unity3d.com/Documentation/ScriptReference/Material.SetMatrix.html

You can just add "matrix [_Rotation]" to your shader pass in your existing shader if you don't want to build your own shader at run-time as they did in this example.

The full transformation matrix is built for you so you don't need to understand how the 4x4 Matrix works internally, just plug in your offset, scale and rotation values. http://docs.unity3d.com/Documentation/ScriptReference/Matrix4x4.TRS.html?from=Material

The real problem I have at the moment is HOW DO YOU DETECT THE RESOLUTION OF THE CAMERA???? You can't scale the resulting image to give the correct aspect ratio without knowing this making the feature fairly useless. Is there something I missed here? I need to build for iOS and Android, have only just hit this problem so will post back if I find a solution.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image amykaroline · Nov 02, 2012 at 06:54 PM 1
Share

Thank you! This was very helpful. For anyone out there who needs additional hints, the scale I used was Vector3(1,-1,1) and the translation was Vector3(0,1,0).
Iamdain - did you ever figure out how to detect and apply resolution? Thanks!

avatar image Hitori · Jun 06, 2014 at 03:07 AM 0
Share

hi amykaroline, can you attach the whole script here?

avatar image
0

Answer by amykaroline · Nov 02, 2012 at 07:41 PM

Hi Iamdain, I'm having the same problem but am stuck in trying to create the correct inputs for the TRS function. What scale did you use to get the proper flip of the rawdata from the iOS device? Thanks in advance for your help! -Amy

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Texture changes brightness at random – why? (on iPhone) 0 Answers

Texture size for target iOS Version 0 Answers

RaycastHit textureCoords return Vector2.zero on iOS only despite proper setup 2 Answers

Can Rectangle pot PVRTC textures be used on iOS? 1 Answer

Losing texture after going back to menu in Unity5 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges