I’m having an issue with my 360 screenshots in a VR app (Oculus Quest). The code works well, but the images come out extremly dark. Guess it might have to do with linear color space converstion.
Thries everything in regards to rendertexture and Texture2D formats but no luck. The image in the rendertexture appear correct, but once they are saved come out almost black.
Any ideas? Code below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class CapturePanorama : MonoBehaviour
{
public bool stereoscopic = false;
public Camera targetCam;
public Camera camLft;
public Camera camRgt;
public RenderTexture cubeMapLft;
public RenderTexture cubeMapRgt;
public RenderTexture equiRendTex;
void Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
Capture();
}
}
public void Capture() {
if ( !stereoscopic) {
targetCam.RenderToCubemap(cubeMapLft);
cubeMapLft.ConvertToEquirect(equiRendTex);
} else {
camLft.RenderToCubemap(cubeMapLft);
cubeMapLft.ConvertToEquirect(equiRendTex,Camera.MonoOrStereoscopicEye.Right);
camRgt.RenderToCubemap(cubeMapRgt);
cubeMapRgt.ConvertToEquirect(equiRendTex,Camera.MonoOrStereoscopicEye.Left);
}
Save(equiRendTex);
}
public void Save(RenderTexture rt) {
fileNameJPG = Application.dataPath.Replace("/Assets", "") + "/Exports/" + "pano360.JPG";
Texture2D tex = new Texture2D(rt.width, rt.height,TextureFormat.RGB24, false,false);
//Texture2D(int width, int height, TextureFormat textureFormat = TextureFormat.RGBA32, bool mipChain = true, bool linear = false);
RenderTexture.active = rt;
tex.ReadPixels(new Rect(0,0,rt.width,rt.height), 0, 0);
RenderTexture.active = null;
byte[] bytes = tex.EncodeToJPG(85);
System.IO.File.WriteAllBytes(fileNameJPG, bytes);
}
}