2.0.0 • Published 10 years ago
glsl-light-direction v2.0.0
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 --saveexample
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:structinstance ofglsl-lightposition:vec4position of the light
Returns
vec3the computed light direction