When i use CommandBuffer to achive PostProcessing. Something goes wrong, when i enable MSAA.
The Image don't change, when i change camera transform.
Here is my script code:
int rtID = Shader.PropertyToID("_TempRT");
Mesh mesh = new Mesh();
mesh.vertices = new Vector3[] {
new Vector3(-1,-1,0.5f),
new Vector3(-1,1,0.5f),
new Vector3(1,1,0.5f),
new Vector3(1,-1,0.5f)
};
mesh.uv = new Vector2[] {
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,0),
new Vector2(1,1)
};
mesh.SetIndices(new int[] { 0, 1, 2, 3 }, MeshTopology.Quads, 0);
buffer = new CommandBuffer();
buffer.name = "TestBuffer";
camera = GetComponent();
tempRT = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.DefaultHDR);
buffer.SetGlobalTexture(rtID,tempRT);
buffer.CopyTexture(BuiltinRenderTextureType.CameraTarget, tempRT);
buffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
buffer.DrawMesh(mesh, Matrix4x4.identity, mat, 0, 0);
camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, buffer);
And here is my shader Code:
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_TempRT, i.uv);
col = tex2Dlod(_TempRT, half4(i.uv, 0, 0));
col *= float4(1,0,0,1);
return col;
}
,Here is my script code:
int rtID = Shader.PropertyToID("_TempRT");
Mesh mesh = new Mesh();
mesh.vertices = new Vector3[] {
new Vector3(-1,-1,0.5f),
new Vector3(-1,1,0.5f),
new Vector3(1,1,0.5f),
new Vector3(1,-1,0.5f)
};
mesh.uv = new Vector2[] {
new Vector2(0,1),
new Vector2(0,0),
new Vector2(1,0),
new Vector2(1,1)
};
mesh.SetIndices(new int[] { 0, 1, 2, 3 }, MeshTopology.Quads, 0);
buffer = new CommandBuffer();
buffer.name = "TestBuffer";
camera = GetComponent();
tempRT = RenderTexture.GetTemporary(camera.pixelWidth, camera.pixelHeight, 0, RenderTextureFormat.DefaultHDR);
buffer.SetGlobalTexture(rtID,tempRT);
buffer.CopyTexture(BuiltinRenderTextureType.CameraTarget, tempRT);
buffer.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
buffer.DrawMesh(mesh, Matrix4x4.identity, mat, 0, 0);
camera.AddCommandBuffer(CameraEvent.BeforeImageEffects, buffer);
Here is my Shader Code:
v2f vert (appdata v)
{
v2f o;
o.vertex = v.vertex;
o.uv = v.uv;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_TempRT, i.uv);
col = tex2Dlod(_TempRT, half4(i.uv, 0, 0));
col *= float4(1,0,0,1);
return col;
}
And it work well when disable MSAA.
But when i enable MSAA. The image get stuck. And whatever you move your camera, the image won't change.
![alt text][1]
[1]: /storage/temp/189602-1699a793-2cec-4fa5-ac38-c0e8abe859c5.png
I just want to know why, and what happend?
↧