75 lines
No EOL
2.1 KiB
HLSL
75 lines
No EOL
2.1 KiB
HLSL
#if OPENGL
|
|
#define SV_POSITION POSITION
|
|
#define VS_SHADERMODEL vs_3_0
|
|
#define PS_SHADERMODEL ps_3_0
|
|
#else
|
|
#define VS_SHADERMODEL vs_4_0_level_9_1
|
|
#define PS_SHADERMODEL ps_4_0_level_9_1
|
|
#endif
|
|
float2 TexelSize; // should be (1f/textureSize.X, 1f/textureSize.Y)
|
|
int BorderSize;
|
|
float R;
|
|
float G;
|
|
float B;
|
|
|
|
sampler2D SpriteTextureSampler = sampler_state
|
|
{
|
|
Texture = <SpriteTexture>;
|
|
};
|
|
|
|
struct VertexShaderOutput
|
|
{
|
|
float4 Color : COLOR0;
|
|
float2 TextureCoordinates : TEXCOORD0;
|
|
};
|
|
|
|
float4 MainPS(VertexShaderOutput input) : COLOR
|
|
{
|
|
float4 color = tex2D(SpriteTextureSampler, input.TextureCoordinates);
|
|
|
|
if (color.a > 0)
|
|
{
|
|
return color;
|
|
}
|
|
|
|
float2 offsetX = float2(TexelSize.x, 0);
|
|
float2 offsetY = float2( 0, TexelSize.y );
|
|
|
|
for (int i = 1; i < 10; i++)
|
|
{
|
|
if (i<=BorderSize)
|
|
{
|
|
float4 c1 = tex2D(SpriteTextureSampler, input.TextureCoordinates + offsetX*i);
|
|
float4 c2 = tex2D(SpriteTextureSampler, input.TextureCoordinates - offsetX*i);
|
|
float4 c3 = tex2D(SpriteTextureSampler, input.TextureCoordinates + offsetY*i);
|
|
float4 c4 = tex2D(SpriteTextureSampler, input.TextureCoordinates - offsetY*i);
|
|
float4 d1 = tex2D(SpriteTextureSampler, input.TextureCoordinates - (offsetX+offsetY)*i);
|
|
float4 d2 = tex2D(SpriteTextureSampler, input.TextureCoordinates + (offsetX+offsetY)*i);
|
|
float4 d3 = tex2D(SpriteTextureSampler, input.TextureCoordinates - (offsetX-offsetY)*i);
|
|
float4 d4 = tex2D(SpriteTextureSampler, input.TextureCoordinates - (-offsetX+offsetY)*i);
|
|
|
|
if (color.a != c1.a || color.a != c2.a|| color.a != c3.a|| color.a != c4.a
|
|
|| color.a != d1.a
|
|
|| color.a != d2.a
|
|
|| color.a != d3.a
|
|
|| color.a != d4.a
|
|
)
|
|
{
|
|
color.r=R;
|
|
color.g=G;
|
|
color.b=B;
|
|
color.a=1;
|
|
}
|
|
}
|
|
}
|
|
|
|
return color;
|
|
}
|
|
|
|
technique SpriteDrawing
|
|
{
|
|
pass P0
|
|
{
|
|
PixelShader = compile PS_SHADERMODEL MainPS();
|
|
}
|
|
}; |