-1

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!

genpfault
  • 51,148
  • 11
  • 85
  • 139

1 Answers1

0

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);
Tommy
  • 99,986
  • 12
  • 185
  • 204
  • I tried that, still getting the same issue, any other solutions? – user2272511 Apr 12 '13 at 00:46
  • Having turned the `varying`s into variables, `NdotL` into a `float` and `gl_FrontMaterial.diffuse.a` into a constant, your code ran fine through the GLSL sandbox at http://www.mrdoob.com/projects/glsl_sandbox/ so I don't immediately have any other ideas — though some GLSL implementations require a newline at the end of the file; do you have one of those? – Tommy Apr 12 '13 at 00:49
  • I did, thank you though sir, gonna just break this laptop instead of fixing it >. – user2272511 Apr 12 '13 at 01:04
  • ....I didn't put the file in the resource folder. I'm the worst at this game. – user2272511 Apr 12 '13 at 01:10