GLSL 着色器未在 android 上编译
GLSL shader not compiling on android
此着色器无法在 android 上编译,但在 Windows 上可以完美运行。
我正在使用 libGDX 并且我对着色器还很陌生,所以我不知道发生了什么。
如果确实重要 - 使用了带有 Adreno 305 的 LG F60。
片段:
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform float time;
uniform sampler2D u_sampler2D;
uniform vec4 u_neon;
void main() {
vec4 color = texture2D(u_sampler2D, v_texCoord0) * v_color;
float cx = (gl_FragCoord.x / 100) + 0.5*sin(time/5);
float cy = ( gl_FragCoord.y / 10) + 0.5*cos(time/3);
color.r = sin(0.24*((gl_FragCoord.x/100)*sin(time/3)+(gl_FragCoord.y/100)*cos(time/5))+time) - sin(sqrt(0.3*(cx*cx+time*cy)+1)+time);
color.b = color.r * 0.5 + sin(sqrt(0.3*(cx*cx+cy*cy)+1)+time);
color.g = color.r - sin(sqrt(0.004*(cx*cx+cy*cy)+1)+time);
color.a = 1;
gl_FragColor = color;
}
顶点:
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(void) {
v_color = a_color;
v_texCoord0 = a_texCoord0;
gl_Position = u_projTrans * vec4(a_position, 1.0);
}
Logcat:
01-12 20:11:14.777: I/System.out(15485): ERROR: 0:16: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.777: I/System.out(15485): ERROR: 0:16: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'uniform float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.777: I/System.out(15485): ERROR: 0:17: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.787: I/System.out(15485): ERROR: 0:17: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'uniform float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.787: I/System.out(15485): ERROR: 0:20: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.787: I/System.out(15485): ERROR: 0:20: '/'
01-12 20:11:14.867: W/Adreno-ES20(15485): <core_glTexParameteriv:566>: GL_INVALID_ENUM
vvvvvvvvvvvvvv float vvvv ditto
float cx = (gl_FragCoord.x / 100) + 0.5*sin(time/5);
^^^ int ^ ditto
GLSL ES 1.0 不会自动将 int
s 提升到 float
s,并且是类型兼容性的坚持者。
尝试这样的事情:
float cx = (gl_FragCoord.x / 100.0) + 0.5*sin(time/5.0);
^^^^^ float ^^^ ditto
此着色器无法在 android 上编译,但在 Windows 上可以完美运行。 我正在使用 libGDX 并且我对着色器还很陌生,所以我不知道发生了什么。 如果确实重要 - 使用了带有 Adreno 305 的 LG F60。
片段:
varying vec4 v_color;
varying vec2 v_texCoord0;
uniform float time;
uniform sampler2D u_sampler2D;
uniform vec4 u_neon;
void main() {
vec4 color = texture2D(u_sampler2D, v_texCoord0) * v_color;
float cx = (gl_FragCoord.x / 100) + 0.5*sin(time/5);
float cy = ( gl_FragCoord.y / 10) + 0.5*cos(time/3);
color.r = sin(0.24*((gl_FragCoord.x/100)*sin(time/3)+(gl_FragCoord.y/100)*cos(time/5))+time) - sin(sqrt(0.3*(cx*cx+time*cy)+1)+time);
color.b = color.r * 0.5 + sin(sqrt(0.3*(cx*cx+cy*cy)+1)+time);
color.g = color.r - sin(sqrt(0.004*(cx*cx+cy*cy)+1)+time);
color.a = 1;
gl_FragColor = color;
}
顶点:
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(void) {
v_color = a_color;
v_texCoord0 = a_texCoord0;
gl_Position = u_projTrans * vec4(a_position, 1.0);
}
Logcat:
01-12 20:11:14.777: I/System.out(15485): ERROR: 0:16: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.777: I/System.out(15485): ERROR: 0:16: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'uniform float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.777: I/System.out(15485): ERROR: 0:17: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.787: I/System.out(15485): ERROR: 0:17: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'uniform float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.787: I/System.out(15485): ERROR: 0:20: '/' : wrong operand types no operation '/' exists that takes a left-hand operand of type 'float' and a right operand of type 'const int' (or there is no acceptable conversion)
01-12 20:11:14.787: I/System.out(15485): ERROR: 0:20: '/'
01-12 20:11:14.867: W/Adreno-ES20(15485): <core_glTexParameteriv:566>: GL_INVALID_ENUM
vvvvvvvvvvvvvv float vvvv ditto
float cx = (gl_FragCoord.x / 100) + 0.5*sin(time/5);
^^^ int ^ ditto
GLSL ES 1.0 不会自动将 int
s 提升到 float
s,并且是类型兼容性的坚持者。
尝试这样的事情:
float cx = (gl_FragCoord.x / 100.0) + 0.5*sin(time/5.0);
^^^^^ float ^^^ ditto