Lighting component

This component defines light source nodes.

See also X3D specification of the Lighting component.


1. Supported nodes

We support all light nodes:

Lights shine on shapes, making them brighter. Only the "lit" shapes (with non-nil material node) are affected by lights.

All these conditions must be satisfied in order for the light to shine (contribute to a color) on a given shape:

  • The light node must be in a "traversed" part of the node graph. This means that if the light is inside an inactive Switch or LOD child, it doesn't shine on anything. This is consistent with the general idea that stuff inside inactive Switch or LOD children is never visible.

  • The shape must be within the light radius (in case of PointLight, SpotLight).

  • If the light has global field set to FALSE, then it only affects the shapes nodes that are sibling to it or below. By default, DirectionalLight has global=FALSE (otherwise it would affect the whole scene), while PointLight and SpotLight have global=TRUE (because they are typically limited by their radius field).

    See the example below. The light L1 shines on both sphere and box. The light L2 shines only on a sphere. You can easily actually test it: save this example as test.x3dv file, and open it with view3dscene.
    Deprecated: Function create_function() is deprecated in /var/www/cge-www-preview/geshi/geshi.php on line 4751

    #X3D V3.2 utf8
    PROFILE Interchange
    NavigationInfo {
      # turn off headlight
      headlight FALSE
    DEF L1 DirectionalLight {
      color 1 0 0 # red
    Shape {
      # assign Appearance and Material to make the shape lit
      appearance Appearance {
        material Material { }
      geometry Box { }
    Transform {
      translation 2 0 0
      children [
        DEF L2 DirectionalLight {
          color 0 1 0 # green
        Shape {
          # assign Appearance and Material to make the shape lit
          appearance Appearance {
            material Material { }
          geometry Sphere { }

Note that, while your whole scene can have an unlimited number of lights, the number of lights that affect a particular shape is limited. It is limited to 8 inside the engine (for now). In general, having too many lights affect a single shape is costly (in "forward rendering mode" that we use), and it's also not necessary in normal circumstances.

2. Per-pixel lighting

By default we render most shapes using Gouraud shading (per-vertex lighting calculation). This is fast, but not always pretty. See the Shape.shading field for a description on other shading approaches, and how to activate them.

Using the "View -> Phong Shading on Everything" option in view3dscene forces everything to be rendered using Phong shading (per-pixel lighting). This is sometimes a significant boost to quality.

  • Per-pixel lighting means that local lighting effects, in particular spot light cones and specular highlights, are precisely rendered.

  • Lights attenuation is also calculated per-pixel, this sometimes gives much better results.

  • Lights with radius with fixed-function pipeline rendering
    Light with radius with per-pixel lighting (shader pipeline)

    Light radius is also checked per-pixel when necessary (when shape is partially inside, partially outside the light radius). This allows to use "radius" field (on point and spot lights) for much more dramatic lighting effects. For example, compare the two screenshots from light_street_lights_radius demo on the right (from our VRML/X3D demo models).

You can also switch to Phong shading for particular shapes.

Pascal Developers: you can switch to Phong for the whole scene by Scene.Attributes.PhongShading := true or only for a particular shape using Shape.Shading := shPhong.

2.1. Problems? Get latest GPU drivers

Using the shader pipeline (right now activated by certain features, like Phong Shading or shadow maps or bump mapping; may be default in the future) requires a good graphic card with latest drivers. Before reporting problems, make sure that you have the latest OS version, with the latest drivers. You may need to download latest drivers from

Windows often comes with quite outdated drivers, so be sure to get drivers from above sites. On Linux and Mac OS X, it should be enough to make sure you use the latest version of your system, with all updates applied. On Linux, you may need to install the proprietary OpenGL drivers to squeeze best performance from your NVidia/Radeon GPU. (Although latest Mesa may also be quite capable of handling simpler stuff, even with shaders.)