Skip to content

How to use OSL camera

Tugcga edited this page Aug 15, 2026 · 1 revision

Consider the following simple geometric scene.

img_001

Select the camera and add a CyclesCamera property.

img_002

Next, we need an OSL shader for the camera. We will use the simple example from the Blender documentation.

shader perspective_camera(
    float focal_length = 90.0 [[ float sensitivity = 0.2, float min = 0 ]],
    output point position = 0.0,
    output vector direction = 0.0,
    output color throughput = 1.0) {
  vector sensor_size;
  getattribute("cam:sensor_size", sensor_size);

  point Pcam = camera_shader_raster_position() - point(0.5);
  Pcam *= sensor_size / focal_length;
  direction = normalize(vector(Pcam.x, Pcam.y, 1.0));
}

Save this code in any file with the extension *.osl (e.g., camera.osl).

Next, set the camera Type to OSL and select this OSL file.

img_003

A new OSL tab appears in the PPG. It contains all the input parameters of the shader. In our case, there is only one float parameter, focal_length.

img_004

That's all we need. Now render the view from the camera.

img_005

It uses the shader's focal length parameter instead of the native camera parameters. That is why the preview perspective does not coincide with the rendered one.

Tweak the value of the focal_length parameter; the rendered view changes accordingly.

img_006

The Reparse Parameters button is required when the OSL shader code is changed and parameters are added or deleted. It then reparses the shader parameters and creates a new list of values.

Clone this wiki locally