2 using System.Collections.Generic;
6 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera.Segmentation {
14 Renderer[] _all_renders = null;
18 MaterialPropertyBlock _block = null;
20 [SerializeField] Shader segmentation_shader = null;
21 [SerializeField] Camera _camera = null;
25 public Dictionary<Material, Color> ColorsDictGameObject {
get;
set; } =
new Dictionary<Material, Color>();
29 public override Dictionary<String, Color> ColorsDict {
31 var colors =
new Dictionary<String, Color>();
32 foreach (var key_val
in this.ColorsDictGameObject) {
33 if (!colors.ContainsKey(key_val.Key.name)) {
34 colors.Add(key_val.Key.name, key_val.Value);
45 void Start() { this.Setup(); }
48 if (this._block == null) {
49 this._block =
new MaterialPropertyBlock();
53 SynthesisUtilities.CapturePass[] _capture_passes = {
54 new SynthesisUtilities.CapturePass {
69 this._all_renders = FindObjectsOfType<Renderer>();
71 this._camera = this.GetComponent<Camera>();
72 SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera,
73 this.segmentation_shader,
74 ref this._capture_passes);
76 this.ColorsDictGameObject =
new Dictionary<Material, Color>();
78 foreach (var r
in this._all_renders) {
79 r.GetPropertyBlock(this._block);
80 var sm = r.sharedMaterial;
82 var
id = sm.GetInstanceID();
83 var color = ColorEncoding.EncodeIdAsColor(
id);
84 if (!this.ColorsDictGameObject.ContainsKey(sm)) {
85 this.ColorsDictGameObject.Add(sm, color);
88 this._block.SetColor(SynthesisUtilities._Shader_MaterialId_Color_Name, color);
89 r.SetPropertyBlock(this._block);