wow, it works!

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1190 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
chrisf
2007-07-13 09:15:06 +00:00
parent bbbb25909a
commit d37bab15d0
16 changed files with 136 additions and 57 deletions

View File

@@ -2,7 +2,7 @@
// Author: C. Forbes
//--------------------------------------------------------
shared texture DiffuseTexture;
shared texture DiffuseTexture, Palette;
shared float2 Scroll;
shared float2 r1, r2; // matrix elements
@@ -18,32 +18,57 @@ sampler s_DiffuseTexture = sampler_state {
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;
float2 Tex0: TEXCOORD0;
float3 Tex0: TEXCOORD0;
float4 ChannelMask: TEXCOORD1;
};
struct FragmentIn {
float2 Tex0: TEXCOORD0;
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 = v.Tex0;
o.Tex0 = float3(v.Tex0.x, v.Tex0.y, v.Tex1.x);
o.ChannelMask = DecodeChannelMask( v.Tex1.y );
return o;
}
float4 Simple_fp(FragmentIn f) : COLOR0 {
float4 color = tex2D(s_DiffuseTexture, f.Tex0);
return color;
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 {
@@ -53,7 +78,7 @@ technique low_quality {
ZEnable = false;
CullMode = None;
VertexShader = compile vs_2_0 Simple_vp();
PixelShader = compile ps_2_0 Simple_fp();
PixelShader = compile ps_2_0 Palette_fp();
}
}
@@ -64,7 +89,7 @@ technique high_quality {
ZEnable = false;
CullMode = None;
VertexShader = compile vs_2_0 Simple_vp();
PixelShader = compile ps_2_0 Simple_fp();
PixelShader = compile ps_2_0 Palette_fp();
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;