-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathenbdepthoffield.fx
277 lines (231 loc) · 6.14 KB
/
enbdepthoffield.fx
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*
Magic ENB
*/
#include "enb_include/Common.hlsl"
#include "enb_include/Macros.hlsl"
//======//
//Macros//
//======//
// Use color + depth for edge detection if 1
#define SMAA_FX_USE_PREDICATION 1
//========//
//Uniforms//
//========//
float4 DofParameters;
float uSMAA_Threshold <
string UIName = "<SMAA> Threshold";
string UIWidget = "spinner";
float UIMin = 0.0;
float UIMax = 0.5;
> = 0.1;
int uSMAA_MaxSearchSteps <
string UIName = "<SMAA> Max Search Steps";
string UIWidget = "spinner";
int UIMin = 0;
int UIMax = 112;
> = 16;
int uSMAA_MaxDiagonalSearchSteps <
string UIName = "<SMAA> Max Diagonal Search Steps";
string UIWidget = "spinner";
int UIMin = 0;
int UIMax = 20;
> = 8;
int uSMAA_CornerRounding <
string UIName = "<SMAA> Corner Rounding";
string UIWidget = "spinner";
int UIMin = 0;
int UIMax = 100;
> = 25;
//========//
//Textures//
//========//
Texture2D TextureCurrent;
Texture2D TexturePrevious;
Texture2D TextureOriginal;
Texture2D TextureColor;
Texture2D TextureDepth;
Texture2D TextureFocus;
Texture2D TextureAperture;
Texture2D TextureAdaptation;
Texture2D RenderTargetRGBA32;
Texture2D RenderTargetRGBA64;
Texture2D RenderTargetRGBA64F;
Texture2D RenderTargetR16F;
Texture2D RenderTargetR32F;
Texture2D RenderTargetRGB32F;
//======//
//States//
//======//
DepthStencilState DisableDepthStencil {
DepthEnable = FALSE;
StencilEnable = FALSE;
};
DepthStencilState DisableDepthReplaceStencil {
DepthEnable = FALSE;
StencilEnable = TRUE;
FrontFaceStencilPass = REPLACE;
};
DepthStencilState DisableDepthUseStencil {
DepthEnable = FALSE;
StencilEnable = TRUE;
FrontFaceStencilFunc = EQUAL;
};
BlendState Blend {
AlphaToCoverageEnable = FALSE;
BlendEnable[0] = TRUE;
SrcBlend = BLEND_FACTOR;
DestBlend = INV_BLEND_FACTOR;
BlendOp = ADD;
};
BlendState NoBlending {
AlphaToCoverageEnable = FALSE;
BlendEnable[0] = FALSE;
};
//==========//
//SMAA Setup//
//==========//
#define SMAA_RT_METRICS float4(uPixelSize, uResolution)
#define SMAA_HLSL_4_1
#define SMAA_PRESET_CUSTOM
#define SMAA_THRESHOLD uSMAA_Threshold
#define SMAA_MAX_SEARCH_STEPS uSMAA_MaxSearchSteps
#define SMAA_MAX_SEARCH_STEPS_DIAG uSMAA_MaxDiagonalSearchSteps
#define SMAA_CORNER_ROUNDING uSMAA_CornerRounding
#define SMAA_PREDICATION SMAA_FX_USE_PREDICATION
Texture2D tArea <string ResourceName = "enb_textures/AreaTex.dds";>;
Texture2D tSearch <string ResourceName = "enb_textures/SearchTex.dds";>;
//#define tEdges RenderTargetRGB32F
#define tBlend RenderTargetRGBA64F
#include "enb_include/SMAA.hlsl"
//=======//
//Shaders//
//=======//
void VS_SMAA_EdgeDetection(
float3 vertex : POSITION,
out float4 position : SV_POSITION,
inout float2 uv : TEXCOORD0,
out float4 offset[3] : TEXCOORD1
) {
position = float4(vertex, 1.0);
SMAAEdgeDetectionVS(uv, offset);
}
float4 PS_SMAA_EdgeDetection(
float4 position : SV_POSITION,
float2 uv : TEXCOORD0,
float4 offset[3] : TEXCOORD1
) : SV_TARGET {
#if SMAA_FX_USE_PREDICATION
float2 ret = SMAAColorEdgeDetectionPS(uv, offset, TextureOriginal, TextureDepth);
#else
float2 ret = SMAAColorEdgeDetectionPS(uv, offset, TextureOriginal);
#endif
return float4(ret, 0.0, 1.0);
}
void VS_SMAA_BlendingWeightCalculation(
float3 vertex : POSITION,
out float4 position : SV_POSITION,
inout float2 uv : TEXCOORD0,
out float2 pix_uv : TEXCOORD1,
out float4 offset[3] : TEXCOORD2
) {
position = float4(vertex, 1.0);
SMAABlendingWeightCalculationVS(uv, pix_uv, offset);
}
float4 PS_SMAA_BlendingWeightCalculation(
float4 position : SV_POSITION,
float2 uv : TEXCOORD0,
float2 pix_uv : TEXCOORD1,
float4 offset[3] : TEXCOORD2
) : SV_TARGET {
return SMAABlendingWeightCalculationPS(
uv,
pix_uv,
offset,
TextureColor, // last pass/edges tex
tArea,
tSearch,
0.0
);
}
void VS_SMAA_NeighborhoodBlending(
float3 vertex : POSITION,
out float4 position : SV_POSITION,
inout float2 uv : TEXCOORD0,
out float4 offset : TEXCOORD1
) {
position = float4(vertex, 1.0);
SMAANeighborhoodBlendingVS(uv, offset);
}
float4 PS_SMAA_NeighborhoodBlending(
float4 position : SV_POSITION,
float2 uv : TEXCOORD0,
float4 offset : TEXCOORD1
) : SV_TARGET {
return SMAANeighborhoodBlendingPS(uv, offset, TextureOriginal, tBlend);
}
float4 PS_Aperture(
float4 position : SV_POSITION,
float2 uv : TEXCOORD
) : SV_TARGET {
return float4(0.0, 0.0, 0.0, 1.0);
}
float4 PS_ReadFocus(
float4 position : SV_POSITION,
float2 uv : TEXCOORD
) : SV_TARGET {
return float4(0.0, 0.0, 0.0, 1.0);
}
float4 PS_Focus(
float4 position : SV_POSITION,
float2 uv : TEXCOORD
) : SV_TARGET {
return float4(0.0, 0.0, 0.0, 1.0);
}
//==========//
//Techniques//
//==========//
// SMAA Edge Detection
technique11 Magic <string UIName = "Magic";> {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_SMAA_EdgeDetection()));
SetPixelShader(CompileShader(ps_5_0, PS_SMAA_EdgeDetection()));
SetDepthStencilState(DisableDepthReplaceStencil, 1);
SetBlendState(NoBlending, float4(0.0, 0.0, 0.0, 0.0), 0xFFFFFFFF);
}
}
// SMAA Blending Weight Calculation
technique11 Magic1 <string RenderTarget = TOSTRING(tBlend);> {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_SMAA_BlendingWeightCalculation()));
SetPixelShader(CompileShader(ps_5_0, PS_SMAA_BlendingWeightCalculation()));
SetDepthStencilState(DisableDepthUseStencil, 1);
SetBlendState(NoBlending, float4(0.0, 0.0, 0.0, 0.0), 0xFFFFFFFF);
}
}
// SMAA Neighborhood Blending
technique11 Magic2 {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_SMAA_NeighborhoodBlending()));
SetPixelShader(CompileShader(ps_5_0, PS_SMAA_NeighborhoodBlending()));
SetDepthStencilState(DisableDepthStencil, 0);
SetBlendState(NoBlending, float4(0.0, 0.0, 0.0, 0.0), 0xFFFFFFFF);
}
}
technique11 Aperture {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_PostProcess()));
SetPixelShader(CompileShader(ps_5_0, PS_Aperture()));
}
}
technique11 ReadFocus {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_PostProcess()));
SetPixelShader(CompileShader(ps_5_0, PS_ReadFocus()));
}
}
technique11 Focus {
pass {
SetVertexShader(CompileShader(vs_5_0, VS_PostProcess()));
SetPixelShader(CompileShader(ps_5_0, PS_Focus()));
}
}