Graphics3D 1280,1024,32,2SetBuffer BackBuffer()camera=CreateCamera()PositionEntity camera,0,0,-3;RotateEntity camera,10,0,0light=CreateLight()PositionEntity light,0,10,0sphere=CreateCube()PositionEntity sphere,0,0,0RotateEntity sphere,90,0,0tex=LoadTexture ("rock.jpg")EntityTexture sphere,texbump=LoadTexture ("rock_bump.jpg")applybumpmap( sphere,"rock.jpg",bump)While Not KeyDown(1)TurnEntity sphere,.01,.02,.03If KeyDown(200) Then TranslateEntity light,0,1,0If KeyDown(208) Then TranslateEntity light,0,-1,0RenderWorldText 0,0,"light y = "+EntityY(light)Flip Wend End Function ApplyBumpMap( Mesh, SearchTexture$, BumpMap, Frame=0, LightMapped=1 ) ;this function changes the texture on a mesh so you can apply a bump/normal map Local SurfS=CountSurfaces( Mesh ) Local SurfI=0 Local BlankBrush = CreateTexture( 64, 64 ) Local t0, t1, t2, t3 SetBuffer TextureBuffer( BlankBrush ) ClsColor 255, 255, 255 Cls ClsColor 0, 0, 0 SetBuffer BackBuffer() For SurfI=1 To Surfs s=GetSurface( Mesh, SurfI ) b=GetSurfaceBrush(s) t0=GetBrushTexture( b, 0 ) t1=GetBrushTexture( b, 1 ) t2=GetBrushTexture( b, 2 ) If Upper$( StripPath$( TextureName$( t0 ) ) ) = Upper$( SearchTexture$ ) BrushTexture b, BumpMap, Frame, 0 BrushTexture b, t0, Frame, 2 ;lightmap is always on channel (index) 1 If LightMapped=0 BrushTexture b, BlankBrush, 0, 1 Else BrushTexture b, t1, 0, 1 EndIf PaintSurface s, b EndIf If t0<>0 FreeTexture t0 EndIf Next FreeTexture BlankBrushEnd FunctionFunction StripPath$(file$) ;borrowed from Blitz Help file If Len(file$)>0 For i=Len(file$) To 1 Step -1 mi$=Mid$(file$,i,1) If mi$="" Or mi$="/" Then Return name$ Else name$=mi$+name$ Next EndIf Return name$ End Function