General Form of Equation of a Line

Hi! I’m sorry for interupting you, but I need a tiny help…

I wrote a shader, which makes pixels above a line invisible, it discads them:

clip (_a*IN.uv_MainTex.x + _b*IN.uv_MainTex.y + _c);

It works quite well, but the “border line” is not in the right position. It has perfect direction, but the distance is wrong. I try to send three arguments to shader:

renderer.material.SetFloat("_a", direction.x);
renderer.material.SetFloat("_b", direction.y);
renderer.material.SetFloat("_c", -direction.x * destPoint.x - direction.y * destPoint.y);

“direction” is a vector perpendicular to the direction I need, “destPoint” is supposed to be the point the lines goes through… Both have zero z-coordinate…

Please, excuse my terrible English. And have a nice day!
For some reason, this does not work, the direction of the line is good, but it does not go through the point destPoint…

Do you know, what is wrong? I will appriciate any help…

Re: Your PM

The general form for a straight line is y = ax + b (not ax + by + c)
where a is the incline of the line (dir.y / dir.x) and b is the y-intercept [y where x = 0] (LinePoint.y - a * LinePoint.x)
You can then simply discard a pixel if y > ax + b

Your script will read something like:

Vector3 startPos = ....
Vector3 endPos = ...
Vector3 dir = endPos - startPos;
float a = dir.y / dir.x;
float b = startPos.y - a * startPos.x;
//SetFloats a and b

And your shader clip like this:

clip( uv.y > _a * uv.x + b ? 1 : -1 );

Oh! Thanks a lot for explaining, now I understand… I know this form, but I had no idea, that I could possibly use it in do elegant way. Thank you!

Unfortunately, it still doesn’t work, the line has wrong position, but the numbers are set perfectly, so it’s probably fault of my shader, I have to rewrite it and find, what is wrong. But it is really interesting mistake, the line goes through one of quad’s vertices instead of destPoint…
(EDIT: I had no idea, that I need to set up pixel’s world position in the shader, because I’m blind and unconscious, probably. Need to learn more about that…)

Thanks for making me a bit cleverer! Have a nice day…

When i did it, everything was in the 0->1 range, so the quad had verts at 0,0 0,1 1,0 1,1, and the uvs were 0,0 0,1, etc. Normalising everything makes these things easier (not literally)

Well, I’m trying to use this for one repeating sprite, but that seems to be pretty hard. So I’m OK with this quad. Anyway, I do not use vertices, I try to find a different solution, even if it may sound foolish.
I am gonna try to convert _b argument from world to object coordinates, which is a bit tough for me, beacuse shaders are still incredible magic written in really wierd languge… I’m gonna keep studying…
But thank you, you helped me so much with understanding at least a little bit!