Blitz3D+ Command Reference

BrushShader brush,shader

Parameters

brush - brush handle

shader - material shader handle, or 0 to remove it

Description

Stores a custom material shader in a brush.

Surfaces painted from the brush with PaintEntity or PaintSurface keep the shader, which makes a brush the natural way to reuse one material - a toon brush, a hologram brush - across many models. The brush retains the attached instance, so freeing your script handle later is safe.

At draw time the renderer picks, in order: the entity's EntityShader if present, otherwise the surface brush's shader, otherwise the brush's Standard or classic appearance. The common surprise follows directly: changing a brush shader has no visible effect while the owning entity has an entity shader, because the entity override wins.

Pass 0 to remove the shader and return painted surfaces to their normal appearance. Post-processing shaders cannot be stored in a brush - they raise a runtime error and belong with CameraEffect.

For the full story, see entity and brush precedence in the shader guide.

Requires Extended mode.

See also: EntityShader, LoadShader, BrushStandard, PaintSurface.

Example

; BrushShader Example
; -------------------
; Requires Extended mode.

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

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

light=CreateLight()
RotateEntity light,35,-30,0

; Load a material shader and give it a purple tint
shader=LoadShader("assets/help_surface.b3shader")
ShaderColor shader,"Tint",180,70,255

brush=CreateBrush()
cube=CreateCube()

attached=True

While Not KeyDown(1)

    ; Press Space to attach or remove the brush shader
    If KeyHit(57) Then attached=Not attached

    ; Store the shader in the brush (zero removes it) and repaint
    If attached Then BrushShader brush,shader Else BrushShader brush,0
    PaintEntity cube,brush

    TurnEntity cube,0.2,0.4,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

    Color 255,255,255
    Text 0,0,"Space: toggle shader   Arrow keys: move camera   Esc: exit"
    If attached Then Text 0,20,"BrushShader brush,shader" Else Text 0,20,"BrushShader brush,0 (classic rendering)"

    Flip

Wend

FreeBrush brush
FreeShader shader
End

Index