jPCT-AE - a 3d engine for Android > Support
Fragment shader not loading on different Android device
(1/1)
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:
--- Code: ---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;
}
--- End code ---
Fragment shader:
--- Code: ---uniform sampler2D textureUnit0;
varying vec2 texCoords;
void main() {
gl_FragColor = texture2D(textureUnit0, texCoords);
}
--- End code ---
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...
Navigation
[0] Message Index
Go to full version