| 404 | |
| 405 | |
| 406 | void Tr2VolumetricsRenderer::UpdateFogEnvironmentMap( Tr2RenderContext& renderContext ) |
| 407 | { |
| 408 | bool froxelsEnabled = m_froxelFogSettings.thickness.value > 0.0f; |
| 409 | bool environmentLightingEnabled = froxelsEnabled && m_froxelFogSettings.environmentIntensity.value > 0; |
| 410 | |
| 411 | |
| 412 | uint32_t environmentMapResolution = 1; |
| 413 | if( environmentLightingEnabled ) |
| 414 | { |
| 415 | environmentMapResolution = 128; |
| 416 | |
| 417 | CCP_ASSERT( environmentMapResolution % 8 == 0 ); |
| 418 | } |
| 419 | |
| 420 | auto& mieEnvironmentMap = *m_mieEnvironmentMap->GetTexture(); |
| 421 | if( !mieEnvironmentMap.IsValid() || mieEnvironmentMap.GetWidth() != environmentMapResolution ) |
| 422 | { |
| 423 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 424 | |
| 425 | m_environmentBlendCounter = 0; //reset counter so we start back from 0 when we enabled it next time. |
| 426 | |
| 427 | if( environmentLightingEnabled ) |
| 428 | { |
| 429 | //Full 32-bit precision is needed due to blending to this texture with a low weight. |
| 430 | Tr2BitmapDimensions dimensions( Tr2RenderContextEnum::TEX_TYPE_CUBE, Tr2RenderContextEnum::PIXEL_FORMAT_R32G32B32A32_FLOAT, environmentMapResolution, environmentMapResolution, 1, 1, 6 ); |
| 431 | |
| 432 | mieEnvironmentMap.Create( dimensions, Tr2GpuUsage::UNORDERED_ACCESS | Tr2GpuUsage::SHADER_RESOURCE, renderContext ); |
| 433 | } |
| 434 | else |
| 435 | { |
| 436 | //Create dummy texture |
| 437 | Tr2BitmapDimensions dimensions( Tr2RenderContextEnum::TEX_TYPE_CUBE, Tr2RenderContextEnum::PIXEL_FORMAT_R8G8B8A8_UNORM, 1, 1, 1, 1, 6 ); |
| 438 | |
| 439 | uint8_t black[4] = {}; |
| 440 | Tr2SubresourceData initialData[6]; |
| 441 | for( uint32_t i = 0; i < 6; ++i ) |
| 442 | { |
| 443 | initialData[i].m_sysMem = black; |
| 444 | initialData[i].m_sysMemPitch = 4; |
| 445 | initialData[i].m_sysMemSlicePitch = 4; |
| 446 | } |
| 447 | |
| 448 | mieEnvironmentMap.Create( dimensions, Tr2GpuUsage::UNORDERED_ACCESS | Tr2GpuUsage::SHADER_RESOURCE, initialData, renderContext ); |
| 449 | } |
| 450 | if( !mieEnvironmentMap.IsValid() ) |
| 451 | { |
| 452 | CCP_LOGERR( "Tr2VolumetricsRenderer failed to create environment cubemap with size %ix", int( environmentMapResolution ) ); |
| 453 | return; |
| 454 | } |
| 455 | |
| 456 | m_mieEnvironmentMap->OnTextureChange().Broadcast(); |
| 457 | } |
| 458 | |
| 459 | if( environmentLightingEnabled ) |
| 460 | { |
| 461 | GPU_REGION( renderContext, "Update Fog Environment Map" ); |
| 462 | |
| 463 | const float g = 1.61803398874989484820; |
no test coverage detected