I've been trying again and again to make use of RenderTexture.active and it has never worked once so far.
I tried everything I could think of, using Pro assets and mainly ImageEffects as an example as well.
I tried using different ways to draw a quad to the render texture: Graphics.DrawTexture, Graphics.DrawMeshNow, GL (GL.QUADS), Graphics.Blit. Not once has there been anything drawn into the render texture, which remained completely black and transparent at all times.
This is the most stripped down version I've been trying to make work, in a scene bereft of all but the camera and this script attached to it:
And the shader:
This version uses GL, but as I said, I won't get any better results using other ways to render a quad on the screen such as Graphics.DrawTexture
Whyyyyyyyyyyy? I'm desperate! Please help!
Thanks in advance.
asked Apr 27 '10 at 03:04 PM
I found out what the problem was:
this will apparently clean up matrix information (amongst other things).
So, instead of:
that will render over the entire RT (the viewport's coordinates go from -1 to 1).
Also, bear in mind that DrawTexture expects pixel positions, so all parameters will be cast into ints internally. As a consequence, you can't give it things like
as it all will be floored down to the nearest integer.
If like me you'd like to keep DrawTexture to use 'screen' coordinates (here, pixel positions) you'll have to rebuild a projection matrix yourself, something like that:
and pass it on to the vertex shader and multiply your vertices positions with it. And then you can use pixel positions in the Rect you pass to DrawTexture instead of -1,-1,2,2 .
answered May 07 '10 at 07:56 AM
First, you'll need to be using Pro. Render textures are one of the goodies explicitly left out of the freebie version. Second, check out the cubemapping scripts in the manual for examples of how to create a real-time cube texture. I believe there are very similar functions for rendering to traditional textures instead.
Now, if you're looking for a way to hack into the final ~screen buffer~ texture (what gets drawn to the window)... I'm still chewing on that one myself. Best solution I've found is to render a regular texture and slap it on a simple plane fit to the window. Wastes some VRAM, but meh.
answered May 06 '10 at 09:54 PM