//added language version /***************************************************************************** * * Author: Joa Ebert * http://blog.je2050.de * Contact: j -at- je2050.de * * This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License * http://creativecommons.org/licenses/by-sa/3.0/ *****************************************************************************/ kernel Spherize < nameSpace: "popforge::ImageProcessing"; vendor: "Joa Ebert"; version: 1; //added namespace metadata namespace: "added by AIF QE"; description: "Applies spherical displacement map to an image."; > { parameter float refractionIndex < minValue: 0.0; maxValue: 1.0; defaultValue: 0.30; aeDisplayName: "Refraction index"; description: "Refraction index of the sphere."; >; parameter float radius < minValue: 1.0; maxValue: 2880.0; defaultValue: 100.0; aeDisplayName: "Radius"; description: "Radius of the sphere."; >; parameter float2 center < minValue: float2(0.0); maxValue: float2(2880.0); defaultValue: float2(120.0, 120.0); aeDisplayName: "Center"; description: "Center of the sphere."; >; //converted from old-style hyrda to pbk input image4 source; output pixel4 result; void evaluatePixel(/*in image4 source, out pixel4 result*/) { float2 coord = outCoord(); float2 dist = coord - center; float radius2 = radius * radius; float r2 = dist.x * dist.x + dist.y * dist.y; //maybe there is a function for this? remember its not |dist| // check if we actually want to displace or not if ( r2 > 0.0 && r2 < radius2 ) { // distance from radius float z2 = radius2 - r2; float z = sqrt(z2); // refraction float xa = asin( dist.x / sqrt( dist.x * dist.x + z2 ) ); float xb = xa - xa * refractionIndex; float ya = asin( dist.y / sqrt( dist.y * dist.y + z2 ) ); float yb = ya - ya * refractionIndex; // displace by refraction coord.x -= z * tan( xb ); coord.y -= z * tan( yb ); } // sample with interpolation result = sampleLinear(source,coord); } }