92 lines
No EOL
2.3 KiB
HLSL
92 lines
No EOL
2.3 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 shadow;
|
|
int BorderSize;
|
|
float R;
|
|
float G;
|
|
float B;
|
|
|
|
Texture2D SpriteTexture;
|
|
sampler2D SpriteTextureSampler = sampler_state
|
|
{
|
|
Texture = <SpriteTexture>;
|
|
};
|
|
struct VertexShaderOutput
|
|
{
|
|
float4 Color : COLOR0;
|
|
float2 TextureCoordinates : TEXCOORD0;
|
|
};
|
|
|
|
sampler ColorMapSampler = sampler_state
|
|
{
|
|
Texture = <ColorMap>;
|
|
MinFilter = Linear;
|
|
MagFilter = Linear;
|
|
MipFilter = Linear;
|
|
AddressU = Clamp;
|
|
AddressV = Clamp;
|
|
};
|
|
|
|
|
|
float4 MainPS(VertexShaderOutput input) : COLOR
|
|
{
|
|
float4 color = tex2D(ColorMapSampler, input.TextureCoordinates);
|
|
float2 offsetX = float2(TexelSize.x, 0);
|
|
float2 offsetY = { 0, TexelSize.y };
|
|
|
|
float2 offsetd1 = { TexelSize.x, TexelSize.y };
|
|
float2 offsetd2 = { -TexelSize.x, -TexelSize.y };
|
|
float2 offsetd3 = { TexelSize.x, -TexelSize.y };
|
|
float2 offsetd4 = { -TexelSize.x, TexelSize.y };
|
|
|
|
if (color.a == 0)
|
|
{
|
|
for (int i = 1; i < 16; i++)
|
|
{
|
|
if (i<=BorderSize)
|
|
{
|
|
float4 c1 = tex2D(ColorMapSampler, input.TextureCoordinates + offsetX*i);
|
|
float4 c2 = tex2D(ColorMapSampler, input.TextureCoordinates - offsetX*i);
|
|
float4 c3 = tex2D(ColorMapSampler, input.TextureCoordinates + offsetY*i);
|
|
float4 c4 = tex2D(ColorMapSampler, input.TextureCoordinates - offsetY*i);
|
|
|
|
float4 d1 = tex2D(ColorMapSampler, input.TextureCoordinates - offsetd1*i);
|
|
float4 d2 = tex2D(ColorMapSampler, input.TextureCoordinates - offsetd2*i);
|
|
float4 d3 = tex2D(ColorMapSampler, input.TextureCoordinates - offsetd3*i);
|
|
float4 d4 = tex2D(ColorMapSampler, input.TextureCoordinates - offsetd4*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;
|
|
}
|
|
|
|
|
|
return color;
|
|
}
|
|
|
|
technique SpriteDrawing
|
|
{
|
|
pass P0
|
|
{
|
|
PixelShader = compile PS_SHADERMODEL MainPS();
|
|
}
|
|
}; |