glsl-light-direction

2.0.0 • Public • Published

glsl-light-direction

GLSL function for computing lighting direction. Designed for use as a shader component with glslify and glsl-light.

install

To make avaialble in your project

npm install glsl-light-direction --save

example

Define a light in your shader

pragma glslify: Light = require('glsl-light')
uniform Light light;

Then compute light direction from the vertex position

pragma glslify: direction = require('glsl-light-direction')
vec3 dir = direction(light, position);

algorithm

The calculated direction depends on the position parameter of the light, a vec4 in homogenous coordinates. The fourth element determines whether the light is directional or not.

  • If the fourth element is 0.0, the direction will be the normalized light position.
  • If the fourth element is 1.0, the direction will point from the light to the vertex.

API

direction(light, position)

Parameters

  • light : struct instance of glsl-light
  • position : vec4 position of the light

Returns

  • vec3 the computed light direction

Package Sidebar

Install

npm i glsl-light-direction

Weekly Downloads

1

Version

2.0.0

License

MIT

Last publish

Collaborators

  • freeman-lab