2 using System.Collections.Generic;
7 namespace droid.Runtime.Utilities.GameObjects.NeodroidCamera.Segmentation {
23 Renderer[] _all_renders = null;
27 MaterialPropertyBlock _block = null;
29 [SerializeField] Shader segmentation_shader = null;
30 [SerializeField] Camera _camera = null;
36 [SerializeField] ScriptableObjects.Segmentation _segmentation_preset = null;
40 public bool _Replace_Untagged_Color =
true;
44 public Color _Untagged_Color = Color.black;
48 public ColorByCategory[] ColorsByCategory {
get {
return this._colors_by_category; } }
52 public Dictionary<string, Color> ColorsDictGameObject {
get;
set; } =
new Dictionary<string, Color>();
56 public override Dictionary<string, Color> ColorsDict {
58 var colors =
new Dictionary<string, Color>();
59 foreach (var key_val
in this.ColorsDictGameObject) {
60 colors.Add(key_val.Key, key_val.Value);
75 void Awake() { this.Setup(); }
78 if (this._block == null) {
79 this._block =
new MaterialPropertyBlock();
83 SynthesisUtilities.CapturePass[] _capture_passes;
88 if (this._colors_by_category != null && this._colors_by_category.Length > 0) {
89 foreach (var tag_color
in this._colors_by_category) {
90 if (!this.ColorsDictGameObject.ContainsKey(tag_color._Category_Name)) {
91 this.ColorsDictGameObject.Add(tag_color._Category_Name, tag_color._Color);
96 if (this._segmentation_preset) {
97 var segmentation_color_by_tags = this._segmentation_preset._color_by_categories;
98 if (segmentation_color_by_tags != null) {
99 foreach (var tag_color
in segmentation_color_by_tags) {
100 if (!this.ColorsDictGameObject.ContainsKey(tag_color._Category_Name)) {
101 this.ColorsDictGameObject.Add(tag_color._Category_Name, tag_color._Color);
107 this._all_renders = FindObjectsOfType<Renderer>();
109 this._camera = this.GetComponent<Camera>();
112 if (this.ColorsDictGameObject == null) {
113 this.ColorsDictGameObject =
new Dictionary<string, Color>();
116 switch (this._segmentation_mode) {
118 this._capture_passes =
new[] {
119 new SynthesisUtilities.CapturePass {
125 _SupportsAntialiasing =
131 this._capture_passes =
new[] {
132 new SynthesisUtilities.CapturePass {
138 _SupportsAntialiasing =
143 default:
throw new ArgumentOutOfRangeException();
146 SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera,
147 this.segmentation_shader,
148 ref this._capture_passes);
151 foreach (var a_renderer
in this._all_renders) {
152 a_renderer.GetPropertyBlock(this._block);
153 string category_name;
154 var category_int = 0;
156 string shader_data_name;
157 switch (this._segmentation_mode) {
159 category_name = a_renderer.tag;
160 shader_data_name = SynthesisUtilities._Shader_Tag_Color_Name;
163 category_int = a_renderer.gameObject.layer;
164 category_name = LayerMask.LayerToName(category_int);
165 shader_data_name = SynthesisUtilities._Shader_Layer_Color_Name;
167 default:
throw new ArgumentOutOfRangeException();
170 if (!this.ColorsDictGameObject.ContainsKey(category_name)) {
171 switch (this._segmentation_mode) {
173 category_int = category_name.GetHashCode();
174 color = ColorEncoding.EncodeTagHashCodeAsColor(category_int);
178 color = ColorEncoding.EncodeLayerAsColor(category_int);
182 throw new ArgumentOutOfRangeException();
185 this.ColorsDictGameObject.Add(category_name, color);
187 color = this.ColorsDictGameObject[category_name];
190 this._block.SetColor(shader_data_name, color);
192 a_renderer.SetPropertyBlock(this._block);