Vizard 8 » Reference » Shaders » Effects » Effect Basics
8.0

Effect Basics

Vizard's effect framework provides a simple yet powerful interface for creating complex shader effects. Multiple effects can be combined together, making it easy to maintain and reuse shader code. The vizfx library also includes many common effects, including:

Introduction

The effect framework introduces two new Vizard objects: effects and composers. Effects are used to define small units of shader code and any associated properties (floats, colors, textures, ...). Composers are used to define how the effects are combined to generate the final shader code.

 

The vizfx.addChild or vizfx.addAvatar commands can be used to load a model and automatically apply shader effects. For example:

# Use vizfx module to load models and generate effects
import vizfx

# Load environment model
env = vizfx.addChild('gallery.osgb')

# Load avatar model
avatar = vizfx.addAvatar('vcc_male2.cfg')

# Add directional light
vizfx.addDirectionalLight(euler=(0,45,0))

In most cases, this is all that is needed to use the effect framework. However, effects and composers can also be manually created using the viz.addEffect and viz.addEffectComposer commands. Effects and composers must be applied to a node in order for it to render the effect. The <node3d>.apply command is used to apply effects and composers to a node.  Multiple effects can be applied to a node, however only one composer can be applied.

Note: When enabling effects on an object, many built-in texture related commands will not work properly since they rely on fixed-function rendering.

Generated Effects

The vizfx.addChild and vizfx.addAvatar commands in the example above automatically generate effects for the model from the following sources:

Effects can also be generated manually by using the <node3d>.generateEffects command.

Composers

As mentioned in the introduction, composer objects are necessary for combining and rendering effects on an object. The vizfx library automatically creates a default global composer and applies it to a node when using the vizfx.addChild or vizfx.addAvatar commands.

 

The default composer can be accessed using the vizfx.getComposer() command. For example, if you want to apply a global texture projector effect, you can add it to the default composer:

# Create texture 
texture = viz.addTexture('crosshair.png')

# Create projector
projector = vizfx.addProjector(texture)

# Apply projector effect to composer
vizfx.getComposer().addEffect(projector.getEffect())

The default vizfx composer also applies an ambient light effect. The ambient light color can be accessed using the vizfx.setAmbientColor and vizfx.getAmbientColor commands. The following example changes the ambient color to a light blue:

# Set global ambient color
vizfx.setAmbientColor([0.8,0.8,1])

Or you can turn off the ambient light by changing the color to black:

# Turn off ambient light
vizfx.setAmbientColor(viz.BLACK)

Effect Basics

Lighting Effects

Projector Effects

Custom Effects

Example Effects