
Per pixel lighting?
Posted Saturday, 14 April, 2012 - 23:36 by .-_ inI am trying to achieve per pixel lighting in my game. When I run my game, everything shows up solid black.
My VS:
varying vec2 texture_coordinate; void main() { vec3 normal, lightDir; vec4 diffuse; float NdotL; // Positions gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; texture_coordinate = vec2(gl_MultiTexCoord0); // Normals normal = normalize(gl_NormalMatrix * gl_Normal); lightDir = normalize(vec3(gl_LightSource[0].position)); NdotL = max(dot(normal, lightDir), 0.0); // Colors diffuse = gl_FrontMaterial.diffuse * gl_LightSource[0].diffuse; gl_FrontColor = NdotL * diffuse; }
My FS:
varying vec2 texture_coordinate; uniform sampler2D color_texture; void main() { gl_FragColor = texture2D(color_texture, texture_coordinate) * gl_Color; }
I don't really know how to set gl_LightSource[0], I set them parameters on light source 0, and enable it.
Any help?


Comments
Re: Per pixel lighting?
(I sense this is a really simply question)
Yep it is rather.
With the corrosponding Disable to stop ....
Re: Per pixel lighting?
Derp. Thanks.
Re: Per pixel lighting?
Adding the GL.Enable statement gives me this exception:
Could it be hardware limitations? How would I check? I will post back with samplers result soon, but i'd like to get the colors working first so i can see the textures.
EDIT:
sqrt'ing the output of the fragment shader helps. Things are now bright enough to see, however, all objects are alpha blended. This did not happen with fixed function. Should I be using GL.Disable for blending before drawing something non-transparent?
EDIT 2:
Samplers have been added. Still no textures, though. Changes have been pushed to github.
Re: Per pixel lighting?
EDIT:
sqrt'ing the output of the fragment shader helps. Things are now bright enough to see, however, all objects are alpha blended. This did not happen with fixed function. Should I be using GL.Disable for blending before drawing something non-transparent?
Yes, you should disable Blending, at begining of render, draw everything which does not need belnding, then enable blending, draw what needs to be blended, Like text etc. and end your render loop, rinse and repeat.
EDIT 2:
Samplers have been added. Still no textures, though. Changes have been pushed to github.
I'll chect it out and have a look, busy setting up the Mac with mono, so hopefully that will help me run the code and see what you see :D
I'll repost with the results.
Re: Per pixel lighting?
What about the exception? Is enabling sRGB out needed?