Hello,
I’m facing an issue with URP 7.5.3 on VR devices (Oculus and Pico G2 4K)
In fact, I am trying to render a 360 stereo image during the runtime process. Therefore I used the “Camera.RenderToCubemap” function provided, for each eye, and then convert it to Equirect using the “Camera.ConvertToEquirect” to get the full texture.
private RenderTexture leftEye;
private RenderTexture rightEye;
private RenderTexture equirect;
public Camera LeftCameraEye;
public Camera RightCameraEye;
public bool shouldRenderCubemap;
private void Start()
{
leftEye = RenderTexture.GetTemporary(ResolutionWidth, ResolutionHeight, 24, RenderTextureFormat.ARGB32);
rightEye = RenderTexture.GetTemporary(ResolutionWidth, ResolutionHeight, 24, RenderTextureFormat.ARGB32);
leftEye.dimension = UnityEngine.Rendering.TextureDimension.Cube;
rightEye.dimension = UnityEngine.Rendering.TextureDimension.Cube;
equirect = RenderTexture.GetTemporary(ResolutionWidth, 2 * ResolutionHeight, 24, RenderTextureFormat.ARGB32);
}
private void LateUpdate()
{
if (shouldRenderCubemap)
{
CaptureEye(LeftCameraEye, Camera.MonoOrStereoscopicEye.Left, leftEye);
CaptureEye(RightCameraEye, Camera.MonoOrStereoscopicEye.Right, rightEye);
shouldRenderCubemap = false;
SaveEquirectCapture();
}
}
private void CaptureEye(Camera eyeCamera, Camera.MonoOrStereoscopicEye eyeSide, RenderTexture target)
{
var rect = new Rect(0, 0, 1, 1);
var r = eyeCamera.rect;
eyeCamera.rect = rect;
eyeCamera.RenderToCubemap(target, 63, eyeSide);
eyeCamera.rect = r;
target.ConvertToEquirect(equirect, eyeSide);
}
private void OnDestroy()
{
RenderTexture.ReleaseTemporary(leftEye);
RenderTexture.ReleaseTemporary(rightEye);
RenderTexture.ReleaseTemporary(equirect);
}
private void SaveEquirectCapture()
{
var rt = RenderTexture.active;
RenderTexture.active = equirect;
var stereoTex = new Texture2D(equirect.width, equirect.height, TextureFormat.ARGB32, false);
stereoTex.ReadPixels(new Rect(0, 0, equirect.width, equirect.height), 0, 0);
RenderTexture.active = rt;
var bytes = stereoTex.EncodeToPNG();
System.IO.File.WriteAllBytes(System.IO.Path.Combine(Application.persistentDataPath, "Capture_" + DateTime.Now.ToString("dd-MM-yy_H-mm-ss") + ".png"), bytes);
DestroyImmediate(stereoTex);
}
However, the result that I get from the Editor is different from the one that I get in the Headset.
Here is the result from the Editor:
Here is the result from the Pico G2 Headset (the result is the same on the Oculus Quest 1):
As you can see in the images, by using the same approach from the Editor and from the Headset, the image got from the headset is weird, whereas the one from the editor is what I wanted to obtain from the headset.
I’m using:
- Unity 2019.4.21ff (I got the same result with Unity 2019.4.20f1).
- URP 7.5.3.
- Oculus Quest 1.
- Pico G2 4K.
Does someone have any idea of what is happening and how to resolve this?
Thanks in advance for your reply.