9 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera.Experimental {
17 Renderer[] _all_renders = null;
21 MaterialPropertyBlock _block = null;
23 [SerializeField] RenderTexture depthRenderTexture = null;
24 [SerializeField] RenderTexture objectIdRenderTexture = null;
25 [SerializeField] RenderTexture tagIdRenderTexture = null;
26 [SerializeField] RenderTexture flowRenderTexture = null;
30 void Start() { this.Setup(); }
37 if (this._block == null) {
38 this._block =
new MaterialPropertyBlock();
44 [SerializeField] Camera _camera;
45 [SerializeField] Boolean debug =
true;
46 [SerializeField] Boolean always_re =
true;
47 [SerializeField] Mesh m_quad;
48 [SerializeField] GUISkin gui_style = null;
57 new Vector3(1.0f, 1.0f, 0.0f),
58 new Vector3(-1.0f, 1.0f, 0.0f),
59 new Vector3(-1.0f, -1.0f, 0.0f),
60 new Vector3(1.0f, -1.0f, 0.0f)
62 triangles =
new[] {0, 1, 2, 2, 3, 0}
64 r.UploadMeshData(
true);
71 if (!this.gui_style) {
72 this.gui_style = Resources.FindObjectsOfTypeAll<GUISkin>().First(a => a.name ==
"BoundingBox");
75 this._all_renders = FindObjectsOfType<Renderer>();
76 if (this._capture_passes == null || this._capture_passes.Length == 0 ||
this.always_re) {
77 this._capture_passes =
new[] {
79 BuiltinRenderTextureType.Depth) {
87 BuiltinRenderTextureType.MotionVectors) {
95 BuiltinRenderTextureType.None) {
100 .objectIdRenderTexture,
103 .PropertyToID(
"_TmpFrameBuffer")
106 BuiltinRenderTextureType.None) {
107 _SupportsAntialiasing
114 .PropertyToID(
"_CameraDepthTexture")
119 if (this.m_quad == null) {
120 this.m_quad = CreateFullscreenQuad();
123 this._camera = this.GetComponent<Camera>();
126 this._camera.RemoveAllCommandBuffers();
128 this._camera.depthTextureMode = DepthTextureMode.Depth | DepthTextureMode.MotionVectors;
130 foreach (var capture_pass
in this._capture_passes) {
131 var cb =
new CommandBuffer {name = capture_pass.Source.ToString()};
135 if (capture_pass._Material) {
136 cb.GetTemporaryRT(capture_pass._TextureId, -1, -1, 0, FilterMode.Point);
138 cb.Blit(capture_pass.Source, capture_pass._TextureId);
139 cb.SetRenderTarget(
new RenderTargetIdentifier[] {capture_pass._RenderTexture},
140 capture_pass._RenderTexture);
141 cb.DrawMesh(this.m_quad, Matrix4x4.identity, capture_pass._Material, 0, 0);
142 cb.ReleaseTemporaryRT(capture_pass._TextureId);
144 cb.Blit(capture_pass.Source, capture_pass._RenderTexture);
147 this._camera.AddCommandBuffer(capture_pass.When, cb);
151 foreach (var r
in this._all_renders) {
152 r.GetPropertyBlock(this._block);
153 var sm = r.sharedMaterial;
155 var
id = sm.GetInstanceID();
156 var color = ColorEncoding.EncodeIdAsColor(
id);
158 this._block.SetColor(SynthesisUtilities._Shader_MaterialId_Color_Name, color);
159 r.SetPropertyBlock(this._block);
164 const int _size = 100;
165 const int _margin = 20;
171 foreach (var pass
in this._capture_passes) {
172 var xi = (_size + _margin) * index++;
173 var x = xi % (Screen.width - _size);
174 var y = (_size + _margin) * (xi / (Screen.width - _size));
175 var r =
new Rect(_margin + x, _margin + y, _size, _size);
178 GUI.DrawTexture(r, pass._RenderTexture, ScaleMode.ScaleToFit);
179 GUI.TextField(r, pass.Source.ToString(), this.gui_style.box);
201 BuiltinRenderTextureType source = BuiltinRenderTextureType.CurrentActive) {
203 this.Source = source;
204 this._Material = null;
205 this._RenderTexture = null;
206 this._SupportsAntialiasing =
false;
207 this._NeedsRescale =
false;
214 Material _m_vf_lip_material;
215 RenderTexture _m_work_texture;
218 this._m_sh_v_flip = Shader.Find(
"Neodroid/Experimental/VerticalFlipper");
219 if (this._m_sh_v_flip) {
220 this._m_vf_lip_material =
new Material(this._m_sh_v_flip);
224 public void Flip(RenderTexture target) {
225 if (this._m_work_texture == null
226 || this._m_work_texture.width != target.width
227 ||
this._m_work_texture.height != target.height) {
228 UnityHelpers.Destroy(this._m_work_texture);
229 this._m_work_texture =
new RenderTexture(target.width,
233 RenderTextureReadWrite.Linear);
236 if (this._m_vf_lip_material) {
237 Graphics.Blit(target, this._m_work_texture, this._m_vf_lip_material);
238 Graphics.Blit(this._m_work_texture, target);
243 UnityHelpers.Destroy(this._m_work_texture);
244 this._m_work_texture = null;
245 if (this._m_vf_lip_material) {
246 UnityHelpers.Destroy(this._m_vf_lip_material);
247 this._m_vf_lip_material = null;
257 public static class UnityHelpers {
258 public static void Destroy(
Object obj,
bool allow_destroying_assets =
false) {
263 if (EditorApplication.isPlaying) {
266 Object.DestroyImmediate(obj, allow_destroying_assets);
274 public static bool IsPlaying() {
276 return EditorApplication.isPlaying;
RenderTexture _RenderTexture
static Mesh CreateFullscreenQuad()
bool _SupportsAntialiasing
void Flip(RenderTexture target)
CapturePassMaterial(CameraEvent when=CameraEvent.AfterEverything, BuiltinRenderTextureType source=BuiltinRenderTextureType.CurrentActive)
BuiltinRenderTextureType Source