-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdxgi.fx
executable file
·386 lines (322 loc) · 13.4 KB
/
dxgi.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
/**
* Copyright (C) 2011 Jorge Jimenez ([email protected])
* Copyright (C) 2011 Belen Masia ([email protected])
* Copyright (C) 2011 Jose I. Echevarria ([email protected])
* Copyright (C) 2011 Fernando Navarro ([email protected])
* Copyright (C) 2011 Diego Gutierrez ([email protected])
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the following disclaimer
* in the documentation and/or other materials provided with the
* distribution:
*
* "Uses SMAA. Copyright (C) 2011 by Jorge Jimenez, Jose I. Echevarria,
* Belen Masia, Fernando Navarro and Diego Gutierrez."
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
* IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are
* those of the authors and should not be interpreted as representing official
* policies, either expressed or implied, of the copyright holders.
*/
//Include SweetFX settings
#include "SweetFX_preset.txt"
/**
* Setup mandatory defines. Use a real macro here for maximum performance!
*/
#ifndef SMAA_PIXEL_SIZE // It's actually set on runtime, this is for compilation time syntax checking.
#define SMAA_PIXEL_SIZE float2(1.0 / 1280.0, 1.0 / 720.0)
#endif
/**
* This is only required for temporal modes (SMAA T2x).
*/
int4 subsampleIndices;
/*
#define SMAA_PRESET_CUSTOM
#ifdef SMAA_PRESET_CUSTOM
#define SMAA_THRESHOLD threshld
#define SMAA_MAX_SEARCH_STEPS maxSearchSteps
#define SMAA_MAX_SEARCH_STEPS_DIAG maxSearchStepsDiag
#define SMAA_CORNER_ROUNDING cornerRounding
#define SMAA_FORCE_DIAGONAL_DETECTION 1
#define SMAA_FORCE_CORNER_DETECTION 1
#endif
*/
// Set the HLSL version:
#ifndef SMAA_HLSL_4_1
#define SMAA_HLSL_4 1
#endif
/*
#ifdef SMAA_PRESET_CUSTOM
#include "SMAA_settings.h" //include custom settings
#endif
*/
// And include our header!
#include "SweetFX\Shaders\SMAA.h"
// Set pixel shader version accordingly:
#if SMAA_HLSL_4_1 == 1
#define PS_VERSION ps_4_1
#else
#define PS_VERSION ps_4_0
#endif
/**
* DepthStencilState's and company
*/
DepthStencilState DisableDepthStencil {
DepthEnable = FALSE;
StencilEnable = FALSE;
};
DepthStencilState DisableDepthReplaceStencil {
DepthEnable = FALSE;
StencilEnable = TRUE;
FrontFaceStencilPass = REPLACE;
};
DepthStencilState DisableDepthUseStencil {
DepthEnable = FALSE;
StencilEnable = TRUE;
FrontFaceStencilFunc = EQUAL;
};
BlendState NoBlending {
AlphaToCoverageEnable = FALSE;
BlendEnable[0] = FALSE;
};
/**
* Input textures
*/
Texture2D colorTexPrev;
Texture2D colorTex;
Texture2D colorTexGamma;
Texture2D depthTex;
Texture2D velocityTex;
/**
* Temporal textures
*/
Texture2D edgesTex;
Texture2D blendTex;
/**
* Pre-computed area and search textures
*/
Texture2D areaTex;
Texture2D searchTex;
#include "SweetFX/Shaders/Main.h"
/**
* Function wrappers
*/
void DX10_SMAAEdgeDetectionVS(float4 position : POSITION,
out float4 svPosition : SV_POSITION,
inout float2 texcoord : TEXCOORD0,
out float4 offset[3] : TEXCOORD1) {
SMAAEdgeDetectionVS(position, svPosition, texcoord, offset);
}
void DX10_SMAABlendWeightCalculationVS(float4 position : POSITION,
out float4 svPosition : SV_POSITION,
inout float2 texcoord : TEXCOORD0,
out float2 pixcoord : TEXCOORD1,
out float4 offset[3] : TEXCOORD2) {
SMAABlendWeightCalculationVS(position, svPosition, texcoord, pixcoord, offset);
}
void DX10_SMAANeighborhoodBlendingVS(float4 position : POSITION,
out float4 svPosition : SV_POSITION,
inout float2 texcoord : TEXCOORD0,
out float4 offset[2] : TEXCOORD1) {
SMAANeighborhoodBlendingVS(position, svPosition, texcoord, offset);
}
void DX10_SMAAResolveVS(float4 position : POSITION,
out float4 svPosition : SV_POSITION,
inout float2 texcoord : TEXCOORD0) {
SMAAResolveVS(position, svPosition, texcoord);
}
[earlydepthstencil]
float4 DX10_SMAALumaEdgeDetectionPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1,
uniform SMAATexture2D colorTexGamma) : SV_TARGET {
#if SMAA_PREDICATION == 1
return SMAALumaEdgeDetectionPS(texcoord, offset, colorTexGamma, depthTex);
#else
return SMAALumaEdgeDetectionPS(texcoord, offset, colorTexGamma);
#endif
}
[earlydepthstencil]
float4 DX10_SMAAColorEdgeDetectionPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1,
uniform SMAATexture2D colorTexGamma) : SV_TARGET {
#if SMAA_PREDICATION == 1
return SMAAColorEdgeDetectionPS(texcoord, offset, colorTexGamma, depthTex);
#else
return SMAAColorEdgeDetectionPS(texcoord, offset, colorTexGamma);
#endif
}
[earlydepthstencil]
float4 DX10_SMAADepthEdgeDetectionPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1,
uniform SMAATexture2D depthTex) : SV_TARGET {
return SMAADepthEdgeDetectionPS(texcoord, offset, depthTex);
}
[earlydepthstencil]
float4 DX10_SMAABlendingWeightCalculationPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float2 pixcoord : TEXCOORD1,
float4 offset[3] : TEXCOORD2,
uniform SMAATexture2D edgesTex,
uniform SMAATexture2D areaTex,
uniform SMAATexture2D searchTex) : SV_TARGET {
return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesTex, areaTex, searchTex, subsampleIndices);
}
[earlydepthstencil]
float4 DX10_SMAANeighborhoodBlendingPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[2] : TEXCOORD1,
uniform SMAATexture2D colorTex,
uniform SMAATexture2D blendTex) : SV_TARGET {
float4 SMAAoutput = SMAANeighborhoodBlendingPS(texcoord, offset, colorTex, blendTex);
SMAAoutput = SweetFX_main(texcoord,SMAAoutput); // Add the other effects
return SMAAoutput; //Returning the pixel
}
[earlydepthstencil]
float4 DX10_SMAAResolvePS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
uniform SMAATexture2D colorTex,
uniform SMAATexture2D colorTexPrev,
uniform SMAATexture2D velocityTex) : SV_TARGET {
#if SMAA_REPROJECTION == 1
return SMAAResolvePS(texcoord, colorTex, colorTexPrev, velocityTex);
#else
return SMAAResolvePS(texcoord, colorTex, colorTexPrev);
#endif
}
#if (USE_SMAA_ANTIALIASING == 1)
/**
* Edge detection techniques
*/
technique10 LumaEdgeDetection {
pass LumaEdgeDetection {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAAEdgeDetectionVS()));
SetGeometryShader(NULL);
#if COLOR_EDGE_DETECTION == 1
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAAColorEdgeDetectionPS(colorTexGamma)));
#else
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAALumaEdgeDetectionPS(colorTexGamma)));
#endif
SetDepthStencilState(DisableDepthReplaceStencil, 1);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
technique10 ColorEdgeDetection {
pass ColorEdgeDetection {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAAEdgeDetectionVS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAAColorEdgeDetectionPS(colorTexGamma)));
SetDepthStencilState(DisableDepthReplaceStencil, 1);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
technique10 DepthEdgeDetection {
pass DepthEdgeDetection {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAAEdgeDetectionVS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAADepthEdgeDetectionPS(depthTex)));
SetDepthStencilState(DisableDepthReplaceStencil, 1);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
/**
* Blending weight calculation technique
*/
technique10 BlendingWeightCalculation {
pass BlendingWeightCalculation {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAABlendWeightCalculationVS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAABlendingWeightCalculationPS(edgesTex, areaTex, searchTex)));
SetDepthStencilState(DisableDepthUseStencil, 1);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
/**
* Neighborhood blending technique
*/
technique10 NeighborhoodBlending {
pass NeighborhoodBlending {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAANeighborhoodBlendingVS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAANeighborhoodBlendingPS(colorTex, blendTex)));
SetDepthStencilState(DisableDepthStencil, 0);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
/**
* Temporal resolve technique
*/
technique10 Resolve {
pass Resolve {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAAResolveVS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(PS_VERSION, DX10_SMAAResolvePS(colorTex, colorTexPrev, velocityTex)));
SetDepthStencilState(DisableDepthStencil, 0);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
#else //SMAA off
/*------------------------.
| :: SweetFX - structs :: |
'------------------------*/
struct Output
{
float4 position_cs : SV_POSITION;
float2 texcoord : TEXCOORD;
};
/*---------------------------------------.
| :: SweetFX - SMAA_off vertex shader :: |
'---------------------------------------*/
Output DX10_SMAA_off_VS(uint id: SV_VertexID) {
Output output;
output.texcoord = float2((id << 1) & 2, id & 2);
output.position_cs = float4(output.texcoord * float2(2, -2) + float2(-1, 1), 0, 1);
return output;
}
/*--------------------------------------.
| :: SweetFX - SMAA_off pixel shader :: |
'--------------------------------------*/
[earlydepthstencil]
float4 main(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
/*float4 offset[2] : TEXCOORD1,*/
uniform SMAATexture2D colorTexGamma) : SV_TARGET {
float4 SMAAoutput = myTex2D(colorTexGamma, texcoord);
SMAAoutput = SweetFX_main(texcoord,SMAAoutput); // Add the other effects
return SMAAoutput; //Returning the pixel
}
/*--------------------------.
| :: SweetFX - Technique :: |
'--------------------------*/
/**
* SMAA_off technique
*/
technique10 LumaEdgeDetection {
pass LumaEdgeDetection {
SetVertexShader(CompileShader(vs_4_0, DX10_SMAA_off_VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(PS_VERSION, main(colorTexGamma)));
SetDepthStencilState(DisableDepthStencil, 0); //SetDepthStencilState(DisableDepthReplaceStencil, 1);
SetBlendState(NoBlending, float4(0.0f, 0.0f, 0.0f, 0.0f), 0xFFFFFFFF);
}
}
#endif