Velator

03-22-2015, 04:17 AM

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

vec3 specular=vec3(distance(Pos,lightpos)/8.0f);

vec3 result = (specular ) * Color;

outColor = vec4(result, 1.0f)

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

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

lightpos is just the position of the light.

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

1679

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:

If Pos refers 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 the fragment position? How would my fragment shader code be different if I just want the brightness of the plane to be proportional to the distance of the vertex rather than the fragment? Basically what if I want this effect instead (the closer the light, the brighter color value for those vertices):

1680

Thanks

vec3 specular=vec3(distance(Pos,lightpos)/8.0f);

vec3 result = (specular ) * Color;

outColor = vec4(result, 1.0f)

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

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

lightpos is just the position of the light.

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

1679

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:

If Pos refers 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 the fragment position? How would my fragment shader code be different if I just want the brightness of the plane to be proportional to the distance of the vertex rather than the fragment? Basically what if I want this effect instead (the closer the light, the brighter color value for those vertices):

1680

Thanks