using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DroneCameraShading : MonoBehaviour {

    public Material mat;
    public Texture noSignal;
    //private RenderTexture _storedTexture;
    public bool singleShotOnly;

    //public bool saveShotThisFrame;
    public bool render;
    private bool renderedAlready;

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (render)
        {
            renderedAlready = true;
            var activeDrone = DroneController.active;
            if (activeDrone != null)
            {
                mat.SetFloat("_Colorfulness", activeDrone.colorfulness);
                mat.SetFloat("_BlackNoise", activeDrone.darkness + AC.instance.timeWithoutPower * 0.01f);
            }
            Graphics.Blit(source, destination, mat);

            if (singleShotOnly)
                render = false;
        }

        if (!renderedAlready)
        {
            Graphics.Blit(noSignal, destination);
        }

        //if (saveShotThisFrame)
        //{
        //    if (_storedTexture != null)
        //        _storedTexture.Release();
        //    _storedTexture = new RenderTexture(source.width, source.height, source.depth);
        //    _storedTexture.Create();

        //    Graphics.Blit(source, _storedTexture, mat);
        //}

        //if (_storedTexture != null)
        //{
        //    RenderTexture.active = null;
        //    _storedTexture.Release();
        //    _storedTexture = null;
        //}
        //else if (_storedTexture != null)
        //{
        //    Graphics.Blit(_storedTexture, null as RenderTexture);
        //}
    }
}
