1
\$\begingroup\$

Alright, Ive asked this various ways but my situation is I have several (over 100) objects that have screens that need to play animated videos on them. There does not need to be sound, but this is for VR so performance is an issue.

So far, after trying render textures and video materials and seeing that fps dropped, Ive been using this script to flip through sets of pngs and put them in the diffuse slot of a material:

public class VideoPlayerRawImage : MonoBehaviour
{
    public Texture[] frames;
    public int framesPerSecond = 60;

    public bool isEmissive = false;

    void Update()
    {
        int index = (int)(Time.time * framesPerSecond) % frames.Length;

        this.GetComponent<Renderer>().material.mainTexture = frames[index];
        if(isEmissive)
        {
            this.GetComponent<Renderer>().material.SetTexture("_EmissionMap", frames[index]);
        }

        if(index >= frames.Length-1)
        {
            index = 0;
        }

    }

Is this the most efficient way to play videos? What would be a drawback to this method/is there a better way?

\$\endgroup\$
  • 1
    \$\begingroup\$ If I understand correctly, you've divined a video into individual (image) frames, and you are basically animating them all together based on time? Have you taken a look at Unity's VideoPlayer ? \$\endgroup\$ – TomTsagk Feb 18 at 10:01
  • \$\begingroup\$ When the videos on all screens are synchronized, then you could do so by changing the .sharedMaterial through only one of the Renderers. \$\endgroup\$ – Philipp Feb 19 at 15:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.