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.
Shader "ColorMaskShader" {
Properties{
_ColorMask("ColorMask", Color) = (0,0,0,1)
}
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 100
Pass {
Lighting Off
ZWrite On
Cull Back
SetTexture[_] {
constantColor[_ColorMask]
Combine constant
}
}
}
}
ColorMask is a color property that I set on the object (like a mesh renderer) with the following code:
private void ApplyColorMask<T>(GameObject root, Func<T, Color> colorConverter) where T : Component
{
var children = root.GetComponentsInChildren<T>();
foreach (var child in children)
{
var renderers = child.transform.GetComponentsInChildren<Renderer>();
foreach (var renderer in renderers)
{
MaterialPropertyBlock propertyBlock = new MaterialPropertyBlock();
renderer.GetPropertyBlock(propertyBlock);
Color color = colorConverter(child);
propertyBlock.SetColor("_ColorMask", color);
renderer.SetPropertyBlock(propertyBlock);
}
}
}
