I've been trying to figure this out for days. This is my fragment shader code in main:

Code :vec3 specular=vec3(distance(Pos,lightpos)/8.0f); vec3 result = (specular ) * Color; outColor = vec4(result, 1.0f)

Posis the vertex position which is outputted from the vertex shader:

Code :"Pos = vec3(model* vec4(position, 1.0f));"

lightposis just the position of the light.

This is the effect I get. The closer the light to the plane, the darker those pixels get:

Untitled.jpg

But why do I get this effect? All I do is pass the vertex position. Why do I get a gradient effect? It looks as if the fragment shader measures the distance from each pixel rather than the vertex, but Pos is the vertex position. I just don't understand how the fragment shader does this? Can someone please explain this to me?

Here's the question stated a little more clearly:

IfPosrefers to the vertex position, and the brightness of the plane is proportional to distance of each vertex(Pos) from the light position, why does it look as if, instead, it's proportional to thefragmentposition? How would my fragment shader code be different if I just want the brightness of the plane to be proportional to the distance of thevertexrather than the fragment? Basically what if I want this effect instead (the closer the light, the brighter color value for those vertices):

h.jpg

Thanks