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
0
Question by RyFridge · Jan 04, 2016 at 02:43 PM · colorlightmovietexturegetpixel

How to get pixel color from MovieTexture?

Dear game developers,

I am creating a TV asset that needs to light the room based on the footage running on its screen.

 Renderer r = GetComponent<Renderer>();
 MovieTexture movie = (MovieTexture)r.material.GetTexture("_EmissionMap");
 movie.Play();

Playing the movie (*.mov) is not a problem. However, there seems to be no way to access the current frame's Texture2D to use its GetPixel function and get some Colors out of there (updating a Light's Color). I tried to pull out a Texture, which did not throw an error, but I could not convert this Texture to a Texture2D. Trying to directly get a Texture2D is not possible either (returns Null):

 Texture2D tex = r.material.GetTexture("_EmissionMap") as Texture2D;

Any ideas? Thanks a lot!

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

2 Replies

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

Answer by yelman · Jan 05, 2016 at 08:16 AM

Do you have to get pixels every frame? It's very performance intensive.

A possible solution is to render current camera to rendertexture and than call Texture2D.ReadPixels Something like this should work:

         // Render movie from camera to render texture
         RenderTexture rt = RenderTexture.GetTemporary(256, 256, 24);
         Camera.main.targetTexture = rt;
         Camera.main.Render();
         RenderTexture.active = rt;

         // Copy pixels from active render texture to texture2d
         targetTexture.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
         targetTexture.Apply();
 
Comment
Add comment · Show 3 · 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 RyFridge · Jan 07, 2016 at 01:10 PM 0
Share

Thanks @yelman! It worked out perfectly! I placed a camera in front of the TV that only sees the TV screen to get its output. I made the RenderTexture and Texture2D targetTexture both 16x16 and calculated the average Color for my Light.

avatar image yelman RyFridge · Jan 07, 2016 at 02:28 PM 0
Share

You can create a quad, set it's material to the one with the movie texture. Change camera to orographic and set it size to match the quad size. Than when you render from camera to render texture it will render only the quad wich has your movie texture.

avatar image RyFridge yelman · Jan 07, 2016 at 03:53 PM 0
Share

Thanks again @yelman, here is what it looks like:

tv

old-tv-wip05a.png (227.2 kB)
avatar image
0

Answer by oburacodacara · Aug 14, 2020 at 06:40 PM

Could you post your code here? i am realy trying to make this work with just what we have here but i cant see through Thanks!

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 gareth_untether · Mar 05, 2021 at 07:07 PM 0
Share

This thread could be of help with retrieving pixel information from a video:

https://stackoverflow.com/questions/42747285/get-current-frame-texture-from-videoplayer/42747609#42747609

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

6 People are following this question.

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

Related Questions

How can I achieve homogenous lighting? (Same intensity no matter the range from origin) 0 Answers

Change Fog Color Smoothly 1 Answer

Change light color when entering trigger 1 Answer

How can I change the color of a light over time? 3 Answers

Light Looks Weird 2 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