Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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
0
Question by Roktom · Dec 14, 2015 at 07:12 PM · mobileoptimizationbackgroundimage effectswebcamtexture

WebCam background optimisation

Hi everyone, i am creating an app where there is a background with camera feed, it's supposed to be gray like in the screenshot below.

Now the problem is that with current code, on Android app runs with 3FPS when 1280x720 on SGS4, not good (and I don't want to have resolution of 320x240). What I want is somewhat good quality as well as at least 30FPS.

Right now I am using CameraWebTexture, which is saved in Color[] array, then I process this Array to make image gray and brighten it. Then I apply this array to Texture2D which is further applied on RawImage texture and material.mainTexture.

What I need is ways to optimize the code or alternatives which would let accomplish this task. This should be possible , as for example SnapChat has the same effect on login screen. Willing for your help :)

alt text

 WebCamTexture webCamTexture;
     Color32[] modColors;
     Texture2D modTexture;
 
     void Start()
     {
         SetupTexture();
     }
 
     void Update()
     {
         ModifyTexture();
         ApplyTexture();
     }
 
     void SetupTexture()
     {
         webCamTexture = new WebCamTexture(1280,720,30);
         webCamTexture.Play();
 
         modTexture = new Texture2D(webCamTexture.width,webCamTexture.height);
         RawImage rawImage = GetComponent<RawImage>();
         rawImage.texture = modTexture;
         rawImage.material.mainTexture = modTexture;
 
         
     }
 
     void ModifyTexture()
     {
         modColors = webCamTexture.GetPixels32();
         for (int i = 0; i < modColors.Length; i++)
         {
             byte modColor   = (byte)((modColors[i].r + modColors[i].g + modColors[i].b) / 3);
             modColor        = (byte)(192 + (modColor / 4));
             modColors[i]    = new Color32(modColor, modColor, modColor, 255);
 
         }
     }
 
     void ApplyTexture()
     {
         modTexture.SetPixels32(modColors);
         modTexture.Apply();
     }
12387865-881199725327913-423082047-n.jpg (18.6 kB)
Comment
Add comment · Show 3
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 G4merSylver · Dec 14, 2015 at 07:24 PM 0
Share

I am not exactly sure, but the high strain might be because of the way you use the arrays, I am not sure if I completely understood this but the way you are calculating the image should have an massive amount of processing each second.

avatar image Roktom G4merSylver · Dec 14, 2015 at 07:38 PM 0
Share

True, but even without any image processing I get only 8-9FPS

avatar image Roktom Roktom · Dec 14, 2015 at 07:44 PM 0
Share

Also I am not sure if it is right to process and apply texture every Update() frame, maybe I need to check for camera feed and only then do all that stuff... as well as if it was really good idea to use RawImage GameObject.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Lanre · May 26, 2016 at 07:23 PM

@Roktom, On Android especially, WebCamTexture has terrible performance. Try using NatCam.

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

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.

Follow this Question

Answers Answers and Comments

33 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 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 avatar image avatar image avatar image

Related Questions

Image Effect problem on mobile & optimization 0 Answers

if i make a realistic scene and bake the realistic lightning, will it have a big performance impact on android? 0 Answers

How to make looped background?(Character enters left side and appears from right) 2 Answers

Alternative to SendMessage()? / Mobile Optimization 1 Answer

Question about Multithreaded rendering! 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