Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Source/URLab/Private/MuJoCo/Components/Sensors/MjCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,12 @@ void UMjCamera::SetupRenderTarget()
const bool bDepthMode = (CaptureMode == EMjCameraMode::Depth);
if (bDepthMode)
{
RT->RenderTargetFormat = ETextureRenderTargetFormat::RTF_R32f;
RT->InitCustomFormat(resolution[0], resolution[1], PF_R32_FLOAT, /*bForceLinearGamma=*/true);
// UE 5.7's Vulkan backend cannot convert VK_FORMAT_R32_SFLOAT to
// FLinearColor during ReadSurfaceData (it asserts in
// VulkanRenderTarget.cpp). Use a four-channel float target so the
// stock cross-RHI readback path is valid; scene depth remains in R.
RT->RenderTargetFormat = ETextureRenderTargetFormat::RTF_RGBA32f;
RT->InitCustomFormat(resolution[0], resolution[1], PF_A32B32G32R32F, /*bForceLinearGamma=*/true);
}
else
{
Expand Down Expand Up @@ -711,10 +715,8 @@ void UMjCamera::RequestReadback()

if (CaptureMode == EMjCameraMode::Depth)
{
// PF_R32_FLOAT render target: ReadSurfaceFData lands a 4-channel
// FLinearColor per pixel; we keep just the R channel post-fence.
// Slightly wasteful at readback (4x temp memory) but uses the
// stock UE async API.
// RGBA32f render target: ReadSurfaceData lands a four-channel
// FLinearColor per pixel; scene depth is carried in R.
ENQUEUE_RENDER_COMMAND(MjCameraReadbackDepth)(
[Resource, FloatPtr, Rect](FRHICommandListImmediate& RHICmdList) {
TArray<FLinearColor> Scratch;
Expand Down
2 changes: 1 addition & 1 deletion Source/URLab/Private/UI/MjCameraFeedEntry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void UMjCameraFeedEntry::RefreshBrush()
? W * static_cast<float>(BoundCamera->resolution[1]) / static_cast<float>(BoundCamera->resolution[0])
: W * 0.75f;

// Depth RT is R32f — slate can't display it directly. Build (or reuse)
// Depth RT is RGBA32f (linear depth in R) — slate can't display it directly. Build (or reuse)
// a BGRA UTexture2D preview and bind THAT as the brush. For all other
// modes the RT is BGRA8 and we can bind it directly.
UObject* BrushResource = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Source/URLab/Public/UI/MjCameraFeedEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class URLAB_API UMjCameraFeedEntry : public UUserWidget
/** @brief (Re-)applies the FSlateBrush to FeedImage using the current render target. */
void RefreshBrush();

/** @brief Depth mode: CPU-copy the R32f RT into DepthPreviewTexture as
/** @brief Depth mode: CPU-copy the RGBA32f RT (depth in R) into DepthPreviewTexture as
* grayscale, normalised by the camera's DepthNear/Far range. */
void UpdateDepthPreview();

Expand Down
11 changes: 7 additions & 4 deletions Source/URLabEditor/Private/Tests/MjCameraTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ bool FMjCameraRealModeConfig::RunTest(const FString& Parameters)

// ============================================================================
// URLab.Camera.DepthMode_ConfiguresSceneDepthFloat
// Depth mode → RT is R32f, CaptureSource is SCS_SceneDepth, near clip overridden.
// Depth mode → RT is RGBA32f (cross-RHI float readback; depth is in R),
// CaptureSource is SCS_SceneDepth, near clip overridden.
// ============================================================================
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FMjCameraDepthModeConfig,
"URLab.Camera.DepthMode_ConfiguresSceneDepthFloat",
Expand All @@ -120,7 +121,8 @@ bool FMjCameraDepthModeConfig::RunTest(const FString& Parameters)
S.Cleanup();
return false;
}
TestEqual(TEXT("RT format"), (int32)Cam->RenderTarget->RenderTargetFormat, (int32)ETextureRenderTargetFormat::RTF_R32f);
TestEqual(TEXT("RT format"), (int32)Cam->RenderTarget->RenderTargetFormat, (int32)ETextureRenderTargetFormat::RTF_RGBA32f);
TestEqual(TEXT("pixel format"), (int32)Cam->RenderTarget->GetFormat(), (int32)PF_A32B32G32R32F);

if (TestNotNull(TEXT("capture component"), Cam->CaptureComponent))
{
Expand All @@ -143,7 +145,7 @@ bool FMjCameraDepthModeConfig::RunTest(const FString& Parameters)
// ============================================================================
// URLab.Camera.ModeCycle_RebuildsRenderTarget
// Toggling streaming off then on after a mode change rebuilds the RT with
// the new format. Real → Depth should switch RTF_RGBA8 → RTF_R32f.
// the new format. Real → Depth should switch RTF_RGBA8 → RTF_RGBA32f.
// ============================================================================
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FMjCameraModeCycleRebuildsRT,
"URLab.Camera.ModeCycle_RebuildsRenderTarget",
Expand Down Expand Up @@ -176,7 +178,8 @@ bool FMjCameraModeCycleRebuildsRT::RunTest(const FString& Parameters)
S.Cleanup();
return false;
}
TestEqual(TEXT("new format"), (int32)Cam->RenderTarget->RenderTargetFormat, (int32)ETextureRenderTargetFormat::RTF_R32f);
TestEqual(TEXT("new format"), (int32)Cam->RenderTarget->RenderTargetFormat, (int32)ETextureRenderTargetFormat::RTF_RGBA32f);
TestEqual(TEXT("new pixel format"), (int32)Cam->RenderTarget->GetFormat(), (int32)PF_A32B32G32R32F);

S.Cleanup();
return true;
Expand Down