Search Unity

Forcing TextureCubeArray and the Unity shader compiler to be friends

Discussion in 'Shaders' started by Aieth, May 16, 2015.

  1. Aieth

    Aieth

    Joined:
    Apr 13, 2013
    Posts:
    805
    I am attempting to bind and use a TextureCubeArray in a shader that exists within Unity. The TextureCubeArray is created in a native plugin and bound to a texture register. However, Unitys compiler does not seem to like TextureCubeArray. I am assuming it does reflection and becomes puzzled when it finds a texture type it is not used to. I am wondering if there is any way to get the following code to compile, and if not, any chance it could be added in a future patch? I am currently atlasing cubemaps using equirectangular projection, but I'd much prefer the simplicity of a cubemap array.

    I am completely fine with a hacky solution, if one exists. As long as I can bind a TextureCubeArray, created in native code, to a Unity shader I am a happy camper.

    The error when compiling the shader
    The shader code

    Code (CSharp):
    1. Shader "CubemapArray"
    2. {
    3.     Properties
    4.     {
    5.     }
    6.  
    7.     SubShader
    8.     {                    
    9.         Pass
    10.         {          
    11.             CGPROGRAM
    12.             #pragma vertex vert
    13.             #pragma fragment frag
    14.             #pragma target 5.0
    15.             #pragma only_renderers d3d11
    16.          
    17.             struct a2v
    18.             {
    19.                 float4 vertex     : POSITION;
    20.                 float3 normal     : NORMAL;
    21.             };
    22.          
    23.             struct v2f
    24.             {
    25.                 float4 pos         : SV_POSITION;
    26.                 float3 normal    : TEXCOORD0;
    27.             };
    28.        
    29.             TextureCubeArray myCubeArray : register(t0);
    30.             SamplerState mySamplerState : register(s0);
    31.          
    32.             v2f vert(a2v v)
    33.             {
    34.                 v2f o;
    35.                      
    36.                 o.pos         = mul(UNITY_MATRIX_MVP, v.vertex);
    37.                 o.normal     = normalize(mul(v.normal, (float3x3)_World2Object));
    38.              
    39.                 return o;
    40.             }
    41.          
    42.             float4 frag(v2f i) : COLOR
    43.             {        
    44.                 return myCubeArray.Sample(mySamplerState, float4(1,0,0,0));
    45.             }
    46.          
    47.             ENDCG
    48.         }
    49.     }
    50. }
    51.  
    52.  
     
    Last edited: May 16, 2015
  2. Aieth

    Aieth

    Joined:
    Apr 13, 2013
    Posts:
    805
    Bumping this, hoping for an answer :)
     
  3. Zicandar

    Zicandar

    Joined:
    Feb 10, 2014
    Posts:
    388
  4. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Any resolution for this @Aras - anyone at unity ;) seems ongoing...
     
  5. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Love how you suggested Aras straight up... :D I'm not surprised you did though, judging by some of this amazing posts. :)
     
  6. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Or maybe he's responsible for helping design unity's entire shader system as it is today.