知识点1:Camera.targetTexture
https://docs.unity3d.com/ScriptReference/Camera-targetTexture.html
public RenderTexture targetTexture;
usually cameras render directly to screen, but for some effects it is useful to make a camera render into a texture.
this is done by creating a RenderTexture object and setting it as targetTexture on the camera. the camera will then render into that texture.
when targetTexture is null, camera renders to screen.
when rendering into a texture, the camera always renders into the whole texture;
it is also possible to make camera render into separate RenderBuffers, or into multiple textures at once, using SetTargetBuffers function.
知识点2:Camera.ImageEffects
这里会有一个Camera.ImageEffects,这是后处理效果。我猜测是OnRenderImage的方法调用。
这是将TempBuffer中的内容拷贝到BackBuffer的过程。
而RenderTexture.ResolveAA则是因为相机开启了抗锯齿。如果我们把它关闭了,则不会有这行了。
知识点3:Camera.targetTexture和SetTargetBuffers的区别
如果我们使用下面的代码:
using UnityEngine;
public class SetTargetBuffers : MonoBehaviour
{
public Camera m_camera;
public RenderTexture rt;
void Start()
{
rt = new RenderTexture(m_camera.pixelWidth, m_camera.pixelHeight, 0);
rt.name = "xxx";
m_camera.targetTexture = rt;
//m_camera.SetTargetBuffers(rt.colorBuffer, rt.depthBuffer);
}
private void OnPostRender()
{
Debug.LogError(RenderTexture.active);
}
}
而如果使用这样的代码:
using UnityEngine;
public class SetTargetBuffers : MonoBehaviour
{
public Camera m_camera;
public RenderTexture rt;
void Start()
{
rt = new RenderTexture(m_camera.pixelWidth, m_camera.pixelHeight, 0);
rt.name = "xxx";
//m_camera.targetTexture = rt;
m_camera.SetTargetBuffers(rt.colorBuffer, rt.depthBuffer);
}
private void OnPostRender()
{
Debug.LogError(RenderTexture.active);
}
}
后者没有了ImageEffects的调用了。