glsl-point-light

A reusable GLSL point light function

glsl-point-light

A reusable GLSL point light function for use with glslify.

view demo

Exports 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:

#pragma glslify: light_a require(glsl-point-light, kc=1.0, kl=0.05, kq=0.05) 
#pragma glslify: 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 over space. kc is the constant attenuation, whereas kl is linear and kq is quadratic. For more information check out this article.

See shaders/terrain.vert for a full example.