Question

When I try to compile the simplified vertex shader below on Galaxy S (PowerVR SGX540, Android), it does not compile and no error is given. Just "Compile failed." is in the log.

#ifdef GL_ES
   precision mediump float;
   precision lowp int;
#endif

uniform mat4 u_m;   //model 
uniform mat4 u_mvp; //model view projection
uniform vec3 u_lightPos[1];

uniform int u_lightCount;

attribute vec3 a_position;

varying vec3 v_lightDir[1];

void pointLight(int i, vec3 vertPos){
    v_lightDir[i] = u_lightPos[i] - vertPos;
}

void main( void )
{   
    vec3 vertPos = (u_m * vec4(a_position, 1.0)).xyz;

    if(u_lightCount > 0){
        pointLight(0, vertPos);
    }

    gl_Position = u_mvp * vec4(a_position, 1.0);
}

However, when I move the function block into the main function, it compiles just fine:

#ifdef GL_ES
   precision mediump float;
   precision lowp int;
#endif

uniform mat4 u_m;   //model 
uniform mat4 u_mvp; //model view projection
uniform vec3 u_lightPos[1];

uniform int u_lightCount;

attribute vec3 a_position;

varying vec3 v_lightDir[1];

void main( void )
{   
    vec3 vertPos = (u_m * vec4(a_position, 1.0)).xyz;

    if(u_lightCount > 0){
        v_lightDir[0] = u_lightPos[0] - vertPos;
    }

    gl_Position = u_mvp * vec4(a_position, 1.0);
}

On desktop, both compiles. I can't figure out, why it behaves that way. Could anyone explain it or is it a bug inside the system?

Was it helpful?

Solution

It seems that your OpenGL ES implementation does not support array indexing by variable (v_lightDir[i] = ...)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top