Context: I have one camera perform two separate renders for each eye into render textures. I then want to process the textures further with Blit.
What is the best way to create a packed stereo texture?
My initial approach was to try and render the left eye into the left half of a target texture and then render the right eye into the right half of the texture. Unfortunately it doesn’t seem like it is possible to render the camera into only one part of a larger texture.
If there is a way to do this, I believe this is the most ideal straightforward solution.
In the manual it claims
“When rendering into a texture, the camera always renders into the whole texture; effectively rect and pixelRect are ignored.”
and my attempt to change the rects of the Camera have demonstrated this statement as being true. I have however seen older forum posts about it actually being possible regardless of the statement in the manual, maybe it has been patched out?
My second approach was too render the left and right eye into smaller textures and attempt to combine the texture together into a larger texture.
I first tried Graphics.CopyTexture, however I quickly realized the input textures must be the same size as the output texture.
I then looked at using Graphics.Blit to do this, my plan was to Blit the left texture onto the left half of the larger texture and the same for the right.
Here is the fragment shader I wanted to use to do this with.
//Left Half
return tex2D(_MainTex, float2(i.uv.x*2-1, i.uv.y))
//Right Half
return tex2D(_MainTex, float2(i.uv.x*2-1, i.uv.y))
This works fine except for one major problem, when I for example blit the left texture onto the larger texture, instead of the left side being the left texture and the right side being black, the right side will either be a repeated texture or it will have clamp streaks.
Is it possible to only effect one side of a texture with a fragment shader or at least output just black (which is the same as no effect) such as below?
Are there any other approaches to this? Is there a standard way to do this?