Android Open GLES片段着色器错误

时间:2015-10-23 10:32:35

标签: android opengl-es libgdx fragment-shader

我有一个单色.vs

attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_textCoord0;
varying vec4 v_color;
varying vec2 v_textCoords;
uniform mat4 u_projTrans;

void main(){
   v_color = a_color;
   v_textCoords = a_textCoord0;
   gl_Position = u_projTrans * a_position;
}

我有一个片段着色器monochrome.fs

#ifdef GL_ES
precision mediump float
#endif

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float u_amount;


void main(){
   vec4 color = v_color* texture(u_texture,v_texCoords);
   float greyScale = dot(color.rgb,vec3(0.222,0.707,0.071));
   color.rgb = mix(color.rgb,vec3(greyScale));
   gl_FragColor =color;
}

我在Android设备上通过libGDX运行它。

我正在使用代码

if(!shaderProgram.isCompiled()){
        String msg = "shader not compiled ->"+shaderProgram.getLog();
        throw new GdxRuntimeException(msg);
    }

产生以下输出

10-23 11:21:49.546 4979-5018/? E/AndroidRuntime: com.badlogic.gdx.utils.GdxRuntimeException: shader not compiled ->Fragment shader compilation failed.
10-23 11:21:49.546 4979-5018/? E/AndroidRuntime: ERROR: 0:5: 'varying' : Syntax error:  syntax error
10-23 11:21:49.546 4979-5018/? E/AndroidRuntime: ERROR: 1 compilation errors.  No code generated.

我真的无法看到我做错了什么,也无法找到答案,有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

问题是分号,所以我改变了

#ifdef GL_ES
precision mediump float
#endif

#ifdef GL_ES
precision mediump float;
#endif

varying vec4 v_color;
varying vec2 v_texCoords;
uniform sampler2D u_texture;
uniform float u_amount;


void main(){
  vec4 color = v_color* texture2D(u_texture,v_texCoords);
  float greyScale = dot(color.rgb,vec3(0.222,0.707,0.071));
  color.rgb = mix(color.rgb,vec3(greyScale),u_amount);
  gl_FragColor =color;
}

现在可行了