Normal mapping is fun.

No, I won't give you the texture ¬_¬

No, I won't give you the texture ¬_¬


;; decipher this, <censored> ;; this code is public domain. so is the crappy media. Graphics3D 800,600,32,2 SetBuffer(BackBuffer()) c = CreateCamera() s = CreateCylinder(32,0) ScaleMesh s,2,1,2 UpdateNormals s SetBuffer(BackBuffer()) CameraClsMode c,1,1 EntityBlend(s,3) EntityFX s,1+2 surf = GetSurface(s,1) SpecularMap = LoadTexture("spec.png") BumpMap = LoadTexture("bump.png") DiffuseMap = LoadTexture("diffuse.png") TextureBlend SpecularMap,5 TextureBlend BumpMap,4 TextureBlend DiffuseMap,2 ScaleTexture specularmap,.125,1 ScaleTexture DiffuseMap,.125,1 ScaleTexture BumpMap,.125,1 SpecBrush = CreateBrush() BrushTexture SpecBrush,SpecularMap,0,0 BumpBrush = CreateBrush() BrushTexture BumpBrush,BumpMap,0,0 BrushTexture BumpBrush,DiffuseMap,0,1 BrushBlend SpecBrush,3 BrushBlend BumpBrush,0 BrushFX SpecBrush,1+2 BrushFX BumpBrush,1+2 p = CreatePivot() lrange# = 8 PositionEntity c,2,2,2 PointEntity c,s CameraRange c,.001,500 MoveMouse 0,0 lrange = 8 specularity# = 1.5 l.Light = New Light CameraClsColor c,50,50,50 PointEntity c,s Repeat ; TurnEntity s,.1,.2,.3 If KeyHit(57) lm = Not lm Select lm Case 0 L\X# = Sin(MilliSecs()*.05)*12 L\Y# = Cos(MilliSecs()*.05)*12 L\Z# = 0 lrange = 8 Case 1 l\x = EntityX(c,1) l\y = EntityY(c,1) l\z = EntityZ(c,1) lrange = 2 End Select EndIf If lm = 1 Then l\x = EntityX(c,1) l\y = EntityY(c,1) l\z = EntityZ(c,1) Else L\X# = 8+Sin(MilliSecs()*.05)*9 L\Y# = 8+Sin(MilliSecs()*.05)*9 L\Z# = 8 EndIf lrange = lrange + MouseZSpeed()*.05 If lrange < .0001 Then lrange = 0.0001 TurnEntity c,MouseYSpeed(),-MouseXSpeed(),0 RotateEntity c,EntityPitch(c),EntityYaw(c),0 MoveEntity c,(KeyDown(32)-KeyDown(30))*.1,0,(KeyDown(17)-KeyDown(31))*.1 EntityBlend s,3 MoveMouse 400,300 t = MilliSecs() CameraClsMode c,1,1 PaintEntity s,BumpBrush EntityBlend s,0 For n = 1 To CountSurfaces(s) surf = GetSurface(s,n) For v = 0 To CountVertices(surf)-1 TFormPoint VertexX(surf,v),VertexY(surf,v),VertexZ(surf,v),s,0 x# = TFormedX() - l\x y# = TFormedY() - l\y z# = TFormedZ() - l\z TFormNormal VertexNX(surf,v),VertexNY(surf,v),VertexNZ(surf,v),s,0 dist# = Sqr(x*x+y*y+z*z) Intensity# = 1.0 - (dist/(lrange*8)) If intensity < 0 Then intensity = 0 PositionEntity p,TFormedX(),TFormedY(),TFormedZ(),1 AlignToVector p,TFormedX(),TFormedY(),TFormedZ(),3,1 RotateEntity p,EntityPitch(p,1),EntityYaw(p,1),0,1 TFormNormal x,y,z,0,p VertexColor surf,v,(1.0-TFormedX())*127,(1.0-TFormedY())*127,((1.0-TFormedZ())*127)*Intensity Next Next RenderWorld CameraClsMode c,0,0 PaintEntity s,specbrush For n = 1 To CountSurfaces(s) surf = GetSurface(s,n) For v = 0 To CountVertices(surf)-1 VertexColor surf,v,0,0,0 Next Next TFormPoint l\x,l\y,l\z,0,s LightMesh(s,Specularity*255,Specularity*255,Specularity*255,lrange*.5*Intensity,TFormedX(),TFormedY(),TFormedZ()) RenderWorld t = MilliSecs()-t Text 0,0,t Flip Until KeyHit(1) Type Light Field X# Field Y# Field Z# Field R# Field G# Field B# End Type Function RenderNormals(Mesh,BumpBrush,SpecBrush) End Function Function GradientRect(X,Y,Width,Height,Buffer,Direction) LockBuffer(Buffer) d# = Sqr(Width*Width+Height*Height) For ix = X To X + Width For iy = Y To Y + Width Select Direction Case 1 c# = (Float(ix-X)/Width)*255 Case 2 c# = (1.0 - Float(ix-X)/Width)*255 Case 3 c# = (Float(iy-Y)/Height)*255 Case 4 c# = (1.0 - Float(iy-Y)/Height)*255 Case 5 k# = Sqr((iy-Y-Height/2)^2 + (ix-X-Width/2)^2)/d If k >= 1 Then Stop c# = (1.0-k)*255 End Select If c > 255 : c = 255 : Stop : EndIf If c < 0 :Stop : c = 0 : : EndIf Pixel = 255 Shl 24 Or c Shl 16 Or c Shl 8 Or c WritePixelFast ix,iy,Pixel,Buffer Next Next UnlockBuffer(Buffer) End Function
