CameraShadows camera[,enabled]
Parameters
|
camera - camera handle enabled (optional) - True renders shadows for this camera; True (default) |
Description
|
Turns automatic shadows on or off for one camera. Shadows appear only when the whole chain is enabled: Shadows turns the system on, a shadow-enabled light is selected (LightShadows), the camera keeps CameraShadows on, and casters and receivers keep EntityShadows on. Cameras start enabled, so this command is the opt-out. Every shadow-enabled camera gets shadow maps fitted to its own view, and that work is repeated per camera. Secondary cameras usually do not need it: a minimap, a rear-view mirror, an item-preview camera or a UI render camera looks fine without shadows and renders noticeably cheaper with them off. Requires Extended mode. See also: Shadows, LightShadows, EntityShadows, CreateCamera. |
Example
; CameraShadows Example ; --------------------- ; Requires Extended mode. Graphics3D 640,480,0,2 SetBuffer BackBuffer() ; Main game camera camera=CreateCamera() PositionEntity camera,0,5,-9 RotateEntity camera,25,0,0 ; Second top-down camera drawn as a minimap in the corner minimap=CreateCamera() PositionEntity minimap,0,22,4 RotateEntity minimap,90,0,0 CameraViewport minimap,460,10,170,130 ; A directional sun; the shadow system selects it automatically sun=CreateLight(1) AmbientLight 70,75,85 ; Ground plane that receives the shadows ground=CreateCube() ScaleEntity ground,10,0.1,10 PositionEntity ground,0,-0.1,4 EntityColor ground,170,190,170 ; A crate and a pillar to cast shadows crate=CreateCube() PositionEntity crate,-2.5,1,4 EntityColor crate,210,150,80 pillar=CreateCylinder() ScaleEntity pillar,0.7,2,0.7 PositionEntity pillar,2.5,2,5 EntityColor pillar,120,160,220 ; Turn on the automatic shadow system Shadows 1 mini_shadows=1 angle#=0 While Not KeyDown(1) ; Press Space to toggle shadow work for the minimap camera only If KeyHit(57) Then mini_shadows=1-mini_shadows ; Disable shadows on a secondary camera to save GPU work CameraShadows minimap,mini_shadows ; Swing the sun so the shadows sweep across the ground angle=angle+0.3 RotateEntity sun,55,angle,0 TurnEntity crate,0,1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Space: toggle minimap shadows Arrow keys: move camera Esc: exit" Text 0,20,"CameraShadows minimap,"+mini_shadows+" (main camera keeps its shadows)" Flip Wend End
Index