// Ok, so the problem is that the width and height of the image should be given as paramaters. // otherwise this won't work correctly. Defaults to an image size 256x256. kernel Polar { parameter bool cartesian_to_polar; parameter float radius < minValue: float(0.0); maxValue: float(256.0); defaultValue: float(128.0); >; parameter float2 center < minValue: float2(0.0, 0.0); maxValue: float2(256.0, 256.0); defaultValue: float2(128.0, 128.0); >; void evaluatePixel(in image4 src, out pixel4 dst) { float2 coord = outCoord(); float2 p = coord-center; // point float d = length(p); // length float w = radius*2.0; // width float h = radius*2.0; // height if(!cartesian_to_polar){ float theta = atan(p.y/p.x); // angle if(coord.x < radius) theta += 3.14; float degrees = degrees(theta) + 90.0; float dx = w - (degrees*w/360.0); float dy = (d*h/radius); coord.x = (dx>=w) ? w-1.0:dx; coord.y = (dy>=h) ? h-1.0:dy; }else{ float polardegrees = 90.0 - (coord.x + w)/w*360.0; float polard = coord.y*radius/h; float polartheta = radians(polardegrees); float polarx = center.x - polard*cos(polartheta); float polary = center.y - polard*sin(polartheta); coord.x = polarx; coord.y = polary; } dst = sampleNearest(src, coord); } }