Question

I'm just working on some per fragment lighting, working in visual studio 2010 C++ and using GLSL, and for some reason, only this fragment shader is having issues, I have pass through fragment shaders that work, and all of my vertex shaders work, so it's something to do with this specific guy. Basically my shader looks like this:

#version 120

varying vec3 normal;
varying vec3 lightDir;
varying vec4 ambient;
varying vec4 diffuse;

void main()
{
float NdotL = max(dot(lightDir,normalize(normal)),0.0);
gl_FragColor = vec4((NdotL * diffuse.rgb + ambient.rgb),  gl_FrontMaterial.diffuse.a);
}

Does anybody have any ideas to help? As I said, I already load multiple shaders into the program, but only this guy doesn't work

EDIT: Switched the vec3 to a float, still getting the same issue. HALP!

Was it helpful?

Solution

dot(lightDir,normalize(normal)) is the dot product. So it returns a scalar.

max(scalar, scalar) also evaluates to a scalar.

Therefore:

vec3 NdotL = max(dot(lightDir,normalize(normal)),0.0);

Attempts to assign a scalar to a vector. Which is invalid.

So what you probably wanted was:

float NdotL = max(dot(lightDir,normalize(normal)),0.0);
gl_FragColor = vec4((NdotL * diffuse.rgb + ambient.rgb),  gl_FrontMaterial.diffuse.a);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top