88 lines
No EOL
2.8 KiB
HLSL
88 lines
No EOL
2.8 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
|
|
int BorderSize;
|
|
float R;
|
|
float G;
|
|
float B;
|
|
float2 ImageSize;
|
|
|
|
sampler2D SpriteTextureSampler = sampler_state
|
|
{
|
|
Texture = <SpriteTexture>;
|
|
};
|
|
|
|
struct VertexShaderOutput
|
|
{
|
|
float4 Color : COLOR0;
|
|
float2 TextureCoordinates : TEXCOORD0;
|
|
};
|
|
|
|
float4 MainPS(VertexShaderOutput input) : COLOR
|
|
{
|
|
float4 color = tex2Dlod(SpriteTextureSampler, float4(input.TextureCoordinates.x, input.TextureCoordinates.y, 0, 0));
|
|
|
|
if(color.a == 1)
|
|
{
|
|
return color;
|
|
}
|
|
|
|
float2 pixel = (int2)input.TextureCoordinates * ImageSize;
|
|
|
|
float2 offsets[8] = {float2(-1,0), float2(1,0), float2(0,1), float2(0,-1), float2(-1,1), float2(1,1), float2(1,-1), float2(-1,-1)};
|
|
|
|
float2 checkp1 = pixel + (float)BorderSize * offsets[0];
|
|
float2 curUV1 = input.TextureCoordinates + checkp1/(float2)ImageSize;
|
|
float alpha1 = tex2Dlod(SpriteTextureSampler, float4(curUV1.x, curUV1.y,0,0)).a;
|
|
|
|
float2 checkp2 = pixel + (float)BorderSize * offsets[1];
|
|
float2 curUV2 = input.TextureCoordinates + checkp2/(float2)ImageSize;
|
|
float alpha2 = tex2Dlod(SpriteTextureSampler, float4(curUV2.x, curUV2.y,0,0)).a;
|
|
|
|
float2 checkp3 = pixel + (float)BorderSize * offsets[2];
|
|
float2 curUV3 = input.TextureCoordinates + checkp3/(float2)ImageSize;
|
|
float alpha3 = tex2Dlod(SpriteTextureSampler, float4(curUV3.x, curUV3.y,0,0)).a;
|
|
|
|
float2 checkp4 = pixel + (float)BorderSize * offsets[3];
|
|
float2 curUV4 = input.TextureCoordinates + checkp4/(float2)ImageSize;
|
|
float alpha4 = tex2Dlod(SpriteTextureSampler, float4(curUV4.x, curUV4.y,0,0)).a;
|
|
|
|
float2 checkp5 = pixel + (float)BorderSize * offsets[4];
|
|
float2 curUV5 = input.TextureCoordinates + checkp5/(float2)ImageSize;
|
|
float alpha5 = tex2Dlod(SpriteTextureSampler, float4(curUV5.x, curUV5.y,0,0)).a;
|
|
|
|
float2 checkp6 = pixel + (float)BorderSize * offsets[5];
|
|
float2 curUV6 = input.TextureCoordinates + checkp6/(float2)ImageSize;
|
|
float alpha6 = tex2Dlod(SpriteTextureSampler, float4(curUV6.x, curUV6.y,0,0)).a;
|
|
|
|
float2 checkp7 = pixel + (float)BorderSize * offsets[6];
|
|
float2 curUV7 = input.TextureCoordinates + checkp7/(float2)ImageSize;
|
|
float alpha7 = tex2Dlod(SpriteTextureSampler, float4(curUV7.x, curUV7.y,0,0)).a;
|
|
|
|
float2 checkp8 = pixel + (float)BorderSize * offsets[7];
|
|
float2 curUV8 = input.TextureCoordinates + checkp8/(float2)ImageSize;
|
|
float alpha8 = tex2Dlod(SpriteTextureSampler, float4(curUV8.x, curUV8.y,0,0)).a;
|
|
|
|
float alpha = alpha1 + alpha2 + alpha3 + alpha4 + alpha5 + alpha6 + alpha7 + alpha8;
|
|
|
|
if (alpha>0)
|
|
{
|
|
return float4(R,G,B,1);
|
|
}
|
|
|
|
return color;
|
|
|
|
};
|
|
|
|
technique SpriteDrawing
|
|
{
|
|
pass P0
|
|
{
|
|
PixelShader = compile PS_SHADERMODEL MainPS();
|
|
}
|
|
}; |