Neodroid  0.2.0
Machine Learning Environment Prototyping Tool
FlowCameraBehaviour.cs
Go to the documentation of this file.
1 using UnityEngine;
2 
3 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera {
7  [ExecuteInEditMode]
8  [RequireComponent(typeof(Camera))]
9  public class FlowCameraBehaviour : MonoBehaviour {
12  [SerializeField]
13  Color _background_color = Color.white;
14 
15  [SerializeField] [Range(0, 1)] float _blending = 0.5f;
16 
19  Material _material;
20 
21  [SerializeField] [Range(0, 100)] float _overlay_amplitude = 60;
22 
25  [SerializeField]
26  Shader _shader = null;
27 
30  void Awake() {
31  this.GetComponent<Camera>().depthTextureMode |= DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
32  }
33 
38  void OnRenderImage(RenderTexture source, RenderTexture destination) {
39  if (this._material == null) {
40  var shader = this._shader;
41  if (shader != null) {
42  this._material = new Material(shader) {hideFlags = HideFlags.DontSave};
43  }
44  }
45 
46  var material = this._material;
47  if (material != null) {
48  material.SetColor("_BackgroundColor", this._background_color);
49  material.SetFloat("_Blending", this._blending);
50  material.SetFloat("_Amplitude", this._overlay_amplitude);
51  Graphics.Blit(source, destination, material);
52  }
53  }
54 
57  void OnDestroy() {
58  /*if (this._material != null) {
59  if (Application.isPlaying) {
60  Destroy(this._material);
61  } else {
62  DestroyImmediate(this._material);
63  }
64  }*/
65  }
66  }
67 }