forked from OpenRA/OpenRA
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsprite.fx
99 lines (82 loc) · 2.11 KB
/
sprite.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
// OpenRA test shader
// Author: C. Forbes
//--------------------------------------------------------
shared texture DiffuseTexture, Palette;
shared float2 Scroll;
shared float2 r1, r2; // matrix elements
sampler s_DiffuseTexture = sampler_state {
Texture = <DiffuseTexture>;
MinFilter = None;
MagFilter = None;
MipFilter = None;
AddressU = Wrap;
AddressV = Wrap;
AddressW = Wrap;
};
sampler s_PaletteTexture = sampler_state {
Texture = <Palette>;
MinFilter = None;
MagFilter = None;
MipFilter = None;
AddressU = Clamp;
AddressV = Clamp;
};
struct VertexIn {
float4 Position: POSITION;
float2 Tex0: TEXCOORD0;
float2 Tex1: TEXCOORD1;
};
struct VertexOut {
float4 Position: POSITION;
float3 Tex0: TEXCOORD0;
float4 ChannelMask: TEXCOORD1;
};
struct FragmentIn {
float3 Tex0: TEXCOORD0;
float4 ChannelMask: TEXCOORD1;
};
float4 DecodeChannelMask( float x )
{
if (x > 0)
return (x > 0.5f) ? float4(1,0,0,0) : float4(0,1,0,0);
else
return (x <-0.5f) ? float4(0,0,0,1) : float4(0,0,1,0);
}
VertexOut Simple_vp(VertexIn v) {
VertexOut o;
float2 p = (v.Position.xy - Scroll.xy) * r1 + r2;
o.Position = float4(p.x,p.y,0,1);
o.Tex0 = float3(v.Tex0.x, v.Tex0.y, v.Tex1.x);
o.ChannelMask = DecodeChannelMask( v.Tex1.y );
return o;
}
const float2 texelOffset = float2( 0, 1.0f/32.0f );
float4 Palette_fp(FragmentIn f) : COLOR0 {
float4 x = tex2D(s_DiffuseTexture, f.Tex0.xy);
float2 p = float2( dot(x, f.ChannelMask), f.Tex0.z );
return tex2D(s_PaletteTexture, p + texelOffset);
}
technique low_quality {
pass p0 {
AlphaBlendEnable = false;
ZWriteEnable = false;
ZEnable = false;
CullMode = None;
FillMode = Solid;
VertexShader = compile vs_2_0 Simple_vp();
PixelShader = compile ps_2_0 Palette_fp();
}
}
technique high_quality {
pass p0 {
AlphaBlendEnable = true;
ZWriteEnable = false;
ZEnable = false;
CullMode = None;
FillMode = Solid;
VertexShader = compile vs_2_0 Simple_vp();
PixelShader = compile ps_2_0 Palette_fp();
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
}
}