Camera.targetTexture和SetTargetBuffers的区别

知识点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.targetTexture和SetTargetBuffers的区别
这里会有一个Camera.ImageEffects,这是后处理效果。我猜测是OnRenderImage的方法调用。
这是将TempBuffer中的内容拷贝到BackBuffer的过程。
而RenderTexture.ResolveAA则是因为相机开启了抗锯齿。如果我们把它关闭了,则不会有这行了。
Camera.targetTexture和SetTargetBuffers的区别

知识点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);
    }
}

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);
    }
}

Camera.targetTexture和SetTargetBuffers的区别
后者没有了ImageEffects的调用了。

Camera.targetTexture和SetTargetBuffers的区别Camera.targetTexture和SetTargetBuffers的区别 wodownload2 发布了616 篇原创文章 · 获赞 96 · 访问量 33万+ 他的留言板 关注
上一篇:使用CDO发送电子邮件并首先检查连接状态


下一篇:[LNOI2014] LCA(树链剖分+主席树+标记永久化)