Search Unity

Setting Render Texture for Single Pass Instanced Camera

Discussion in 'General Graphics' started by themdubs, May 15, 2019.

  1. themdubs

    themdubs

    Joined:
    Jan 12, 2014
    Posts:
    26
    I'm trying to get a render texture setup for a single pass instanced camera using its target texture property. Currently only the left eye is rendering out to the render texture and the right eye is rendering completely transparent. I create this render texture through the following code:

    Code (CSharp):
    1.     _targetTexture = new RenderTexture(_childCamera.pixelWidth,_childCamera.pixelHeight, 24, RenderTextureFormat.ARGB32);
    2.     _targetTexture.dimension = UnityEngine.Rendering.TextureDimension.Tex2DArray;
    3.     _targetTexture.anisoLevel = 0;
    4.     _targetTexture.antiAliasing = 2;
    5.     _targetTexture.volumeDepth = 2;
    6.     _targetTexture.vrUsage = VRTextureUsage.TwoEyes;
    7.     _targetTexture.Create();
    I also created a custom shader to check this render texture, I setup the shader following the instructions provided here. In my frag function I can check both sides of the render texture by changing the stereoEyeIndex value from 0.0 (for left) to 1.0 (to right).

    Code (CSharp):
    1. UNITY_DECLARE_TEX2DARRAY(_MainTex);
    2.  
    3. fixed4 frag (v2f i) : SV_Target
    4. {
    5.     UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
    6.  
    7.     float stereoEyeIndex = 0.0;
    8.     fixed4 col = UNITY_SAMPLE_TEX2DARRAY(_MainTex, float3(i.uv, stereoEyeIndex));
    9.     return col;
    10. }
    Note that I am aware of the UNITY_SAMPLE_SCREENSPACE_TEXTURE method however for control purposes I decided to use UNITY_SAMPLE_TEX2DARRAY.
     
    FunSTW likes this.