Skip to content

Commit

Permalink
Don't write camera aperture parameters if they're already set (Autode…
Browse files Browse the repository at this point in the history
…sk#1952)

* Don't author camera aperture parameters if they're already set MTOA-1951

* Add changelog

* Remove spurious empty line
  • Loading branch information
sebastienblor authored Jun 26, 2024
1 parent 64c0ed1 commit 5e2e35c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- [usd#1927](https://github.com/Autodesk/arnold-usd/issues/1927) - Fix procedural updates during iteractive changes of non-leaf primitives
- [usd#1661](https://github.com/Autodesk/arnold-usd/issues/1661) - In the procedural the subdivision meshes will use the normals generated by the subdivision algorithm instead of the normal primvar.
- [usd#1919](https://github.com/Autodesk/arnold-usd/issues/1919) - Fix rendering multiple frames with husk.
- [usd#1952](https://github.com/Autodesk/arnold-usd/issues/1952) - Don't write camera aperture parameters if they're already set

## Pending bugfix release
- [usd#1940](https://github.com/Autodesk/arnold-usd/issues/1940) - Incorrect handling of shaders referenced in multiple materials
Expand Down
35 changes: 21 additions & 14 deletions libs/translator/writer/write_camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,28 @@ void UsdArnoldWriteCamera::Write(const AtNode *node, UsdArnoldWriter &writer)

if (persp) {
AtNode *options = AiUniverseGetOptions(writer.GetUniverse());

float fov = AiNodeGetFlt(node, AtString("fov"));
float horizontalAperature = tan(fov * AI_DTOR * 0.5f);
horizontalAperature *= (2.f * 50.f * GfCamera::FOCAL_LENGTH_UNIT);
horizontalAperature /= GfCamera::APERTURE_UNIT;

writer.SetAttribute(cam.CreateHorizontalApertureAttr(), horizontalAperature);
float verticalAperture = horizontalAperature;

// Use the options image resolution to determine the vertical aperture
if (options) {
verticalAperture *= (float)AiNodeGetInt(options, AtString("yres")) / (float)AiNodeGetInt(options, AtString("xres"));
// Arnold only knows about FOV and not about horizontal & vertical aperture.
// We want to dump some aperture values in the usd file, as this is used by other
// usd tools, but we can't compute an exact value (we'd need a focal length)
// we only author these values if they weren't previously set. MTOA-1951
if (!cam.GetHorizontalApertureAttr().HasAuthoredValue() &&
!cam.GetVerticalApertureAttr().HasAuthoredValue()) {

float fov = AiNodeGetFlt(node, AtString("fov"));
float horizontalAperature = tan(fov * AI_DTOR * 0.5f);
// The formula below assumes a focal length of 50, which is the default value but
// not necessarily the right one. Therefore we can't author an exact value here.
horizontalAperature *= (2.f * 50.f * GfCamera::FOCAL_LENGTH_UNIT);
horizontalAperature /= GfCamera::APERTURE_UNIT;
writer.SetAttribute(cam.CreateHorizontalApertureAttr(), horizontalAperature);

float verticalAperture = horizontalAperature;
// Use the options image resolution to determine the vertical aperture
if (options) {
verticalAperture *= (float)AiNodeGetInt(options, AtString("yres")) / (float)AiNodeGetInt(options, AtString("xres"));
}
writer.SetAttribute(cam.CreateVerticalApertureAttr(), verticalAperture);
}

writer.SetAttribute(cam.CreateVerticalApertureAttr(), verticalAperture);
// Note that we're not adding "fov" to the list of exported attrs, because we still
// want it to be set as an arnold-specific attribute. This way, when it's read from usd,
// we can get the exact same value without any difference caused by the back and forth conversions
Expand Down

0 comments on commit 5e2e35c

Please sign in to comment.