/***************************************************************************** * * Circular 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 circularGradient < nameSpace : "com.quasimondo.hydra.circularGradient"; vendor : "Quasimondo.com"; version : 1; description : "Create Variations of Circular Gradients"; > { const float PI = 3.14159265; parameter float2 center < minValue:float2(0.0,0.0); maxValue:float2(2048.0,2048.0); defaultValue:float2(128.0,128.0); >; parameter float size < minValue:float(0.0); maxValue:float(2048.0); defaultValue:float(10.0); >; parameter float offset < 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 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 factor = mod( mod( length ( pos ) / size, 1.0 ) + 1.0 + offset / repeatF, 1.0 ); factor = mod( factor, 1.0 / repeatF ) * repeatF; float mirrored = abs( factor - 0.5 ) * 2.0; factor = mirror ? mirrored : factor; float temp = 0.5 * ( 1.0 + cos( (1.0 - factor) * PI ) ); factor = linearOrSine ? factor : temp; temp = ( factor - (0.5 - smoothThresholdEdges) ) / (smoothThresholdEdges * 2.0 ) + (0.5 - smoothThresholdEdges); temp = max( 0.0, min( 1.0, temp )); factor = threshold ? temp : factor; dst = mix( rgba1, rgba2, factor ); } }