I'm working on a stereo viewing system. I want to render a right and left camera to a right and left RenderTexture, then use 'main camera' to view those two textures side-by-side. That all works fine.
The problem I have is this: I want a final aspect ration of 4x3. Each 'eye' camera (right/left) should produce a 4x3 aspect ratio image. So the planes I render to have that aspect ratio. But the RT's themselves are 'square' (or whatever power of two), and render the left-most portion of each plane correctly, but only up to where width == height (a square). After that, the clamped texture just stretches ugly to make up the last quarter of the width of the image. If I set the texture to Tile, it does that, but what I really need is 'stretch' rather than 'tile'.
How can I do that?
asked Sep 02 '11 at 11:39 PM
Stretch vs. tile is a function of the UV coords. If you take a normal plane, scale it however, the UV corners should still be set to exactly one texture. If somehow, your UV coords are set to 1.5 textures, your options are clamp or tile for the extra 0.5 -- stretch isn't possible. A hack is to set the UV matrix top line to, ummmm, all time 0.6666 (will cut the sideways coords by 2/3s so that 1.5 counts as 1.)
May be helpful, this is from using render textures in XNA, but how different can it be?:
The render texture should be as many pixels large as the "screen" you are drawing to. If you swap in a 600x600 renderTo texture for an 800x600 screen, the rightmost 200 pixels are just falling off. Easier than scaling the texture after it's created, is scaling down the screen as you render it. In the camera's projection matrix you can multiply the top row (x) by width/height (or vise-versa.) That tells the camera to shrink the width as it renders. the 800 pixels across it was going to write to, are now 600 pixels. I think ViewPort Rect (the answer above) is another way to set the Projection matrix.
I think you're going to have some aspect problems even if you solve the edge-clamp issue -- drawing a whole screen on half a screen (with a square texture) won't look right. I'm thinking the solution is to have a renderTo texture the size of half a screen, and then look up how to set the projection matrix to a tall, narrow area, the size of half a screen (this isn't Unity stuff -- plenty of places to look up "if aspect ratio is this, use these #s for projMat.")
answered Sep 03 '11 at 05:15 PM
This does not really answer your question, but if i understood you right you could try a different approach. Instead of render textures you can just have two cameras with different viewport rects. Left camera: x=0 y=0 w=0.5 h=1. Right camera: x=0.5 y=0 w=0.5 h=1 for example.