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也表示不需要写回显存。