【问题标题】:Android Open GLES fragment shader errorAndroid Open GLES 片段着色器错误
【发布时间】:2016-01-22 20:49:14
【问题描述】:

我有一个单色.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;
}

我有一个片段着色器单色.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;
}

我在安卓设备上通过 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.

我真的看不出我做错了什么,也找不到关于 SO 的答案,有什么帮助吗?

【问题讨论】:

  • 你忘记了precision mediump float后面的分号。

标签: android opengl-es libgdx fragment-shader


【解决方案1】:

问题是分号,所以我改了

#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;
}

现在可以使用了

【讨论】:

    猜你喜欢
    • 2017-10-05
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-04
    • 2018-07-03
    相关资源
    最近更新 更多