
Need help with lightning
Posted Thursday, 4 February, 2010 - 23:46 by chandragon inHi
I started learning the use of OpenGl/OpenTK short time ago so please forgive my clumsiness.
I try to render basic shapes with a basic light effect (I have a sphere and I would like to see it lit on one side and dark on the other depending on the light, and be able to change the light direction and intensity).
I use a little GLSL code I found in a lightning tutorial and vertex/index buffers like in the OpenTK sample "simple GLSL", but I didn't manage to use a normals buffer (I tried to do the same operation as for the vertex buffer, only changing EnableCap.VertexArray to EnableCap.NormalArray but it didn't work).
I changed the GLSL code so that it gets the normal vectors from the vertex position but I don't get a satisfying result:
The light intensity on the sphere's pixels seems to be determined by the distance of this pixel from the center of the screen ... not natural at all.
I didn't find how to change the light direction, only the light intensity with:
GL.Light(LightName.Light0, LightParameter.Ambient or ConstantAttenuation);
If you could show me a sample code of the difficult points it would help me much.
Thank you


Comments
Re: Need help with lightning
No answers ... maybe I didn't formulate very well my question ?
Anyway, I found out how to do.
The fact is that we don't set the light direction as I thought but it's position with GL.Light(LightName.Light0, LightParameter.Position, pos) where pos is a Vector4.
And to solve my normals buffer problem I used the code of the Vbo sample I found on this forum.
I also changed some pieces of the GLSL code and now it works fine !