Search Unity

Bug Capture depth using simulation capture gets the depth of the previous frame

Discussion in 'Unity Simulation' started by hadardasim_isi, Feb 17, 2022.

Thread Status:
Not open for further replies.
  1. hadardasim_isi

    hadardasim_isi

    Joined:
    Feb 5, 2021
    Posts:
    2
    Hi,
    I am using simulation capture in HDRP project to capture RGB and depth per frame.
    The RGB image is correct but the depth I am getting is of the previous frame.
    When using the same capture code with URP, both RGB and depth are correct.

    Versions information
    • Unity Editor 2021.2.10f1 (Windows X64)
    • HDRP 12.1.4
    • Simulation capture 0.0.10-preview.24
    Example HDRP project
    https://github.com/hadardasim/HDRP-Capture

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Simulation;
    5. using UnityEngine.Experimental.Rendering;
    6. using System.IO;
    7.  
    8. public class CameraHandler : MonoBehaviour
    9. {
    10.     // number of frames to move from one side to the other
    11.     public int moveFrameCounter = 4;
    12.     public Vector3 moveOffset = new Vector3(4, 0, 0);
    13.  
    14.     Vector3 startPosition;
    15.     string baseDir;
    16.     Camera captureCamera;
    17.  
    18.  
    19.     void Start()
    20.     {
    21.         baseDir = Manager.Instance.GetDirectoryFor(DataCapturePaths.ScreenCapture);
    22.         startPosition = transform.position;
    23.         captureCamera = GetComponent<Camera>();
    24.     }
    25.  
    26.    
    27.     void Update()
    28.     {
    29.         int _step = Time.frameCount % (moveFrameCounter * 2);
    30.         float _ratio = _step / (float)moveFrameCounter;
    31.         if (_step > moveFrameCounter)
    32.             _ratio = 2 - _ratio;
    33.         transform.position = startPosition + moveOffset * _ratio;
    34.     }
    35.  
    36.     private void LateUpdate()
    37.     {
    38.         if (Time.frameCount < 10 || Time.frameCount > 20)
    39.             return;
    40.  
    41.         string colorPath = Path.Combine(baseDir, $"rgb_{Time.frameCount}.png");
    42.         string depthPath = Path.Combine(baseDir, $"depth_{Time.frameCount}.exr");
    43.  
    44.         CaptureCamera.CaptureColorAndDepthToFile(captureCamera, GraphicsFormat.B8G8R8A8_SRGB, colorPath, CaptureImageEncoder.ImageFormat.Png,
    45.             GraphicsFormat.R32_SFloat, depthPath, CaptureImageEncoder.ImageFormat.Exr);
    46.     }
    47. }
     

    Attached Files:

Thread Status:
Not open for further replies.