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

* 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.
`` 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);
// ...
}
`
For more flexibility, you can supply mat3 camera in placevec3 ro, vec3 ta
of . This way, you can use your own cameraglsl-camera-ray`.
modules alongside
See stackgl/contributing for details.
MIT. See LICENSE.md for details.