Vizard 8 » Reference » Shaders » Effects » Lighting Effects
8.0

Lighting Effects

The vizfx library includes various lighting related effects for use with effect-enabled objects.

Lights

The vizfx library supports three basic types of lights: directional, spot, and point.

 

Directional lights are typically used to simulate sunlight or infinitely far lights. They only cast light in a single direction. The rotation of the light object controls the direction of the light. The position of the light has no effect. The vizfx.addDirectionalLight command is used to create a directional light:

# Add a white directional light pointing down
light = vizfx.addDirectionalLight(euler=(0,90,0), color=viz.WHITE)

Spot lights are used to simulate lights that are focused in a specific direction (e.g. flashlights). The position and rotation of the light object affect how it is cast upon objects. The <light>.spread command can be used to control how narrow or wide the focus of the spot light is. The vizfx.addSpotLight command is used to create a spot light:

# Add a yellow spot light
light = vizfx.addSpotLight(euler=(0,45,0), pos=(0,3,0), color=viz.YELLOW)

Point lights are used to simulate lights that cast in all directions. The position and rotation of the light object affect how it is cast upon objects. The vizfx.addPointLight command is used to create a point light:

# Add white point light
light = vizfx.addPointLight(color=viz.WHITE, pos=(0,2,0))

Light Textures

The vizfx.addSpotLight and vizfx.addPointLight commands support an optional texture parameter that allows projecting an image from the light source. The color in the projected texture is multiplied against the light color.

 

For spot lights, the texture must be a standard 2D <texture> object. The example below shows how to attach a standard texture to a spot light:

# Create spot light with texture attached
tex = viz.addTexture('smiley.png')
light = vizfx.addSpotLight(texture=tex, color=viz.WHITE)
Spot light with attached texture

For point lights, the texture must be a cube map <texture> object. When attaching a texture to a point light, the rotation of the light will affect the projected direction of the cube map texture. The example below shows how to create a point light with a cube map texture attached:

# Create point light with cube map texture attached
tex = viz.addEnvironmentMap('holes.png')
light = vizfx.addPointLight(texture=tex, color=viz.WHITE)
Point light with attached cube map texture

Ambient Lighting

Ambient light represents the light coming from the environment and affects all surfaces equally. The default composer automatically applies an ambient light effect. The image below uses the default gray ambient color:

Default gray ambient color

The default ambient light color can be accessed using the vizfx.setAmbientColor and vizfx.getAmbientColor commands. For example, the following code would change the default ambient color to blue:

# Set ambient color to blue
vizfx.setAmbientColor(viz.BLUE)
Blue ambient color

Setting the ambient color to black will effectively disable the ambient light:

# Disable ambient light
vizfx.setAmbientColor(viz.BLACK)
Black ambient color

An ambient light effect can also be manually created using the vizfx.addAmbientEffect command. The resulting effect can be applied to any node to override the default ambient color:

# Create ambient light effect
effect = vizfx.addAmbientEffect(color=viz.RED)

# Apply to model (overrides default ambient color)
model.apply(effect)

Directional ambient lighting can also be specified using a cube map. This is commonly used with low frequency cubemaps, where the normal vector is used to look up the ambient light for the surface. This can result in more realistic ambient lighting for dynamic objects in localized environments. The vizfx.addAmbientCubeEffect command can be used to create directional ambient light effects. The following example creates a directional ambient light effect and replaces the default ambient color effect with it:

# Create ambient cube map effect
cubemap = viz.addEnvironmentMap('ambient.png')
effect = vizfx.addAmbientCubeEffect(cubemap)

# Apply to default composer (replaces default ambient effect)
vizfx.getComposer().addEffect(effect)
Directional ambient light using cube map
Ambient cube map

Lighting Model

The lighting model controls how the surface properties of an object interact with lights to produce shading. The default composer automatically applies a lighting model effect that uses the Lambert model for diffuse shading and the Phong model for specular reflectance. The image below uses the default lighting model:

Default Lambert diffuse model and Phong specular model

A lighting model effect can be manually created using the vizfx.addLightingModel command. The command allows for changing the diffuse model (Lambert, Half-Lambert), the specular model (Blinn-Phong, Phong, ...), and using ramped diffuse lighting with a texture.

 

For example, the global lighting model can be easily changed to use the Half-Lambert diffuse technique using the following code:

# Create Half-Lambert lighting model effect
effect = vizfx.addLightingModel(diffuse=vizfx.DIFFUSE_HALFLAMBERT)

# Apply to default composer (replaces default lighting model effect)
vizfx.getComposer().addEffect(effect)
Half-Lambert diffuse lighting model

The following example shows how to use a diffuse ramp texture to create a stylized diffuse shading model:

# Create diffuse ramp lighting model effect
ramp = viz.addTexture('diffuse_ramp.png')
effect = vizfx.addLightingModel(diffuse=vizfx.DIFFUSE_HALFLAMBERT, diffuseRamp=ramp)

# Apply to model (overrides default lighting model)
model.apply(effect)
Diffuse ramped lighting model
Diffuse ramp texture

Effect Basics

Lighting Effects

Projector Effects

Custom Effects

Example Effects