/***************************************************************************** * * Radial Gradient v1.0 * Last Change: Oct 3 2007 * * 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 radialGradient < nameSpace : "com.quasimondo.hydra.radialGradient"; vendor : "Quasimondo.com"; version : 1; description : "Create Variations of Radial 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 rotation < minValue:float(-1.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 bool mirror; parameter bool linearOrSine; parameter bool threshold; parameter int repeat < minValue:int(1); maxValue:int(100); defaultValue:int(1); >; parameter float smoothThresholdEdges < minValue:float(0.00000001); maxValue:float(0.5); defaultValue:float(0.00000001); >; void evaluatePixel(in image4 src, out pixel4 dst) { float repeatF = float( repeat ); float2 pos = outCoord() - center; float angle = mod( atan( pos.y, pos.x ) / PI2 + 1.0 + rotation / repeatF , 1.0 ); angle = mod( angle, 1.0 / repeatF ) * repeatF; float mirroredAngle = abs( angle - 0.5 ) * 2.0; angle = mirror ? mirroredAngle : angle; float temp = 0.5 * ( 1.0 + cos( (1.0 - angle) * PI ) ); angle = linearOrSine ? angle : temp; temp = ( angle - (0.5 - smoothThresholdEdges) ) / (smoothThresholdEdges * 2.0 ) + (0.5 - smoothThresholdEdges); temp = max( 0.0, min( 1.0, temp )); angle = threshold ? temp : angle; dst = mix( rgba1, rgba2, angle ); } }