I can't really spend any more time on this. Here is a demo that uses a very small amount of code. Maybe someone else can play with it:
http://www.leadwerks.com/post/DOOM3BB.zip (57 kb)
http://www.leadwerks.com/post/DOOM3BB.zip (57 kb)
Function NormalMapMesh(mesh,x#=-1,y#=-1,z#=1,style=0,range#=200) If EntityClass(mesh)="Mesh" temp=CreatePivot() If style=0 AlignToVector temp,x,y,z,3 RotateEntity temp,EntityPitch(temp),EntityYaw(temp),0 EndIf For s=1 To CountSurfaces(mesh) surf=GetSurface(mesh,s) For v=0 To CountVertices(surf)-1 Select style ;Directional light Case 0 TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,temp r#=(1.0-TFormedX())*127.5 g#=(1.0-TFormedY())*127.5 b#=(1.0-TFormedZ())*127.5 If TFormedZ()>0 r=127.5 g=127.5 b=0 EndIf ;Point light Case 1 RotateEntity temp,0,0,0 TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,temp AlignToVector temp,TFormedX(),TFormedY(),TFormedZ(),3 RotateEntity temp,EntityPitch(temp),EntityYaw(temp),0 TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,temp r#=(1.0-TFormedX())*127.5 g#=(1.0-TFormedY())*127.5 b#=(1.0-TFormedZ())*127.5 If TFormedZ()>0 b=0 TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,temp d#=PointDistance(TFormedX(),TFormedY(),TFormedZ(),0,0,0) If d<range d#=Sqr((range-d)/range) b#=d*255 Else r=127.5 g=127.5 b=0 EndIf End Select VertexColor surf,v,r,g,b Next Next FreeEntity temp EndIf For c=1 To CountChildren(mesh) normalmapmesh GetChild(mesh,c) Next End Function