-
Notifications
You must be signed in to change notification settings - Fork 1
/
d3d9.fx
340 lines (288 loc) · 11.6 KB
/
d3d9.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
/**
* Copyright (C) 2011 Jorge Jimenez (jorge@iryoku.com)
* Copyright (C) 2011 Belen Masia (bmasia@unizar.es)
* Copyright (C) 2011 Jose I. Echevarria (joseignacioechevarria@gmail.com)
* Copyright (C) 2011 Fernando Navarro (fernandn@microsoft.com)
* Copyright (C) 2011 Diego Gutierrez (diegog@unizar.es)
* 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_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 can be ignored; its purpose is to support interactive custom parameter
* tweaking.
*/
/*
float threshold;
float maxSearchSteps;
float maxSearchStepsDiag;
*/
/*
#ifdef SMAA_PRESET_CUSTOM
#define SMAA_THRESHOLD threshold
#define SMAA_MAX_SEARCH_STEPS maxSearchSteps
#define SMAA_MAX_SEARCH_STEPS_DIAG maxSearchStepsDiag
#define SMAA_FORCE_DIAGONALS 1
#endif
*/
// Set the HLSL version:
#define SMAA_HLSL_3 1
// And include our header!
#include "SweetFX\Shaders\SMAA.h"
/**
* Input vars and textures.
*/
texture2D colorTex2D;
/*texture2D depthTex2D;*/
texture2D edgesTex2D;
texture2D blendTex2D;
texture2D areaTex2D;
texture2D searchTex2D;
/**
* DX9 samplers.
*/
sampler2D colorTex {
Texture = <colorTex2D>;
AddressU = Clamp; AddressV = Clamp;
MipFilter = Point; MinFilter = Linear; MagFilter = Linear;
SRGBTexture = true;
};
sampler2D colorTexG {
Texture = <colorTex2D>;
AddressU = Clamp; AddressV = Clamp;
MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
SRGBTexture = false;
};
/*
sampler2D depthTex {
Texture = <depthTex2D>;
AddressU = Clamp; AddressV = Clamp;
MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
SRGBTexture = false;
};
*/
sampler2D edgesTex {
Texture = <edgesTex2D>;
AddressU = Clamp; AddressV = Clamp;
MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
SRGBTexture = false;
};
sampler2D blendTex {
Texture = <blendTex2D>;
AddressU = Clamp; AddressV = Clamp;
MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
SRGBTexture = false;
};
sampler2D areaTex {
Texture = <areaTex2D>;
AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
MipFilter = Linear; MinFilter = Linear; MagFilter = Linear;
SRGBTexture = false;
};
sampler2D searchTex {
Texture = <searchTex2D>;
AddressU = Clamp; AddressV = Clamp; AddressW = Clamp;
MipFilter = Point; MinFilter = Point; MagFilter = Point;
SRGBTexture = false;
};
#include "SweetFX/Shaders/Main.h"
/**
* Function wrappers
*/
void DX9_SMAAEdgeDetectionVS(inout float4 position : POSITION,
inout float2 texcoord : TEXCOORD0,
out float4 offset[3] : TEXCOORD1) {
SMAAEdgeDetectionVS(position, position, texcoord, offset);
}
void DX9_SMAABlendWeightCalculationVS(inout float4 position : POSITION,
inout float2 texcoord : TEXCOORD0,
out float2 pixcoord : TEXCOORD1,
out float4 offset[3] : TEXCOORD2) {
SMAABlendWeightCalculationVS(position, position, texcoord, pixcoord, offset);
}
void DX9_SMAANeighborhoodBlendingVS(inout float4 position : POSITION,
inout float2 texcoord : TEXCOORD0,
out float4 offset[2] : TEXCOORD1) {
SMAANeighborhoodBlendingVS(position, position, texcoord, offset);
}
float4 DX9_SMAALumaEdgeDetectionPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1,
uniform SMAATexture2D colorGammaTex) : COLOR {
return SMAALumaEdgeDetectionPS(texcoord, offset, colorGammaTex);
}
float4 DX9_SMAAColorEdgeDetectionPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1,
uniform SMAATexture2D colorGammaTex) : COLOR {
return SMAAColorEdgeDetectionPS(texcoord, offset, colorGammaTex);
}
float4 DX9_SMAADepthEdgeDetectionPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[3] : TEXCOORD1,
uniform SMAATexture2D depthTex) : COLOR {
return SMAADepthEdgeDetectionPS(texcoord, offset, depthTex);
}
float4 DX9_SMAABlendingWeightCalculationPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float2 pixcoord : TEXCOORD1,
float4 offset[3] : TEXCOORD2,
uniform SMAATexture2D edgesTex,
uniform SMAATexture2D areaTex,
uniform SMAATexture2D searchTex) : COLOR {
return SMAABlendingWeightCalculationPS(texcoord, pixcoord, offset, edgesTex, areaTex, searchTex, 0);
}
float4 DX9_SMAANeighborhoodBlendingPS(float4 position : SV_POSITION,
float2 texcoord : TEXCOORD0,
float4 offset[2] : TEXCOORD1,
uniform SMAATexture2D colorTex,
uniform SMAATexture2D blendTex) : COLOR {
float4 SMAAoutput = SMAANeighborhoodBlendingPS(texcoord, offset, colorTex, blendTex);
SMAAoutput = main(texcoord,SMAAoutput); // Add the other effects
return SMAAoutput; //Returning the pixel
}
/*-----------------------------------------------------------.
/ SweetFX - SMAA_off function /
'-----------------------------------------------------------*/
/**
* SMAA off Vertex Shader
*/
void SMAA_off_VS(float4 position,
out float4 svPosition,
inout float2 texcoord){
svPosition = position;
}
void DX9_SMAA_off_VS(inout float4 position : POSITION,
inout float2 texcoord : TEXCOORD0) {
//SMAA_off_VS(position, position, texcoord);
}
float4 DX9_SMAA_off_PS( float2 texcoord : TEXCOORD0) : COLOR {
float4 SMAAoutput = tex2D(s0, texcoord);
SMAAoutput = main(texcoord,SMAAoutput); // Add the other effects
return SMAAoutput; //Returning the pixel
}
/*----------------------------------------------------------*/
#if (USE_SMAA_ANTIALIASING == 1)
/**
* Time for some techniques!
*/
technique LumaEdgeDetection { // Pass 1A
pass LumaEdgeDetection {
VertexShader = compile vs_3_0 DX9_SMAAEdgeDetectionVS();
#if COLOR_EDGE_DETECTION == 1
PixelShader = compile ps_3_0 DX9_SMAAColorEdgeDetectionPS(colorTexG);
#else
PixelShader = compile ps_3_0 DX9_SMAALumaEdgeDetectionPS(colorTexG);
#endif
ZEnable = false;
SRGBWriteEnable = false;
AlphaBlendEnable = false;
// We will be creating the stencil buffer for later usage.
StencilEnable = true;
StencilPass = REPLACE;
StencilRef = 1;
}
}
/*
technique ColorEdgeDetection { // Pass 1B
pass ColorEdgeDetection {
VertexShader = compile vs_3_0 DX9_SMAAEdgeDetectionVS();
PixelShader = compile ps_3_0 DX9_SMAAColorEdgeDetectionPS(colorTexG);
ZEnable = false;
SRGBWriteEnable = false;
AlphaBlendEnable = false;
// We will be creating the stencil buffer for later usage.
StencilEnable = true;
StencilPass = REPLACE;
StencilRef = 1;
}
}
*/
/*
technique DepthEdgeDetection { // Pass 1C
pass DepthEdgeDetection {
VertexShader = compile vs_3_0 DX9_SMAAEdgeDetectionVS();
PixelShader = compile ps_3_0 DX9_SMAADepthEdgeDetectionPS(depthTex);
ZEnable = false;
SRGBWriteEnable = false;
AlphaBlendEnable = false;
// We will be creating the stencil buffer for later usage.
StencilEnable = true;
StencilPass = REPLACE;
StencilRef = 1;
}
}
*/
technique BlendWeightCalculation { // Pass 2
pass BlendWeightCalculation {
VertexShader = compile vs_3_0 DX9_SMAABlendWeightCalculationVS();
PixelShader = compile ps_3_0 DX9_SMAABlendingWeightCalculationPS(edgesTex, areaTex, searchTex);
ZEnable = false;
SRGBWriteEnable = false;
AlphaBlendEnable = false;
// Here we want to process only marked pixels.
StencilEnable = true;
StencilPass = KEEP;
StencilFunc = EQUAL;
StencilRef = 1;
}
}
technique NeighborhoodBlending { // Pass 3
pass NeighborhoodBlending {
VertexShader = compile vs_3_0 DX9_SMAANeighborhoodBlendingVS();
PixelShader = compile ps_3_0 DX9_SMAANeighborhoodBlendingPS(colorTex, blendTex);
ZEnable = false;
SRGBWriteEnable = false;
AlphaBlendEnable = false;
// Here we want to process all the pixels.
StencilEnable = false;
}
}
#else
// if SMAA is off
technique SMAA_off { // Not doing SMAA.
pass SMAA_off {
VertexShader = compile vs_3_0 DX9_SMAA_off_VS();
PixelShader = compile ps_3_0 DX9_SMAA_off_PS(); //Use this with GPU Shaderanalyzer
ZEnable = false;
SRGBWriteEnable = false;
AlphaBlendEnable = false;
// Here we want to process all the pixels.
StencilEnable = false;
}
}
#endif