Search Unity

(GPU) access to array with non-constant indexes

Discussion in 'Shaders' started by lorenzo.cambiaghi, Mar 21, 2012.

  1. lorenzo.cambiaghi

    lorenzo.cambiaghi

    Joined:
    Aug 16, 2011
    Posts:
    10
    When I try to access to an array with non costant indexes I have this error message: "Profile requires arrays with non-constant indexes to be uniform".

    Code (csharp):
    1.  
    2.            CGPROGRAM
    3.         #pragma vertex vert
    4.         #pragma fragment frag
    5.         #pragma fragmentoption ARB_precision_hint_fastest
    6.         #include "UnityCG.cginc"
    7.        
    8.         #define BSIZE 32
    9.         #define FULLSIZE 66
    10.         #define NOISEFRAC 0.03125
    11. //doesn't work
    12.                 //return pg[5];  if I write a constant index it works
    13.         }
    14.  
    15.               ...etc
    16.  
    17.  

    :confused: Is there any solution?
    I can't store values in a texture because I need to access them in a vertex shader. I need it for perlin noise :( and I want that it works in Opengl ES 2.0 (no shader model 3.0 solution)


    I've also try

    const float4 pg[FULLSIZE] = {
    float4(-0.569811,0.432591,-0.698699,0),
    ..
    ..
    }


    float4 getPG(int num,const uniform float4 pgT[FULLSIZE])
    {
    return pgT[num];
    }


    when i call getPG(value,pg) works(no compile error) but return 0 as the array is empty
     
    Last edited: Mar 21, 2012
  2. Owen

    Owen

    Joined:
    Apr 20, 2011
    Posts:
    79
    Nevermind, misread.