Graphics.Blit with custom shader gives black screen under iOS

I have the following

public Material shaderMaterial;
void OnRenderImage (RenderTexture source, RenderTexture destination) {
	//rotoscopeMaterial.color = Color.white;
	Graphics.Blit(source, destination, shaderMaterial);
}

where shaderMaterial is associated with a simple GLSL shader. This works fine in the development environment but when I build the app for iOS and run it on a device see nothing but a black screen. However, when I Blit() the image directly with no shader I do see the correct output. Any ideas?

It’s probably late for an answer, but maybe it helps someone. I had this same issue using a custom shader for some post-processing effects and the reason was the custom shader was not being included in the build. You have to:

1 - reference it in some material

2 - add it under “Allways included shaders”, or

3 - put shader or something that reference it on “Resources” folder

as stated in Shader.Find doc

There seems to be a bug in Unity (as of 4.0.1) under iOS where in OnRenderImage you cannot directly Blit to the destination with a Material. Doing so effectively renders nothing (whatever was previously in the backbuffer, which may be black, or garbage, or the previously rendered frames). You can however, as a workaround, render to an intermediate buffer and then Blit to the destination without a material. For example:

public Material shaderMaterial;
public RenderTexture intermediateRT;
void OnRenderImage (RenderTexture source, RenderTexture destination) {
    //rotoscopeMaterial.color = Color.white;
    Graphics.Blit(source, intermediateRT, shaderMaterial);
    Graphics.Blit(intermediateRT, destination);
}

This of course costs the additional overhead of another RenderTexture and draw call, but it at least works. Hopefully Unity will fix this in future versions.

The way I isolated this was by using different materials of varying complexity, some that just do diffuse texturing, and some that just output a flat color, none of them worked. They work in the editor but not on a device. Also, all my RenderTexture formats were identical RGBA32s (save some resolution differences). But once I Blit without a Material to destination it renders as expected. My conclusion was that it must be the presence of a Material that is causing the issue.