Trying to export faithfully my segmentation mask from a blueprint graph - synthetic dataset for detection using segmentation masks

UE 5.7.4 Bug Report – SceneCapture2D Post Process RenderTarget exports incorrect image

Summary

I am generating a synthetic dataset (RGB + segmentation mask) using two SceneCaptureComponent2Ds. The mask of my vehicle is taking into account the objects occluding it. Thus, the expected shape is not perfectly regular but occluded where other objects stand. I use CustomDepth, SceneDepth and CustomStencil. The resulting mask works as expected. However, once exported it is not rendered at all, or corrupted, or wrong. I did not implement a blueprint loop as I first want to ensure one iteration works well. I therefore want an automated generation->capture->export process (see all details below, I tried numerous settings/configs). Thanks in advance!!

The RGB capture exports correctly.

The mask capture renders correctly inside Unreal Engine (TextureRenderTarget preview), but exporting the RenderTarget produces either:

  • the RGB image instead of the mask,

  • an empty/corrupted image,

  • or an unreadable file,

depending on the SceneCapture settings.

This prevents generation of synchronized RGB/mask datasets.


Engine version

Unreal Engine 5.7.4


Goal

I have two SceneCapture2D components:

  • RGB SceneCapture

  • Mask SceneCapture

Both share the same transform and therefore should produce perfectly aligned images.

The mask SceneCapture uses a Post Process Material to generate a binary segmentation mask while preserving occlusions.


RGB SceneCapture settings

  • Capture Source:

    • Final Color (LDR)
  • Texture Target:

    • 1024×1024

    • RTF_RGBA8

  • Post Process Material:

    • None
  • Primitive Render Mode:

    • Render Scene Primitives
  • Composite Mode:

    • Overwrite

RGB exports correctly.


Mask SceneCapture settings

  • Capture Source:

    • Tested:

      • Final Color (LDR)

      • SceneColor HDR

      • SceneColor HDR + SceneDepth

      • Final Color HDR (Linear Working Color Space)

  • Texture Target:

    • 1024×1024

    • RTF_RGBA8

    • Target Gamma tested at 0.0 and 2.2

  • Primitive Render Mode:

    • Render Scene Primitives
  • Composite Mode:

    • Overwrite
  • Post Process Blend Weight:

    • 1.0
  • Post Process Material:

    • Added directly to SceneCaptureComponent2D
  • Project Settings

    • Custom Depth-Stencil Pass:

      • Enabled with Stencil

Post Process Material

Material Domain:

Post Process

Blendable Location:

Scene Color After Tonemap

Material outputs only through Emissive.

Logic:

  1. Read CustomDepth

  2. Read SceneDepth

  3. Compare both depths to determine visibility/occlusion

  4. Read CustomStencil

  5. Keep only stencil == 1

  6. Multiply visibility by stencil

  7. Output to Emissive

The material correctly produces a binary mask inside the RenderTarget preview.


Expected behavior

The exported PNG should exactly match the TextureRenderTarget preview.


Actual behavior

Case 1

Capture Every Frame = ON

Always Persist Rendering State = OFF

TextureRenderTarget preview:

Correct binary mask.

Export:

RGB image (identical to RGB SceneCapture).


Case 2

Capture Every Frame = OFF

Always Persist Rendering State = OFF

TextureRenderTarget preview:

RGB image (same as RGB capture).

Export:

RGB image.


Case 3

Capture Every Frame = OFF

Always Persist Rendering State = ON

TextureRenderTarget preview:

Correct binary segmentation mask.

Export:

Empty/corrupted/unreadable PNG.

File sizes vary around:

  • approximately 30 KB

  • approximately 2 MB

depending on capture source.

The exported file cannot be opened.


Additional experiments

Constant color material

The complete segmentation material was replaced by:

Material Domain = Post Process

Constant3Vector(1,0,0)

connected directly to Emissive.

Result:

TextureRenderTarget preview:

Solid red.

Export:

Empty/corrupted image.

Therefore the issue does not appear to originate from CustomDepth or CustomStencil.


Material simplification

The following were tested independently:

  • CustomStencil only

  • CustomDepth only

  • SceneDepth only

No change.


Capture Source tests

Tested:

  • Final Color (LDR)

  • SceneColor HDR

  • SceneColor HDR + SceneDepth

  • Final Color HDR Linear Working Color Space

No configuration solved the issue.


Primitive Render Mode

Tested:

  • Render Scene Primitives (Legacy)

  • Render Scene Primitives

No difference.


Ray Tracing

Use Ray Tracing If Enabled:

Tested ON and OFF.

No difference.


Support UAV

Enabled and disabled.

No difference.


Composite Mode

Overwrite.

No difference.


Post Process Blend Weight

1.0

No difference.


Capture timing

Tested:

  • CaptureScene

  • Delay Until Next Tick

  • 1 second delays

  • Capturing RGB first

  • Capturing Mask first

  • Multiple CaptureScene calls

No change.


Export methods

Tested:

  • Export To Disk

  • Export Render Target

Both produce the same issue.


Texture Target

1024 × 1024

RTF_RGBA8

Target Gamma tested at:

  • 0.0

  • 2.2

Changing gamma only affects RGB brightness.

It does not affect the mask export problem.


Observations

The key observation is:

The TextureRenderTarget preview consistently displays the correct segmentation mask while the exported file does not correspond to the displayed RenderTarget.

This suggests that either:

  • ExportRenderTarget / ExportToDisk is reading a different GPU resource than the RenderTarget preview,

or

  • SceneCapture2D post-process output is not correctly resolved before export.

Why I believe this is a rendering issue

The problem persists after eliminating:

  • timing issues

  • asynchronous image writing

  • capture ordering

  • CustomDepth logic

  • CustomStencil logic

  • SceneDepth logic

  • Capture Source

  • RenderTarget format

  • Primitive Render Mode

  • Ray tracing

  • UAV support

Replacing the entire segmentation material with a constant red output still results in a red RenderTarget preview but an invalid exported image.

This suggests that the RenderTarget itself is being rendered correctly but the exported image is not reading the same rendered contents.