| 134 | } |
| 135 | |
| 136 | bool RendererBase::updateFrameDataGPUStruct(FrameData* pStaging) |
| 137 | { |
| 138 | FrameData frameData; |
| 139 | |
| 140 | // Get the camera properties: |
| 141 | // - The view-projection matrix. |
| 142 | // - The inverse view matrix, transposed. |
| 143 | // - The dimensions of the view (in world units) at a distance of 1.0 from the camera, derived |
| 144 | // from the [0,0] and [1,1] elements of the projection matrix. |
| 145 | // - Whether the camera uses an orthographic projection, defined by the [3,3] element of the |
| 146 | // projection matrix. |
| 147 | // - Focal distance and lens radius, for depth of field. |
| 148 | frameData.cameraViewProj = _cameraProj * _cameraView; |
| 149 | frameData.cameraInvView = transpose(inverse(_cameraView)); |
| 150 | frameData.viewSize = vec2(2.0f / _cameraProj[0][0], 2.0f / _cameraProj[1][1]); |
| 151 | frameData.isOrthoProjection = _cameraProj[3][3] == 1.0f; |
| 152 | frameData.focalDistance = _focalDistance; |
| 153 | frameData.lensRadius = _lensRadius; |
| 154 | |
| 155 | // Get the scene size, specifically the maximum distance between any two points in the scene. |
| 156 | // This is computed as the distance between the min / max corners of the bounding box. |
| 157 | const Foundation::BoundingBox& bounds = _pScene->bounds(); |
| 158 | frameData.sceneSize = glm::length(bounds.max() - bounds.min()); |
| 159 | |
| 160 | // Copy the current light buffer for the scene to this frame's light data. |
| 161 | memcpy(&frameData.lights, &_pScene->lights(), sizeof(frameData.lights)); |
| 162 | |
| 163 | int debugMode = _values.asInt(kLabelDebugMode); |
| 164 | int traceDepth = _values.asInt(kLabelTraceDepth); |
| 165 | traceDepth = glm::max(1, glm::min(kMaxTraceDepth, traceDepth)); |
| 166 | frameData.traceDepth = traceDepth; |
| 167 | frameData.isDenoisingEnabled = _values.asBoolean(kLabelIsDenoisingEnabled) ? 1 : 0; |
| 168 | frameData.isForceOpaqueShadowsEnabled = |
| 169 | _values.asBoolean(kLabelIsForceOpaqueShadowsEnabled) ? 1 : 0; |
| 170 | frameData.isDiffuseOnlyEnabled = _values.asBoolean(kLabelIsDiffuseOnlyEnabled) ? 1 : 0; |
| 171 | frameData.maxLuminance = _values.asFloat(kLabelMaxLuminance); |
| 172 | frameData.isDisplayErrorsEnabled = debugMode == kDebugModeErrors ? 1 : 0; |
| 173 | |
| 174 | // If there are no changes compared local CPU copy, then do nothing and return false. |
| 175 | if (memcmp(&_frameData, &frameData, sizeof(FrameData)) == 0) |
| 176 | return false; // No changes. |
| 177 | |
| 178 | // Set the local copy of frame data to use for next comparison. |
| 179 | _frameData = frameData; |
| 180 | |
| 181 | // If staging buffer pointer was passed in, copy to that. |
| 182 | if (pStaging) |
| 183 | *pStaging = frameData; |
| 184 | |
| 185 | return true; |
| 186 | } |
| 187 | |
| 188 | bool RendererBase::updatePostProcessingGPUStruct(PostProcessing* pStaging) |
| 189 | { |