Camera.RenderWithShader 功能无法正常工作

Camera.RenderWithShader function doesn't work properly

我目前在 Unity 5 中处理一个项目。我正在尝试使用 Camera.RenderWithShader 将着色器应用到我的一个相机,然后读取并保存图像。这是代码:

Texture2D screenshot = new Texture2D(this.screenWidth, this.screenHeight, TextureFormat.RGB24, false);
this.mainCamera.RenderWithShader(this.myShader,"RenderType");
screenshot.ReadPixels(new Rect(0, 0, this.cameraWidth, this.cameraHeight), 0, 0);

问题是,在我将屏幕截图纹理保存为位图后,着色器并未应用于整个图像。

但如果我使用 Camera.Render() 并使用 OnRenderImage(RenderTexture,RenderTexture) 应用着色器,它就可以工作。

void OnRenderImage(RenderTexture source, RenderTexture destination)
{
     Graphics.Blit(source, destination, this.disparityMaterial);
}

所以,我的问题是:这两种方法有什么区别,我怎样才能使 Camera.RenderWithShader 函数正常工作?

RenderWithShader and OnRenderImage are two completely different things and have nothing to do with each other.
Read the linked manual pages for details and a better understand, but long story short:
Prior is applying a shader to all (game)objects the camera can see without any image filters applied so basically it's about using a different shader for the same objects/prefabs/materials to alter something the way you want for the viewer (in your case, GOs should also have their tag set to "RenderType", otherwise the shader will not be applied on them),
Latter one however is a "post processing" feature, applying filters only on images already rendered. I.e. an image effect 特征。

所以对先前的一个很好的使用是例如夜视 on/off,或者用玩家可以把手放在上面的特殊眼镜从小鸡身上取下布料 (mmmmm),等等,而后者显然只是图像效果,例如一个秘密特工在单指杀死敌人时拍照,但当他被击中时,他的设备损坏越来越多,所以作为英特尔拍摄的照片越来越模糊,破碎等等 - 如果这是有道理的。