Skip to content

Commit baf0c78

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

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

include/GafferCycles/IECoreCyclesPreview/CameraAlgo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ namespace CameraAlgo
5151
{
5252

5353
/// Converts the specified IECoreScene::Camera into a ccl::Camera.
54-
IECORECYCLES_API ccl::Camera *convert( const IECoreScene::Camera *camera, const std::string &nodeName );
54+
IECORECYCLES_API ccl::Camera *convert( const IECoreScene::Camera *camera, const std::string &nodeName, int frame );
5555

5656
} // namespace CameraAlgo
5757

src/GafferCycles/IECoreCyclesPreview/CameraAlgo.cpp

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ using namespace IECoreCycles;
5252
namespace
5353
{
5454

55-
ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string &nodeName )
55+
ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string &nodeName, int frame )
5656
{
5757
assert( camera->typeId() == IECoreScene::Camera::staticTypeId() );
5858
ccl::Camera *ccam = new ccl::Camera();
@@ -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,27 +116,23 @@ 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+
ccam->shuttertime = abs( shutter.y - shutter.x );
122+
123+
// Set the correct motion position.
124+
const Imath::V2f relativeShutter = shutter - Imath::V2f( frame );
125+
if ( ( relativeShutter.x >= 0.0f ) && ( relativeShutter.y > 0.0f ) )
121126
{
122127
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;
129128
}
130-
else if ((shutter.x < 0.0) && (shutter.y <= 0.0))
129+
else if ( ( relativeShutter.x < 0.0f ) && ( relativeShutter.y <= 0.0f ) )
131130
{
132131
ccam->motion_position = ccl::Camera::MOTION_POSITION_END;
133-
ccam->shuttertime = abs(shutter.x) + abs(shutter.y);
134132
}
135133
else
136134
{
137135
ccam->motion_position = ccl::Camera::MOTION_POSITION_CENTER;
138-
ccam->shuttertime = 1.0;
139136
}
140137

141138
return ccam;
@@ -155,9 +152,9 @@ namespace CameraAlgo
155152

156153
{
157154

158-
ccl::Camera *convert( const IECoreScene::Camera *camera, const std::string &nodeName )
155+
ccl::Camera *convert( const IECoreScene::Camera *camera, const std::string &nodeName, int frame )
159156
{
160-
return convertCommon( camera, nodeName );
157+
return convertCommon( camera, nodeName, frame );
161158
}
162159

163160
} // namespace CameraAlgo

src/GafferCycles/IECoreCyclesPreview/Renderer.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,16 +1909,18 @@ 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+
a->second = SharedCCameraPtr( CameraAlgo::convert( camera, name, frame ) );
19221924
}
19231925

19241926
return a->second;
@@ -2961,7 +2963,7 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
29612963

29622964
ObjectInterfacePtr camera( const std::string &name, const IECoreScene::Camera *camera, const AttributesInterface *attributes ) override
29632965
{
2964-
SharedCCameraPtr ccamera = m_cameraCache->get( camera, name );
2966+
SharedCCameraPtr ccamera = m_cameraCache->get( camera, name, m_frame );
29652967
if( !ccamera )
29662968
{
29672969
return nullptr;
@@ -3347,7 +3349,7 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
33473349
}
33483350
else
33493351
{
3350-
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first );
3352+
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first, m_frame );
33513353
if( m_scene->camera != ccamera.get() )
33523354
{
33533355
m_scene->camera = ccamera.get();
@@ -3373,7 +3375,7 @@ class CyclesRenderer final : public IECoreScenePreview::Renderer
33733375
}
33743376
else
33753377
{
3376-
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first );
3378+
auto ccamera = m_cameraCache->get( cameraIt->second.get(), cameraIt->first, m_frame );
33773379
m_instanceCache->updateDicingCamera( ccamera.get() );
33783380
}
33793381
}

0 commit comments

Comments
 (0)