private static void SetEncoding(EffectParameter parameter, ColorEncoding encoding) { // Constants need to be kept in sync with ColorEncoder.fx. const float rgbEncoding = 0; const float sRgbEncoding = 1; const float rgbmEncoding = 2; const float rgbeEncoding = 3; const float logLuvEncoding = 4; if (encoding is RgbEncoding) { parameter.SetValue(new Vector4(rgbEncoding, 0, 0, 0)); } else if (encoding is SRgbEncoding) { parameter.SetValue(new Vector4(sRgbEncoding, 0, 0, 0)); } else if (encoding is RgbmEncoding) { float max = GraphicsHelper.ToGamma(((RgbmEncoding)encoding).Max); parameter.SetValue(new Vector4(rgbmEncoding, max, 0, 0)); } else if (encoding is RgbeEncoding) { parameter.SetValue(new Vector4(rgbeEncoding, 0, 0, 0)); } else if (encoding is LogLuvEncoding) { parameter.SetValue(new Vector4(logLuvEncoding, 0, 0, 0)); } }
public TensorBitmap(SpanTensor3 <T> tensor, ColorEncoding encoding) { _ChannelX = tensor.Dimensions[0] > 0 ? tensor[0].Span : default; _ChannelY = tensor.Dimensions[0] > 1 ? tensor[1].Span : default; _ChannelZ = tensor.Dimensions[0] > 2 ? tensor[2].Span : default; _ChannelW = tensor.Dimensions[0] > 3 ? tensor[3].Span : default; _Channels = tensor.Dimensions[0]; _Width = tensor.Dimensions[2]; _Height = tensor.Dimensions[1]; _Encoding = encoding; }
public TensorBitmap(SpanTensor2 <T> tensor, ColorEncoding encoding) { _ChannelX = tensor.Span; _ChannelY = default; _ChannelZ = default; _ChannelW = default; _Channels = 1; _Width = tensor.Dimensions[1]; _Height = tensor.Dimensions[0]; _Encoding = encoding; }
/// <summary> /// Initializes a new instance of the <see cref="ColorEncoder"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public ColorEncoder(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load <Effect>("DigitalRune/PostProcessing/ColorEncoder"); _viewportSizeParameter = _effect.Parameters["ViewportSize"]; _sourceTextureParameter = _effect.Parameters["SourceTexture"]; _sourceEncodingParameter = _effect.Parameters["SourceEncoding"]; _targetEncodingParameter = _effect.Parameters["TargetEncoding"]; _sourceEncoding = ColorEncoding.Rgb; _targetEncoding = ColorEncoding.Rgb; }
private static void VerifyEncoding(ColorEncoding encoding) { if (encoding is RgbEncoding || encoding is SRgbEncoding || encoding is RgbmEncoding || encoding is RgbeEncoding || encoding is LogLuvEncoding) { return; } throw new NotSupportedException("The given color encoding is not supported by the ColorEncoder."); }
/// <summary> /// </summary> void Setup() { this._camera = this.GetComponent <Camera>(); SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera, this.segmentation_shader, ref this._capture_passes); this.ColorsDictGameObject = new Dictionary <GameObject, Color>(); this._all_renders = FindObjectsOfType <Renderer>(); this.CheckBlock(); foreach (var r in this._all_renders) { r.GetPropertyBlock(this._block); var game_object = r.gameObject; var id = game_object.GetInstanceID(); var layer = game_object.layer; var go_tag = game_object.tag; if (!this.ColorsDictGameObject.ContainsKey(game_object)) { this.ColorsDictGameObject.Add(game_object, ColorEncoding.EncodeIdAsColor(id)); } else { #if NEODROID_DEBUG if (true) { Debug.LogWarning($"ColorDict Duplicate {game_object}"); } #endif } this._block.SetColor(SynthesisUtilities._Shader_ObjectId_Color_Name, ColorEncoding.EncodeIdAsColor(id)); /* * this._block?.SetInt(SynthesisUtils._Shader_OutputMode_Name,(int) SynthesisUtils.ReplacementModes * .Object_id_); */ //this._block.SetColor("_CategoryIdColor", ColorEncoding.EncodeLayerAsColor(layer)); //this._block.SetColor("_MaterialIdColor", ColorEncoding.EncodeIdAsColor(id)); //this._block.SetColor("_CategoryColor", ColorEncoding.EncodeTagHashCodeAsColor(go_tag)); r.SetPropertyBlock(this._block); } }
//-------------------------------------------------------------- #region Creation & Cleanup //-------------------------------------------------------------- /// <summary> /// Initializes a new instance of the <see cref="ColorEncoder"/> class. /// </summary> /// <param name="graphicsService">The graphics service.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="graphicsService"/> is <see langword="null"/>. /// </exception> public ColorEncoder(IGraphicsService graphicsService) : base(graphicsService) { _effect = GraphicsService.Content.Load<Effect>("DigitalRune/PostProcessing/ColorEncoder"); _viewportSizeParameter = _effect.Parameters["ViewportSize"]; _sourceTextureParameter = _effect.Parameters["SourceTexture"]; _sourceEncodingParameter = _effect.Parameters["SourceEncoding"]; _targetEncodingParameter = _effect.Parameters["TargetEncoding"]; _sourceEncoding = ColorEncoding.Rgb; _targetEncoding = ColorEncoding.Rgb; }
public static unsafe BitmapSampler <TPixel> From(SpanTensor2 <TPixel> tensor, ColorEncoding encoding) { var w = tensor.BitmapSize.Width; var h = tensor.BitmapSize.Height; var b = MMARSHALL.Cast <TPixel, byte>(tensor.Span); var e = encoding; return(new BitmapSampler <TPixel>(b, w * sizeof(TPixel), w, h, e)); }
public void OnSceneChange() { sentColorCorrespondence = false; var renderers = UnityEngine.Object.FindObjectsOfType <Renderer>(); colorIds = new Dictionary <Color, string> (); var mpb = new MaterialPropertyBlock(); foreach (var r in renderers) { var layer = r.gameObject.layer; var tag = r.gameObject.tag; SimObj simObj = r.gameObject.GetComponent <SimObj> (); if (simObj == null) { simObj = r.gameObject.GetComponentInParent <SimObj> (); } Color classColor; Color objColor; if (simObj == null) { classColor = ColorEncoding.EncodeTagAsColor("" + r.name); objColor = ColorEncoding.EncodeTagAsColor(getUniqueId(r.gameObject)); } else { classColor = ColorEncoding.EncodeTagAsColor("" + simObj.Type); objColor = ColorEncoding.EncodeTagAsColor("" + simObj.UniqueID); //Debug.Log ("renderer type " + simObj.Type + " " + simObj.name + " " + simObj.UniqueID + " " + MD5Hash(simObj.UniqueID) + " " + MD5Hash(simObj.UniqueID).GetHashCode()); } capturePasses [0].camera.WorldToScreenPoint(r.bounds.center); //mpb.SetVector ("_Scale", scaleVector); //mpb.SetVector ("_Shift", shiftVector); // Make transparent if light ray. if (simObj != null) { colorIds [objColor] = "" + simObj.UniqueID; colorIds [classColor] = "" + simObj.name; Debug.Log("colored " + simObj.UniqueID); } else { colorIds [objColor] = r.gameObject.name; if (r.gameObject.name == "Cube.100") { Debug.Log(r.gameObject.name); } } // if (r.material.name.ToLower().Contains ("lightray")) { // objColor.a = 0; // classColor.a = 0; // mpb.SetFloat ("_Opacity", 0); // // } else { // objColor.a = 1; // classColor.a = 1; // mpb.SetFloat ("_Opacity", 1); // } // // updated per @danielg - replaces commented out code if (r.material.name.ToLower().Contains("lightray")) { r.enabled = false; continue; } objColor.a = 1; classColor.a = 1; mpb.SetFloat("_Opacity", 1); mpb.SetColor("_CategoryColor", classColor); mpb.SetColor("_ObjectColor", objColor); r.SetPropertyBlock(mpb); } }
/// <summary> /// </summary> void Setup() { if (this._colors_by_category != null && this._colors_by_category.Length > 0) { foreach (var tag_color in this._colors_by_category) { if (!this.ColorsDictGameObject.ContainsKey(tag_color._Category_Name)) { this.ColorsDictGameObject.Add(tag_color._Category_Name, tag_color._Color); } } } if (this._segmentation_preset) { var segmentation_color_by_tags = this._segmentation_preset._color_by_categories; if (segmentation_color_by_tags != null) { foreach (var tag_color in segmentation_color_by_tags) { if (!this.ColorsDictGameObject.ContainsKey(tag_color._Category_Name)) { this.ColorsDictGameObject.Add(tag_color._Category_Name, tag_color._Color); } } } } this._all_renders = FindObjectsOfType <Renderer>(); if (!this._camera) { this._camera = this.GetComponent <Camera>(); } if (this.ColorsDictGameObject == null) { this.ColorsDictGameObject = new Dictionary <string, Color>(); } switch (this._segmentation_mode) { case SegmentationMode.Tag_: this._capture_passes = new[] { new SynthesisUtilities.CapturePass { _Name = "_tag_id", _ReplacementMode = SynthesisUtilities.ReplacementModes .Tag_id_, _SupportsAntialiasing = false } }; break; case SegmentationMode.Layer_: this._capture_passes = new[] { new SynthesisUtilities.CapturePass { _Name = "_layer_id", _ReplacementMode = SynthesisUtilities.ReplacementModes .Layer_id_, _SupportsAntialiasing = false } }; break; default: throw new ArgumentOutOfRangeException(); } SynthesisUtilities.SetupCapturePassesReplacementShader(this._camera, this.segmentation_shader, ref this._capture_passes); this.CheckBlock(); foreach (var a_renderer in this._all_renders) { a_renderer.GetPropertyBlock(this._block); string category_name; var category_int = 0; Color color; string shader_data_name; switch (this._segmentation_mode) { case SegmentationMode.Tag_: category_name = a_renderer.tag; shader_data_name = SynthesisUtilities._Shader_Tag_Color_Name; break; case SegmentationMode.Layer_: category_int = a_renderer.gameObject.layer; category_name = LayerMask.LayerToName(category_int); shader_data_name = SynthesisUtilities._Shader_Layer_Color_Name; break; default: throw new ArgumentOutOfRangeException(); } if (!this.ColorsDictGameObject.ContainsKey(category_name)) { if (!this._Replace_Untagged_Color) { switch (this._segmentation_mode) { case SegmentationMode.Tag_: category_int = category_name.GetHashCode(); color = ColorEncoding.EncodeTagHashCodeAsColor(category_int); //color = ColorEncoding.EncodeIdAsColor(category_int); break; case SegmentationMode.Layer_: color = ColorEncoding.EncodeLayerAsColor(category_int); break; default: //color = ColorEncoding.EncodeIdAsColor(category_int); throw new ArgumentOutOfRangeException(); } } else { color = this._Untagged_Color; } this.ColorsDictGameObject.Add(category_name, color); } else { color = this.ColorsDictGameObject[category_name]; } this._block.SetColor(shader_data_name, color); a_renderer.SetPropertyBlock(this._block); } }