-
Notifications
You must be signed in to change notification settings - Fork 2
How to use OSL camera
Consider the following simple geometric scene.
Select the camera and add a CyclesCamera property.
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.
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.
That's all we need. Now render the view from the camera.
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.
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.