A reusable GLSL point light function
A reusable GLSL point light function for use with glslify.
vec3 point_light, which takes the following arguments:
vec3 color: the RGB values of the light.
vec3 light_position: the x/y/z position of the light.
vec3 current_position: the x/y/z position of the current fragment/vertex.
vec3 normal: a normalized normal vector for the current fragment/vertex.
You must also specify your lighting's attenuation properties when requiring this module:
# light_a = require(glsl-point-light, kc=1.0, kl=0.05, kq=0.05)# light_b = require(glsl-point-light, kc=1.0, kl=0.04, kq=0.025)
In other words, these variables will effect the rate at which your light fades
kc is the constant attenuation, whereas
kl is linear and
is quadratic. For more information check out
See shaders/terrain.vert for a full example.