| 538 | } |
| 539 | |
| 540 | Tr2GpuResourcePool::Texture Tr2SSAO::ComputeCORTAO( const Tr2TextureAL& depthBuffer, const Tr2TextureAL& normalBuffer, Tr2GpuResourcePool& gpuResourcePool, Tr2RenderContext& renderContext, bool temporal ) |
| 541 | { |
| 542 | uint32_t width = depthBuffer.GetWidth(); |
| 543 | uint32_t height = depthBuffer.GetHeight(); |
| 544 | |
| 545 | Tr2GpuResourcePool::Texture packedBuffer; |
| 546 | { |
| 547 | uint32_t mipLevels = 1; |
| 548 | uint32_t res = max( width, height ); |
| 549 | for( ; mipLevels < 8; mipLevels++ ) |
| 550 | { |
| 551 | res /= 2; |
| 552 | if( res < 32 ) |
| 553 | { |
| 554 | break; |
| 555 | } |
| 556 | } |
| 557 | Tr2BitmapDimensions desc( width, height, mipLevels, PixelFormat::PIXEL_FORMAT_R32_FLOAT ); |
| 558 | packedBuffer = gpuResourcePool.GetTempTexture( "cortao_packed", desc, Tr2GpuUsage::UNORDERED_ACCESS | Tr2GpuUsage::SHADER_RESOURCE ); |
| 559 | } |
| 560 | |
| 561 | |
| 562 | if( !m_cortaoConstantBuffer.IsValid() ) |
| 563 | { |
| 564 | CR_RETURN_VAL( m_cortaoConstantBuffer.Create( uint32_t( sizeof( CortaoPerObjectData ) ), renderContext.GetPrimaryRenderContext() ), {} ); |
| 565 | } |
| 566 | |
| 567 | CortaoPerObjectData* data; |
| 568 | CR_RETURN_VAL( m_cortaoConstantBuffer.Lock( (void**)&data, renderContext ), {} ); |
| 569 | { |
| 570 | Matrix viewMatrix = Tr2Renderer::GetViewTransform(); |
| 571 | |
| 572 | Matrix projectionMatrix = Tr2Renderer::GetProjectionTransform(); |
| 573 | Matrix inverseProjectionMatrix = Inverse( projectionMatrix ); |
| 574 | |
| 575 | float nearPlane = Tr2Renderer::GetBackClip(); |
| 576 | float farPlane = Tr2Renderer::GetFrontClip(); |
| 577 | |
| 578 | data->resolution = Vector4( (float)width, (float)height, 1.0f / (float)width, 1.0f / (float)height ); |
| 579 | |
| 580 | data->projectionParams = Vector4( |
| 581 | +0.5f * projectionMatrix._11, |
| 582 | -0.5f * projectionMatrix._22, |
| 583 | -0.5f + projectionMatrix._31 * +0.5f, |
| 584 | -0.5f + projectionMatrix._32 * -0.5f ); |
| 585 | |
| 586 | data->unprojectParams = Vector4( |
| 587 | +2.0f * inverseProjectionMatrix._11, |
| 588 | -2.0f * inverseProjectionMatrix._22, |
| 589 | -inverseProjectionMatrix._11 + inverseProjectionMatrix._41, |
| 590 | +inverseProjectionMatrix._22 - inverseProjectionMatrix._42 ); |
| 591 | |
| 592 | data->depthParams = Vector2( ( nearPlane - farPlane ) / ( nearPlane * farPlane ), 1.0f / nearPlane ); |
| 593 | |
| 594 | data->radius = m_cortaoRadius; |
| 595 | |
| 596 | data->normalBias = inverseProjectionMatrix._11 * sqrtf( 2.0f ) / width; |
| 597 |
nothing calls this directly
no test coverage detected