glsl-camera-ray
Generates a ray for Shadertoy-style raycasting in GLSL
Last updated 6 years ago by hughsk .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install glsl-camera-ray 
SYNC missed versions from official npm registry.

glsl-camera-ray

stable

Generates a ray for Shadertoy-style raycasting in GLSL. Accepts either either a camera origin/target or an arbitrary mat3 matrix.

Usage

NPM

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
  • 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.
#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 for details.

License

MIT. See LICENSE.md for details.

Current Tags

  • 1.0.0                                ...           latest (6 years ago)

1 Versions

  • 1.0.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (10)

Copyright 2014 - 2016 © taobao.org |