- Home /
Spot light projector using video player
So I'm trying to create a projector (like in movie theaters) and I've semi succeded. I've got the video playing, it's just the it runs... really really badly. Here's my code.
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; public class projector : MonoBehaviour { public VideoPlayer video; Texture2D videoFrame; public RenderTexture render; private void Start() { videoFrame = new Texture2D(render.width, render.height); video.sendFrameReadyEvents = true; video.frameReady += OnNewFrame; } void OnNewFrame(VideoPlayer source, long frameIdx) { int width = source.texture.width; int height = source.texture.width; RenderTexture.active = render; videoFrame.ReadPixels(new Rect(0, 0, render.width, render.height), 0, 0); videoFrame.Apply(); Texture2D texture = new Texture2D(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { Color color = Color.black; color.a = videoFrame.GetPixel(x, y).r; texture.SetPixel(x, y, color); } } texture.Apply(); GetComponent<Light>().cookie = texture; } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613005021im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
movie texture 360 low fps 0 Answers
Lens-Flare Muzzleflash 0 Answers
lightbulb effect 1 Answer