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;
}