TGC Codebase Backup



Atmospheric Fog by TinTin

24th Apr 2007 7:56
Summary

Example of how to create some atmospheric fog



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `********************************************************************************************
` Program : Atmospheric Fog Demonstration
`  Author : Alan Barclay (TinTin)
`********************************************************************************************
Set Display Mode 800,600,32
Sync Rate 0 : Sync On
AutoCam Off : Hide Mouse : Position Camera 0,1.6,0
Position Light 0,0,0,0 : Point Light 0,1,-1,1
cBackdrop = RGB(160,32,16) :Color Backdrop cBackdrop
Set Normalization On : FastSync

` Show Welcome Message                                                                      *
Center Text Screen Width()/2,(Screen Height()-Text Height("|"))/2,"Building Textures"
FastSync

` Create Terrain Matrix & Texture                                                           *
Lock Pixels
 For X=0 to 128
  For Y=0 to 128
    Dot X,Y,RGB(8+Rnd(16),24+Rnd(32),16+Rnd(32))
  Next
 Next
Unlock Pixels
Get Image 1,0,0,128,128,1
Make Matrix 1,100,100,50,50 : Position Matrix 1,-50,0,-50
Prepare Matrix Texture 1,1,1,1
For X=0 to 50
 For Y=0 to 50
  H#=(rnd(50)-25)/100.0
  Set Matrix Height 1,X,Y,H#
  Set Matrix Normal 1,X,Y,1,1,1
 Next
Next
Update Matrix 1

` Create Fog Objects & Texture                                                              *
Create Bitmap 1,256,256
Set Current Bitmap 1
Lock Pixels
 For X=0 to 128 Step 8
  For Y=0 to 128 Step 8
    C=RND(255) : C=RGB(C,C,C)
    Box X,Y,X+8,Y+8,C,C,C,C
  Next
 Next
Unlock Pixels
For I=1 to 2
 Blur Bitmap 1,5
Next

` Tile Texture to make seamless                                                              *
Get Image 2,0,0,128,128,1
Paste Image 2, 128,   0
Paste Image 2,   0, 128
Paste Image 2, 128, 128
For I=1 to 2
 Blur Bitmap 1,5
Next
Get Image 2,64,64,128+64,128+64,1
Set Current Bitmap 0 : Delete Bitmap 1
Make Object Cylinder 1,-10 : Position Object 1,0,1,0
Scale Object 1,100,100,100 : Set Object Light 1,0
Texture Object 1,2 : Set Alpha Mapping On 1,4
Clone Object 2,1
Scale Object 1,200,200,200
Set Alpha Mapping On 2,8

` Create some random cubes                                                                   *
for o=3 to 15
   Make Object Cube O,2
   X=(Rnd(20)+5):If RND(2)<=1 Then X=-X
   Z=(Rnd(20)+5):If RND(2)<=1 Then Z=-Z
   YRotate Object O,Rnd(90)*4
   Position Object O,X,1,Z
Next

` Use Distant Fog same colour as backdrop                                                    *
Fog On
Fog Color cBackdrop
Fog Distance 40

` Main Loop                                                                                  *
Do
   Scroll Object Texture 1,0,-0.0004
   Scroll Object Texture 2,0,-0.0008
   Control Camera Using Arrowkeys 0,0,1
   FastSync
Loop
End
`***[END]*************************************************************************************