Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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
4
Question by yanivderidder · Nov 22, 2015 at 12:40 AM · 2dshadertexturewebcampost-process-effect

How to Post Process a WebCamTexture in realtime.

Working on an iOS project where I need to post process the image coming from the iPhone camera.

WebCamTexture doesnt inherit from RenderTexture nor Texture2D and I can't find an optimized way to get the texture out of the WebCamTexture in order to apply some post processing effects (shader based).

I would like to do this in realtime and creating a new Texture2D and SetPixels / GetPixels is very slow. I also read about passing the pointer but it definitely doesn't work. (it crashes as people mention)

Is there an alternative ? Im not an expert in Unity. I hope there is a way to achieve this with reasonable performances ?

Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by ArtOfWarfare · Aug 21, 2016 at 02:04 AM

This is working on my Windows laptop without any trouble. I haven't tried putting it on iOS yet.

 public class Script : MonoBehavior {
     WebCamTexture webcam;
     Texture2D     output;
     Color32[]     data;

     IEnumerator Start() {
         yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
         if (Application.HasUserAuthorization(UserAuthorization.WebCam)) {
             webcam = new WebCamTexture();
             webcam.Play();
             output = new Texture2D(webcam.width, webcam.height);
             GetComponent<Renderer>().material.mainTexture = output;
             data = new Color32[webcam.width * webcam.height];
         }
     }

     void Update()  {
         if (data != null) {
             webcam.GetPixels32(data);

             // You can play around with data however you want here.
             // Color32 has member variables of a, r, g, and b. You can read and write them however you want.

             output.SetPixels32(data);
             output.Apply();
         }
     }
 } 
Comment
Add comment · Show 4 · 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 philmzo · Oct 24, 2016 at 01:43 PM 0
Share

Works perfectly for me. Comments are encouraging too :) Thank you @ArtOfWarfare

avatar image nilsubimax philmzo · Mar 07, 2018 at 02:23 PM 0
Share

Isn't this solution using SetPixels/GetPixels which you mentioned are very slow? What makes this solution usable?

avatar image ArtOfWarfare nilsubimax · Mar 07, 2018 at 02:57 PM 0
Share

It ran fast enough for me in a proof of concept. I didn't end up ever building this into a full game. Seems to be good enough for philmzo. Why not just try it and see if it is good enough for you? If it's not good enough, you could try using a shader ins$$anonymous$$d... I have almost no experience with shaders in general though, and definitely none with shaders in Unity in particular (I've used them a tiny bit with webgl.)

Show more comments
avatar image
0

Answer by philmzo · Oct 24, 2016 at 01:43 PM

Works perfectly for me. Comments are encouraging too :) Thank you @ArtOfWarfare

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 team_enso · May 13, 2019 at 01:38 PM

Can we add a delay? like 800ms or a variable delay and show output after that delay ... @ArtOfWarfare

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 shreyanshanchlia · Jun 14, 2020 at 05:32 PM

If anyone is still searching for this issue. I was able to solve this. Enable URP. Make a shader graph. Make a material from the shader. Apply the material to the Raw image and render webcam texture on the raw image. Any changes you make to the shader are directly reflected in the raw image with almost no loss in performance.

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

9 People are following this question.

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

Related Questions

Rewrite simple alphamask fixed function shader to surface or cg shader 2 Answers

is it possible to make 2d real time coloring with masks (paint app) 1 Answer

Dynamic Shader to Outline Adjacent Textures? 0 Answers

Torchlight effect in 2D 3 Answers

Frosted glass effect 0 Answers


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