/* This kernel divides up an input image by brightness into four ranges. Each range is determined by low, high, and softness. Each range adds to the result, from four other input images. dvb09. */ kernel MixByLevels < namespace : "Your Namespace"; vendor : "Your Vendor"; version : 1; description : "your description"; > { input image4 src; input image4 srcA; input image4 srcB; input image4 srcC; input image4 srcD; output pixel4 dst; parameter float range_1_low; parameter float range_1_high; parameter float range_1_soft; parameter float range_2_low; parameter float range_2_high; parameter float range_2_soft; parameter float range_3_low; parameter float range_3_high; parameter float range_3_soft; parameter float range_4_low; parameter float range_4_high; parameter float range_4_soft; pixel4 ranger(pixel4 noPixel,pixel4 srcPixel,pixel4 samplePixel,float low,float high,float soft) { soft = clamp(soft,0.001,1.0); float intensity = srcPixel.r * .3 + srcPixel.b * .2 + srcPixel.g * .5; float lowMixer = (intensity - low - soft / 2.0) / soft; float highMixer = (high + soft / 2.0 - intensity) / soft; float mixer = clamp(min(lowMixer,highMixer),0.0,1.0); pixel4 result = mix(noPixel,samplePixel,mixer); return result; } void evaluatePixel() { pixel3 x3 = pixel3(0,0,0); pixel4 srcPixel = sampleNearest(src,outCoord()); pixel4 noPixel = pixel4(0,0,0,1); pixel4 samplePixel1 = sampleNearest(srcA,outCoord()); pixel4 samplePixel2 = sampleNearest(srcB,outCoord()); pixel4 samplePixel3 = sampleNearest(srcC,outCoord()); pixel4 samplePixel4 = sampleNearest(srcD,outCoord()); dst = ranger(noPixel,srcPixel,samplePixel1,range_1_low,range_1_high,range_1_soft); dst += ranger(noPixel,srcPixel,samplePixel2,range_2_low,range_2_high,range_2_soft); dst += ranger(noPixel,srcPixel,samplePixel3,range_3_low,range_3_high,range_3_soft); dst += ranger(noPixel,srcPixel,samplePixel4,range_4_low,range_4_high,range_4_soft); } }