/***************************************************************************** * * Spiral Gradient v2.0 * Last Change: Apr 26 2008 * * Author: Mario Klingemann * http://www.quasimondo.com * Contact: mario@quasimondo.com * * * This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License * http://creativecommons.org/licenses/by-sa/3.0/ * *****************************************************************************/ kernel spiralGradient < nameSpace : "com.quasimondo.filters.spiralGradient"; vendor : "Quasimondo.com"; version : 2; description : "Create Variations of Spiral Gradients"; > { const float PI = 3.14159265; const float PI2 = 6.2831854; parameter float2 center < minValue:float2(0.0,0.0); maxValue:float2(2048.0,2048.0); defaultValue:float2(128.0,128.0); >; parameter float scale < minValue:float(1.0); maxValue:float(100.0); defaultValue:float(10.0); >; parameter float offset < minValue:float(0.0); maxValue:float(1.0); defaultValue:float(0.0); >; parameter float rotation < minValue:float(0.0); maxValue:float(1.0); defaultValue:float(0.0); >; parameter float4 rgba1 < minValue:float4(0.0,0.0,0.0,0.0); maxValue:float4(1.0,1.0,1.0,1.0); defaultValue:float4(0.0,0.0,0.0,1.0); >; parameter float4 rgba2 < minValue:float4(0.0,0.0,0.0,0.0); maxValue:float4(1.0,1.0,1.0,1.0); defaultValue:float4(1.0,1.0,1.0,1.0); >; parameter int mirror < minValue:int(0); maxValue:int(1); defaultValue:int(0); >; parameter int linearOrSine < minValue:int(0); maxValue:int(1); defaultValue:int(0); >; parameter int threshold < minValue:int(0); maxValue:int(1); defaultValue:int(1); >; parameter int repeat1 < minValue:int(1); maxValue:int(100); defaultValue:int(1); >; parameter int repeat2 < minValue:int(1); maxValue:int(100); defaultValue:int(1); >; parameter float smoothThresholdEdges < minValue:float(0.00000001); maxValue:float(0.5); defaultValue:float(0.00000001); >; input image4 src; output float4 dst; void evaluatePixel() { float repeat1F = float( repeat1 ); float repeat2F = float( repeat2 ); float2 pos = (outCoord() - center) * 0.001 * scale; float factor1 = mod( mod( length ( pos ), 1.0 ) + 1.0 + offset / repeat1F, 1.0 ); float factor2 = mod( atan( pos.y, pos.x ) / PI2 + 1.0 + rotation / repeat2F , 1.0 ); factor1 = mod( factor1, 1.0 / repeat1F ) * repeat1F; factor2 = mod( factor2, 1.0 / repeat2F ) * repeat2F; float factor = mod( factor1 + factor2 ,1.0); float mirrored = abs( factor - 0.5 ) * 2.0; factor = mirror == 1 ? mirrored : factor; float temp = 0.5 * ( 1.0 + cos( (1.0 - factor) * PI ) ); factor = linearOrSine == 1 ? factor : temp; temp = ( factor - (0.5 - smoothThresholdEdges) ) / (smoothThresholdEdges * 2.0 ) + (0.5 - smoothThresholdEdges); temp = max( 0.0, min( 1.0, temp )); factor = threshold == 1? temp : factor; dst = mix( rgba1, rgba2, factor ); } }