Fredborgs Dot3 code

Blitz3D Forums/Blitz3D Programming/Fredborgs Dot3 code

Function UpdateBumpNormals(mesh,light,lighttype=0)

	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.0
			grn2# = 0.0
			blu2# = 0.0	
			For d3l.Dot3Light = Each Dot3Light
				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
					TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),mesh,0
					nx# = -TFormedX()
					ny# = -TFormedY()
					nz# = -TFormedZ()
					TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),mesh,0
					red# = TFormedX()-EntityX(d3l\ent,True)
					grn# = TFormedY()-EntityY(d3l\ent,True)
					blu# = TFormedZ()-EntityZ(d3l\ent,True)
					d# = Sqr(red*red + grn*grn + blu*blu)
					red = red/d
					grn = grn/d
					blu = blu/d
				Else
					RuntimeError "Do it yourself, will ya?"
				End If

				dot# = (red*nx + grn*ny + blu*nz)
				If dot<0.0 Then dot = 0.0	

				red# = ((1.0+(red*dot))*127.5)*d3l\mul
				grn# = ((1.0+(grn*dot))*127.5)*d3l\mul
				blu# = ((1.0+(blu*dot))*127.5)*d3l\mul
				If red<0 Then red = 0
				If grn<0 Then grn = 0
				If blu<0 Then blu = 0				
				red2# = red2+red
				grn2# = grn2+grn
				blu2# = blu2+blu	
			Next
			
			VertexColor surf,v,red2,grn2,blu2
		Next
	Next

End Function


Here is the original Code....
For that you can compare it easier..