Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL Shader Error on Mac, but not Windows: cannot convert from 'const int' to '4-component vector of float'

I'm new to shaders and I started playing around with some of them yesterday. They compile fine on my Windows PC, but when they're ran on Mac, there is an error for both:

ERROR: 0:14: '=' : cannot convert from 'const int' to '4-component vector of float'

On Android only the second shader gives me an error. It has the error above an mentions that there is no matching function dot that is overloaded.

They use the same vertex shader:

attribute vec4 a_position;
attribute vec4 a_color;
attribute vec2 a_texCoord0;

uniform mat4 u_projTrans;

varying vec4 vColor;
varying vec2 vTexCoord;

void main() {
    vColor = a_color;
    vTexCoord = a_texCoord0;
    gl_Position =  u_projTrans * a_position;
}

One Fragment Shader (Error on Mac):

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

varying LOWP vec4 vColor;
varying vec2 vTexCoord; 
uniform sampler2D u_texture;
void main() {
    vec4 texColor = texture2D(u_texture, vTexCoord); 
    texColor.rgb = 1.0 - texColor.rgb;
    gl_FragColor = texColor * vColor;
}

The other Fragment Shader (Error on mac and android):

#ifdef GL_ES
#define LOWP lowp
precision mediump float;
#else
#define LOWP
#endif

varying LOWP vec4 vColor;
varying vec2 vTexCoord; 
uniform sampler2D u_texture;            
void main() {
    vec4 texColor = texture2D(u_texture, vTexCoord); 
    vec3 gray = vec3(0.2125, 0.7154, 0.0721);
    vec4 color = dot(gray, texColor);
    color.a = texColor.a;
    gl_FragColor = color * vColor;
}
like image 636
DustinRiley Avatar asked Dec 16 '12 22:12

DustinRiley


1 Answers

In first shader you have error in this line - texColor.rgb = 1.0 - texColor.rgb; You need to write:

texColor.rgb = vec3(1.0) - texColor.rgb;

In second shader you have error in this line - vec4 color = dot(gray, texColor); Gray is vec3, texcolor is vec4. What is dot product between vec3 and vec4? There is no such dot function that does that. You can call either float dot(vec3, vec3) or float dot(vec4, vec4). So change that line to:

vec4 color = vec4(dot(gray, texColor.rgb));

or

vec4 color = vec4(dot(vec4(gray, ???), texColor)); // put in ??? float number you want

(and next time please show us in which line exactly error occurs)

like image 77
Mārtiņš Možeiko Avatar answered Sep 19 '22 14:09

Mārtiņš Možeiko