using UnityEngine; //----------------------------------------------------------------------------- // Copyright 2012-2022 RenderHeads Ltd. All rights reserved. //----------------------------------------------------------------------------- namespace RenderHeads.Media.AVProMovieCapture.Demos { /// /// Animates a procedural texture effect driven by a shader /// public class TextureCaptureDemo : MonoBehaviour { [SerializeField] Shader _shader = null; [SerializeField] int _textureWidth = 1024; [SerializeField] int _textureHeight = 1024; [SerializeField] CaptureFromTexture _movieCapture = null; // State private Material _material; private RenderTexture _texture; private void Start() { _material = new Material(_shader); RenderTextureReadWrite readWrite = QualitySettings.activeColorSpace == ColorSpace.Gamma ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB; _texture = new RenderTexture(_textureWidth, _textureHeight, 0, RenderTextureFormat.ARGB32, readWrite); _texture.filterMode = FilterMode.Bilinear; _texture.Create(); if (_movieCapture) { _movieCapture.SetSourceTexture(_texture); } } private void OnDestroy() { if (_material != null) { Material.Destroy(_material); _material = null; } if (_texture != null) { RenderTexture.Destroy(_texture); _texture = null; } } private void Update() { UpdateTexture(); } private void UpdateTexture() { Graphics.Blit(Texture2D.whiteTexture, _texture, _material); } private void OnGUI() { if (_texture != null) { GUI.depth = 100; GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height), _texture, ScaleMode.ScaleToFit, false); } } } }