Per-Vertex Lighting vs. Per-Pixel Lighting

I’m very new to OpenGL and also to C++. I’m following a long tutorial on creating an OpenGL game engine. Its going pretty good so far, but one thing I’ve noticed is that the lighting looks really terrible sometimes. It uses per-vertex lighting so it ends up looking pretty ugly. I know that per-pixel lighting is more expensive to calculate, but I have a feeling it will look a lot nicer, and that it will be worth the performance hit.

I’m afraid my question is very vague but try to do your best to help me :). What are the coding differences between Per-Vertex lighting and per-Pixel lighting, that is to say: how can I change my existing code so it uses per-pixel calculations instead of per vertex? Is it just a few minor changes or does it require an entire re-working of the way the lighting rendering works?

Thanks in advance!

Assuming you’ve already coded your lighting in a vertex shader, it’s largely just pushing that lighting code into the fragment shader. Pretty simple.

For all the lighting equations, see the Lighting chapter in the OpenGL Programming Guide.