- Home /
Question by
qw3452151 · Dec 06, 2021 at 09:34 AM ·
shaderpost processinganti-aliasing
CommandBuffer Problem, use CommandBuffer to achive PostProcessing,How to use CommandBuffer to achive postprocessing?
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<Camera>();
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<Camera>();
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.
I just want to know why, and what happend?
1699a793-2cec-4fa5-ac38-c0e8abe859c5.png
(191.2 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613050241im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Shader shadow anti-aliasing problem 1 Answer
Postprocessing effect in Oculus GO 0 Answers
Can you process a color with postprocessing stack's color grading? 2 Answers
Post processing effects. 1 Answer
Transparency shader 1 Answer