Hi
I am currently trying to write an image effect that uses the stencil buffer, and this really drives me mad!
Seemingly there is no way to make this work even though I have read from people that achieved this, and there are at least two ways described on how this could work.
My Questions:
1. Lots of people saying that this cannot work with OnImageRender flatout. Seemingly they had good results using OnPostRender() and manually setting up the correct RenderTextures.
Tried many things, but I cannot get the Blit in this method to work correctly. All I get is a thin strip at the top in the Game View of the editor covered by my simple shader (which should color the stenciled parts green) colored green, which hides the lowest button bar of the UI, but not the game view.
Is there any obvious mistake I could have made that would result in such a behaviour?
2. Unity documentation itself contains this paragraph on the page about Graphics.Blit:
Sooooo. An example on this would have been to much to ask for? Anyway, I gave it a try, but all I get is a black screen… most probably because I neither tell Unity about the shader I would like to use for this quad, nor that the src RenderTexture should be somehow involved. What I currently have is this:
void OnRenderImage(RenderTexture src, RenderTexture dest)
{
Graphics.SetRenderTarget(dest.colorBuffer, src.depthBuffer);
GL.LoadOrtho();
material.SetPass(0);
GL.Begin(GL.QUADS);
GL.End();
//Graphics.Blit(src, material);
}
I just faithfully reproduced what the Unity documentation told me to. I guess I am missing half the code that is needed, but without any indication on what is missing I cannot really make any progress there.
So could anyone give me any pointers as to what the Unity documentation left out?
3. Oh, and while experimenting with the OnPostRender() MEthod of doing things, I had to manually assign a renderTexture to the camera. Which I couldn’t get off it again, and the RenderTexture was still stuck to the cam in the editor. Had to manually remove it in the Editor UI after every playtesting session. Why?
Is there a way to remove such a rendertexture again from the cam before the game closes?