Issue with shader

Greetings,

I have a (beginner) issue with the below shader which performs a Phong rendering (and display the Red color channel only).
This shader works on one PC with an old NVidia graphics card but fails (I get the error 1282 after calling glUseProgram()) on my laptop which has an Intel Graphics chip. So it would seem like a support issue from the Intel chip but it is not that obvious (at least to me);
The last three lines of the fragment shader are the problem it seems

vec4 colorG = color.b;
colorG.a = 1.0;
gl_FragColor = colorG;

If I comment them and uncomment the line just above them:

//gl_FragColor = color;

then the shader links and works.
I know that gl_FragColor is deprecated but that does not seem to be the issue since the code below works:

gl_FragColor = color;

Below is the full shader code.
Thank you for any help!

uniform sampler2D map0;
uniform bool reversed;
varying vec3 esVertex, esNormal;
varying vec4 vPos;	

float snoise(vec2 v) {
  return fract(sin(dot(v.xy, vec2(12.9898, 78.233)))*43758.5453);
}
		
void main()
{
    vec4 texColor = texture2D(map0, gl_TexCoord[0].st);
	if ( snoise(floor(vPos.xy*2000.)/2000.) < 1.-gl_FrontMaterial.diffuse.a*texColor.a) {
	 discard;	 
	}
    vec3 normal = normalize(esNormal);
    vec3 light;
    if(gl_LightSource[0].position.w == 0.0)
    {
        light = normalize(gl_LightSource[0].position.xyz);
    }
    else
    {
        light = normalize(gl_LightSource[0].position.xyz - esVertex);
    }
    if (reversed){
      normal = -normal;
	  //light = -light;
	  light.y = -light.y;
	  //normal.y = -normal.y;
	 }
    vec3 reflectVec = reflect(-light, normal);
    vec3 viewVec = normalize(-esVertex);
    vec4 color = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
    float dotNL = max(dot(normal, light), 0.0);
    color += gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse * dotNL;
    color *= texColor;
	vec3 halfVec = normalize(viewVec+light);
    float dotVR = max(dot(normal, halfVec), 0.0);
	 //float dotVR = max(dot(viewVec, reflectVec), 0.0);
    /*vec4 specular = (vec4(1.0) - color) * gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(dotVR, gl_FrontMaterial.shininess);
    color += specular;*/
    color += gl_FrontMaterial.specular * gl_LightSource[0].specular * pow(dotVR, gl_FrontMaterial.shininess*4.f); 

    //gl_FragColor = color;
	vec4 colorG = vec4(color.b);
	colorG.a = 1.0;
	gl_FragColor = colorG;	

}

That’s GL_INVALID_PROGRAM. I’m guessing that the program didn’t compile and link successfully. You should check the compilation and linking status with glGetShaderiv(GL_COMPILE_STATUS) and glGetProgramiv(GL_LINK_STATUS), and also retrieve and display the compiler/linker output using glGetShaderInfoLog and glGetShaderInfoLog.

Also: when posting code to the forums, use triple backticks to preserve formatting and also to prevent interpretation of markup characters (e.g. asterisk is used denote italics, so your posted code is missing some multiplication signs).

Note that this isn’t valid according to the spec:

The RHS is a float, the LHS a vec4; there is no implicit conversion from scalars to vectors, although you can initialise a vector from a scalar, e.g.

vec4 colorG = vec4(color.r);

Initialising a vector from a scalar initialises all components to the same value.

1 Like

Thank you @GClements for spending some time on my problem, that was spot on.
Problem was indeed the improper initialization of the vec4 colorG variable as per your last advice.
Apology for the poor post editing, I should have seen this in the guidelines. I think I corrected it