Blitz3D+ Command Reference

BrushBlend brush,blend

Parameters

brush - brush handle
blend - blend mode:
0: automatic - solid, or alpha when the brush has any transparency (default)
1: alpha
2: multiply
3: add

Description

Sets the blending mode of a brush.

The blend mode decides how painted geometry combines with the scene already drawn behind it. Alpha is normal transparency, weighted by the brush's alpha. Multiply darkens - useful for shadows and stained glass. Add brightens - the classic look for flames, lasers and glows (black areas become invisible).

A new brush is on automatic: it draws solid unless something makes it transparent (BrushAlpha below 1, a texture with alpha, or vertex alpha via flag 32), in which case it alpha-blends. Note that mode 1 behaves the same way - it still only actually blends when there is some transparency to apply.

This is the brush-level twin of EntityBlend; TextureBlend is different - it controls how texture layers combine with each other within the material.

See also: EntityBlend, TextureBlend, BrushAlpha, BrushFX, PaintMesh.

Example

; BrushBlend 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 painted 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 cube we will paint. A brush is a 'paint recipe' applied with PaintEntity.
cube=CreateCube()
PositionEntity cube,0,0,5

; Half-alpha yellow brush, so the alpha blend mode is visible too
brush=CreateBrush(255,255,0)
BrushAlpha brush,0.5

blend=1

While Not KeyDown(1)

    ; Keys 1-3 pick the brush 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"

    ; Set the brush blend mode, then repaint the cube so the change shows
    BrushBlend brush,blend
    PaintEntity cube,brush

    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,"BrushBlend brush,"+blend+"  ("+blend_name+")"

    Flip

Wend

End

Index