summaryrefslogtreecommitdiffstatshomepage
path: root/hlsl/vector.fx
diff options
context:
space:
mode:
author ImJezze <jezze@gmx.net>2016-06-05 23:50:44 +0200
committer ImJezze <jezze@gmx.net>2016-06-05 23:50:44 +0200
commit6ea15072a718b093e3688d22f7f6954e44e383b6 (patch)
treeb65e08cad8e07f8ce1f5f52f7e2438181cad158b /hlsl/vector.fx
parent396c2a094622e742e96ab3d16a72dfca4e498eaf (diff)
Procedural texture for vectors in HLSL
* added simple procedural texture for vectors with rounded line ends and beam smoothness * added optional -vector_beam_smooth option * removed -antialias option, antialiasing is now always applied, except for plain D3D
Diffstat (limited to 'hlsl/vector.fx')
-rw-r--r--hlsl/vector.fx50
1 files changed, 44 insertions, 6 deletions
diff --git a/hlsl/vector.fx b/hlsl/vector.fx
index 95957d57c80..71d53d030bc 100644
--- a/hlsl/vector.fx
+++ b/hlsl/vector.fx
@@ -1,5 +1,5 @@
// license:BSD-3-Clause
-// copyright-holders:Ryan Holtz
+// copyright-holders:Ryan Holtz,ImJezze
//-----------------------------------------------------------------------------
// Vector Effect
//-----------------------------------------------------------------------------
@@ -13,7 +13,7 @@ struct VS_OUTPUT
float4 Position : POSITION;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
- float2 LineInfo : TEXCOORD1;
+ float2 SizeInfo : TEXCOORD1;
};
struct VS_INPUT
@@ -21,17 +21,27 @@ struct VS_INPUT
float3 Position : POSITION;
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
- float2 LineInfo : TEXCOORD1;
+ float2 SizeInfo : TEXCOORD1;
};
struct PS_INPUT
{
float4 Color : COLOR0;
float2 TexCoord : TEXCOORD0;
- float2 LineInfo : TEXCOORD1; // x is the line length, y is unused
+ float2 SizeInfo : TEXCOORD1;
};
//-----------------------------------------------------------------------------
+// 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;
+}
+
+//-----------------------------------------------------------------------------
// Vector Vertex Shader
//-----------------------------------------------------------------------------
@@ -49,7 +59,7 @@ VS_OUTPUT vs_main(VS_INPUT Input)
Output.Position.xy *= 2.0f; // zoom
Output.TexCoord = Input.TexCoord;
- Output.LineInfo = Input.LineInfo;
+ Output.SizeInfo = Input.SizeInfo;
Output.Color = Input.Color;
@@ -64,10 +74,35 @@ 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
+uniform float BeamSmooth;
+
+float GetRoundCornerFactor(float2 coord, float2 bounds, float radiusAmount, float smoothAmount)
+{
+ // reduce smooth amount down to radius amount
+ smoothAmount = min(smoothAmount, radiusAmount);
+
+ float range = min(bounds.x, bounds.y);
+ float amountMinimum = range > 0.0f ? 1.0f / range : 0.0f;
+ float radius = range * max(radiusAmount, amountMinimum);
+ float smooth = 1.0f / (range * max(smoothAmount, amountMinimum * 3.0f));
+
+ // 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);
+}
float4 ps_main(PS_INPUT Input) : COLOR
{
- float lineLength = Input.LineInfo.x / max(QuadDims.x, QuadDims.y); // normalize
+ float2 lineSize = Input.SizeInfo / max(QuadDims.x, QuadDims.y); // normalize
+
+ float lineLength = lineSize.x;
float lineLengthRatio = LengthRatio;
float lineLengthScale = LengthScale;
@@ -78,6 +113,9 @@ float4 ps_main(PS_INPUT Input) : COLOR
float4 outColor = float4(timeLengthModulate, timeLengthModulate, timeLengthModulate, 1.0f);
outColor *= Input.Color;
+ float RoundCornerFactor = GetRoundCornerFactor(Input.TexCoord - 0.5f, Input.SizeInfo, 1.0f, BeamSmooth);
+ outColor.rgb *= RoundCornerFactor;
+
return outColor;
}