Confusing compile error

I’m trying to code a simple toon shader to visualize some models in a neat way. I borrowed the vertex/fragment shader off a friend, who has it working on his machine, but it would not compile on mine. The shader is so simple, and the error confuses me. Any help deciphering and fixing this error would be greatly appreciated! Maybe one of us has an outdated GLSL, but we’re both using the C# Tao wrapper for OpenGL so it seems unlikely… I’m not sure why it compiles and works on his machine and not on mine. (I have a separate Phong shader that compiles and works, so I doubt it’s my shader compiling/linking code)

EDIT: By the way, I wish GLSL would have an easy-to-find listing of all their error codes with descriptions. Then I could probably solve this (probably easy) problem by myself. :\ But I’m really new to GLSL, and I can’t devote an evening to this when I really should be working on things that aren’t extras, like a second shader. :slight_smile:

Shader cannot compile, because:
FRAGMENT SHADER LOG:
(1) : warning C7011: implicit cast from “int” to “float”
(1) : error C1102: incompatible type for parameter #2 (“b”)

Vertex shader:


varying vec3 normal; 
varying vec4 baseColor;

void main()
{ 
	normal = gl_NormalMatrix * gl_Normal;
	baseColor = gl_Color;
	gl_Position = ftransform();
}



Fragment shader:


varying vec3 normal;
varying vec4 baseColor;

void main()
{
	float intensity; 
	vec4 color;
	vec3 n = normalize(normal);
	
	intensity = dot(normalize(gl_LightSource[0].position), n);
		
	if (intensity > 0.9975)
		color = vec4(1, 1, 1, 1);
	else if (intensity > 0.75)
		color = baseColor;
	else if (intensity > 0.5)
		color = 0.75 * baseColor;
	else if (intensity > 0.20)
		color = 0.25 * baseColor;
	else
		color = 0.075 * baseColor;
		
	gl_FragColor = color;
	gl_FragColor.w = 1;
}


To fix the error, try changing the line

intensity = dot(normalize(gl_LightSource[0].position), n);

to

intensity = dot(normalize(gl_LightSource[0].position.xyz), n);

The position attribute is a vec4 and needs to be converted to a vec3. I would bet this works on your friend’s computer because he is on Nvidia and you are not. Nvidia is more lax by default in what its GLSL compiler accepts.

As for the implicit cast warning, try changing your “1” values to “1.0”.

Yep, that did the trick. Thanks a lot. I had a suspicion it was an Nvidia vs. ATI driver problem, but had no idea where to go from there. Thanks a lot!

“By the way, I wish GLSL would have an easy-to-find listing of all their error codes with descriptions.”

The reason we don’t have such a listing is that the contents of the info logs are currently unspecified (other than to be generally useful for development).

Probably your best bet is to grab a good shader debugger and have at it that a way. AMD and NVIDIA have their own proprietary tools and there are several independent debuggers out there too, like glIntercept, glslDevil and gDEBugger to plug a few.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.