Skip to content

Commit

Permalink
Merge pull request #376 from favreau/master
Browse files Browse the repository at this point in the history
Added stereo to fisheye camera
  • Loading branch information
favreau authored Jun 7, 2024
2 parents d07152a + ebf9ac5 commit cfd0a30
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ void MediaMakerPlugin::_setCamera(const CameraDefinition &payload)
camera.updateProperty(CAMERA_PROPERTY_FOCAL_DISTANCE.name, payload.focalDistance);

// Stereo
if (camera.hasProperty(CAMERA_PROPERTY_STEREO.name))
camera.updateProperty(CAMERA_PROPERTY_STEREO.name, payload.interpupillaryDistance != 0.0);
if (camera.hasProperty(CAMERA_PROPERTY_INTERPUPILLARY_DISTANCE.name))
camera.updateProperty(CAMERA_PROPERTY_INTERPUPILLARY_DISTANCE.name, payload.interpupillaryDistance);

Expand Down
9 changes: 4 additions & 5 deletions bioexplorer/pythonsdk/bioexplorer/movie_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def export_frames(
samples_per_pixel=1,
start_frame=0,
end_frame=0,
interpupillary_distance=0.0,
interpupillary_distance=0.0635,
export_intermediate_frames=False,
frame_buffer_mode=FRAME_BUFFER_MODE_COLOR,
keywords=list(),
Expand All @@ -247,7 +247,7 @@ def export_frames(
:start_frame: Optional value if the rendering should start at a specific frame.
:end_frame: Optional value if the rendering should end at a specific frame.
:export_intermediate_frames: Exports intermediate frames (for every sample per pixel)
:interpupillary_distance: Distance between pupils. Stereo mode is activated if different
:interpupillary_distance: Distance between pupils
from zero. This is used to resume the rendering of a previously canceled sequence)
:return: Result of the request submission
:rtype: Response
Expand Down Expand Up @@ -531,7 +531,7 @@ def create_movie(
samples_per_pixel=1,
start_frame=0,
end_frame=0,
interpupillary_distance=0.0,
interpupillary_distance=0.0635,
export_intermediate_frames=True,
):
"""
Expand All @@ -544,8 +544,7 @@ def create_movie(
:samples_per_pixel: Samples per pixel
:start_frame: Start frame to export in the provided sequence
:end_frame: Last frame to export in the provided sequence
:interpupillary_distance: Interpupillary distance for stereo rendering. If set to 0, stereo
is disabled
:interpupillary_distance: Interpupillary distance for stereo rendering
:export_intermediate_frames: If True, intermediate samples are stored to disk. Otherwise,
only the final accumulation is exported
"""
Expand Down
2 changes: 2 additions & 0 deletions platform/engines/ospray/OSPRayEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ void OSPRayEngine::_createCameras()
PropertyMap properties;
properties.setProperty(CAMERA_PROPERTY_FIELD_OF_VIEW);
properties.setProperty(aspect);
properties.setProperty(stereoProperty);
properties.setProperty(CAMERA_PROPERTY_INTERPUPILLARY_DISTANCE);
properties.setProperty(CAMERA_PROPERTY_APERTURE_RADIUS);
properties.setProperty(CAMERA_PROPERTY_FOCAL_DISTANCE);
properties.setProperty(CAMERA_PROPERTY_ENABLE_CLIPPING_PLANES);
Expand Down
23 changes: 23 additions & 0 deletions platform/engines/ospray/ispc/camera/FishEyeCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,41 @@ void FishEyeCamera::commit()
{
Camera::commit();

aspect = getParamf(CAMERA_PROPERTY_ASPECT_RATIO.name.c_str(), DEFAULT_CAMERA_ASPECT_RATIO);
enableClippingPlanes =
getParam(CAMERA_PROPERTY_ENABLE_CLIPPING_PLANES.name.c_str(), DEFAULT_CAMERA_ENABLE_CLIPPING_PLANES);
clipPlanes = enableClippingPlanes ? getParamData(CAMERA_PROPERTY_CLIPPING_PLANES, nullptr) : nullptr;
apertureRadius = getParamf(CAMERA_PROPERTY_APERTURE_RADIUS.name.c_str(), DEFAULT_CAMERA_APERTURE_RADIUS);
focalDistance = getParamf(CAMERA_PROPERTY_FOCAL_DISTANCE.name.c_str(), DEFAULT_CAMERA_FOCAL_DISTANCE);
useHardwareRandomizer = getParam(COMMON_PROPERTY_USE_HARDWARE_RANDOMIZER.name.c_str(),
static_cast<int>(DEFAULT_COMMON_USE_HARDWARE_RANDOMIZER));
stereoMode = getParam(CAMERA_PROPERTY_STEREO.name.c_str(), static_cast<int>(DEFAULT_CAMERA_STEREO))
? CameraStereoMode::side_by_side
: CameraStereoMode::mono;
interpupillaryDistance =
getParamf(CAMERA_PROPERTY_INTERPUPILLARY_DISTANCE.name.c_str(), DEFAULT_CAMERA_INTERPUPILLARY_DISTANCE);

dir = normalize(dir);
::ospray::vec3f dirU = normalize(cross(dir, up));
::ospray::vec3f dirV = cross(dirU, dir);

::ospray::vec3f org = pos;
const ::ospray::vec3f ipd_offset = 0.5f * interpupillaryDistance * dirU;

switch (stereoMode)
{
case CameraStereoMode::left:
org -= ipd_offset;
break;
case CameraStereoMode::right:
org += ipd_offset;
break;
case CameraStereoMode::side_by_side:
aspect *= 0.5f;
break;
case CameraStereoMode::mono:
break;
}

if (apertureRadius > 0.f)
{
Expand All @@ -76,6 +98,7 @@ void FishEyeCamera::commit()
::ispc::FishEyeCamera_set(getIE(), (const ::ispc::vec3f&)org, (const ::ispc::vec3f&)invDir,
(const ::ispc::vec3f&)dirU, (const ::ispc::vec3f&)dirV,
(const ::ispc::vec4f*)clipPlaneData, numClipPlanes, apertureRadius,
(const ::ispc::vec3f&)ipd_offset, stereoMode,
useHardwareRandomizer);
}

Expand Down
6 changes: 6 additions & 0 deletions platform/engines/ospray/ispc/camera/FishEyeCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "camera/Camera.h"

#include <platform/core/common/Properties.h>
#include <platform/core/common/CommonTypes.h>
#include <platform/engines/ospray/OSPRayProperties.h>

namespace core
Expand All @@ -44,10 +45,15 @@ struct OSPRAY_SDK_INTERFACE FishEyeCamera : public ::ospray::Camera
bool enableClippingPlanes{false};
::ospray::Ref<::ospray::Data> clipPlanes;

double aspect;
float apertureRadius{DEFAULT_CAMERA_APERTURE_RADIUS};
float focalDistance{DEFAULT_CAMERA_FOCAL_DISTANCE};
float exposure{DEFAULT_COMMON_EXPOSURE};
bool useHardwareRandomizer{DEFAULT_COMMON_USE_HARDWARE_RANDOMIZER};

// Stereo
CameraStereoMode stereoMode;
double interpupillaryDistance;
};
} // namespace ospray
} // namespace engine
Expand Down
21 changes: 21 additions & 0 deletions platform/engines/ospray/ispc/camera/FishEyeCamera.ispc
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct FishEyeCamera

float aperture;

// Stereo
bool side_by_side;
vec3f ipd_offset;

// Hardware randomizer
bool useHardwareRandomizer;
};
Expand All @@ -56,6 +60,20 @@ void FishEyeCamera_initRay(uniform Camera* uniform _self, varying Ray& ray, cons
vec2f screen = sample.screen;
vec3f org = self->org;

if (self->side_by_side)
{
screen.x *= 2.f;
if (screen.x < 1.f)
{
org = org - self->ipd_offset;
}
else
{
org = org + self->ipd_offset;
screen.x -= 1.f;
}
}

screen = Camera_subRegion(_self, screen);

float xp = screen.x * 2.f - 1.f;
Expand Down Expand Up @@ -120,6 +138,7 @@ export void* uniform FishEyeCamera_create(void* uniform cppE)
export void FishEyeCamera_set(void* uniform _self, const uniform vec3f& org, const uniform vec3f& dir,
const uniform vec3f& dirU, const uniform vec3f& dirV, const uniform vec4f clipPlanes[],
const uniform unsigned int numClipPlanes, const uniform float aperture,
const uniform vec3f& ipd_offset, const uniform bool side_by_side,
const uniform bool useHardwareRandomizer)
{
uniform FishEyeCamera* uniform self = (uniform FishEyeCamera * uniform) _self;
Expand All @@ -129,6 +148,8 @@ export void FishEyeCamera_set(void* uniform _self, const uniform vec3f& org, con
self->dirV = dirV;
self->clipPlanes = clipPlanes;
self->numClipPlanes = numClipPlanes;
self->side_by_side = side_by_side;
self->ipd_offset = ipd_offset;
self->aperture = aperture;
self->useHardwareRandomizer = useHardwareRandomizer;
}

0 comments on commit cfd0a30

Please sign in to comment.