57 lines
1.3 KiB
HLSL
57 lines
1.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
|
|
|
|
matrix WorldViewProjection;
|
|
float thickness;
|
|
|
|
struct VertexShaderInput
|
|
{
|
|
float4 Position : POSITION0;
|
|
float4 Color : COLOR0;
|
|
float2 Normal : TEXCOORD0;
|
|
};
|
|
|
|
struct VertexShaderOutput
|
|
{
|
|
float4 Position : SV_POSITION;
|
|
float4 Color : COLOR0;
|
|
float2 Normal : TEXCOORD0;
|
|
};
|
|
|
|
VertexShaderOutput MainVS(in VertexShaderInput input)
|
|
{
|
|
VertexShaderOutput output = (VertexShaderOutput)0;
|
|
float4 temp = input.Position + (float4(input.Normal,0.0,0.0) * thickness);
|
|
output.Position = mul(temp, WorldViewProjection);
|
|
output.Color = input.Color;
|
|
output.Normal = input.Normal;
|
|
return output;
|
|
}
|
|
|
|
float4 MainPS(VertexShaderOutput input) : COLOR
|
|
{
|
|
float feather = 0.2; //Fade off part
|
|
float4 res = input.Color;
|
|
float distFromLine = length(input.Normal);
|
|
float alpha = 1.0 - ((clamp(distFromLine, (1.0 - feather),1.0) - (1.0 - feather)) / feather);
|
|
res.a = alpha;
|
|
return res;
|
|
}
|
|
|
|
technique BasicColorDrawing
|
|
{
|
|
pass P0
|
|
{
|
|
AlphaBlendEnable = TRUE;
|
|
DestBlend = INVSRCALPHA;
|
|
SrcBlend = SRCALPHA;
|
|
VertexShader = compile VS_SHADERMODEL MainVS();
|
|
PixelShader = compile PS_SHADERMODEL MainPS();
|
|
}
|
|
}; |