-
Notifications
You must be signed in to change notification settings - Fork 226
/
BokehEffect.h
133 lines (106 loc) · 4.54 KB
/
BokehEffect.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//--------------------------------------------------------------------------------------
// BokehEffect12.h
//
// Demonstrates how to render depth of field using point sprites.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#include "DeviceResources.h"
namespace ATG
{
class BokehEffect
{
public:
struct Parameters
{
// CoC
float focusLength;
float FNumber;
float focalPlane;
// performance
float maxCoCSizeNear;
float maxCoCSizeFar;
float switchover1[2];
float switchover2[2];
// quality
float initialEnergyScale;
bool useFastShader;
};
BokehEffect(ID3D11Device* device);
void ResizeResources(ID3D11Device* device, int width, int height, DXGI_FORMAT format);
void Render(
ID3D11DeviceContextX* context,
ID3D11ShaderResourceView* srcColorSRV,
ID3D11ShaderResourceView* srcDepthSRV,
ID3D11RenderTargetView* dstRTV,
const DirectX::XMMATRIX& matInvProj,
const Parameters& params,
bool useDebugShader);
private:
void CreateDeviceDependentResources(ID3D11Device* device);
void StartRendering(ID3D11DeviceContextX* context, const D3D11_TEXTURE2D_DESC& texDesc, const DirectX::XMMATRIX& matInvProj, const Parameters& params);
void StopRendering(ID3D11DeviceContextX* context);
struct BokehCB
{
float maxCoCDiameterNear;
float focusLength;
float focalPlane;
float FNumber;
float depthBufferSize[2];
float dofTexSize[2];
float srcScreenSize[2];
float maxCoCDiameterFar;
float irisTextureOffset;
float viewports[6][4];
float switchover1[2];
float switchover2[2];
float initialEnergyScale;
float pad[3];
float mInvProj[16];
};
private:
template <typename T>
using ComPtr = Microsoft::WRL::ComPtr<T>;
// weights texture
ComPtr<ID3D11Texture1D> m_energiesTex;
ComPtr<ID3D11ShaderResourceView> m_energiesTexSRV;
ComPtr<ID3D11UnorderedAccessView> m_energiesTexUAV;
ComPtr<ID3D11Texture3D> m_scratchTex;
ComPtr<ID3D11UnorderedAccessView> m_scratchTexUAV;
// the texture that takes front and back blur of the source texture
ComPtr<ID3D11Texture2D> m_DOFColorTexture;
ComPtr<ID3D11RenderTargetView> m_DOFColorTextureRTV;
ComPtr<ID3D11ShaderResourceView> m_DOFColorTextureSRV;
// in focus copy
ComPtr<ID3D11Texture2D> m_sourceColorTextureRGBZCopy;
ComPtr<ID3D11RenderTargetView> m_sourceColorTextureRGBZCopyRTV;
ComPtr<ID3D11ShaderResourceView> m_sourceColorTextureRGBZCopySRV;
ComPtr<ID3D11Texture2D> m_sourceColorTextureRGBZHalfCopy;
ComPtr<ID3D11RenderTargetView> m_sourceColorTextureRGBZHalfCopyRTV;
ComPtr<ID3D11ShaderResourceView> m_sourceColorTextureRGBZHalfCopySRV;
// iris texture
ComPtr<ID3D11ShaderResourceView> m_irisTexSRV;
// constant buffer
ComPtr<ID3D11Buffer> m_bokehCB;
// shaders
ComPtr<ID3D11VertexShader> m_quadPointVS;
ComPtr<ID3D11GeometryShader> m_quadPointGS;
ComPtr<ID3D11GeometryShader> m_quadPointFastGS;
ComPtr<ID3D11PixelShader> m_quadPointPS;
ComPtr<ID3D11VertexShader> m_quadVS;
ComPtr<ID3D11PixelShader> m_recombinePS;
ComPtr<ID3D11PixelShader> m_recombineDebugPS;
ComPtr<ID3D11PixelShader> m_createRGBZPS;
ComPtr<ID3D11PixelShader> m_downsampleRGBZPS;
ComPtr<ID3D11ComputeShader> m_createEnergyTexCS;
ComPtr<ID3D11BlendState> m_pointsBS;
ComPtr<ID3D11SamplerState> m_sampler;
int m_width;
int m_height;
DXGI_FORMAT m_format;
D3D11_VIEWPORT m_vpSplitOutput[6];
D3D11_RECT m_scissorSplitOutput[6];
};
}