0

I want to use a point light calculated in GLSL. I works fine, but if I calculate it per pixel it still looks the same as the Vertex based calculation.

My Vertex Code:

uniform vec3 LightPos;
varying vec2 UVCoord;
varying vec3 Normal;
varying vec3 posToLight;

void main()
{           
    UVCoord = gl_MultiTexCoord0.st;
    gl_Position = ftransform();
    Normal = normalize(gl_NormalMatrix * gl_Normal);

    vec3 pos = vec3(gl_ModelViewMatrix * gl_Vertex);
    posToLight = normalize(LightPos - pos);
}

My Fragment Code:

uniform sampler2D tex1;
varying vec2 UVCoord;
varying vec3 Normal;
varying vec3 posToLight;

void main()
{
    vec3 Color = vec3(texture2D(tex1, UVCoord));
    float LightIntensity = pow(max(dot(posToLight, Normal), 0.0), 10.0);
    gl_FragColor = vec4(Color * (LightIntensity), 1.0);
}

Does anybody have an idea what I am doing wrong?

user3075425
  • 332
  • 1
  • 6
  • 23
  • 1
    first of all, you have sent vertex shader instead of fragment shader :) – Jaa-c Dec 27 '13 at 12:54
  • 2
    That is not point lighting; it's directional. Even so, the pow should yield an easily visible difference even though you should consider normalizing the normal in the fragment shader. –  Dec 27 '13 at 13:29

0 Answers0