Files
test2/source/blender/io/collada/CameraExporter.cpp
Lukas Stockner bf412ed9dd Cycles: Support for custom OSL cameras
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
2025-04-25 19:27:30 +02:00

87 lines
2.4 KiB
C++

/* SPDX-FileCopyrightText: 2010-2022 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup collada
*/
#include <string>
#include "COLLADASWCamera.h"
#include "DNA_camera_types.h"
#include "CameraExporter.h"
#include "collada_internal.h"
CamerasExporter::CamerasExporter(COLLADASW::StreamWriter *sw, BCExportSettings &export_settings)
: COLLADASW::LibraryCameras(sw), export_settings(export_settings)
{
}
template<class Functor>
void forEachCameraObjectInExportSet(Scene *sce, Functor &f, LinkNode *export_set)
{
LinkNode *node;
for (node = export_set; node; node = node->next) {
Object *ob = (Object *)node->link;
if (ob->type == OB_CAMERA && ob->data) {
f(ob, sce);
}
}
}
void CamerasExporter::exportCameras(Scene *sce)
{
openLibrary();
forEachCameraObjectInExportSet(sce, *this, this->export_settings.get_export_set());
closeLibrary();
}
void CamerasExporter::operator()(Object *ob, Scene *sce)
{
Camera *cam = (Camera *)ob->data;
std::string cam_id(get_camera_id(ob));
std::string cam_name(id_name(cam));
switch (cam->type) {
case CAM_CUSTOM:
case CAM_PANO:
case CAM_PERSP: {
COLLADASW::PerspectiveOptic persp(mSW);
persp.setXFov(RAD2DEGF(focallength_to_fov(cam->lens, cam->sensor_x)), "xfov");
persp.setAspectRatio(float(sce->r.xsch) / float(sce->r.ysch), false, "aspect_ratio");
persp.setZFar(cam->clip_end, false, "zfar");
persp.setZNear(cam->clip_start, false, "znear");
COLLADASW::Camera ccam(mSW, &persp, cam_id, cam_name);
exportBlenderProfile(ccam, cam);
addCamera(ccam);
break;
}
case CAM_ORTHO:
default: {
COLLADASW::OrthographicOptic ortho(mSW);
ortho.setXMag(cam->ortho_scale / 2, "xmag");
ortho.setAspectRatio(float(sce->r.xsch) / float(sce->r.ysch), false, "aspect_ratio");
ortho.setZFar(cam->clip_end, false, "zfar");
ortho.setZNear(cam->clip_start, false, "znear");
COLLADASW::Camera ccam(mSW, &ortho, cam_id, cam_name);
exportBlenderProfile(ccam, cam);
addCamera(ccam);
break;
}
}
}
bool CamerasExporter::exportBlenderProfile(COLLADASW::Camera &cm, Camera *cam)
{
cm.addExtraTechniqueParameter("blender", "shiftx", cam->shiftx);
cm.addExtraTechniqueParameter("blender", "shifty", cam->shifty);
cm.addExtraTechniqueParameter("blender", "dof_distance", cam->dof.focus_distance);
return true;
}