/* * Copyright 2008 (c) muta * * http://unbland.net/ * http://unbland.net/blog/ * * Licensed under the MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ kernel RadialBlur < namespace : "org.unbland"; vendor : "muta"; version : 1; > { parameter float2 center < minValue : float2(1.0, 1.0); maxValue : float2(4096.0, 4096.0); //defaultValue : float2(1.0, 1.0); defaultValue : float2(160.0, 160.0); >; parameter float amount < minValue : float(1.0); maxValue : float(100.0); defaultValue : float(1.0); >; parameter float rotation < minValue : float(-90.0); maxValue : float(90.0); defaultValue : float(0.0); >; input image4 source; output pixel4 result; void evaluatePixel() { float numSamples = 9.0; float base = 4.0; float2 coord = outCoord(); float2 dist = coord - center; float radian = atan(dist.y, dist.x) + radians(rotation); float rate = amount / 200.0 * length(dist) / numSamples; float2 n = float2(cos(radian), sin(radian)); float d; float2 p; float4 c; float4 color = float4(0.0, 0.0, 0.0, 1.0); float w = 0.0; d = (0.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (1.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (2.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (3.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (4.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c * 3.0; w += 3.0; } d = (5.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (6.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (7.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } d = (8.0 - base) * rate; p.x = d * n.x + coord.x; p.y = d * n.y + coord.y; c = sampleNearest(source, p); if (c.a != 0.0) { color += c; w += 1.0; } result = color / w; } }