Lighting component

This component defines light source nodes.

See also X3D specification of the Lighting component.


1. Support

Supported nodes:

  • DirectionalLight (API reference),
    PointLight (API reference),
    SpotLight (API reference)

    Note: VRML 2.0 SpotLight.beamWidth idea cannot be translated to a standard OpenGL spotlight, so if you set beamWidth < cutOffAngle then the light will not look exactly VRML 2.0-spec compliant. Honestly I don't see any sensible way to fix this (as long as we talk about real-time rendering using OpenGL). And other open-source VRML implementations rendering to OpenGL also don't seem to do anything better.

    VRML 2.0 spec requires that at least 8 lights are supported. Our engine can support as many lights as are allowed by your OpenGL implementation, which is at least 8.

    global field from X3D is also supported. The default value of this field is consistent with VRML 2.0 specification (that always wants directional lights non-global, and other lights always global).

2. Per-pixel lighting

By default we render most shapes using OpenGL fixed-function pipeline, and VRML/X3D lights are simply used as OpenGL lights. This means that lighting is calculated per-vertex (Gouraud shading). This is fast, but not always perfect.

Using the "Shaders->Enable For Everything" option in view3dscene forces everything to be rendered through GLSL shaders, which always perform per-pixel lighting. This is usually slower but also more beautiful than default "Shaders->Enable When Required".

  • 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.

  • Spot lights beamWidth is correctly applied (for fixed-function rendering, beamWidth could not be perfectly represented by OpenGL spot exponent).

  • 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).

Note that you can use our extension to force Phong shading on particular shapes.

2.1. Problems? Get latest GPU drivers

Using shader pipeline (forced on everything by "Shaders->Enable For Everything", or activated automatically for shapes using shadow maps or bump mapping or requesting Phong shading) 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.)

Note that by default ("Shaders->Enable When Required") models without effects are still rendered using standard fixed-function pipeline. Which means that they still work fast even on older hardware.