Dot 3?

Blitz3D Forums/Blitz3D Beginners Area/Dot 3?

I've not tried the following, but take a look anyway:
http://www.blitzbasic.com/codearcs/codearcs.php?code=1145


I always found this one effective:
Type Dot3Light
	Field ent
	Field mul#
	Field typ
End Type

Graphics3D 800,600,32,2

cube=CreateCube()
ScaleEntity cube,5,.1,5
PositionEntity cube,0,-1,0
EntityColor cube,255,0,0

decl=LoadTexture( "tex.png",1+8)
bump=LoadTexture( "norm.png",1+8)
MeshEntity=LoadMesh("Floor16.x")

;MeshEntity=CreateSphere(16)
;ScaleEntity Meshentity,.7,.7,.7
;ScaleTexture decl,.1,.1
;ScaleTexture bump,.1,.1

PositionEntity MeshEntity,0,0,1

EntityFX MeshEntity,1+2
TextureBlend bump,4
EntityTexture MeshEntity,bump,0,0
EntityTexture MeshEntity,decl,0,1
Global piv=CreatePivot()

pivvy=CreatePivot()
light = Dot3_CreateLight(2,piv,1.0,1)
lighticon = CreateSphere(8,light)
EntityFX lighticon,1
ScaleEntity lighticon,0.01,0.01,0.01
Dot3_LightRange light,10

camera=CreateCamera()
CameraClsColor camera,100,120,130
PositionEntity camera,0,.2,-1.0

EntityParent camera,piv,1
EntityParent MeshEntity,piv,1

CameraRange camera,0.1,100

AmbientLight 100,100,100

declon = True
bumpon = True
doAnim=1
wire=1

While Not KeyHit(1)
	For d3l.dot3light = Each dot3light
		PositionEntity d3l\ent,Float((MouseX()-400))/200,-Float((MouseY()-300))/200,0,0
	Next
	
	If KeyHit(17)
		wire=Not wire
		WireFrame wire
	End If
	
	If KeyHit(57) doAnim=Not doAnim
	If KeyHit(2)
		If declon
			TextureBlend decl,0
		Else
			TextureBlend decl,2
		End If
		declon = Not declon
	End If
	If KeyHit(3)
		If bumpon
			TextureBlend bump,0
			EntityFX MeshEntity,0
		Else
			TextureBlend bump,4
			EntityFX MeshEntity,1+2
		End If
		bumpon = Not bumpon
	End If

	If KeyDown(4) TurnEntity MeshEntity,0,-1,0
	If KeyDown(5) TurnEntity MeshEntity,0,1,0
		
	If KeyDown(200) TurnEntity piv, 1,0,0
	If KeyDown(208) TurnEntity piv,-1,0,0
	
	If KeyDown(205) TurnEntity piv,0,-5,0
	If KeyDown(203) TurnEntity piv,0, 5,0
	
	If KeyDown(30) MoveEntity camera,0,0,0.05
	If KeyDown(44) MoveEntity camera,0,0,-0.05
	
	processtime=MilliSecs()
	If bumpon
		UpdateBumpNormals(MeshEntity,light,1)
	End If
	processtime=MilliSecs() - processtime
	
	UpdateWorld
	RenderWorld
	declstr$="OFF"
	If declon declstr$="ON "
	
	bumpstr$="OFF"
	If bumpon bumpstr$="ON "
		
	Text 10,20,"Process Time: "+processtime+"ms"
	Text GraphicsWidth()/2,0,"1 - Toggle Texture: "+declstr$+"   2 - Toggle Bumpmap: "+bumpstr$,True,False
	Text GraphicsWidth()/2,14,"A & Z to zoom in/out",True
	Text GraphicsWidth()/2,28,"3,4 Spins Sphere localy, cursors turns entire world except Cube ground",True
	
	Flip
Wend

Function UpdateBumpNormals(mesh,light,lighttype=0)
	EP=GetParent(mesh)
	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
End Function