SVG Lighting: feDistantLight and fePointLight Guide

SVG filters enable realistic 3D depth and texture on two-dimensional vector graphics by utilizing light source elements. This article explains how <feDistantLight> and <fePointLight> function within parent lighting filters, detailing their core attributes, spatial behaviors, and implementation methods so you can accurately control light positioning, angles, and surface illumination in your SVG designs.

The Foundation of SVG Lighting

Light source elements do not function independently. They must be placed as child elements inside one of two primary lighting filter primitives:

The parent filter defines the surface properties (such as surfaceScale, diffuseConstant, specularConstant, and lighting-color), while the nested light source dictates the origin, direction, and shape of the light beam.

Configuring feDistantLight

The <feDistantLight> element defines a light source placed at an infinite distance, functioning identically to natural sunlight. Because the source is infinitely far away, all light rays striking the SVG surface travel in parallel lines, casting consistent light across the entire graphic regardless of position coordinates.

It relies on two angular attributes to define the direction of the light rays:

Example Syntax

<filter id="distantLightFilter">
  <feDiffuseLighting lighting-color="#ffffff" surfaceScale="2">
    <feDistantLight azimuth="45" elevation="60" />
  </feDiffuseLighting>
</filter>

Configuring fePointLight

The <fePointLight> element simulates a localized omnidirectional light source, similar to an incandescent bulb or an LED positioned near the surface. Unlike distant light, point light radiates outward in all directions from a specific three-dimensional coordinate, resulting in radial gradients and intensity falloff based on distance from the center point.

It is configured using three coordinate attributes:

Example Syntax

<filter id="pointLightFilter">
  <feSpecularLighting specularConstant="1.5" specularExponent="20" lighting-color="#ffffff">
    <fePointLight x="150" y="100" z="50" />
  </feSpecularLighting>
</filter>

Key Differences and When to Use Each