forked from aly/qstbak
33 lines
778 B
C#
33 lines
778 B
C#
using System;
|
|
using System.Numerics;
|
|
using Auspex.Rendering.Direct3D;
|
|
|
|
namespace Auspex;
|
|
|
|
public readonly struct AxLinearGradient : IPctGradient
|
|
{
|
|
private readonly Vector3 _start;
|
|
|
|
private readonly Vector3 _axis;
|
|
|
|
private readonly float _invLenSq;
|
|
|
|
private readonly Vector4 _colorStart;
|
|
|
|
private readonly Vector4 _colorEnd;
|
|
|
|
public AxLinearGradient(Vector3 start, Vector3 end, uint colorStart, uint colorEnd)
|
|
{
|
|
_start = start;
|
|
_axis = end - start;
|
|
_invLenSq = 1f / Vector3.Dot(_axis, _axis);
|
|
_colorStart = colorStart.ToVector4();
|
|
_colorEnd = colorEnd.ToVector4();
|
|
}
|
|
|
|
public uint ColorAt(Vector3 point)
|
|
{
|
|
float amount = Math.Clamp(Vector3.Dot(point - _start, _axis) * _invLenSq, 0f, 1f);
|
|
return Vector4.Lerp(_colorStart, _colorEnd, amount).ToUint();
|
|
}
|
|
}
|