Search Unity

[Solved] How to turn off anti-aliasing effect in RenderWithShader for use with for ML masks

Discussion in 'Scripting' started by don-gillett, Dec 3, 2019.

  1. don-gillett

    don-gillett

    Joined:
    May 21, 2019
    Posts:
    3
    I'm rendering out a scene with a special shader (using RenderWithShader) to be used for ML as ground truth data. The values in the image are masks with an object ID encoded into the color pixel. The problem I have is that for most of the image the color value is preserved but for the edges it is blended with the background. I'm not sure if this is a anti-alias effect or some filter mode setting that I don't understand. Attached is my shader.

    Code (CSharp):
    1. Shader "ColorMaskShader" {
    2.     Properties{
    3.         _ColorMask("ColorMask", Color) = (0,0,0,1)
    4.     }
    5.  
    6.         SubShader{
    7.             Tags { "RenderType" = "Opaque" }
    8.             LOD 100
    9.             Pass {
    10.                 Lighting Off
    11.                 ZWrite On
    12.                 Cull Back
    13.                 SetTexture[_] {
    14.                     constantColor[_ColorMask]
    15.                     Combine constant
    16.                 }
    17.             }
    18.     }
    19. }
    ColorMask is a color property that I set on the object (like a mesh renderer) with the following code:
    Code (CSharp):
    1. private void ApplyColorMask<T>(GameObject root, Func<T, Color> colorConverter) where T : Component
    2.     {
    3.         var children = root.GetComponentsInChildren<T>();
    4.         foreach (var child in children)
    5.         {
    6.             var renderers = child.transform.GetComponentsInChildren<Renderer>();
    7.             foreach (var renderer in renderers)
    8.             {
    9.                 MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
    10.                 renderer.GetPropertyBlock(propertyBlock);
    11.                 Color color = colorConverter(child);
    12.                 propertyBlock.SetColor("_ColorMask", color);
    13.                 renderer.SetPropertyBlock(propertyBlock);
    14.             }
    15.         }
    16.     }
    Edges.png
     
  2. don-gillett

    don-gillett

    Joined:
    May 21, 2019
    Posts:
    3
    [I realized I should have posted this to a graphics forum. I don't see how to move so I'll see if I get some action here before re-posting. Am I missing a way to move or delete so that I can repost?]
     
  3. don-gillett

    don-gillett

    Joined:
    May 21, 2019
    Posts:
    3
    Solved, the camera had MSAA turned on.