Cycles OSL Camera - Feedback

It would be nice if a exact replica of the standard blender camera would be provided in the OSL camera examples. The “Advanced Camera” seems to be doing that, only with a couple of extra features.

Maybe just add support for depth of field the “Basic Camera” example, that seems to replicate the standard camera. Or add a “Standard Camera” example that will replicate the standard camera exact:

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));
  
  float focal_distance;
  getattribute("cam:focal_distance", focal_distance);
  getattribute("cam:aperture_position", position);

  point Pfocus = direction * focal_distance / direction.z;
  direction = normalize(Pfocus - position);
}

Also, I guess this has been discussed before; The “Focal Length” parameter is hidden when the camera Type is set to Custom, but it’s still used to determine the viewport field of view. This also applies to the other camera types except from the Orthographic type.

I don’t think its a good idea to just hide it, maybe bring that parameter back? Maybe it would fit into the “Camera” panel instead, to make a distinction between parameters that changes the OSL rays directly and those who don’t.

Shift X/Y and the Clip Start/End parameter seems to have an influence on the OSL shader without it having to implement it in the code, so it make sense to have that in the Lens panel. While the Sensor Height for example needs to be implemented for it to have an influence on the render. So for me it makes sense to move the Focal Length parameter over there instead.

It would also be great to be able to reference it with the getattribute function like this:

getattribute("cam:focal_length", focal_length);
3 Likes