directPointLight
Calculates the light direction and the physically attenuated light color for a single point light at a specific shading point.
Core Advantages
Encapsulates the complex physical attenuation formula for point lights (involving distance calculation, inverse square law, etc.) into a single node, making code cleaner, more readable, and ensuring behavior consistent with Three.js's built-in materials.
Common Uses
Providing the light direction and incoming light color for custom lighting models (e.g., Phong).
Determining brightness steps in toon shading based on light intensity.
Creating light debugging materials to directly visualize a light's attenuation range and intensity.
Serving as a mixing factor to blend textures or colors based on illumination.
How to adjust
Effects are changed by adjusting its input parameters. Changing `color` is like swapping the lightbulb's color and power; decreasing `cutoffDistance` creates a hard cutoff for the light's range; adjusting `decayExponent` from 1 (linear) to 2 (physical) makes the light's falloff appear more realistic.
Code Examples
1// Calculate lighting info for a point light at the current shading point
2const lightInfo = directPointLight(
3 light.color, // Light color and intensity
4 light.position.sub( positionWorld ), // Vector from shading point to light
5 light.distance, // Light cutoff distance
6 light.decay // Attenuation exponent
7);