I'm trying to write a post processing effect that alters what is eventually drawn to the screen. However, that requires getting what's currently being drawn, modifying it, and then drawing it back.
The first two steps seem to work just fine. The third step....renders all gray.
public class PostProcess : MonoBehaviour {
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
Texture2D proc = new Texture2D(src.width, src.height);
proc.ReadPixels(new Rect(0, 0, src.width, src.height), 0, 0);
Color[] line = proc.GetPixels(src.width / 2, 0, 1, src.height);
Debug.Log(line[0] + " : " + line[line.Length-1]);
proc.Apply(); //per comments
Graphics.Blit(proc, dest);
}
}
My goal is to eventually take the line pulled from the Texture2D and place it back into the texture at another point, creating a distortion. What I'm currently getting though is useless. I can see that the Texture2D.ReadPixels()
call performs flawlessly as I can see that the red pixels of that UI image are visible in the texture (via the debug line) and black for the top of that column (which is correct: the camera renders a solid black background, not the skybox). However, blitting that texture back to the screen results in useless gray nothing.
If I do Graphics.Blit(src, dest);
instead, then it renders the scene just fine.
Update
After adding proc.Apply()
the screen is no longer gray. It is however, heavily distorted:
Scene view approximates what the camera should render, while the camera view shows what's actually rendered (again, no skybox, although turning it on makes the entire view a riot of reds and purples).
Update 2
I gave things a whack on a different machine running a different (older) version of Unity annd...it works. I should have realized that it was likely a Unity bug first and foremost (this is the third one I've found in 5.6 and the second this week).