# glsl-light-direction

> GLSL function for computing lighting direction

Latest version **2.0.0** (published 2016-03-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install glsl-light-direction
pnpm add glsl-light-direction
yarn add glsl-light-direction
bun add glsl-light-direction
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2016-03-12 |
| First published | 2016-03-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | freeman-lab |
| Maintainers | freeman-lab |
| Keywords | webgl, shader, light, lightig, 3d |

## Links

- npm: https://www.npmjs.com/package/glsl-light-direction
- Repository: https://github.com/freeman-lab/glsl-light-direction
- Homepage: https://github.com/freeman-lab/glsl-light-direction#readme
- Issues: https://github.com/freeman-lab/glsl-light-direction/issues
- npm.io page: https://npm.io/package/glsl-light-direction

## Dependencies (1)

- [glsl-light](https://npm.io/package/glsl-light.md) ^2.0.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2016-03-12
- 1.0.0 — 2016-03-09

## README

# glsl-light-direction

GLSL function for computing lighting direction. Designed for use as a shader component with [`glslify`](https://github.com/stackgl/glslify) and [`glsl-light`](https://github.com/freeman-lab/glsl-light).

## install

To make avaialble in your project

```javascript
npm install glsl-light-direction --save
```

## example

Define a light in your shader

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

Then compute light direction from the vertex position

```glsl
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`](https://github.com/freeman-lab/glsl-light)
- `position` : `vec4` position of the light

Returns
- `vec3` the computed light direction

---
_Source: https://npm.io/package/glsl-light-direction · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
