| 4141 | } |
| 4142 | |
| 4143 | void EveSpaceScene::ProcessOutdatedRTAnimations( Tr2RenderContext& renderContext ) |
| 4144 | { |
| 4145 | TriFrustumOrtho sunShadowFrustum; |
| 4146 | auto sunDir = m_sunData.DirWorld; |
| 4147 | |
| 4148 | { // Process Sun light |
| 4149 | // Let's compute left, right, top, bottom of the frustum divided by the near clipping plane. We need this for SetupShadowSplit. |
| 4150 | Matrix cameraProjection = Tr2Renderer::GetProjectionTransform(); |
| 4151 | float rightMinusLeft = 2.f / cameraProjection._11; // = ( r - l ) / zn |
| 4152 | float bottomMinusTop = 2.f / -cameraProjection._22; // = ( b - t ) / zn |
| 4153 | float left = ( cameraProjection._31 - 1.f ) / 2.f * rightMinusLeft; // = l / zn |
| 4154 | float top = ( -cameraProjection._32 - 1.f ) / 2.f * bottomMinusTop; // = t / zn |
| 4155 | float right = rightMinusLeft + left; // = r / zn |
| 4156 | float bottom = bottomMinusTop + top; // = b / zn |
| 4157 | |
| 4158 | // Make a projection matrix that fills |
| 4159 | auto sunProjection = PerspectiveOffCenterMatrix( left, right, bottom, top, MIN_SHADOW_SPLIT, MAX_SHADOW_SPLIT ); |
| 4160 | |
| 4161 | // we can apply the inverse of the view and projection matrices on the corner points of the unit cube to get the frustum corners in world space |
| 4162 | Matrix invViewProj = Inverse( sunProjection ) * Tr2Renderer::GetInverseViewTransform(); |
| 4163 | |
| 4164 | // Find light view |
| 4165 | Matrix lightView = Inverse( OrthoNormalBasisZ( -m_sunData.DirWorld ) ); |
| 4166 | |
| 4167 | Vector3 corners[8]; |
| 4168 | |
| 4169 | AxisAlignedBoundingBox aabb = Tr2ShadowMap::CalculateAABB( sunProjection, Tr2Renderer::GetInverseViewTransform(), lightView, corners ); |
| 4170 | |
| 4171 | // create shadow frustum out from lightView, aabb.min, aabb.max |
| 4172 | sunShadowFrustum.DeriveFrustum( lightView, aabb.m_min, aabb.m_max ); |
| 4173 | } |
| 4174 | |
| 4175 | std::vector<const Tr2LightManager::PerLightData*> pointsLightDatas; |
| 4176 | std::vector<TriFrustum> spotLightFrustums; |
| 4177 | |
| 4178 | // Process other lights |
| 4179 | if( auto lightManager = Tr2LightManager::GetInstance() ) |
| 4180 | { |
| 4181 | if( lightManager->GetShadowCastingLights().size() > 0 ) |
| 4182 | { |
| 4183 | for( uint32_t lightIndex : lightManager->GetShadowCastingLights() ) |
| 4184 | { |
| 4185 | const Tr2LightManager::PerLightData* lightData = &lightManager->GetLightData( lightIndex ); |
| 4186 | |
| 4187 | // Point light |
| 4188 | if( lightData->innerAngle <= 0.0f ) |
| 4189 | { |
| 4190 | pointsLightDatas.push_back( lightData ); |
| 4191 | } |
| 4192 | else // Spot light |
| 4193 | { |
| 4194 | Matrix projection; |
| 4195 | Matrix view; |
| 4196 | GetLightMatrices( *lightData, projection, view ); |
| 4197 | |
| 4198 | TriFrustum shadowFrustum; |
| 4199 | shadowFrustum.DeriveFrustum( &view, &lightData->position, &projection, renderContext.m_esm.GetViewport() ); |
| 4200 | spotLightFrustums.push_back( shadowFrustum ); |
nothing calls this directly
no test coverage detected