This allows users to implement arbitrary camera models using OSL by writing shaders that take an image position as input and compute ray origin and direction. The obvious applications for this are e.g. panorama modes, lens distortion models and realistic lens simulation, but the possibilities are endless. Currently, this is only supported on devices with OSL support, so CPU and OptiX. However, it is independent from the shading model used, so custom cameras can be used without getting the performance hit of OSL shading. A few samples are provided as Text Editor templates. One notable current limitation (in addition to the limited device support) is that inverse mapping is not supported, so Window texture coordinates and the Vector pass will not work with custom cameras. Pull Request: https://projects.blender.org/blender/blender/pulls/129495
19 lines
539 B
Plaintext
19 lines
539 B
Plaintext
/* SPDX-FileCopyrightText: 2011-2025 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
|
|
|
/* A basic perspective camera. */
|
|
|
|
shader camera(float focal_length = 90.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));
|
|
}
|