2015-05-12 09:18:09 +02:00
|
|
|
// license:BSD-3-Clause
|
2016-06-05 23:50:44 +02:00
|
|
|
// copyright-holders:Ryan Holtz,ImJezze
|
2012-12-31 22:29:02 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-31 16:32:35 +01:00
|
|
|
// Vector Effect
|
2012-12-31 22:29:02 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Vertex Definitions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct VS_OUTPUT
|
|
|
|
{
|
|
|
|
float4 Position : POSITION;
|
|
|
|
float4 Color : COLOR0;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
2016-06-05 23:50:44 +02:00
|
|
|
float2 SizeInfo : TEXCOORD1;
|
2012-12-31 22:29:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VS_INPUT
|
|
|
|
{
|
|
|
|
float3 Position : POSITION;
|
|
|
|
float4 Color : COLOR0;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
2016-06-05 23:50:44 +02:00
|
|
|
float2 SizeInfo : TEXCOORD1;
|
2012-12-31 22:29:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PS_INPUT
|
|
|
|
{
|
|
|
|
float4 Color : COLOR0;
|
|
|
|
float2 TexCoord : TEXCOORD0;
|
2016-06-05 23:50:44 +02:00
|
|
|
float2 SizeInfo : TEXCOORD1;
|
2012-12-31 22:29:02 +01:00
|
|
|
};
|
|
|
|
|
2016-06-05 23:50:44 +02:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Functions
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// www.iquilezles.org/www/articles/distfunctions/distfunctions.htm
|
|
|
|
float roundBox(float2 p, float2 b, float r)
|
|
|
|
{
|
|
|
|
return length(max(abs(p) - b + r, 0.0f)) - r;
|
|
|
|
}
|
|
|
|
|
2012-12-31 22:29:02 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-31 16:32:35 +01:00
|
|
|
// Vector Vertex Shader
|
2012-12-31 22:29:02 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2013-08-28 02:36:02 +02:00
|
|
|
uniform float2 ScreenDims;
|
2016-09-28 15:22:38 +02:00
|
|
|
uniform float2 TargetDims;
|
2016-03-12 16:03:28 +01:00
|
|
|
|
2012-12-31 22:29:02 +01:00
|
|
|
VS_OUTPUT vs_main(VS_INPUT Input)
|
|
|
|
{
|
|
|
|
VS_OUTPUT Output = (VS_OUTPUT)0;
|
2015-10-25 11:02:52 +01:00
|
|
|
|
2012-12-31 22:29:02 +01:00
|
|
|
Output.Position = float4(Input.Position.xyz, 1.0f);
|
2013-08-28 02:36:02 +02:00
|
|
|
Output.Position.xy /= ScreenDims;
|
2016-04-13 19:21:57 +02:00
|
|
|
Output.Position.y = 1.0f - Output.Position.y;
|
2015-10-25 11:02:52 +01:00
|
|
|
Output.Position.xy -= 0.5f; // center
|
2016-04-13 19:21:57 +02:00
|
|
|
Output.Position.xy *= 2.0f; // zoom
|
2015-10-25 11:02:52 +01:00
|
|
|
|
2016-03-12 16:03:28 +01:00
|
|
|
Output.TexCoord = Input.TexCoord;
|
2016-06-05 23:50:44 +02:00
|
|
|
Output.SizeInfo = Input.SizeInfo;
|
2015-10-25 11:02:52 +01:00
|
|
|
|
|
|
|
Output.Color = Input.Color;
|
|
|
|
|
2012-12-31 22:29:02 +01:00
|
|
|
return Output;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-31 16:32:35 +01:00
|
|
|
// Vector Pixel Shader
|
2012-12-31 22:29:02 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2016-05-22 14:32:08 +02:00
|
|
|
uniform float TimeRatio; // Frame time of the vector (not set)
|
|
|
|
uniform float TimeScale; // How much frame time affects the vector's fade (not set)
|
|
|
|
uniform float LengthRatio; // Size at which fade is maximum
|
|
|
|
uniform float LengthScale; // How much length affects the vector's fade
|
2016-06-05 23:50:44 +02:00
|
|
|
uniform float BeamSmooth;
|
|
|
|
|
2016-09-28 15:22:38 +02:00
|
|
|
float GetBoundsFactor(float2 coord, float2 bounds, float radiusAmount, float smoothAmount)
|
2016-06-05 23:50:44 +02:00
|
|
|
{
|
|
|
|
// reduce smooth amount down to radius amount
|
|
|
|
smoothAmount = min(smoothAmount, radiusAmount);
|
|
|
|
|
|
|
|
float range = min(bounds.x, bounds.y);
|
2016-06-19 22:23:02 +02:00
|
|
|
float amountMinimum = 1.0f / range;
|
2016-06-05 23:50:44 +02:00
|
|
|
float radius = range * max(radiusAmount, amountMinimum);
|
2016-06-19 22:23:02 +02:00
|
|
|
float smooth = 1.0f / (range * max(smoothAmount, amountMinimum * 2.0f));
|
2016-06-05 23:50:44 +02:00
|
|
|
|
|
|
|
// compute box
|
|
|
|
float box = roundBox(bounds * (coord * 2.0f), bounds, radius);
|
|
|
|
|
|
|
|
// apply smooth
|
|
|
|
box *= smooth;
|
|
|
|
box += 1.0f - pow(smooth * 0.5f, 0.5f);
|
|
|
|
|
|
|
|
float border = smoothstep(1.0f, 0.0f, box);
|
|
|
|
|
|
|
|
return saturate(border);
|
|
|
|
}
|
2016-05-22 14:32:08 +02:00
|
|
|
|
2012-12-31 22:29:02 +01:00
|
|
|
float4 ps_main(PS_INPUT Input) : COLOR
|
|
|
|
{
|
2016-09-28 15:22:38 +02:00
|
|
|
float2 lineSize = Input.SizeInfo / max(TargetDims.x, TargetDims.y); // normalize
|
2016-06-05 23:50:44 +02:00
|
|
|
|
|
|
|
float lineLength = lineSize.x;
|
2016-05-22 14:32:08 +02:00
|
|
|
float lineLengthRatio = LengthRatio;
|
|
|
|
float lineLengthScale = LengthScale;
|
2013-01-21 03:40:48 +01:00
|
|
|
|
2016-05-22 14:32:08 +02:00
|
|
|
float timeModulate = lerp(1.0f, TimeRatio, TimeScale);
|
|
|
|
float lengthModulate = 1.0f - clamp(lineLength / lineLengthRatio, 0.0f, 1.0f);
|
|
|
|
float timeLengthModulate = lerp(1.0f, timeModulate * lengthModulate, LengthScale);
|
2013-01-21 03:40:48 +01:00
|
|
|
|
2016-05-22 14:32:08 +02:00
|
|
|
float4 outColor = float4(timeLengthModulate, timeLengthModulate, timeLengthModulate, 1.0f);
|
2016-03-12 16:03:28 +01:00
|
|
|
outColor *= Input.Color;
|
|
|
|
|
2016-09-28 15:22:38 +02:00
|
|
|
float RoundCornerFactor = GetBoundsFactor(Input.TexCoord - 0.5f, Input.SizeInfo, 1.0f, BeamSmooth);
|
2016-06-05 23:50:44 +02:00
|
|
|
outColor.rgb *= RoundCornerFactor;
|
|
|
|
|
2013-01-21 03:40:48 +01:00
|
|
|
return outColor;
|
2012-12-31 22:29:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-31 16:32:35 +01:00
|
|
|
// Vector Technique
|
2012-12-31 22:29:02 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-12-31 16:32:35 +01:00
|
|
|
technique DefaultTechnique
|
2012-12-31 22:29:02 +01:00
|
|
|
{
|
|
|
|
pass Pass0
|
|
|
|
{
|
|
|
|
Lighting = FALSE;
|
|
|
|
|
|
|
|
VertexShader = compile vs_2_0 vs_main();
|
2016-03-12 16:03:28 +01:00
|
|
|
PixelShader = compile ps_2_0 ps_main();
|
2012-12-31 22:29:02 +01:00
|
|
|
}
|
|
|
|
}
|