Sorry More DOT3 stuff

Blitz3D Forums/Blitz3D Programming/Sorry More DOT3 stuff

this only seems to work when the light is supposed t be on one side..
the colors stop working when the light is on the other side of the cube, they get screwed up and i get a black thing... any one help?

EP=GetParent(mesh)
	If EP	EntityParent mesh,0,1

	n_surf = CountSurfaces(mesh)
	For s = 1 To n_surf
		surf = GetSurface(mesh,s)
		n_vert = CountVertices(surf)-1
		For v = 0 To n_vert
			red2# = 0
			grn2# = 0
			blu2# = 0
			For d3l.Dot3Light = Each Dot3Light
				lx#=EntityX(d3l\ent,True)
				ly#=EntityY(d3l\ent,True)
				lz#=EntityZ(d3l\ent,True)
	
				If d3l\typ = 1 ; Directional light
					TFormVector 0,0,1,d3l\ent,0
					nx# = TFormedX()
					ny# = TFormedY()
					nz# = TFormedZ()
					TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0
					red# = TFormedX()
					grn# = TFormedY()
					blu# = TFormedZ()
					
					
				ElseIf d3l\typ = 2 ; Point light		
					; Vertex Normal in World coordinates
					TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0
					Vnx# = TFormedX()
					Vny# = TFormedY()
					Vnz# = TFormedZ()
					
					; Vertex > Light Vector in World coordinates
					TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,0
					Lvx# = lx - TFormedX()
					Lvy# = ly - TFormedY()
					Lvz# = lz - TFormedZ()

					; Normalize Vertex > Light Vector
					d# = Sqr(Lvx*Lvx + Lvy*Lvy + Lvz*Lvz)
					Lvx	=	Lvx / d
					Lvy = Lvy / d
					Lvz = Lvz / d
				End If

				; Theta Angle between Vertex Normal & Vertex>Light Normal
				dot# = (Lvx*Vnx + Lvy*Vny + Lvz*Vnz)

				; Clamp Colors to 0
				If dot<0.0 Then dot# = 0
				
				; If the Mesh had a Parent, Convert Light Vector into that Parents Local coordinates
				; unsure if this'll work with multiple hierarchy
				If EP
					TFormNormal Lvx,Lvy,Lvz,0,EP
					Lvx# = TFormedX()
					Lvy# = TFormedY()
					Lvz# = TFormedZ()
				End If
				
				red# = ( (1.0+( Lvx * dot)) * 127) * d3l\mul
				grn# = ( (1.0+( Lvy * dot)) * 127) * d3l\mul
				blu# = ( (1.0+( Lvz * dot)) * 127) * d3l\mul
				
				red2# = red2+red
				grn2# = grn2+grn
				blu2# = blu2+blu
			Next
			VertexColor surf,v,red2,grn2,blu2
		Next
	Next
	If EP EntityParent mesh,EP,1