| 2367 | } |
| 2368 | |
| 2369 | void EveSpaceScene::RenderIntoCloudShadowMap( Tr2RenderContext& renderContext, const ITr2VolumetricRenderable::ShadowInfo* cloudShadowInformation, std::vector<IEveShadowCaster*> shadowCasters ) |
| 2370 | { |
| 2371 | CCP_STATS_ZONE( __FUNCTION__ ); |
| 2372 | |
| 2373 | // Get distance from camera to zFar |
| 2374 | auto direction = Tr2Renderer::GetViewPosition() - cloudShadowInformation->aabbMax; |
| 2375 | float dist = Length( direction ); |
| 2376 | |
| 2377 | auto projection = PerspectiveFovMatrix( Tr2Renderer::GetFieldOfView(), Tr2Renderer::GetAspectRatio(), m_updateContext.GetFrustum().m_zNear, dist ); |
| 2378 | auto invViewProj = Inverse( projection ) * Tr2Renderer::GetInverseViewTransform(); |
| 2379 | const Matrix viewProj = Inverse( invViewProj ); |
| 2380 | |
| 2381 | TriFrustum frustum; |
| 2382 | frustum.ExtractFrustum( &viewProj ); |
| 2383 | |
| 2384 | { |
| 2385 | CCP_STATS_ZONE( "get shadowbatches for volumetrics" ); |
| 2386 | auto shadowFrustum = TriShadowOrthoFrustum( cloudShadowInformation->shadowFrustum, cloudShadowInformation->shadowMapSize, m_sunData.DirWorld ); |
| 2387 | float sizeInShadow = 0.0f; |
| 2388 | for( auto& caster : shadowCasters ) |
| 2389 | { |
| 2390 | caster->IsCastingShadow( frustum, shadowFrustum, TR2RENDERREASON_NORMAL, sizeInShadow ); |
| 2391 | // special threshold check |
| 2392 | if( sizeInShadow > 5.0f ) |
| 2393 | { |
| 2394 | auto perObjData = caster->GetShadowPerObjectData( m_shadowBatches[0].get() ); |
| 2395 | caster->GetShadowBatches( m_shadowBatches[0].get(), perObjData, sizeInShadow ); |
| 2396 | } |
| 2397 | } |
| 2398 | m_instancedMeshManager->GetShadowBatches( m_updateContext.GetFrustum(), shadowFrustum, m_updateContext.GetInvLodFactor(), { { TRIBATCHTYPE_OPAQUE, *m_shadowBatches[0] } } ); |
| 2399 | } |
| 2400 | |
| 2401 | m_shadowBatches[0]->Finalize(); |
| 2402 | PerFrameVSData data; |
| 2403 | data.ViewProjectionMat = Transpose( cloudShadowInformation->lightViewProj ); |
| 2404 | |
| 2405 | static const unsigned perFrameVsMask = |
| 2406 | ( 1 << VERTEX_SHADER ) | |
| 2407 | SHADER_TYPE_EXISTS( COMPUTE_SHADER ) | |
| 2408 | SHADER_TYPE_EXISTS( GEOMETRY_SHADER ) | |
| 2409 | SHADER_TYPE_EXISTS( HULL_SHADER ) | |
| 2410 | SHADER_TYPE_EXISTS( DOMAIN_SHADER ); |
| 2411 | FillAndSetConstants( m_shadowPerFrameVSBuffer, &data, sizeof( data ), perFrameVsMask, Tr2Renderer::GetPerFrameVSStartRegister(), renderContext ); |
| 2412 | |
| 2413 | if( m_shadowBatches[0]->GetBatchCount() ) |
| 2414 | { |
| 2415 | renderContext.m_esm.SetInvertedDepthTest( false ); |
| 2416 | ON_BLOCK_EXIT( [&] { renderContext.m_esm.SetInvertedDepthTest( true ); } ); |
| 2417 | renderContext.m_esm.ApplyStandardStates( Tr2EffectStateManager::RM_OPAQUE ); |
| 2418 | renderContext.RenderBatches( m_shadowBatches[0].get(), BlueSharedString( "Shadow" ) ); |
| 2419 | } |
| 2420 | |
| 2421 | m_shadowBatches[0]->Clear(); |
| 2422 | |
| 2423 | renderContext.SetReadOnlyDepth( false ); |
| 2424 | |
| 2425 | renderContext.m_esm.PopRenderTarget(); |
| 2426 | renderContext.m_esm.PopDepthStencilBuffer(); |
nothing calls this directly
no test coverage detected