Re: More fun with Kernel language.
Subject : Re: More fun with Kernel language.
From: Steve Israelson <email@hidden >
Date: Tue, 27 Sep 2005 07:45:42 -0700
Delivered-to: email@hidden
Delivered-to: email@hidden
Here is what I use to draw a line: (my math sucks too:) )
To anti-alias this, pass the results through a gaussian blur filter
before rendering.
I am basically doing what you are doing :)
Though I am making a full paint program....
/*
Draws a rounded line from p1 - p2 of thickness, size
*/
kernel vec4 drawLine(vec2 p1, vec2 p2, float size, __color inColor)
{
vec2 p3 = destCoord();
float u, d0,d1,d2, w = 1.0/size;
u = (p3.x - p1.x) * (p2.x - p1.x) + (p3.y - p1.y) * (p2.y - p1.y);
float dist;
dist = distance(p1, p2);
u = u / (dist*dist);
vec2 r;
r = p1 + u*(p2 - p1);
d0 = distance(r, p3);
d0 = 1.0 - clamp(d0 * w, 0.0, 1.0);
d0 = u < 0.0 ? 0.0 : d0;
d0 = u > 1.0 ? 0.0 : d0;
d1 = 1.0 - clamp(distance(p1, p3) * w, 0.0, 1.0);
d2 = 1.0 - clamp(distance(p2, p3) * w, 0.0, 1.0);
d0 = max(d0, max(d1,d2));
d0 = 1.0 - step(d0, 0.0); // 1.0 = inside, 0 = outside
vec4 color;
color.r = d0 * inColor.r;
color.g = d0 * inColor.g;
color.b = d0 * inColor.b;
color.a = d0 * inColor.a;
return color;
}
On 26-Sep-05, at 5:49 PM, John C. Randolph wrote:
Everyone,
As another step on my road to generating regular polygons in a
CoreImage kernel, I hunted up some code on the net to compute the
distance from a point to a line, and I now have the following kernel:
kernel vec4 drawLine(sampler image, float thickness, float Ax,
float Ay, float Bx, float By)
I'm finding that my math skills were far rustier than I realized,
so if anyone would care to take a pass at optimizing this code, I'm
all ears. ;-) Also, I'd like to anti-alias the result. If anyone
could offer a suggestion of how to do so, I'd certainly appreciate it.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/email@hidden
This email sent to email@hidden
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.