https://docs.unity3d.com/ScriptReference/Graphics.Blit.html
https://blog.csdn.net/candycat1992/article/details/39255575
Leave feedback
public static void Blit(Texture source, RenderTexture dest);
public static void Blit(Texture source, RenderTexture dest, Material mat, int pass = -1);
public static void Blit(Texture source, Material mat, int pass = -1);
public static void Blit(Texture source, RenderTexture dest, Vector2 scale, Vector2 offset);
public static void Blit(Texture source, RenderTexture dest, int sourceDepthSlice, int destDepthSlice);
public static void Blit(Texture source, Material mat, int pass, int destDepthSlice);
public static void Blit(Texture source, RenderTexture dest, Vector2 scale, Vector2 offset, int sourceDepthSlice, int destDepthSlice);
source:source texture
dest:the desination RenderTexture. set this to null to blit directly to screen.
mat:material to use. material’s shader could to some post-processing effect.
pass:if -1 (default), draws all passes in the material. otherwise, draws given pass only.
offset:offset applied to the source texture coordinate.
scale:scale applied to the source texture coordinate.
description:
copies source texture into destination render texture with a shader.
this is mostly used for implementing post-processing effects.
blit sets dest as the render target, set source _MainTex property on the material, and draws a full-screen quad.
if dest is null, the screen backbuffer is used as the blit destination, except if the main camera is currently set to render to a render texture (that is Camera.main has a non-null targetTexture property). in that cast the blit uses the render target of the main camera as destination. in order to ensure that the blit is actually done to the screen backbuffer, make sure to set Camera.main.targetTexture to null before calling blit.
note that if u want to use depth or stencil buffer that is part of source (render) texture, u will have to do equivalent of blit functionally manually.
note that a call to blit with source and dest set to the same RenderTexture may result in undefined behaviour. a better approach is to either ues Custom Render Textures with double buffering, or use two render textures and alternate between them to implement double buffering manually.
using UnityEngine;
public class Example : MonoBehaviour
{ // Copies aTexture to rTex and displays it in all cameras.
Texture aTexture;
RenderTexture rTex;
void Start()
{
if (!aTexture || !rTex)
{
Debug.LogError("A texture or a render texture are missing, assign them.");
}
}
void Update()
{
Graphics.Blit(aTexture, rTex);
}
}
注:
如果主相机上的有render target,则这个OnRenderImage的destination即为整个render texture。否则是:
否则就是back buffer,并且会直接画到屏幕上。
看这个函数:
首先将原始图片,经过dofMaterial材质处理,得到的结果拷贝到coc中去,coc为中间变量render texture。
然后将coc拷贝到destination中去,而此时destination为back buffer,所以会绘制到屏幕上去。
要保证绘制到屏幕上去,那么就需要保证blit的函数的dest为null,也就是摄像机的target texture为null。