- Home /
Question by
GolRouge · Jul 20, 2021 at 08:02 PM ·
screenshotpngcapturepanoramacapturescreenshot
Capturing 360 Image causes to darken the image and show ghosting and artifacts
I made a code to capture 360 image using render texture, When I capture image to render texture it appears fine but when I Encode it to PNG or JPG the problem occurs. .
The image darkens and artifacts / ghosting is very visible.
Here's the image encoded to PNG using code. https://imgur.com/KJDHsWw
Here's a photoshopped version of the image to increase lighting. https://imgur.com/VmUPNaz
and Here's a zoomed images of the artifact https://imgur.com/sSVocSV https://imgur.com/SZlVo9O
below is my code:
public class PanoramaCapture : MonoBehaviour
{
public Camera targetCamera;
public RenderTexture cubemapLeft;
public RenderTexture equirectRT;
public string fileName;
public int captureInstance;
public int imageWidth = 4096;
private void Start()
{
if (fileName == null)
{
fileName = "KitchenCombinations_";
}
captureInstance = 1;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Return))
{
Capture();
}
}
void Capture()
{
targetCamera.stereoSeparation = 0f;
targetCamera.RenderToCubemap(cubemapLeft);
cubemapLeft.ConvertToEquirect(equirectRT);
Save(equirectRT);
captureInstance += 1;
}
public void Save(RenderTexture rt)
{
Texture2D tex = new Texture2D(rt.width, rt.height);
RenderTexture.active = rt;
tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
RenderTexture.active = null;
byte[] bytes = tex.EncodeToPNG();
//data path could be in the game folder or database but we have to figure that out
string path = Application.dataPath + "/" + fileName + captureInstance.ToString() + ".png";
System.IO.File.WriteAllBytes(path, bytes);
}
Comment