Unity Ver: 2019.4.18f1
Hello,
I’m getting the following warning in some scenes of my game:
I have a camera script (below) that basically creates a low-res pixelation camera, and a high res camera which is merged together so the result is things like world text can still be sharp and readable in a scene while everything else like geometry is pixelated.
Should I be concerned about this warning? The camera appears to function as expected so it doesn’t appear to affect anything, but I’m always eager for a nice clean console.
I didn’t write the script I’m using. It was courtesy of @bgolus :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;
[RequireComponent(typeof(Camera))]
public class LowResCam : MonoBehaviour
{
public int lowResHeight = 160;
public int highResMult = 2;
public LayerMask offscreenLayers;
public Shader depthFillShader;
private Material depthCopyMat;
private Material depthFillMat;
private Material compositeMat;
// private new Camera camera;
private Camera newCamera;
private Camera lowCamera;
private Camera highCamera;
private CommandBuffer mainCameraDepthCopy;
private CommandBuffer highFill;
private RenderTexture lowRT;
private RenderTexture highRT;
void Awake()
{
newCamera = GetComponent<Camera>();
lowCamera = new GameObject("Offscreen Camera Low", typeof(Camera)).GetComponent<Camera>();
lowCamera.enabled = false;
lowCamera.transform.SetParent(newCamera.transform, false);
lowCamera.CopyFrom(newCamera);
lowCamera.renderingPath = RenderingPath.Forward;
lowCamera.cullingMask ^= offscreenLayers;
lowCamera.depthTextureMode |= DepthTextureMode.Depth;
depthFillMat = new Material(depthFillShader);
mainCameraDepthCopy = new CommandBuffer();
mainCameraDepthCopy.name = "Copy Depth Texture from Main Camera";
mainCameraDepthCopy.SetGlobalTexture("_MainCameraDepthTexture", BuiltinRenderTextureType.Depth);
lowCamera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, mainCameraDepthCopy);
highCamera = new GameObject("Offscreen Camera High", typeof(Camera)).GetComponent<Camera>();
highCamera.enabled = false;
highCamera.transform.SetParent(newCamera.transform, false);
highCamera.CopyFrom(newCamera);
highCamera.renderingPath = RenderingPath.Forward;
highCamera.cullingMask = offscreenLayers;
highCamera.depthTextureMode = DepthTextureMode.None;
highCamera.useOcclusionCulling = false;
highCamera.backgroundColor = Color.clear;
highCamera.clearFlags = CameraClearFlags.Nothing;
highFill = new CommandBuffer();
highFill.name = "Fill Color & Depth";
highCamera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, highFill);
newCamera.cullingMask = 0;
}
void OnEnable()
{
float ratio = (float)Screen.width / (float)Screen.height;
int lowResWidth = Mathf.RoundToInt((float)lowResHeight * ratio);
int highResWidth = Mathf.Min(Screen.width, lowResWidth * highResMult);
int highResHeight = Mathf.Min(Screen.height, lowResHeight * highResMult);
lowRT = new RenderTexture(lowResWidth, lowResHeight, 24);
lowRT.filterMode = FilterMode.Point;
lowRT.Create();
highRT = new RenderTexture(highResWidth, highResHeight, 24);
highRT.filterMode = FilterMode.Point;
highRT.Create();
highFill.Clear();
highFill.Blit(lowRT, BuiltinRenderTextureType.CurrentActive);
highFill.Blit(BuiltinRenderTextureType.Depth, BuiltinRenderTextureType.CurrentActive, depthFillMat);
}
void OnDisable()
{
Destroy(lowRT);
Destroy(highRT);
}
void OnPreRender()
{
lowCamera.projectionMatrix = newCamera.projectionMatrix;
highCamera.projectionMatrix = newCamera.projectionMatrix;
lowCamera.targetTexture = lowRT;
highCamera.targetTexture = highRT;
}
void OnRenderImage(RenderTexture src, RenderTexture dst)
{
lowCamera.Render();
highCamera.Render();
Graphics.Blit(highRT, dst);
}
}