- Home /
Graphics.ExecuteComputeBuffer only works the first time
I am trying to execute multiple command buffers but the second one always outputs a blank texture. I have tried putting everything into a function that creates and destroys it's own command buffer but it still only works the first time the function is called. The second render texture is always blank. Any clue as to why?
GL.LoadProjectionMatrix(GL.GetGPUProjectionMatrix(textureCamera.projectionMatrix, true));
GL.modelview = modelToExport.transform.localToWorldMatrix * textureCamera.worldToCameraMatrix;
CommandBuffer cb = new CommandBuffer();
// Alpha
cb.Clear();
cb.ClearRenderTarget(true, true, new Color(0,0,0,0));
VertColorUnwrapMaterial.SetInt("_AlphaOnly", 1 );
cb.DrawRenderer(modelToExport.GetComponent<Renderer>(), VertColorUnwrapMaterial);
Graphics.SetRenderTarget(alphaRT);
Graphics.ExecuteCommandBuffer( cb );
// Color
cb.Clear();
cb.ClearRenderTarget(true, true, new Color(0,0,0,0));
VertColorUnwrapMaterial.SetInt("_AlphaOnly", 0 );
cb.DrawRenderer(modelToExport.GetComponent<Renderer>(), VertColorUnwrapMaterial);
Graphics.SetRenderTarget(newRT);
Graphics.ExecuteCommandBuffer( cb );
cb.Release();
cb = null;
RenderTexture.active = newRT;
Texture2D newTex2D = new Texture2D(512, 512, TextureFormat.ARGB32, false);
newTex2D.ReadPixels(new Rect(0, 0, newRT.width, newRT.height), 0, 0);
newTex2D.Apply();
Update:
If I put this is a coroutine with a yield in between executions it will work.
Graphics.Blit will also fail when Graphics.ExecuteCommandBuffer is called above it.
Graphics.Blit results with large textures have errors ( white lines/rectangle outlines) when called after Graphics.ExecuteCommandBuffer even with a yield is used.
Your answer
Follow this Question
Related Questions
dynamic hole in layer / texture / camera 0 Answers
Best way to convert particles and sprites in a single sprite at runTime 1 Answer
Modify Gbuffer Layout / Add RenderTarget 2 Answers
Set dynamic generated alpha mask on shader at runtime 0 Answers
Using Graphics.Blit with the same source and destination 1 Answer