Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aperturesize, resolution, viewplane, shuttertime fixes #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

murraystevenson
Copy link
Contributor

Hey Alex,

I took a closer look at the CameraAlgo behaviour and have come up with the following changes:

  • ccam->aperturesize changed to radius rather than width. This matches the Blender camera conversion logic and visually matches GafferArnold.
  • ccam->resolution changed to use camera->renderResolution() as this returns the resolution as modified by Gaffer's resolutionMultiplier plug.
  • ccam->viewplane.top and .bottom now inverted so camera aperture offsets in Y apply in the correct direction, we also need this flipped for eventual overscan support.
  • ccam->motion_position logic updated to work based on relative shutter times, as camera->getShutter() returns absolute shutter values. With this, camera blur works as expected. Cycles seems fine with receiving either a positive or negative shuttertime so I simplified the logic a bit.

The behaviour of these changes has been visually compared with GafferArnold and the results look good to me.

M

ccam->aperturesize changed to radius rather than width
ccam->resolution changed to use camera->renderResolution() as this includes support for Gaffer's resolutionMultiplier plug
ccam->viewplane.top and .bottom need to be inverted so camera apertureOffsets in Y apply in the correct direction
ccam->motion_position logic simplified and updated to work from relative shutter times, as camera->getShutter() returns absolute shutter values

behaviour of changes validated against GafferArnold
Copy link
Owner

@boberfly boberfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @murraystevenson cheers for the PR, this was definitely something that needed to be looked at again with the right test data and GafferArnold as a comparison, cheers! I've put some notes in, if you don't get around to it I'll try what I've written over here and verify with Arnold.

@@ -36,6 +36,8 @@
#include "GafferCycles/IECoreCyclesPreview/ObjectAlgo.h"
#include "GafferCycles/IECoreCyclesPreview/SocketAlgo.h"

#include "Gaffer/Context.h"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that you are needing to get the current frame somehow on line 129, we don't want a dependency on Gaffer in the IECoreCycles code as it might one day appear in Cortex. What we can do here is use modf() to extract the fractional part of the shutter (good find I didn't know it included the frame in it).

@@ -66,7 +68,7 @@ ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string
ccam->fov = M_PI_2;
if( camera->getFStop() > 0.0f )
{
ccam->aperturesize = camera->getFocalLength() * camera->getFocalLengthWorldScale() / camera->getFStop();
ccam->aperturesize = 0.5f * camera->getFocalLength() * camera->getFocalLengthWorldScale() / camera->getFStop();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've sworn the camera code in Cycles was in diameter not radius, maybe it changed after I implemented this and I didn't notice? But, if it's matching to GafferArnold then I guess I was wrong/it changed! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seems a bit unintuitive but it matches visually with Arnold and based on the below it seems the same is done on the Blender camera conversion:

https://github.com/boberfly/cycles/blob/89cb9a6f74b28e6f797e38304ffafdbb9b395030/src/blender/blender_camera.cpp#L219

@@ -104,6 +106,11 @@ ccl::Camera *convertCommon( const IECoreScene::Camera *camera, const std::string
ccam->nearclip = clippingPlanes.x;
ccam->farclip = clippingPlanes.y;

// Invert the viewplane in Y so Gaffer's aperture offsets and overscan are applied in the correct direction
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we simplify this to the lines above?

	// Invert the viewplane in Y so Gaffer's aperture offsets and overscan are applied in the correct direction
	ccam->viewplane.bottom = -frustum.max.y;
	ccam->viewplane.top = -frustum.min.y;

And will we need to change the crop window to match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with something like that, but I've also been playing with getting overscan working and would need to apply the same flip to the overscan values when modifying the viewplane so figured it'd be cleaner to just flip it all in one place at the end. Happy to take the simpler path and revisit it if/when I put up a PR for overscan.

The crop window doesn't need to be flipped as it applies to the image, rather than the camera viewplane.

const Imath::V2f &shutter = camera->getShutter();
if ((shutter.x > 0.0) && (shutter.y > 0.0))
ccam->shuttertime = shutter.y - shutter.x;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we might need to add an abs here eg. abs( shutter.y - shutter.x ); if we render with a negative frame.

if ((shutter.x > 0.0) && (shutter.y > 0.0))
ccam->shuttertime = shutter.y - shutter.x;

const Imath::V2f relativeShutter = shutter - Imath::V2f( Gaffer::Context::current()->getFrame() );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const Imath::V2f relativeShutter = Imath::V2f( modf( shutter.x, nullptr ), modf( shutter.y, nullptr ) );
I'll test here and see.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright had a bit more of a think to this the next day, modf won't cut it. I'm testing now by bringing this code into Renderer.cpp and hashing the frame number with the camera hash there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried out your camerafixes2 branch with the above changes, renders look good to me.

I guess a simpler way of approaching this would be to calculate the relative shutter time with something like const Imath::V2f relativeShutter = shutter - Imath::V2f( round(shutter.x + shuttertime / 2.0f) );

boberfly added a commit that referenced this pull request Nov 18, 2019
Copy link
Owner

@boberfly boberfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you get the chance @murraystevenson I've got a branch here to try out which should match your changes:
https://github.com/boberfly/GafferCycles/tree/camerafixes2
Let me know if that works fine for you. Cheers!

boberfly added a commit that referenced this pull request Nov 18, 2019
boberfly added a commit that referenced this pull request Nov 18, 2019
boberfly added a commit that referenced this pull request Nov 18, 2019
boberfly added a commit that referenced this pull request Nov 18, 2019
boberfly added a commit that referenced this pull request Feb 11, 2020
johnhaddon pushed a commit to johnhaddon/GafferCycles that referenced this pull request Apr 29, 2022
johnhaddon pushed a commit to johnhaddon/GafferCycles that referenced this pull request Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants