/* * This kernel demonstrates the use of additional parameter * metadata which can be read by a SWF at runtime. The "kind" * property suggests usages for each parameter. */ kernel ViewerDemo { output pixel3 dst; parameter float3 backgroundColor; parameter float spotRadius; parameter float3 spotColor; parameter float spotSquare; // This parameter just gets poked with the rendering dimensions, always // Doesn't get shown to user. In my custom viewer, that is. parameter float2 dims; // "point" means it lives somewhere in the image, as a coordinate. parameter float2 lineStart; parameter float2 lineEnd; parameter float lineWidth; void evaluatePixel() { float2 co = outCoord(); float2 center = dims / 2.0; // start by drawing the spot float d = distance(co,center); if(spotSquare != 0.0) d = max(abs(co.x - center.x),abs(co.y - center.y)); if(d < spotRadius) dst = spotColor; else dst = backgroundColor; // draw the two line's two endpoints if(distance(co,lineStart) < lineWidth/3.0 || distance(co,lineEnd) < lineWidth/3.0) dst = float3(0,.4,0); // and now, a bit of fun math, as we plot a line between two points. float2 uv = co - lineStart; float2 xy = lineEnd - lineStart; float xy2 = dot(xy,xy); float g = dot(uv,xy) / xy2; // if we are between the two points, then g is between 0 and 1. float dl = abs(dot(uv,float2(-xy.y,xy.x)) / xy2 * length(xy)); // dl is now the distance, in pixels, from outCoord to the line // if we're between the endpoints and close enough, draw. if(g >= 0.0 && g <= 1.0 && dl < lineWidth / 2.0) dst = float3(1,0,0); } }