SVG <feDiffuseLighting> Filter

What is <feDiffuseLighting> Filter?

The <feDiffuseLighting> SVG filter primitive lights an image using the alpha channel as a bump map. The output image, which is an RGBA opaque image, depends on the light position, light color and surface geometry of the input bump map.

No Light fePointLight feDistantLight feSpotLight

Example

HTML Online Editor
<!DOCTYPE html> <html lang="en-US"> <body> <svg width="450" height="150" xmlns="http://www.w3.org/2000/svg"> <!-- No light is applied --> <text text-anchor="middle" x="60" y="22">No Light</text> <circle cx="60" cy="80" r="50" fill="#339933" /> <!-- the light source is a fePointLight element --> <text text-anchor="middle" x="170" y="22">fePointLight</text> <filter id="point"> <feDiffuseLighting in="SourceGraphic" result="light" lighting-color="white"> <fePointLight x="150" y="60" z="30" /> </feDiffuseLighting> <feComposite in="SourceGraphic" in2="light" operator="arithmetic" k1="1" k2="0" k3="0" k4="0"/> </filter> <circle cx="170" cy="80" r="50" fill="#339933" filter="url(#point)" /> <!-- the light source is a feDistantLight element --> <text text-anchor="middle" x="280" y="22">feDistantLight</text> <filter id="point1"> <feDiffuseLighting in="SourceGraphic" result="light" lighting-color="white"> <feDistantLight azimuth="240" elevation="20"/> </feDiffuseLighting> <feComposite in="SourceGraphic" in2="light" operator="arithmetic" k1="1" k2="0" k3="0" k4="0"/> </filter> <circle cx="280" cy="80" r="50" fill="#339933" filter="url(#point1)" /> <!-- the light source is a feSpotLight source --> <text text-anchor="middle" x="390" y="22">feSpotLight</text> <filter id="point2"> <feDiffuseLighting in="SourceGraphic" result="light" lighting-color="white"> <feSpotLight x="360" y="5" z="30" limitingConeAngle="20" pointsAtX="390" pointsAtY="80" pointsAtZ="0"/> </feDiffuseLighting> <feComposite in="SourceGraphic" in2="light" operator="arithmetic" k1="1" k2="0" k3="0" k4="0"/> </filter> <circle cx="390" cy="80" r="50" fill="#339933" filter="url(#point2)" /> </svg> </body> </html>

Attributes Value

AttributeExplanation
inSpecifies the input for the given filter primitive.
surfaceScaleSpecifies the height of the surface for a light filter primitive.
diffuseConstantSpecifies the kd value in the Phong lighting model.
kernelUnitLengthSpecifies the intended distance in current filter units.

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author