Author Topic: Fragment shader not loading on different Android device  (Read 2846 times)

Offline take2316

  • byte
  • *
  • Posts: 12
    • View Profile
Fragment shader not loading on different Android device
« on: March 15, 2013, 12:39:16 am »
I can successfully run my shader code on my Android 4.1.1 Samsung Galaxy S3 device, but when I try it on an Android 2.3.4 LG Revolution, I get this error: "ERROR: Failed to load and compile fragment shaders!"

Here are my vertex and fragment shaders:

Vertex shader:
Code: [Select]
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;

attribute vec4 position;
attribute vec3 normal;

varying vec2 texCoords;

void main() {
// apparently, jPCT doesn't support gl_NormalMatrix, but it's okay:
// see: http://www.jpct.net/forum2/index.php/topic,2723.msg20171.html#msg20171
// and: http://www.lighthouse3d.com/tutorials/glsl-tutorial/the-normal-matrix/
vec3 n = normalize(modelViewMatrix * vec4(normal,0.0)).xyz;

vec3 u = (modelViewMatrix * position).xyz;

vec3 r = u - 2.0 * dot(u,n) * n;
float m = 2.0 * sqrt(r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0));
texCoords.x = r.x/m + 0.5;
texCoords.y = r.y/m + 0.5;

gl_Position = modelViewProjectionMatrix * position;
}

Fragment shader:
Code: [Select]
uniform sampler2D textureUnit0;

varying vec2 texCoords;

void main() {
gl_FragColor = texture2D(textureUnit0, texCoords);
}

Do you have any idea why this might be happening?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: Fragment shader not loading on different Android device
« Reply #1 on: March 15, 2013, 01:15:48 am »
You have not defined float precision... add at the first line "precision mediump float;"

Offline take2316

  • byte
  • *
  • Posts: 12
    • View Profile
Re: Fragment shader not loading on different Android device
« Reply #2 on: March 16, 2013, 06:05:41 am »
Thanks so much, it works now. I'm new to OpenGL ES, so I didn't realize there was that requirement. I guess the GPU on the Galaxy S3 phone was just more forgiving...