RenderTextureMemoryless和RenderBufferStoreAction

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class RTTest : MonoBehaviour
{
    public MeshFilter m1;
    public MeshFilter m2;
    public MeshFilter m3;

    private RenderTexture m_rt1;
    private RenderTexture m_rt2;
    public Material m_mat1;
    public Material m_mat2;
    public Camera m_camera;
    private int m_texID = Shader.PropertyToID("_MainTex");


    private void Start()
    {
       
        m_rt2 = RenderTexture.GetTemporary(Screen.width, Screen.height, 16,
            RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 1, RenderTextureMemoryless.None);
        m_rt2.name = "b33333";

        m_rt1 = RenderTexture.GetTemporary(Screen.width, Screen.height, 0,
            RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default, 2, RenderTextureMemoryless.MSAA);
        m_rt1.name = "a33333";


        CommandBuffer cb = new CommandBuffer();
        cb.name = "draw";
        cb.SetRenderTarget(m_rt1, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.DontCare,
            m_rt2, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
        cb.ClearRenderTarget(true, true, new Color(1, 1, 1, 1));

        //CommandBuffer cb2 = new CommandBuffer();
        //cb2.name = "draw2";
        //cb2.SetRenderTarget(m_rt1, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);

        m_camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, cb);
        //m_camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, cb2);

        //cb2.SetGlobalTexture(m_texID, m_rt1);
        cb.DrawMesh(m1.mesh, Matrix4x4.identity, m_mat1);

        //cb2.DrawMesh(m2.mesh, Matrix4x4.identity, m_mat1);


        Matrix4x4 m = Matrix4x4.identity;
        m.SetTRS(m3.transform.position, Quaternion.identity, Vector3.one);
        cb.DrawMesh(m3.mesh, m, m_mat1);
    }

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        Graphics.Blit(m_rt1, destination);
    }
}

上面的代码显示正常,不知道为啥。

总结:
RenderTextureMemoryless.color和RenderBufferStoreAction.DontCare只要只要只要有一个设置了,效果不对。
RenderTextureMemoryless.color表示颜色不需要写回显存memoryless
RenderBufferStoreAction.DontCare也表示不需要写回显存。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值