samples/JamesH/AmbientOcclusion
ambient_occlusion.abs
102 lines of ArcBasic. Words in colour that are commands link to their help page. To run it, download ArcBasic, open the file and press F5.
; Ambient occlusion - ArcBasic extension sample;; CameraAmbientOcclusion darkens the creases, corners and gaps where; surfaces meet, the way real light struggles to reach them. It works on; everything the camera sees, with no extra work for each model.;; Keys: A ambient occlusion on/off; Up/Down intensity [ ] radius; Left/Right orbit camera Escape quitGraphics3D 800,600,0,2SetBuffer BackBuffer()pivot=CreatePivot()camera=CreateCamera(pivot)PositionEntity camera,0,7,-13PointEntity camera,pivotCameraClsColor camera,150,190,230AmbientLight 150,150,160light=CreateLight(1)RotateEntity light,55,35,0LightColor light,150,150,140; a floor and two walls making a cornerfloor=CreatePlane()EntityColor floor,235,215,180 ; light, plain colours show the effect bestwall1=CreateCube()ScaleEntity wall1,8,4,.25PositionEntity wall1,0,4,6EntityColor wall1,240,190,160wall2=CreateCube()ScaleEntity wall2,.25,4,8PositionEntity wall2,-8,4,0EntityColor wall2,160,215,215; a stack of crates pushed into the cornercrate=LoadMesh("wcrate1.3ds")If crate=0 crate=CreateCube() EntityColor crate,170,120,70EndIfFitMesh crate,-1,-1,-1,2,2,2PositionEntity crate,-6.5,1,4.5For i=1 To 5 c=CopyEntity(crate) Select i Case 1 : PositionEntity c,-4.5,1,4.5 Case 2 : PositionEntity c,-6.5,1,2.5 Case 3 : PositionEntity c,-5.5,3,4.5 Case 4 : PositionEntity c,-2,1,4.6 : TurnEntity c,0,25,0 Case 5 : PositionEntity c,-6.5,3,2.5 End SelectNext; steps and a few round things on the floorFor i=0 To 3 s=CreateCube() ScaleEntity s,1.5,.25+i*.25,1 PositionEntity s,5,.25+i*.25,3-i*2 EntityColor s,200,180,235NextFor i=0 To 2 b=CreateSphere(16) PositionEntity b,-1+i*1.6,.8,-3 ScaleEntity b,.8,.8,.8 Select i Case 0 : EntityColor b,240,110,110 Case 1 : EntityColor b,250,220,100 Case 2 : EntityColor b,110,170,240 End SelectNextao=True : intensity#=4 : radius#=2CameraAmbientOcclusion camera,ao,intensity,radiusWhile Not KeyHit(1) changed=False If KeyHit(30) Then ao=Not ao : changed=True If KeyHit(200) Then intensity=intensity+1 : changed=True If KeyHit(208) And intensity>1 Then intensity=intensity-1 : changed=True If KeyHit(27) Then radius=radius+.5 : changed=True If KeyHit(26) And radius>.5 Then radius=radius-.5 : changed=True If changed Then CameraAmbientOcclusion camera,ao,intensity,radius If KeyDown(203) Then TurnEntity pivot,0,1.5,0 If KeyDown(205) Then TurnEntity pivot,0,-1.5,0 RenderWorld Color 255,255,255 Text 10,10,"AMBIENT OCCLUSION (ArcBasic extension)" If ao Then a$="on" Else a$="off" Text 10,30,"A ambient occlusion: "+a$ Text 10,45,"Up/Down intensity: "+Int(intensity) Text 10,60,"[ ] radius: "+radius Text 10,75,"Left/Right orbit Esc quit" Text 10,580,"Look where the crates meet the walls and the floor" FlipWendEnd
