繁体   English   中英

Android Open GLES片段着色器错误

[英]Android Open GLES fragment shader error

我有一个monochrome.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.

我真的看不到我做错了什么,也找不到任何帮助的答案吗?

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

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

现在可以了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM