int screenCopyID = Shader.PropertyToID(“_ScreenCopyTexture”);
buf.GetTemporaryRT (screenCopyID, cam.pixelWidth/2, cam.pixelHeight/2, 0, FilterMode.Bilinear);
//结果错误
//buf.GetTemporaryRT(screenCopyID, cam.pixelWidth, cam.pixelHeight, 0, FilterMode.Bilinear); //结果正确
buf.Blit (BuiltinRenderTextureType.CurrentActive, screenCopyID);
这是因为Forward模式下,想你默认渲染到BackBuffer。 无法直接被使用。
以下几种情况可以避免:
1. HDR
2. OnRenderImage
3. GetComponent().forceIntoRenderTexture = true;
当RenderTexture的尺寸和BackBuffer的大小一致的时候,显示正确(至少DX11上是正确的)
尺寸一致时候调用:CopySubresourceRegion ,它是Copy GPU内存到CPU内存。对纹理类型等有要求。
尺寸不一致时候调用: DrawIndexwed
所以
4. 保持RT的尺寸等于Backbuffer