2007-10-19 17:05:21 +00:00
|
|
|
// Base 2D rendering shader
|
|
|
|
// Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
|
|
|
|
// Pixel input data
|
|
|
|
struct PixelData
|
|
|
|
{
|
|
|
|
float4 pos : POSITION;
|
|
|
|
float2 uv : TEXCOORD0;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Settings
|
|
|
|
// x = texel width
|
|
|
|
// y = texel height
|
|
|
|
// z = blend factor
|
|
|
|
float4 settings;
|
|
|
|
|
|
|
|
// Texture1 input
|
|
|
|
texture texture1
|
|
|
|
<
|
|
|
|
string UIName = "Texture1";
|
|
|
|
string ResourceType = "2D";
|
|
|
|
>;
|
|
|
|
|
|
|
|
// Texture sampler settings
|
|
|
|
sampler2D texture1samp = sampler_state
|
|
|
|
{
|
|
|
|
Texture = <texture1>;
|
2007-10-20 12:34:27 +00:00
|
|
|
MagFilter = Point;
|
|
|
|
MinFilter = Point;
|
|
|
|
MipFilter = Point;
|
2007-10-19 17:05:21 +00:00
|
|
|
AddressU = Wrap;
|
|
|
|
AddressV = Wrap;
|
|
|
|
};
|
|
|
|
|
|
|
|
// This blends the max of 2 pixels
|
|
|
|
float4 addcolor(float4 c1, float4 c2)
|
|
|
|
{
|
|
|
|
return float4(max(c1.r, c2.r),
|
|
|
|
max(c1.g, c2.g),
|
|
|
|
max(c1.b, c2.b),
|
2007-10-20 12:34:27 +00:00
|
|
|
saturate(c1.a + c2.a * 0.5f));
|
2007-10-19 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pixel shader
|
2007-10-21 04:07:36 +00:00
|
|
|
float4 ps_main(PixelData pd) : COLOR
|
2007-10-19 17:05:21 +00:00
|
|
|
{
|
2007-10-20 12:34:27 +00:00
|
|
|
// Take this pixel's color
|
2007-10-19 17:05:21 +00:00
|
|
|
float4 c = tex2D(texture1samp, pd.uv);
|
2007-10-20 12:34:27 +00:00
|
|
|
|
|
|
|
// If this pixel is not drawn on...
|
|
|
|
if(c.a < 0.1f)
|
|
|
|
{
|
|
|
|
// Mix the colors of nearby pixels
|
|
|
|
float4 n = (float4)0;
|
|
|
|
n = addcolor(n, tex2D(texture1samp, float2(pd.uv.x + settings.x, pd.uv.y)));
|
|
|
|
n = addcolor(n, tex2D(texture1samp, float2(pd.uv.x - settings.x, pd.uv.y)));
|
|
|
|
n = addcolor(n, tex2D(texture1samp, float2(pd.uv.x, pd.uv.y + settings.y)));
|
|
|
|
n = addcolor(n, tex2D(texture1samp, float2(pd.uv.x, pd.uv.y - settings.y)));
|
|
|
|
|
|
|
|
// If any pixels nearby where found, return a blend, otherwise return nothing
|
|
|
|
if(n.a > 0.1f) return float4(n.rgb, n.a * settings.z); else return (float4)0;
|
|
|
|
}
|
|
|
|
else return c;
|
2007-10-19 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Technique for shader model 2.0
|
|
|
|
technique SM20
|
|
|
|
{
|
|
|
|
pass p0
|
|
|
|
{
|
|
|
|
VertexShader = null;
|
2007-10-21 04:07:36 +00:00
|
|
|
PixelShader = compile ps_2_0 ps_main();
|
2007-10-19 17:05:21 +00:00
|
|
|
CullMode = None;
|
|
|
|
ZEnable = false;
|
|
|
|
AlphaBlendEnable = true;
|
|
|
|
SrcBlend = SrcAlpha;
|
|
|
|
DestBlend = InvSrcAlpha;
|
|
|
|
}
|
|
|
|
}
|