-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathf2nd.fx
385 lines (329 loc) · 10.4 KB
/
f2nd.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
//----------------------------------------------------------------------------------------------------------------//
// Project Diva F2nd //
// by manashiku //
//----------------------------------------------------------------------------------------------------------------//
float2 viewportSize : VIEWPORTPIXELSIZE;
static float2 viewportOffset = (float2(0.5, 0.5) / viewportSize);
static float2 sampleStep = (float2(1.0, 1.0) / viewportSize);
static float2 blurOffset = (float2(2.0, 2.0) / (viewportSize)) * 2;
float4 clearColor = { 0.5, 0.5, 0.5, 1.0 };
float clearDepth = 1.0;
float script : STANDARDSGLOBAL <
string ScriptOutput = "color";
string ScriptClass = "scene";
string ScriptOrder = "postprocess";
> = 0.8;
#include <material/controllerSliders.fxh>
//----------------------------------------------------------------------------------------------------------------//
// textures :
texture2D baseView : RENDERCOLORTARGET;
texture depthBuffer : RENDERDEPTHSTENCILTARGET;
texture2D blurDownView : RENDERCOLORTARGET;
texture2D blurXView : RENDERCOLORTARGET /*<float2 ViewportRatio = {1.0/4.0, 1.0/4.0};>*/;
texture2D blurYView : RENDERCOLORTARGET /*<float2 ViewportRatio = {1.0/4.0, 1.0/4.0};>*/;
//texture2D blurX2View : RENDERCOLORTARGET /*<float2 ViewportRatio = {1.0/4.0, 1.0/4.0};>*/;
//texture2D blurY2View : RENDERCOLORTARGET /*<float2 ViewportRatio = {1.0/4.0, 1.0/4.0};>*/;
texture2D mixView : RENDERCOLORTARGET;
texture2D finalView : RENDERCOLORTARGET;
texture mainShader : OFFSCREENRENDERTARGET <
string Description = "Main shader for the pdf2nd shader. Think of it like a material tab, change between the main shader and the nose shader etc";
float4 ClearColor = { 0.5, 0.5, 0.5, 1.0 };
float ClearDepth = 1.0;
bool AntiAlias = true;
string DefaultEffect =
"self=hide;"
"Controller.pmx=hide;" // hide the controller mesh from being displayed in this render
"*=material/main.fx;";
>;
texture glowShader : OFFSCREENRENDERTARGET <
string Description = "Glow tab, default effect is off and to turn on the glowing you'll need to change to the other sub effect";
float4 ClearColor = { 0.0, 0.0, 0.0, 1.0 };
float ClearDepth = 1.0;
bool AntiAlias = true;
float2 ViewportRatio = {1.0/4.0, 1.0/4.0};
string DefaultEffect =
"self=hide;"
"Controller.pmx=hide;" // hide the controller mesh from being displayed in this render
"*=material/glowOFF.fx;";
>;
//----------------------------------------------------------------------------------------------------------------//
// samplers :
sampler mainSampler = sampler_state
{
texture = <mainShader>;
FILTER = NONE;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
sampler glowSampler = sampler_state
{
texture = <glowShader>;
FILTER = LINEAR;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
sampler blurDownSampler = sampler_state
{
texture = <blurDownView>;
FILTER = LINEAR;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
sampler blurXSampler = sampler_state
{
texture = <blurXView>;
FILTER = LINEAR;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
sampler blurYSampler = sampler_state
{
texture = <blurYView>;
FILTER = LINEAR;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
//sampler blurX2Sampler = sampler_state
//{
// texture = <blurXView>;
// FILTER = LINEAR;
// ADDRESSU = CLAMP;
// ADDRESSV = CLAMP;
//};
//sampler blurY2Sampler = sampler_state
//{
// texture = <blurYView>;
// FILTER = LINEAR;
// ADDRESSU = CLAMP;
// ADDRESSV = CLAMP;
//};
sampler mixSampler = sampler_state
{
texture = <mixView>;
FILTER = NONE;
ADDRESSU = CLAMP;
ADDRESSV = CLAMP;
};
//----------------------------------------------------------------------------------------------------------------//
// functions :
static const float2 kernelX[13] =
{
{ -6, 0 },
{ -5, 0 },
{ -4, 0 },
{ -3, 0 },
{ -2, 0 },
{ -1, 0 },
{ 0, 0 },
{ 1, 0 },
{ 2, 0 },
{ 3, 0 },
{ 4, 0 },
{ 5, 0 },
{ 6, 0 },
};
static const float2 kernelY[13] =
{
{ 0, -6 },
{ 0, -5 },
{ 0, -4 },
{ 0, -3 },
{ 0, -2 },
{ 0, -1 },
{ 0, 0 },
{ 0, 1 },
{ 0, 2 },
{ 0, 3 },
{ 0, 4 },
{ 0, 5 },
{ 0, 6 },
};
static const float blurWeight[13] =
{
0.002216,
0.008764,
0.026995,
0.064759,
0.120985,
0.176033,
0.199471,
0.176033,
0.120985,
0.064759,
0.026995,
0.008764,
0.002216,
};
//float4 blurImage(float2 uv, float2 offset, bool blurDirection, sampler2D tex)
//{
// offset = (blurDirection) ? float2(offset.x, 0) : float2(0, offset.y);
// float4 sum = tex2D(tex, uv) * blurWeight[0];
// [unroll]
// for (int i = 1; i < 8; i++)
// {
// float3 color = tex2D(tex, uv + offset * i).rgb + tex2D(tex, uv - offset * i).rgb;
// sum.rgb = sum.rgb + color * blurWeight[i];
// }
// return sum;
//}
float4 blurImage(sampler texSampler, float2 uv, float2 offset, float2 kernel[13])
{
float4 color = 0;
float2 offset_new = (float2(2.0, 2.0) / offset);
// sampler = texture
// uv = uv
// offset = viewportSize
[unroll]
for (int p = 0; p < 13; p++)
{
color += tex2D(texSampler, uv + (kernel[p] / offset_new)) * blurWeight[p];
}
return color;
}
//----------------------------------------------------------------------------------------------------------------//
// structures :
struct vs_out
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
};
struct blur_out
{
float4 pos : POSITION;
float2 uv : TEXCOORD0;
float2 offset : TEXCOORD1;
};
//----------------------------------------------------------------------------------------------------------------//
// vertex shaders :
vs_out vs_0(float4 pos : POSITION, float2 uv : TEXCOORD0)
{
vs_out o;
o.pos = pos;
o.uv = uv + viewportOffset;
return o;
}
blur_out vs_blur(float4 pos : POSITION, float2 uv : TEXCOORD0)
{
blur_out o;
o.pos = pos;
o.uv = uv + viewportOffset; // * level
o.offset = sampleStep; // * level
return o; // in the pixel shaders ill do the * level
}
//----------------------------------------------------------------------------------------------------------------//
// pixel shaders :
float4 ps_downscale(blur_out i) : COLOR
{
return tex2D(glowSampler, i.uv );
}
float4 ps_blurX(blur_out i) : COLOR
{
return blurImage(glowSampler, i.uv * 4, sampleStep * 4, kernelX);
}
float4 ps_blurY(blur_out i) : COLOR
{
return blurImage(blurXSampler, i.uv , sampleStep , kernelY);
}
//float4 ps_blurX2(blur_out i) : COLOR
//{
// return blurImage(blurYSampler, i.uv, sampleStep , kernelX);
//}
//float4 ps_blurY2(blur_out i) : COLOR
//{
// return blurImage(blurX2Sampler, i.uv, sampleStep , kernelY);
//}
float4 ps_mix(vs_out i) : COLOR
{
// aliases
float2 uv = i.uv;
// sample needed textures
float4 main = tex2D(mainSampler, uv);
// process color
// gamma control
gammaUp = gammaUp == 0 ? 1 : 1.0 + gammaUp;
gammaDown = gammaUp == 0 ? 0 : gammaDown;
float gammaSlider = gammaUp - gammaDown;
if (gammaSlider == 0)
{
gammaSlider = 0.01;
}
main.rgb = pow(main.rgb, (1.0 / gammaSlider));
// greyscale
float grey = dot(main.rgb, float3(0.2126, 0.7152, 0.0722));
main.rgb = lerp(main.rgb, grey.rrr, saturation);
float3 glowColor = saturate(tex2D(blurYSampler, uv * 0.25 + sampleStep * 0.5) + (tex2D(glowSampler, uv) * 0.5));
glowUp = glowUp == 0 ? 1 : 1.0 + glowUp;
glowDown = glowDown == 0 ? 0 : glowDown;
float glowSlider = glowUp - glowDown;
glowColor *= glowSlider;
main.rgb += glowColor;
return main;
}
float4 ps_final(vs_out i) : COLOR
{
return tex2D(mixSampler, i.uv);
}
//----------------------------------------------------------------------------------------------------------------//
technique post_test <
string Script =
"RenderColorTarget0=finalView;"
"RenderDepthStencilTarget=depthBuffer;"
"ClearSetColor=clearColor;"
"ClearSetDepth=clearDepth;"
"Clear=Color;"
"Clear=Depth;"
"ScriptExternal=Color;"
// blur shit
"RenderColorTarget=blurDownView;"
"Pass=drawDownBlur;"
"RenderColorTarget=blurXView;"
"Pass=drawXBlur;"
"RenderColorTarget=blurYView;"
"Pass=drawYBlur;"
// not sure yet if i really want to do 4 blur passes or just the 2
// render mixed view
"RenderColorTarget=mixView;"
"Pass=drawMix;"
//final pass
"RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"ClearSetColor=clearColor;"
"ClearSetDepth=clearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Pass=drawFinal;"
;>
{
pass drawDownBlur <string Script = "Draw=Buffer;";>
{
AlphaBlendEnable = FALSE; AlphaTestEnable = FALSE;
VertexShader = compile vs_3_0 vs_0();
PixelShader = compile ps_3_0 ps_downscale();
}
pass drawXBlur <string Script = "Draw=Buffer;";>
{
AlphaBlendEnable = FALSE;
AlphaTestEnable = FALSE;
VertexShader = compile vs_3_0 vs_0();
PixelShader = compile ps_3_0 ps_blurX();
}
pass drawYBlur <string Script = "Draw=Buffer;";>
{
AlphaBlendEnable = FALSE;
AlphaTestEnable = FALSE;
VertexShader = compile vs_3_0 vs_0();
PixelShader = compile ps_3_0 ps_blurY();
}
pass drawMix <string Script = "Draw=Buffer;";>
{
ALPHABLENDENABLE = FALSE;
VertexShader = compile vs_3_0 vs_0();
PixelShader = compile ps_3_0 ps_mix();
}
pass drawFinal <string Script = "Draw=Buffer;";>
{
ALPHABLENDENABLE = FALSE;
VertexShader = compile vs_3_0 vs_0();
PixelShader = compile ps_3_0 ps_final();
}
}