Skip to content

Commit f47dccb

Browse files
committed
Based on #33
1 parent 647d36d commit f47dccb

File tree

2 files changed

+34
-32
lines changed

2 files changed

+34
-32
lines changed

src/GafferCycles/IECoreCyclesPreview/CameraAlgo.cpp

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string
6666
ccam->fov = M_PI_2;
6767
if( camera->getFStop() > 0.0f )
6868
{
69-
ccam->aperturesize = camera->getFocalLength() * camera->getFocalLengthWorldScale() / camera->getFStop();
69+
ccam->aperturesize = 0.5f * camera->getFocalLength() * camera->getFocalLengthWorldScale() / camera->getFStop();
7070
ccam->focaldistance = camera->getFocusDistance();
7171
}
7272
}
@@ -87,23 +87,24 @@ ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string
8787

8888
// Screen window/resolution TODO: full_ might be something to do with cropping?
8989
const Imath::Box2f &frustum = camera->frustum();
90-
const Imath::V2i &resolution = camera->getResolution();
90+
const Imath::V2i &resolution = camera->renderResolution();
9191
const float pixelAspectRatio = camera->getPixelAspectRatio();
9292
ccam->width = resolution[0];
9393
ccam->height = resolution[1];
9494
ccam->full_width = resolution[0];
9595
ccam->full_height = resolution[1];
9696
ccam->viewplane.left = frustum.min.x;
9797
ccam->viewplane.right = frustum.max.x;
98-
ccam->viewplane.bottom = frustum.min.y;
99-
ccam->viewplane.top = frustum.max.y;
98+
// Invert the viewplane in Y so Gaffer's aperture offsets and overscan are applied in the correct direction
99+
ccam->viewplane.bottom = -frustum.max.y;
100+
ccam->viewplane.top = -frustum.min.y;
100101
ccam->aperture_ratio = pixelAspectRatio; // This is more for the bokeh, maybe it should be a separate parameter?
101102

102103
// Clipping planes
103104
const Imath::V2f &clippingPlanes = camera->getClippingPlanes();
104105
ccam->nearclip = clippingPlanes.x;
105106
ccam->farclip = clippingPlanes.y;
106-
107+
107108
// Crop window
108109
if ( camera->hasCropWindow() )
109110
{
@@ -115,28 +116,9 @@ ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string
115116
ccam->border.clamp();
116117
}
117118

118-
// Shutter TODO: Need to see if this is correct or not, cycles also has a shutter curve...
119+
// Shutter TODO: Cycles also has a shutter curve...
119120
const Imath::V2f &shutter = camera->getShutter();
120-
if ((shutter.x > 0.0) && (shutter.y > 0.0))
121-
{
122-
ccam->motion_position = ccl::Camera::MOTION_POSITION_START;
123-
ccam->shuttertime = shutter.x + shutter.y;
124-
}
125-
else if ((shutter.x < 0.0) && (shutter.y > 0.0))
126-
{
127-
ccam->motion_position = ccl::Camera::MOTION_POSITION_CENTER;
128-
ccam->shuttertime = abs(shutter.x) + shutter.y;
129-
}
130-
else if ((shutter.x < 0.0) && (shutter.y <= 0.0))
131-
{
132-
ccam->motion_position = ccl::Camera::MOTION_POSITION_END;
133-
ccam->shuttertime = abs(shutter.x) + abs(shutter.y);
134-
}
135-
else
136-
{
137-
ccam->motion_position = ccl::Camera::MOTION_POSITION_CENTER;
138-
ccam->shuttertime = 1.0;
139-
}
121+
ccam->shuttertime = abs( shutter.y - shutter.x );
140122

141123
return ccam;
142124
}

src/GafferCycles/IECoreCyclesPreview/Renderer.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,16 +1909,36 @@ class CameraCache : public IECore::RefCounted
19091909
}
19101910

19111911
// Can be called concurrently with other get() calls.
1912-
SharedCCameraPtr get( const IECoreScene::Camera *camera, const std::string &name )
1912+
SharedCCameraPtr get( const IECoreScene::Camera *camera, const std::string &name, int frame )
19131913
{
1914-
const IECore::MurmurHash hash = camera->Object::hash();
1914+
IECore::MurmurHash hash = camera->Object::hash();
1915+
1916+
hash.append( frame );
19151917

19161918
Cache::accessor a;
19171919
m_cache.insert( a, hash );
19181920

19191921
if( !a->second )
19201922
{
1921-
a->second = SharedCCameraPtr( CameraAlgo::convert( camera, name ) );
1923+
ccl::Camera *ccam = CameraAlgo::convert( camera, name );
1924+
1925+
// Set the correct motion position here as we need access to the current frame.
1926+
const Imath::V2f &shutter = camera->getShutter();
1927+
const Imath::V2f relativeShutter = shutter - Imath::V2f( frame );
1928+
if ( ( relativeShutter.x >= 0.0f ) && ( relativeShutter.y > 0.0f ) )
1929+
{
1930+
ccam->motion_position = ccl::Camera::MOTION_POSITION_START;
1931+
}
1932+
else if ( ( relativeShutter.x < 0.0f ) && ( relativeShutter.y <= 0.0f ) )
1933+
{
1934+
ccam->motion_position = ccl::Camera::MOTION_POSITION_END;
1935+
}
1936+
else
1937+
{
1938+
ccam->motion_position = ccl::Camera::MOTION_POSITION_CENTER;
1939+
}
1940+
1941+
a->second = SharedCCameraPtr( ccam );
19221942
}
19231943

19241944
return a->second;
@@ -2961,7 +2981,7 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
29612981

29622982
ObjectInterfacePtr camera( const std::string &name, const IECoreScene::Camera *camera, const AttributesInterface *attributes ) override
29632983
{
2964-
SharedCCameraPtr ccamera = m_cameraCache->get( camera, name );
2984+
SharedCCameraPtr ccamera = m_cameraCache->get( camera, name, m_frame );
29652985
if( !ccamera )
29662986
{
29672987
return nullptr;
@@ -3347,7 +3367,7 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
33473367
}
33483368
else
33493369
{
3350-
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first );
3370+
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first, m_frame );
33513371
if( m_scene->camera != ccamera.get() )
33523372
{
33533373
m_scene->camera = ccamera.get();
@@ -3373,7 +3393,7 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
33733393
}
33743394
else
33753395
{
3376-
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first );
3396+
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first, m_frame );
33773397
m_instanceCache->updateDicingCamera( ccamera.get() );
33783398
}
33793399
}

0 commit comments

Comments
 (0)