ApplyCameraPostFX ( camera,asset )

Parameters

camera - camera entity

asset - a ready camera effects (postfx) asset, from FindWorldAsset

Description

Replaces a camera's whole chain of post effects with a camera preset.

A camera preset (.postfx file) is an ordered list of screen effects with their settings - bloom, colour adjustment, a vignette - that you design once and reuse: one look for the game, another for a dream sequence or the pause screen. Load the preset with LoadResourceDocument and LoadResourceDocumentAsync, wait for WorldReady, and pass FindWorldAsset(world,"resource").

The preset replaces everything on the camera, including effects added with CameraEffect, and an empty preset clears the chain. Each camera gets its own copies of the effects, and keeps them after you free the world that loaded the preset.

A preset can require HDR rendering and a particular tone-map mode. Those belong to your program: set them with HDRRendering and ToneMapMode before you load the preset, which is checked when it loads as well as when you apply it. Turning them off later, while a camera still uses the preset, is reported as an error when that camera next renders.

Returns True, or False with the reason in AppearanceError(), keeping the camera's previous effects.

For the full story, see the Environment and camera presets guide and its complete 01_Appearance_Presets.bb sample.


See also: ApplyWorldEnvironment, AppearanceError, CameraEffect, HDRRendering, ToneMapMode.

Example

; ApplyWorldEnvironment Example
; -----------------------------

Graphics3D 640,480,0,2
SetBuffer BackBuffer()

; The soft camera preset needs HDR and tone map 2; those belong to the program
HDRRendering True
ToneMapMode 2

camera=CreateCamera()
PositionEntity camera,0,2,-6

light=CreateLight()
RotateEntity light,45,45,0

; A courtyard of simple shapes to light
ground=CreatePlane()
EntityColor ground,120,130,110
pillar=CreateCylinder(16)
ScaleEntity pillar,0.5,1.5,0.5
PositionEntity pillar,-1.5,1.5,1
ball=CreateSphere(16)
PositionEntity ball,1.5,1,0

; Mountain daylight: sky, ambient light and shadows; soft and plain: camera effects
daylight=LoadPreset(LoadResourceDocument("../../../samples/appearance/daylight.environment"))
soft=LoadPreset(LoadResourceDocument("../../../samples/appearance/soft.postfx"))
plain=LoadPreset(CreateResourceDocument("postfx"))
softened=False
message$="Nothing applied yet"

While Not KeyDown(1)

    ; 1 applies the environment to the world we are drawing
    If KeyHit(2) Then
        If ApplyWorldEnvironment(GetWorld(),FindWorldAsset(daylight,"resource")) Then message="ApplyWorldEnvironment returned True"
    EndIf

    ; 2 swaps the camera's whole effect chain: soft, or plain (no effects)
    If KeyHit(3) Then
        softened=Not softened
        effects=FindWorldAsset(plain,"resource")
        If softened Then effects=FindWorldAsset(soft,"resource")
        If ApplyCameraPostFX(camera,effects) Then message="ApplyCameraPostFX returned True"
    EndIf

    ; 3 makes a mistake: an environment is not a camera preset
    If KeyHit(4) Then
        If Not ApplyCameraPostFX(camera,FindWorldAsset(daylight,"resource")) Then message="ApplyCameraPostFX returned False"
    EndIf

    ; 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

    TurnEntity ball,0,1,0
    RenderWorld

    Text 0,0,"Arrow keys: move camera   1: environment   2: effects   3: a mistake   Esc: exit"
    Text 0,20,message
    Text 0,40,"AppearanceError: "+AppearanceError()

    Flip

Wend

; Applied presets keep what they need, so their worlds can go any time
FreeWorld plain
FreeWorld soft
FreeWorld daylight

End

; Load a preset document into a world of its own, and wait for it
Function LoadPreset(document)
    If document=0 Then RuntimeError ResourceDocumentError()
    preset=LoadResourceDocumentAsync(document)
    FreeResourceDocument document
    While Not WorldReady(preset)
        If WorldLoadState(preset)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(preset)
        UpdateAsyncLoads 2
    Wend
    Return preset
End Function

Index