GLSL Rim Highlight

I want to do some half-rim highlighting, I want a GLSL vertex+fragment shader that renders the edge of the model with the original full-bright texture.

This is the effect I'm trying to achieve:
Image

Here's a diagram:
Image

The rendering path I'm trying to get is:
  • Render 3D model darkened to light level of room
  • Find direction of nearest light source
  • If light source is not in-front
  • Start shader program[light_direction] to highlight the model rim with original, undarkened texture

Ideally I want this to be 3 shader programs, one for behind, one for the left, one for the right so I can select which one to use out of 4 states, no program, left program, right program, behind program.

Thanks if anyone can help, I'm pulling my hair out over this one as the internet lacks GLSL tutorials massively.


I've had a second go at this and at the moment I have this based on vertex normals:
Image

Just ignore that poser on the far right!

EDIT: Completed the tint lighting effect that is added to the shader, the dwarf below has a blue tinge in the darkened areas that make the light (Now yellowish) stand out more.
Image

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=77070