home *** CD-ROM | disk | FTP | other *** search
/ Introduction to 3D Game …ogramming with DirectX 12 / Introduction-to-3D-Game-Programming-with-DirectX-12.ISO / Code.Textures / Chapter 23 Character Animation / SkinnedMesh / Ssao.h < prev   
Encoding:
C/C++ Source or Header  |  2016-03-02  |  4.2 KB  |  131 lines

  1. //***************************************************************************************
  2. // Ssao.h by Frank Luna (C) 2015 All Rights Reserved.
  3. //***************************************************************************************
  4.  
  5. #ifndef SSAO_H
  6. #define SSAO_H
  7.  
  8. #pragma once
  9.  
  10. #include "../../Common/d3dUtil.h"
  11. #include "FrameResource.h"
  12.  
  13.  
  14. class Ssao
  15. {
  16. public:
  17.  
  18.     Ssao(ID3D12Device* device, 
  19.         ID3D12GraphicsCommandList* cmdList, 
  20.         UINT width, UINT height);
  21.     Ssao(const Ssao& rhs) = delete;
  22.     Ssao& operator=(const Ssao& rhs) = delete;
  23.     ~Ssao() = default; 
  24.  
  25.     static const DXGI_FORMAT AmbientMapFormat = DXGI_FORMAT_R16_UNORM;
  26.     static const DXGI_FORMAT NormalMapFormat = DXGI_FORMAT_R16G16B16A16_FLOAT;
  27.  
  28.     static const int MaxBlurRadius = 5;
  29.  
  30.     UINT SsaoMapWidth()const;
  31.     UINT SsaoMapHeight()const;
  32.  
  33.     void GetOffsetVectors(DirectX::XMFLOAT4 offsets[14]);
  34.     std::vector<float> CalcGaussWeights(float sigma);
  35.  
  36.  
  37.     ID3D12Resource* NormalMap();
  38.     ID3D12Resource* AmbientMap();
  39.     
  40.     CD3DX12_CPU_DESCRIPTOR_HANDLE NormalMapRtv()const;
  41.     CD3DX12_GPU_DESCRIPTOR_HANDLE NormalMapSrv()const;
  42.     CD3DX12_GPU_DESCRIPTOR_HANDLE AmbientMapSrv()const;
  43.  
  44.     void BuildDescriptors(
  45.         ID3D12Resource* depthStencilBuffer,
  46.         CD3DX12_CPU_DESCRIPTOR_HANDLE hCpuSrv,
  47.         CD3DX12_GPU_DESCRIPTOR_HANDLE hGpuSrv,
  48.         CD3DX12_CPU_DESCRIPTOR_HANDLE hCpuRtv,
  49.         UINT cbvSrvUavDescriptorSize,
  50.         UINT rtvDescriptorSize);
  51.  
  52.     void RebuildDescriptors(ID3D12Resource* depthStencilBuffer);
  53.  
  54.     void SetPSOs(ID3D12PipelineState* ssaoPso, ID3D12PipelineState* ssaoBlurPso);
  55.  
  56.     ///<summary>
  57.     /// Call when the backbuffer is resized.  
  58.     ///</summary>
  59.     void OnResize(UINT newWidth, UINT newHeight);
  60.   
  61.     ///<summary>
  62.     /// Changes the render target to the Ambient render target and draws a fullscreen
  63.     /// quad to kick off the pixel shader to compute the AmbientMap.  We still keep the
  64.     /// main depth buffer binded to the pipeline, but depth buffer read/writes
  65.     /// are disabled, as we do not need the depth buffer computing the Ambient map.
  66.     ///</summary>
  67.     void ComputeSsao(
  68.         ID3D12GraphicsCommandList* cmdList, 
  69.         FrameResource* currFrame, 
  70.         int blurCount);
  71.  
  72.  
  73. private:
  74.  
  75.     ///<summary>
  76.     /// Blurs the ambient map to smooth out the noise caused by only taking a
  77.     /// few random samples per pixel.  We use an edge preserving blur so that 
  78.     /// we do not blur across discontinuities--we want edges to remain edges.
  79.     ///</summary>
  80.     void BlurAmbientMap(ID3D12GraphicsCommandList* cmdList, FrameResource* currFrame, int blurCount);
  81.     void BlurAmbientMap(ID3D12GraphicsCommandList* cmdList, bool horzBlur);
  82.  
  83.     void BuildResources();
  84.     void BuildRandomVectorTexture(ID3D12GraphicsCommandList* cmdList);
  85.  
  86.     void BuildOffsetVectors();
  87.  
  88.  
  89. private:
  90.     ID3D12Device* md3dDevice;
  91.  
  92.     Microsoft::WRL::ComPtr<ID3D12RootSignature> mSsaoRootSig;
  93.     
  94.     ID3D12PipelineState* mSsaoPso = nullptr;
  95.     ID3D12PipelineState* mBlurPso = nullptr;
  96.      
  97.     Microsoft::WRL::ComPtr<ID3D12Resource> mRandomVectorMap;
  98.     Microsoft::WRL::ComPtr<ID3D12Resource> mRandomVectorMapUploadBuffer;
  99.     Microsoft::WRL::ComPtr<ID3D12Resource> mNormalMap;
  100.     Microsoft::WRL::ComPtr<ID3D12Resource> mAmbientMap0;
  101.     Microsoft::WRL::ComPtr<ID3D12Resource> mAmbientMap1;
  102.  
  103.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhNormalMapCpuSrv;
  104.     CD3DX12_GPU_DESCRIPTOR_HANDLE mhNormalMapGpuSrv;
  105.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhNormalMapCpuRtv;
  106.  
  107.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhDepthMapCpuSrv;
  108.     CD3DX12_GPU_DESCRIPTOR_HANDLE mhDepthMapGpuSrv;
  109.  
  110.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhRandomVectorMapCpuSrv;
  111.     CD3DX12_GPU_DESCRIPTOR_HANDLE mhRandomVectorMapGpuSrv;
  112.  
  113.     // Need two for ping-ponging during blur.
  114.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhAmbientMap0CpuSrv;
  115.     CD3DX12_GPU_DESCRIPTOR_HANDLE mhAmbientMap0GpuSrv;
  116.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhAmbientMap0CpuRtv;
  117.  
  118.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhAmbientMap1CpuSrv;
  119.     CD3DX12_GPU_DESCRIPTOR_HANDLE mhAmbientMap1GpuSrv;
  120.     CD3DX12_CPU_DESCRIPTOR_HANDLE mhAmbientMap1CpuRtv;
  121.  
  122.     UINT mRenderTargetWidth;
  123.     UINT mRenderTargetHeight;
  124.  
  125.     DirectX::XMFLOAT4 mOffsets[14];
  126.  
  127.     D3D12_VIEWPORT mViewport;
  128.     D3D12_RECT mScissorRect;
  129. };
  130.  
  131. #endif // SSAO_H