• 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
0

Answer by raja1250 · May 27, 2015 at 01:18 PM

Just rotate the camera to 90 degrees along the z axis(the camera is which is rendering the webcamtexture gameobject).

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 Ravensburg3r · Dec 03, 2013 at 05:44 PM

I found next solution.

1) Create new shader:

 Shader "Custome/Web Camera Shader" 
 {
      Properties 
      {
          _MainTex ( "Main Texture", 2D ) = "white" {}
     }
     
     SubShader 
     {
         Pass
         {
             CGPROGRAM
             
             #pragma vertex vert
             #pragma fragment frag
             
             uniform sampler2D _MainTex;
             uniform float4x4 _Rotation;
             
             struct vertexInput
             {
                 float4 vertex : POSITION;
                 float4 texcoord : TEXCOORD0;
             };
             
             struct vertexOutput
             {
                 float4 pos : SV_POSITION;
                 half2 uv : TEXCOORD0;
             };
             
             
             vertexOutput vert(vertexInput v)
             {
                 vertexOutput o;
                 
                 float4 newPosition = mul( UNITY_MATRIX_MVP, mul(_Rotation, v.vertex) );
                 
                 o.pos = newPosition;
                 o.uv = v.texcoord;
                 
                 return o;
             }
             
             float4 frag(vertexOutput i) : COLOR
             {
                 return tex2D( _MainTex, i.uv );
             }
             
             ENDCG
         }
     }
     Fallback "Diffuse"
 } 

2) Apply shader to material of a plane you want to display WebCamTexture

3) Set matrix for the material (in Start() method):

 Quaternion rotation = Quaternion.Euler (0, 90, 0);
 Matrix4x4 rotationMatrix = Matrix4x4.TRS (Vector3.zero, rotation, new Vector3(1, 1, 1));
 gameObject.renderer.material.SetMatrix ("_Rotation", rotationMatrix);

4) Set WebCamTexture to material texture like this (in Update() method):

 cameraScreen.renderer.material.mainTexture = webCamera.texture;
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 Hitori · Jun 06, 2014 at 03:28 AM 0
Share

hi ravensburg3d, it seems like its not working when i run my app, it doesnt show the image from the webcam

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

please email it to me :)) thank you!!

avatar image
0

Answer by davidf · Dec 10, 2012 at 06:12 PM

Great ideas here!

I am new to Unity IOS. I have tried to do the matrix bit to the best of my abilities with no luck. Iamdain could you please explain your solution in more detail? From a newbies point of view maybe?

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 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
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
  • 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