Graphics.Blit

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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值