Example: OSL Camera Shaders
A camera shader allows you to implement a custom camera type. You could for instance implement a fish-eye camera or you may write a shader which exactly matches the camera used to capture live footage.
There are two types of OSL cameras: the regular OSL camera, which is the usual positioned camera, and the OSL baking camera, which behaves much like the baking camera but the UV coordinate to sample and the resulting ray direction is generated by a shader.
The following is a minimal implementation of a perspective camera. It takes into account the aspect ratio of the image, and allows some of the usual camera features in octane like viewport navigation and stereo rendering.
shader OslCamera(
output point pos = P,
output vector dir = 0)
{
float uv[2];
getattribute("hit:uv", 2, uv);
vector right = cross(I, N);
dir = I + right * (uv[0] - .5) + N * (uv[1] - .5);
}
The vector dir will be normalised by the render engine.
Clipping distance is given as a number of units in the ray direction.
To disable far clipping set the second value to +∞ (1.0/0.0).
If clip defines an empty interval, or if dir has 0 length, the returned ray is considered invalid, and the renderer will not perform any path tracing for this sample.
The third output (clip or tMax) can be omitted if no clipping is necessary. Octane 3.08 only supports the float tMax form.
Cameras may use setmessage("octane:throughput", value) to set the initial throughput of a ray. This can be used for things like optical vignette.