# glsl-camera-ray

> Generates a ray for Shadertoy-style raycasting in GLSL

Latest version **1.0.0** (published 2015-03-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install glsl-camera-ray
pnpm add glsl-camera-ray
yarn add glsl-camera-ray
bun add glsl-camera-ray
```

## 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 | 1.0.0 |
| Published | 2015-03-27 |
| First published | 2015-03-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Hugh Kennedy |
| Maintainers | hughsk |
| Keywords | ecosystem:stackgl |

## Links

- npm: https://www.npmjs.com/package/glsl-camera-ray
- Repository: https://github.com/stackgl/glsl-camera-ray
- Issues: https://github.com/stackgl/glsl-camera-ray/issues
- npm.io page: https://npm.io/package/glsl-camera-ray

## Dependencies (1)

- [glsl-look-at](https://npm.io/package/glsl-look-at.md) ^1.0.0

## Recent versions

- 1.0.0 (latest) — 2015-03-27

## README

# glsl-camera-ray

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Generates a ray for [Shadertoy](http://shadertoy.com)-style raycasting in GLSL.
Accepts either either a camera origin/target or an arbitrary `mat3` matrix.

## Usage

[![NPM](https://nodei.co/npm/glsl-camera-ray.png)](https://nodei.co/npm/glsl-camera-ray/)

### `vec3 cameraRay(vec3 ro, vec3 ta, vec2 screen, float lens)`

* `vec3 ro` is the position of the camera.
* `vec3 ta` is the position the camera is pointing towards.
* `vec2 screen` is the position of the fragment on the screen, generally between -1 and 1. For non-square frames you'll want to normalize this using something like [glsl-square-frame](http://github.com/hughsk/glsl-square-frame)
* `lens` is the lens length of the camera. This works
  similarly to FOV, where `0.0` is horribly wide and `2.0`
  is a decent default.

``` glsl
#pragma glslify: square = require('glsl-square-frame')
#pragma glslify: camera = require('glsl-camera-ray')

uniform vec2  iResolution;
uniform float iGlobalTime;

void main() {
  // Bootstrap a Shadertoy-style raytracing scene:
  float cameraAngle  = 0.8 * iGlobalTime;
  vec3  rayOrigin    = vec3(3.5 * sin(cameraAngle), 3.0, 3.5 * cos(cameraAngle));
  vec3  rayTarget    = vec3(0, 0, 0);
  vec2  screenPos    = square(iResolution.xy);
  float lensLength   = 2.0;

  vec3  rayDirection = camera(rayOrigin, rayTarget, screenPos, lensLength);
  // ...
}
```

### `vec3 cameraRay(mat3 camera, vec2 screen, float lens)`

For more flexibility, you can supply `mat3 camera` in place
of `vec3 ro, vec3 ta`. This way, you can use your own camera
modules alongside `glsl-camera-ray`.

## Contributing

See [stackgl/contributing](https://github.com/stackgl/contributing) for details.

## License

MIT. See [LICENSE.md](http://github.com/stackgl/glsl-camera-ray/blob/master/LICENSE.md) for details.

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