ApplyEnvironmentMap ( brush,asset )

Parameters

brush - the brush to give the reflection map

asset - a ready environment asset that has a reflection map, from FindWorldAsset

Description

Gives a brush an environment preset's reflection map, so shiny surfaces reflect its sky.

Polished metal, car paint and glass look real when they reflect their surroundings. An environment preset can carry a reflection map, usually the same sky image as its skybox. ApplyEnvironmentMap puts that map, at the preset's intensity, on a brush - switching the brush to Standard shading if it is not already, as BrushEnvironmentMap does. Paint objects with the brush as usual, with EntityMaterial or PaintEntity.

ApplyWorldEnvironment does not do this for you: it lights the world, while reflections belong to materials, so you choose which objects shine.

Returns True, or False with the reason in AppearanceError() - for example when the preset has no reflection map. The brush keeps the map after you free the world that loaded the preset.

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


See also: ApplyWorldEnvironment, AppearanceError, BrushEnvironmentMap, EntityMaterial, CreateStandardBrush.

Example

; ApplyEnvironmentMap Example
; ---------------------------

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

camera=CreateCamera()
PositionEntity camera,0,0,-4

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

; A polished metal trophy ball
ball=CreateSphere(32)

; The mountain daylight preset, which carries a reflection map
document=LoadResourceDocument("../../../samples/appearance/daylight.environment")
If document=0 Then RuntimeError ResourceDocumentError()
daylight=LoadResourceDocumentAsync(document)
FreeResourceDocument document
While Not WorldReady(daylight)
    If WorldLoadState(daylight)=WORLD_LOAD_FAILED Then RuntimeError WorldLoadError(daylight)
    UpdateAsyncLoads 2
Wend

; Two Standard metal brushes: plain, and one reflecting the mountains
plain=CreateStandardBrush()
BrushPBR plain,0.9,0.2
shiny=CreateStandardBrush()
BrushPBR shiny,0.9,0.2
If Not ApplyEnvironmentMap(shiny,FindWorldAsset(daylight,"resource")) Then RuntimeError AppearanceError()

; The brush keeps its map, so the preset's world can go
FreeWorld daylight

reflecting=True
EntityMaterial ball,shiny

While Not KeyDown(1)

    ; Space swaps between the plain and the reflective brush
    If KeyHit(57) Then
        reflecting=Not reflecting
        If reflecting Then EntityMaterial ball,shiny Else EntityMaterial ball,plain
    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,0.5,0
    RenderWorld

    Text 0,0,"Arrow keys: move camera   Space: plain / reflective   Esc: exit"
    If reflecting Then
        Text 0,20,"After ApplyEnvironmentMap shiny,daylight: the ball reflects the sky"
    Else
        Text 0,20,"The same metal without an environment map"
    EndIf

    Flip

Wend

FreeBrush shiny
FreeBrush plain

End

Index