2.0.0 • Published 10 years ago
glsl-light v2.0.0
glsl-light
GLSL struct for a light source. Designed for use as a shader component with glslify.
install
To make avaialble in your project
npm install glsl-light --saveexample
Define a light in your shader
pragma glslify: Light = require('glsl-light')
uniform Light light;Then set their properties on a shader created using gl-shader
shader.uniforms.light = {
position: [0.0, 0.0, 0.0, 1.0],
color: [1.0, 0.0, 1.0],
intensity: 1,
radius: 20.0,
ambient: 0.5,
visible: false
}API
Inside your shader just declare the struct type with
pragma glslify: SceneLight = require('glsl-light')and use as you like, e.g. to set a uniform or construct a variable.
The attributes and types on the struct are
position // vec4
color // vec3
intensity // float
radius // float
ambient // float
visible // boolYou can use these in your shader code however you want, but typically:
positioncontrols the position of the light, with the fourth element differentiating between a point or spot light (0.0) or a directional light (1.0)colorandintensitywill together define the luminance, which can exceed 1.0radiuscontrols the extent of the lightambientis the amount of ambient light associated with this light sourcevisibleis a flag to set the light on or off