-
Notifications
You must be signed in to change notification settings - Fork 0
/
butterfly.fx
117 lines (95 loc) · 2.32 KB
/
butterfly.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
extern const texture TextureDiffuse;
extern const texture TextureDepthShadow;
extern const float4x4 World;
extern const float4x4 View;
extern const float4x4 Projection;
extern const float4x4 LightViewProj;
extern const float Angle;
extern const int ShadowTexSize;
sampler SamplerDiffuse = sampler_state
{
Texture = TextureDiffuse;
MinFilter = ANISOTROPIC;
MagFilter = LINEAR;
MipFilter = POINT;
AddressU = WRAP;
AddressV = WRAP;
};
sampler SamplerDepthShadow = sampler_state
{
Texture = TextureDepthShadow;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = NONE;
AddressU = BORDER;
AddressV = BORDER;
BorderColor = 0xFFFFFFFF;
};
struct VsInput
{
float4 Position : POSITION;
float2 Texcoord : TEXCOORD;
};
struct VsOutput
{
float4 Position : POSITION0;
float4 ShadowPos : POSITION1;
float2 Texcoord : TEXCOORD;
};
struct PsInput
{
float4 ShadowPos : POSITION1;
float2 Texcoord : TEXCOORD;
};
static const float texelSize = 1.0 / ShadowTexSize;
static const float2 filterKernel[4] =
{
float2(0 * texelSize, 0 * texelSize),
float2(1 * texelSize, 0 * texelSize),
float2(0 * texelSize, 1 * texelSize),
float2(1 * texelSize, 1 * texelSize)
};
VsOutput Vshader(VsInput In)
{
VsOutput Out = (VsOutput)0;
float4 ModelPosition = In.Position;
float y = cos(Angle);
float x = abs(sin(Angle));
ModelPosition.y = abs(ModelPosition.x) * y;
ModelPosition.x = ModelPosition.x * x;
float4 WorldPosition = mul(World, ModelPosition);
float4 ViewPosition = mul(View, WorldPosition);
Out.Position = mul(Projection, ViewPosition);
Out.ShadowPos = mul(LightViewProj, WorldPosition);
Out.Texcoord = In.Texcoord;
return Out;
}
float4 Pshader(PsInput In) : COLOR
{
float2 shadeUV = {
In.ShadowPos.x / In.ShadowPos.w * 0.5 + 0.5,
-In.ShadowPos.y / In.ShadowPos.w * 0.5 + 0.5
};
float pointDepth = (In.ShadowPos.z / In.ShadowPos.w) - 0.0025;
float shade = 0.0;
for (int i = 0; i < 4; i++)
{
float shadow = step(pointDepth, tex2D(SamplerDepthShadow, shadeUV + filterKernel[i]).r);
shade += shadow * 0.25;
}
float4 color = tex2D(SamplerDiffuse, In.Texcoord).grga;
color.rgb *= (0.5 * shade + 0.5);
return color;
}
technique Normal
{
pass Pass0
{
CullMode = None;
AlphaTestEnable = True;
AlphaFunc = Greater;
AlphaRef = 128;
VertexShader = compile vs_3_0 Vshader();
PixelShader = compile ps_3_0 Pshader();
}
}