63 HdRenderParam *renderParam,
64 HdDirtyBits *dirtyBits)
66 if (*dirtyBits == DirtyBits::Clean) {
71 const SdfPath &
id = GetId();
73#if PXR_VERSION >= 2102
74 if (*dirtyBits & DirtyBits::DirtyTransform) {
75 sceneDelegate->SampleTransform(
id, &_transformSamples);
77 bool transform_found =
false;
78 for (
size_t i = 0; i < _transformSamples.count; ++i) {
79 if (_transformSamples.times[i] == 0.0f) {
80 _transform = _transformSamples.values[i];
81 _data.SetTransform(_transform);
82 transform_found =
true;
87 if (!transform_found && _transformSamples.count) {
88 _transform = _transformSamples.values[0];
89 _data.SetTransform(_transform);
93 if (*dirtyBits & DirtyBits::DirtyViewMatrix) {
94 sceneDelegate->SampleTransform(
id, &_transformSamples);
96 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->worldToViewMatrix);
97 if (!value.IsEmpty()) {
98 _worldToViewMatrix = value.Get<GfMatrix4d>();
99 _worldToViewInverseMatrix = _worldToViewMatrix.GetInverse();
100 _data.SetTransform(_worldToViewInverseMatrix);
105#if PXR_VERSION < 2111
106 if (*dirtyBits & DirtyBits::DirtyProjMatrix) {
107 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->projectionMatrix);
108 if (!value.IsEmpty()) {
109 _projectionMatrix = value.Get<GfMatrix4d>();
110 const float focalLength = _data.GetFocalLength();
111# if PXR_VERSION >= 2102
112 _data.SetFromViewAndProjectionMatrix(GetViewMatrix(), _projectionMatrix, focalLength);
114 if (_projectionMatrix[2][3] < -0.5) {
115 _data.SetProjection(GfCamera::Perspective);
117 const float horizontalAperture = (2.0 * focalLength) / _projectionMatrix[0][0];
118 _data.SetHorizontalAperture(horizontalAperture);
119 _data.SetHorizontalApertureOffset(0.5 * horizontalAperture * _projectionMatrix[2][0]);
120 const float verticalAperture = (2.0 * focalLength) / _projectionMatrix[1][1];
121 _data.SetVerticalAperture(verticalAperture);
122 _data.SetVerticalApertureOffset(0.5 * verticalAperture * _projectionMatrix[2][1]);
124 _data.SetClippingRange(
125 GfRange1f(_projectionMatrix[3][2] / (_projectionMatrix[2][2] - 1.0),
126 _projectionMatrix[3][2] / (_projectionMatrix[2][2] + 1.0)));
129 _data.SetProjection(GfCamera::Orthographic);
131 const float horizontalAperture = (2.0 / GfCamera::APERTURE_UNIT) / _projectionMatrix[0][0];
132 _data.SetHorizontalAperture(horizontalAperture);
133 _data.SetHorizontalApertureOffset(-0.5 * horizontalAperture * _projectionMatrix[3][0]);
134 const float verticalAperture = (2.0 / GfCamera::APERTURE_UNIT) / _projectionMatrix[1][1];
135 _data.SetVerticalAperture(verticalAperture);
136 _data.SetVerticalApertureOffset(-0.5 * verticalAperture * _projectionMatrix[3][1]);
138 const double nearMinusFarHalf = 1.0 / _projectionMatrix[2][2];
139 const double nearPlusFarHalf = nearMinusFarHalf * _projectionMatrix[3][2];
140 _data.SetClippingRange(
141 GfRange1f(nearPlusFarHalf + nearMinusFarHalf, nearPlusFarHalf - nearMinusFarHalf));
148 if (*dirtyBits & DirtyBits::DirtyWindowPolicy) {
149 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->windowPolicy);
150 if (!value.IsEmpty()) {
151 _windowPolicy = value.Get<CameraUtilConformWindowPolicy>();
155 if (*dirtyBits & DirtyBits::DirtyClipPlanes) {
156 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->clipPlanes);
157 if (!value.IsEmpty()) {
158 _clipPlanes = value.Get<std::vector<GfVec4d>>();
162 if (*dirtyBits & DirtyBits::DirtyParams) {
163#if PXR_VERSION >= 2102
164 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->projection);
165 if (!value.IsEmpty()) {
167 _data.SetProjection(_projection != Orthographic ? GfCamera::Perspective :
168 GfCamera::Orthographic);
171 value = sceneDelegate->GetCameraParamValue(
id, _tokens->projection);
172 if (!value.IsEmpty()) {
173 _data.SetProjection(value.Get<TfToken>() != _tokens->orthographic ? GfCamera::Perspective :
174 GfCamera::Orthographic);
178 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->horizontalAperture);
179 if (!value.IsEmpty()) {
180 const auto horizontalAperture = value.Get<
float>();
181#if PXR_VERSION >= 2102
182 _horizontalAperture = horizontalAperture;
184 _data.SetHorizontalAperture(horizontalAperture / GfCamera::APERTURE_UNIT);
187 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->verticalAperture);
188 if (!value.IsEmpty()) {
189 const auto verticalAperture = value.Get<
float>();
190#if PXR_VERSION >= 2102
191 _verticalAperture = verticalAperture;
193 _data.SetVerticalAperture(verticalAperture / GfCamera::APERTURE_UNIT);
196 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->horizontalApertureOffset);
197 if (!value.IsEmpty()) {
198 const auto horizontalApertureOffset = value.Get<
float>();
199#if PXR_VERSION >= 2102
200 _horizontalApertureOffset = horizontalApertureOffset;
202 _data.SetHorizontalApertureOffset(horizontalApertureOffset / GfCamera::APERTURE_UNIT);
205 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->verticalApertureOffset);
206 if (!value.IsEmpty()) {
207 const auto verticalApertureOffset = value.Get<
float>();
208#if PXR_VERSION >= 2102
209 _verticalApertureOffset = verticalApertureOffset;
211 _data.SetVerticalApertureOffset(verticalApertureOffset / GfCamera::APERTURE_UNIT);
214 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->focalLength);
215 if (!value.IsEmpty()) {
216 const auto focalLength = value.Get<
float>();
217#if PXR_VERSION >= 2102
218 _focalLength = focalLength;
220 _data.SetFocalLength(focalLength / GfCamera::FOCAL_LENGTH_UNIT);
223 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->clippingRange);
224 if (!value.IsEmpty()) {
225 const auto clippingRange = value.Get<GfRange1f>();
226#if PXR_VERSION >= 2102
227 _clippingRange = clippingRange;
229 _data.SetClippingRange(clippingRange);
232 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->fStop);
233 if (!value.IsEmpty()) {
234 const auto fStop = value.Get<
float>();
235#if PXR_VERSION >= 2102
238 _data.SetFStop(fStop);
241 value = sceneDelegate->GetCameraParamValue(
id, HdCameraTokens->focusDistance);
242 if (!value.IsEmpty()) {
243 const auto focusDistance = value.Get<
float>();
244#if PXR_VERSION >= 2102
245 _focusDistance = focusDistance;
247 _data.SetFocusDistance(focusDistance);
251 *dirtyBits = DirtyBits::Clean;