-
Notifications
You must be signed in to change notification settings - Fork 1
/
DropShadow_Stage.fx
243 lines (195 loc) · 7.62 KB
/
DropShadow_Stage.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
//Edited to work with stage by KH40 (https://github.com/KH40-khoast40/DropShadow_Stage)
//色
float3 DropColor
<
string UIName = "DropColor";
string UIWidget = "Color";
bool UIVisible = true;
> = float3(1,0.8,0);
///
float3 WorldPos : CONTROLOBJECT < string name = "(self)";>;
float Scale : CONTROLOBJECT < string name = "(self)";>;
float Alpha : CONTROLOBJECT < string name = "(self)";string item = "Tr";>;
static float TexLoop = Scale*0.1;
static float GauseParam = (1-Alpha)*10;
//パターンテクスチャ
texture2D BackTex <
string ResourceName = "Tex.png";
>;
sampler BackSamp = sampler_state {
texture = <BackTex>;
AddressU = WRAP;
AddressV = WRAP;
Filter = LINEAR;
};
texture DropShadowRT: OFFSCREENRENDERTARGET <
string Description = "Uncheck the stage here";
float4 ClearColor = { 0, 0, 0, 0 };
float ClearDepth = 1.0;
string Format = "D3DFMT_A8R8G8B8" ;
bool AntiAlias = true;
string DefaultEffect =
"DropShadow.x = hide";
>;
sampler DropMap = sampler_state {
texture = <DropShadowRT>;
AddressU = CLAMP;
AddressV = CLAMP;
Filter = LINEAR;
};
////////////////////////////////////////////////////////////////////////////////////////////////
// ぼかし処理の重み係数:
// ガウス関数 exp( -x^2/(2*d^2) ) を d=5, x=0~7 について計算したのち、
// (WT_7 + WT_6 + … + WT_1 + WT_0 + WT_1 + … + WT_7) が 1 になるように正規化したもの
#define WT_0 0.0920246
#define WT_1 0.0902024
#define WT_2 0.0849494
#define WT_3 0.0768654
#define WT_4 0.0668236
#define WT_5 0.0558158
#define WT_6 0.0447932
#define WT_7 0.0345379
// スクリーンサイズ
float2 ViewportSize : VIEWPORTPIXELSIZE;
static float2 ViewportOffset = (float2(0.5,0.5)/ViewportSize);
static float2 SampStep = (float2(GauseParam,GauseParam)/ViewportSize);
// レンダリングターゲットのクリア値
float4 ClearColor = {0,0,0,0};
float ClearDepth = 1.0;
// オリジナルの描画結果を記録するためのレンダーターゲット
texture2D ScnMap : RENDERCOLORTARGET <
float2 ViewPortRatio = {1.0,1.0};
int MipLevels = 1;
string Format = "A8R8G8B8" ;
>;
sampler2D ScnSamp = sampler_state {
texture = <ScnMap>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
texture2D DepthBuffer : RENDERDEPTHSTENCILTARGET <
float2 ViewPortRatio = {1.0,1.0};
string Format = "D24S8";
>;
// X方向のぼかし結果を記録するためのレンダーターゲット
texture2D ScnMap2 : RENDERCOLORTARGET <
float2 ViewPortRatio = {1.0,1.0};
int MipLevels = 1;
string Format = "A8R8G8B8" ;
>;
sampler2D ScnSamp2 = sampler_state {
texture = <ScnMap2>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = CLAMP;
AddressV = CLAMP;
};
////////////////////////////////////////////////////////////////////////////////////////////////
// X方向ぼかし
struct VS_OUTPUT {
float4 Pos : POSITION;
float2 Tex : TEXCOORD0;
float2 Tex2 : TEXCOORD1;
float2 TexScene : TEXCOORD2;
};
VS_OUTPUT VS_passX( float4 Pos : POSITION, float4 Tex : TEXCOORD0 ) {
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = Pos;
Out.Pos.zw = 1;
WorldPos.x *= -1;
Tex.xy += WorldPos.xy*0.01;
Tex.xy += float2(-0.5,-0.5);
Tex.xy *= 1+WorldPos.z*0.01;
Tex.xy -= float2(-0.5,-0.5);
Out.Tex = Tex + float2(0, ViewportOffset.y);
return Out;
}
float4 PS_passX( float2 Tex: TEXCOORD0 ) : COLOR {
float4 Color;
Color = WT_0 * tex2D( DropMap, Tex );
Color += WT_1 * ( tex2D( DropMap, Tex+float2(SampStep.x ,0) ) + tex2D( DropMap, Tex-float2(SampStep.x ,0) ) );
Color += WT_2 * ( tex2D( DropMap, Tex+float2(SampStep.x*2,0) ) + tex2D( DropMap, Tex-float2(SampStep.x*2,0) ) );
Color += WT_3 * ( tex2D( DropMap, Tex+float2(SampStep.x*3,0) ) + tex2D( DropMap, Tex-float2(SampStep.x*3,0) ) );
Color += WT_4 * ( tex2D( DropMap, Tex+float2(SampStep.x*4,0) ) + tex2D( DropMap, Tex-float2(SampStep.x*4,0) ) );
Color += WT_5 * ( tex2D( DropMap, Tex+float2(SampStep.x*5,0) ) + tex2D( DropMap, Tex-float2(SampStep.x*5,0) ) );
Color += WT_6 * ( tex2D( DropMap, Tex+float2(SampStep.x*6,0) ) + tex2D( DropMap, Tex-float2(SampStep.x*6,0) ) );
Color += WT_7 * ( tex2D( DropMap, Tex+float2(SampStep.x*7,0) ) + tex2D( DropMap, Tex-float2(SampStep.x*7,0) ) );
return Color;
}
////////////////////////////////////////////////////////////////////////////////////////////////
// Y方向ぼかし
VS_OUTPUT VS_passY( float4 Pos : POSITION, float4 Tex : TEXCOORD0 ){
VS_OUTPUT Out = (VS_OUTPUT)0;
Out.Pos = Pos;
Out.Pos.zw = 1;
WorldPos.x *= -1;
Out.TexScene = Tex + ViewportOffset;
Tex.xy += WorldPos.xy*0.01;
Tex.xy += float2(-0.5,-0.5);
Tex.xy *= 1+WorldPos.z*0.01;
Tex.xy -= float2(-0.5,-0.5);
Out.Tex = Tex + float2(ViewportOffset.x, 0);
Out.Tex2 = Tex;
return Out;
}
float4 PS_passY(float2 Tex: TEXCOORD0,float2 Tex2: TEXCOORD1,float2 TexScene: TEXCOORD2) : COLOR
{
float4 Color;
Color = WT_0 * tex2D( ScnSamp2, Tex );
Color += WT_1 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y ) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y ) ) );
Color += WT_2 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y*2) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y*2) ) );
Color += WT_3 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y*3) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y*3) ) );
Color += WT_4 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y*4) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y*4) ) );
Color += WT_5 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y*5) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y*5) ) );
Color += WT_6 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y*6) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y*6) ) );
Color += WT_7 * ( tex2D( ScnSamp2, Tex+float2(0,SampStep.y*7) ) + tex2D( ScnSamp2, Tex-float2(0,SampStep.y*7) ) );
Tex2 *= normalize(ViewportSize);
float4 Drop = tex2D(BackSamp,Tex2*TexLoop);
Drop.rgb *= DropColor;
float4 Scene = tex2D(ScnSamp,TexScene);
float Mask = tex2D(DropMap,TexScene).a;
Color = lerp(Scene,Drop,Color.a);
Scene = lerp(Color,Scene,Mask);
return Scene;
}
////////////////////////////////////////////////////////////////////////////////////////////////
float Script : STANDARDSGLOBAL <
string ScriptOutput = "color";
string ScriptClass = "scene";
string ScriptOrder = "postprocess";
> = 0.8;
technique DropShadow <
string Script =
"RenderColorTarget0=ScnMap;"
"RenderDepthStencilTarget=DepthBuffer;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"ScriptExternal=Color;"
"RenderColorTarget0=ScnMap2;"
"RenderDepthStencilTarget=DepthBuffer;"
"ClearSetColor=ClearColor;"
"ClearSetDepth=ClearDepth;"
"Clear=Color;"
"Clear=Depth;"
"Pass=Gaussian_X;"
"RenderColorTarget0=;"
"RenderDepthStencilTarget=;"
"Pass=Gaussian_Y;"
;
> {
pass Gaussian_X < string Script= "Draw=Buffer;"; > {
VertexShader = compile vs_2_0 VS_passX();
PixelShader = compile ps_2_0 PS_passX();
}
pass Gaussian_Y < string Script= "Draw=Buffer;"; > {
VertexShader = compile vs_2_0 VS_passY();
PixelShader = compile ps_2_0 PS_passY();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////