Fragment shader not loading on different Android device

Started by take2316, March 15, 2013, 12:39:16 AM

Previous topic - Next topic

take2316

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:

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:

uniform sampler2D textureUnit0;

varying vec2 texCoords;

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


Do you have any idea why this might be happening?

Thomas.

You have not defined float precision... add at the first line "precision mediump float;"

take2316

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...