我目前使用下面的片段着色器的基本黑白效果:GLSL类型不一致
uniform sampler2D texture;
uniform float time_passed_fraction;
//gl_Color: in the fragment shader, the interpolated color passed from the vertex shader
void main()
{
// lookup the pixel in the texture
vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);
vec3 texel = pixel .rgb;
gl_FragColor = pixel;
float bw_val = max(texel.r,max(texel.g,texel.b));
gl_FragColor.r = pixel.r * (1-time_passed_fraction) + bw_val * time_passed_fraction;
gl_FragColor.g = pixel.g * (1-time_passed_fraction) + bw_val * time_passed_fraction;
gl_FragColor.b = pixel.b * (1-time_passed_fraction) + bw_val * time_passed_fraction;
gl_FragColor.a = pixel.a;
// multiply it by the color
//gl_FragColor = gl_Color * pixel;
}
这个片段着色器完美的作品在我的电脑上。但我从他们得到了以下错误的人得到一些反馈:
ERROR: 0:17: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'uniform float' (or there is no acceptable conversion)
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)
ERROR: 0:18: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'uniform float' (or there is no acceptable conversion)
ERROR: 0:18: '*' : 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)
ERROR: 0:19: '-' : wrong operand types no operation '-' exists that takes a left-hand operand of type 'const int' and a right operand of type 'uniform float' (or there is no acceptable conversion)
这似乎暗示了某种类型的错误,但我不理解的地方不一致的来源。有人可能会解释吗?
注:第17行是此行)gl_FragColor.r = pixel.r * (1-time_passed_fraction) + bw_val * time_passed_fraction;
GLSL的IIRC旧版本并没有做隐含INT-漂浮的转换;你可能不得不使用'float(myinteger)'来明确地转换它们。 –