Skip to content

Commit 63762ce

Browse files
Fixing wrong colors in semantic segmentation due to sRGB conversion by changing the shader parameter to a Vector, bypassing sRGB conversion altogether. (#46)
1 parent e5eed6a commit 63762ce

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,18 @@ protected override void Setup()
128128

129129
m_AsyncAnnotations = new Dictionary<int, AsyncAnnotation>();
130130

131-
var renderTextureDescriptor = new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8);
132131
if (targetTexture != null)
132+
{
133+
if (targetTexture.sRGB)
134+
{
135+
Debug.LogError("targetTexture supplied to SemanticSegmentationLabeler must be in Linear mode. Disabling labeler.");
136+
this.enabled = false;
137+
}
138+
var renderTextureDescriptor = new RenderTextureDescriptor(width, height, GraphicsFormat.R8G8B8A8_UNorm, 8);
133139
targetTexture.descriptor = renderTextureDescriptor;
140+
}
134141
else
135-
m_TargetTextureOverride = new RenderTexture(renderTextureDescriptor);
142+
m_TargetTextureOverride = new RenderTexture(width, height, 8, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
136143

137144
targetTexture.Create();
138145
targetTexture.name = "Labeling";

com.unity.perception/Runtime/GroundTruth/Resources/SemanticSegmentation.shader

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
Properties
44
{
5-
[PerObjectData] LabelingId("Labeling Id", Color) = (0,0,0,1)
5+
[PerObjectData] LabelingId("Labeling Id", Vector) = (0,0,0,1)
66
}
77

88
HLSLINCLUDE

com.unity.perception/Runtime/GroundTruth/SemanticSegmentationCrossPipelinePass.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public override void SetupMaterialProperties(MaterialPropertyBlock mpb, Renderer
6969

7070
//Set the labeling ID so that it can be accessed in ClassSemanticSegmentationPass.shader
7171
if (found)
72-
mpb.SetColor(k_LabelingId, entry.color);
72+
mpb.SetVector(k_LabelingId, entry.color);
7373
}
7474
}
7575
}

com.unity.perception/Tests/Runtime/GroundTruthTests/SegmentationGroundTruthTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void OnDestroy()
4444
[UnityPlatform(exclude = new[] {RuntimePlatform.LinuxEditor, RuntimePlatform.LinuxPlayer})]
4545
public class SegmentationPassTests : GroundTruthTestBase
4646
{
47-
static readonly Color32 k_SemanticPixelValue = Color.blue;
47+
static readonly Color32 k_SemanticPixelValue = new Color32(10, 20, 30, Byte.MaxValue);
4848

4949
public enum SegmentationKind
5050
{
@@ -232,7 +232,7 @@ void OnSegmentationImageReceived<T>(int frameCount, NativeArray<T> data, RenderT
232232
catch (Exception)
233233
{
234234
//uncomment to get RenderDoc captures while this check is failing
235-
//RenderDoc.EndCaptureRenderDoc(gameView);
235+
//UnityEditorInternal.RenderDoc.EndCaptureRenderDoc(gameView);
236236
throw;
237237
}
238238
}

0 commit comments

Comments
 (0)