Const winw%=1024*0.5
Const winh%=765*0.5
Graphics winw%,winh%,32,2
Global heightmap%=LoadImage("bump02.jpg")
Global colormap%=LoadImage("color02.jpg")
ResizeImage(heightmap%,winw%,winh%)
ResizeImage(colormap%,winw%,winh%)
SetBuffer BackBuffer()
Global clock%,frame%,fpsc%
While KeyHit(1)=False
Cls
Render(winw%*0.5+Sin(MilliSecs()/6)*80,winh%*0.5+Cos(MilliSecs()/6)*50,20,2000)
FPS()
Flip
Wend
End
;FUNCTIONS------------------------------------------------------------------
Function FPS()
If MilliSecs()>clock%+1000 Then
fpsc%=frame%
frame%=0
clock%=MilliSecs()
Else
frame%=frame%+1
End If
Color 125,125,125
Text 10,10,fpsc%+" FPS "
End Function
Function Render(sx%,sy%,sz%,p%)
Local dist#,c%,heightvalue%,colorvalue%,r%,g%,b%,n%,x%,y%
LockBuffer(GraphicsBuffer())
LockBuffer(ImageBuffer(heightmap%))
LockBuffer(ImageBuffer(colormap%))
For x%=0 To winw%-1
For y%=0 To winh%-1
heightvalue%=GetHeight%(ReadPixelFast(x%,y%,ImageBuffer(heightmap%)))-sz%
colorvalue%=ReadPixelFast(x%,y%,ImageBuffer(colormap%))
dist#=Sqr(Abs(sx%-x%)^2+Abs(sy%-y%)^2+Abs(255-heightvalue%)^2)
c%=Float(255)*(Float(1)/dist#^Float(2))*Float(p%)-100
r%=Limit(RgbR%(colorvalue%)+c%+(255-dist#)*0.2,0,255)
g%=Limit(RgbG%(colorvalue%)+c%+(255-dist#)*0,0,255)
b%=Limit(RgbB%(colorvalue%)+c%+(255-dist#)*0,0,255)
WritePixelFast x%,y%,HexColor%(r%,g%,b%)
Next
Next
UnlockBuffer(ImageBuffer(colormap%))
UnlockBuffer(ImageBuffer(heightmap%))
UnlockBuffer(GraphicsBuffer())
End Function
Function Limit(value%,min%,max%)
If value%>max% Then value%=max%
If value%