Im going to post the code for the problem i have i suppose this is purely a math problem.

I decided to make a line drawing algorithm purely on the shader in a function as part of a desire for ways to visualize variables on the shader itself.

Now i made a line drawing function and it works but not quite right to say it more or less draws kind of a ray instead of a line and it artifacts if the line is horizontal.

The reason i believe is how i compare the conditional using the slope from a to b and a to the current pixel which introduces a larger and larger amount of error with distance.

but i really can’t see any other way to do it.

so the question is how do i make a nice even line between two points or how to determine the distance of a point from the line itself not the two points that make up the line or how to conditionally test properly.

```
float4 FuncLineDraw(float2 a, float2 b, float2 pos, float4 col)
{
float2 p = pos;
float2 AtoB = b - a;
float2 BtoA = a - b;
float2 PtoA = a - p;
float2 PtoB = b - p;
float dotPAtoBA = dot(PtoA, BtoA);
float dotPBtoAB = dot(PtoB, AtoB);
// find if the point is between the other two points.
float isWithinPlanes = sign(dotPAtoBA * dotPBtoAB +0.0001f);
// find the slope and compare the slopes a to b and a to p.
float2 slopeAtoB = (b - a).x / (b - a).y;
float2 slopeAtoPos = (p - a).x / (p - a).y;
float diffpositive = abs(slopeAtoB - slopeAtoPos);
//
// here is the problem the <.01 is the conditional but it is a constant.
// however the angle from a or the slope is not constant with distance ?
//
// how to solve this?
//
if (diffpositive < .01f && isWithinPlanes > 0.0f)
{
// color fall off
float distAtoB = distance(b, a);
float distAtoThisPos = distance(p, a);
// plot color falloff though if im in here im on the line or close to it.
col.r = 1.0f * distAtoThisPos / distAtoB;
col.g = 1.0f - col.r;
col.b = 1.0f;
}
return col;
}
```