Blitz3D+ Command Reference

EntityBlend entity,blend

Parameters

entity - entity handle
blend - blend mode:
0: automatic (default) - the renderer picks
1: alpha
2: multiply
3: add

Description

Sets how an entity is blended into the scene behind it.

This is about the entity against the rest of the world, not about combining texture layers - that is TextureBlend. The pixel that comes out of the entity texture and colour is what gets blended here.

Mode 0 is the default and means the renderer decides: it uses alpha blending when the entity has an alpha below 1, has forced vertex alpha, or wears a single transparent texture, and otherwise draws the entity opaque. Most of the time this is exactly right and you never need to touch the setting.

Alpha (1) mixes the entity into the background in proportion to its alpha - glass, water, ghosts. Multiply (2) darkens what is behind it: white leaves the background alone, mid-grey halves it, black blacks it out. That makes it the mode for shadow blobs, dirt decals and lightmap-style overlays, and the entity alpha has no effect in this mode. Add (3) adds the entity colour to the background, so black is invisible and bright pixels glow - laser bolts, muzzle flashes, fire, explosions and sparks. Additive results clamp at white, so stacking many additive effects turns the middle to flat white.

Additive and multiply entities are transparent as far as sorting goes: they are drawn after solid geometry and can flicker in front of one another. Use EntityOrder if two of them need a fixed order.

See also: EntityAlpha, EntityFX, EntityOrder, TextureBlend, BrushBlend.

Example

; EntityBlend Example
; -------------------

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

camera=CreateCamera()

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

; A textured wall behind, so we can see how the cube blends into it
wall=CreateCube()
ScaleEntity wall,6,4,0.2
PositionEntity wall,0,0,9
wall_tex=LoadTexture("media/MossyGround.BMP")
EntityTexture wall,wall_tex

; The blending cube: half-alpha so the alpha mode is visible
cube=CreateCube()
PositionEntity cube,0,0,5
EntityColor cube,255,255,0
EntityAlpha cube,0.5

blend=1

While Not KeyDown(1)

    ; Keys 1-3 pick the blend mode
    If KeyHit(2) Then blend=1
    If KeyHit(3) Then blend=2
    If KeyHit(4) Then blend=3
    blend_name$="alpha (default)"
    If blend=2 Then blend_name="multiply"
    If blend=3 Then blend_name="add"

    ; Apply the blend mode to the cube
    EntityBlend cube,blend

    TurnEntity cube,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,"1: alpha   2: multiply   3: add   Arrows: camera   Esc: exit"
    Text 0,20,"EntityBlend cube,"+blend+"  ("+blend_name+")"

    Flip

Wend

End

Index