; 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 quit Graphics3D 800,600,0,2 SetBuffer BackBuffer() pivot=CreatePivot() camera=CreateCamera(pivot) PositionEntity camera,0,7,-13 PointEntity camera,pivot CameraClsColor camera,150,190,230 AmbientLight 150,150,160 light=CreateLight(1) RotateEntity light,55,35,0 LightColor light,150,150,140 ; a floor and two walls making a corner floor=CreatePlane() EntityColor floor,235,215,180 ; light, plain colours show the effect best wall1=CreateCube() ScaleEntity wall1,8,4,.25 PositionEntity wall1,0,4,6 EntityColor wall1,240,190,160 wall2=CreateCube() ScaleEntity wall2,.25,4,8 PositionEntity wall2,-8,4,0 EntityColor wall2,160,215,215 ; a stack of crates pushed into the corner crate=LoadMesh("wcrate1.3ds") If crate=0 crate=CreateCube() EntityColor crate,170,120,70 EndIf FitMesh crate,-1,-1,-1,2,2,2 PositionEntity crate,-6.5,1,4.5 For 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 Select Next ; steps and a few round things on the floor For 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,235 Next For 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 Select Next ao=True : intensity#=4 : radius#=2 CameraAmbientOcclusion camera,ao,intensity,radius While 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" Flip Wend End