SetCubeMode texture,mode

Parameters

texture - texture handle (must be created with the cubic environment map flag, 128)

mode - how the cubemap is applied to an entity
1: reflection (default)
2: normal
3: position

Description

Sets how a cubemap texture is mapped onto the entities that wear it.

Mode 1, reflection, is the one games nearly always want: the face shown at each point depends on the camera and the surface angle, so the object looks like polished chrome reflecting its surroundings. Mode 2, normal, picks the face straight from each vertex's normal - the view direction no longer matters. Mode 3, position, picks it from each vertex's position instead. Modes 2 and 3 are mostly for special effects and debugging a cubemap's contents.

On the Blitz3D+ DirectX 12 runtime the mode is stored but not yet applied: whatever mode you set, the texture is currently mapped by the entity's ordinary UV coordinates, as the example says on screen. Calling it is harmless, so classic code runs unchanged - the modes take effect when cubemap rendering lands in the modern renderer.

See also: SetCubeFace, CreateTexture, EntityTexture, TextureBlend.

Example

; SetCubeMode Example
; -------------------

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

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

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

; Flag 128 = cubic environment map, flag 256 = keep it drawable
cube_tex=CreateTexture(128,128,128+256)

; Paint a simple sky-and-ground pattern into the texture
SetBuffer TextureBuffer(cube_tex)
ClsColor 90,150,255
Cls
Color 70,140,60
Rect 0,64,128,64,1
Color 255,255,255
Rect 24,24,24,16,1
Rect 72,20,32,18,1
SetBuffer BackBuffer()

; A shiny pickup that wears the cubemap
ball=CreateSphere(16)
PositionEntity ball,0,1,0
EntityTexture ball,cube_tex

mode=1
SetCubeMode cube_tex,mode

While Not KeyDown(1)

    ; Keys 1/2/3 choose how the cubemap is applied
    If KeyHit(2)
        mode=1
        SetCubeMode cube_tex,mode
    EndIf
    If KeyHit(3)
        mode=2
        SetCubeMode cube_tex,mode
    EndIf
    If KeyHit(4)
        mode=3
        SetCubeMode cube_tex,mode
    EndIf

    TurnEntity ball,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

    name$="reflection (default)"
    If mode=2 Then name$="normal"
    If mode=3 Then name$="position"

    Text 0,0,"1/2/3: cubemap mode   Arrows: camera   Esc: exit"
    Text 0,20,"SetCubeMode cube_tex,"+mode+" - "+name$
    Text 0,40,"Note: this DirectX 12 runtime stores the mode but does not apply"
    Text 0,60,"it yet - the texture maps by the sphere's UVs in every mode."

    Flip

Wend

End

Index