I'm trying to use custom shaders for a libgdx project to run on Android. I have not figured out how to USB debug, so I can't seem to get any logs when running on a real Android device.
The problem is that implementing the shader I wrote results in a black screen on my Samsung Galaxy Nexus. It produces the correct results in the desktop project AND the Android project run on an Android emulator in Eclipse. Not implementing the shader makes it also render right on my Android (albeit without the shader effect).
So I'm presenting the issue hoping someone else can spot any problem(s). Best regards.
The shader setup (in Java):
ShaderProgram.pedantic = false;
shader = new ShaderProgram(
Gdx.files.internal("shaders/vignette.vsh"),
Gdx.files.internal("shaders/vignette.fsh"));
if (! shader.isCompiled()) {
Gdx.app.log("Shader", shader.getLog());
}
renderer.getSpriteBatch().setShader(shader);
glow.batch.setShader(shader);
shader.begin();
shader.setUniformf("u_near", .2f);
shader.setUniformf("u_dim", .85f);
shader.end();
The vertex shader:
precision mediump float;
attribute vec4 a_color;
attribute vec3 a_position;
attribute vec2 a_texCoord0;
uniform mat4 u_projTrans;
varying vec4 v_color;
varying vec2 v_texCoord0;
void main() {
v_color = a_color;
v_texCoord0 = a_texCoord0;
gl_Position = u_projTrans * vec4(a_position, 1.0);
}
Fragment shader:
precision mediump float;
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform vec2 u_lightPos;
uniform float u_radius;
uniform float u_near;
uniform float u_dim;
uniform sampler2D u_sampler2D;
void main() {
vec4 color = texture2D(u_sampler2D, v_texCoord0) * v_color;
vec2 relativePosition = (u_lightPos - gl_FragCoord.xy) / u_radius;
float len = length(relativePosition);
float vignette = smoothstep(.5, u_near, len);
color.rgb = mix(color.rgb, color.rgb * vec3(vignette, vignette, color.b / 3), u_dim);
gl_FragColor = color;
}
The correct result is a "vignette" or spotlight effect.
Target Android version: 4.4.2
MainActivity contains
cfg.useGL20 = true;
AndroidManifest contains
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
Edit: I have set up the projects correctly so that they share assets located in an assets folder in the Android project, including the shader files.