Java GLSL着色器未在android上编译
该着色器无法在android上编译,但在Windows上可以完美地工作。 我正在使用libGDX,而且我对着色器非常陌生,所以我不知道发生了什么。 如果有关系,则使用带有肾上腺素305的LG F60 片段:Java GLSL着色器未在android上编译,java,android,opengl-es,libgdx,glsl,Java,Android,Opengl Es,Libgdx,Glsl,该着色器无法在android上编译,但在Windows上可以完美地工作。 我正在使用libGDX,而且我对着色器非常陌生,所以我不知道发生了什么。 如果有关系,则使用带有肾上腺素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 c
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);
}
日志:
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
01-12 20:11:14.777:I/System.out(15485):错误:0:16:“/”:错误的操作数类型不存在以“float”类型的左侧操作数和“const int”类型的右侧操作数进行运算的“/”(或没有可接受的转换)
01-12 20:11:14.777:I/System.out(15485):错误:0:16:“/”:错误的操作数类型不存在使用“统一浮点”类型的左侧操作数和“常量int”类型的右侧操作数的操作“/”(或没有可接受的转换)
01-12 20:11:14.777:I/System.out(15485):错误:0:17:“/”:错误的操作数类型不存在接受左侧“float”类型操作数和右侧“const int”类型操作数的操作“/”(或没有可接受的转换)
01-12 20:11:14.787:I/System.out(15485):错误:0:17:“/”:错误的操作数类型不存在使用“统一浮点”类型的左侧操作数和“常量int”类型的右侧操作数的操作“/”(或没有可接受的转换)
01-12 20:11:14.787:I/System.out(15485):错误:0:20:“/”:错误的操作数类型不存在接受左侧“float”类型操作数和右侧“const int”类型操作数的操作“/”(或没有可接受的转换)
01-12 20:11:14.787:I/System.out(15485):错误:0:20:“/”
01-12 20:11:14.867:W/Adreno-ES20(15485)::GL\u无效\u枚举
GLSL ES 1.0不会自动将int
s升级为float
s,并且对类型兼容性有严格要求
试着这样做:
float cx = (gl_FragCoord.x / 100.0) + 0.5*sin(time/5.0);
^^^^^ float ^^^ ditto
有一些GPU会自动将它们转换为浮动,即使它不在GLES规范中。如果您碰巧在执行此操作的设备上进行测试,这可能是一个“问题”。编译着色器(
shaderProgram.getLog()
)后检查日志并修复任何警告(如果警告是其他设备上的错误),这是一个好主意。OpenGL着色器由系统中特定于GPU的设备驱动程序(有效地)编译,因此您可以遇到各种特定于平台的行为。请参阅以了解一些Libgdx+Android+OpenGL+着色器陷阱。并始终使用#版本pragma:
float cx = (gl_FragCoord.x / 100.0) + 0.5*sin(time/5.0);
^^^^^ float ^^^ ditto