lygia
/v1.1.6
/lighting
/ray
/direction
)set the direction (and origin in some cases) of a ray
Dependencies:
Use:
rayDirection(inout <Ray> ray, [<vec3> origin,] <vec2> pos, <vec2> resolution, <float> fov)
<Ray> rayDirection(<vec3> origin, <vec2> pos, <vec2> resolution, <float> fov)
#ifndef FNC_RAYDIRECTION
#define FNC_RAYDIRECTION
void rayDirection(inout Ray ray, vec2 pos, vec2 resolution, float fov) {
float aspect = resolution.x / resolution.y;
float tanVFov2 = tan(fov / 2.0);
float tanHFov2 = tanVFov2 * aspect;
ray.direction = vec3(1.0, 0.0, 0.0) * (pos.x * tanHFov2) -
vec3(0.0, -1.0, 0.0) * (pos.y * tanVFov2) +
vec3(0.0, 0.0, -1.0);
}
void rayDirection(inout Ray ray, vec3 origin, vec2 pos, vec2 resolution, float fov) {
float aspect = resolution.x / resolution.y;
float tanVFov2 = tan(fov / 2.0);
float tanHFov2 = tanVFov2 * aspect;
ray.origin = origin;
ray.direction = vec3(1.0, 0.0, 0.0) * (pos.x * tanHFov2) -
vec3(0.0, -1.0, 0.0) * (pos.y * tanVFov2) +
vec3(0.0, 0.0, -1.0);
}
Ray rayDirection(vec3 origin, vec2 pos, vec2 resolution, float fov) {
Ray ray;
ray.origin = vec3(0.0, 0.0, 0.0);
ray.direction = vec3(0.0, 0.0, 1.0);
rayDirection(ray, origin, pos, resolution, fov);
return ray;
}
#endif
LYGIA is dual-licensed under the Prosperity License and the Patron License for sponsors and contributors.
Sponsors and contributors are automatically added to the Patron License and they can ignore the any non-commercial rule of the Prosperity Licensed software (please take a look to the exception).
It's also possible to get a permanent comercial license hook to a single and specific version of LYGIA.
Sign up for the news letter bellow, joing the LYGIA's channel on Discord or follow the Github repository