Blitz3D+ Command Reference

EntityShader entity,shader

Parameters

entity - mesh entity handle

shader - material shader handle, or 0 to restore the normal appearance

Description

Applies a material shader to every surface of an entity.

This is the quickest way to restyle one model: load a shader, apply it, done - a toon-shaded character, a dissolving enemy, a hologram. The shader covers every surface the entity renders, and the entity retains the instance, so it keeps working after you free your handle.

An entity shader overrides any BrushShader on the entity's surfaces - so while one is set, repainting surfaces with a different shader brush changes nothing visible. Child entities are not affected; apply the shader to each child yourself if a whole hierarchy should change.

Pass 0 to remove the shader and return the entity to its brush, Standard or classic appearance. Post-processing shaders cannot be applied to entities - that raises a runtime error; they belong with CameraEffect.

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

Requires Extended mode.

See also: BrushShader, LoadShader, FreeShader, CameraEffect.

Example

; EntityShader 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 for the cube
shader=LoadShader("assets/help_surface.b3shader")

cube=CreateCube()

attached=True

While Not KeyDown(1)

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

    ; Apply the shader to every surface of the cube (zero removes it)
    If attached Then EntityShader cube,shader Else EntityShader cube,0

    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,"EntityShader cube,shader" Else Text 0,20,"EntityShader cube,0 (classic rendering)"

    Flip

Wend

FreeShader shader
End

Index