kernel DisplacementMapFader < namespace : "sk.yoz"; vendor : "Yoz"; version : 1; description : "Displacement by bitmap map"; > { input image4 src; input image1 map; input image4 fader; output pixel4 dst; parameter float dx < minValue: float(-1000.0); maxValue: float(1000.0); defaultValue: float(0.0); description: "The amount of displacement on x axis."; >; parameter float dy < minValue: float(-1000.0); maxValue: float(1000.0); defaultValue: float(0.0); description: "The amount of displacement on y axis."; >; parameter float fadeNear < minValue: float(-5.0); maxValue: float(5.0); defaultValue: float(0.0); description: "The amount of fader alpha on near map areas."; >; parameter float fadeDistant < minValue: float(-5.0); maxValue: float(5.0); defaultValue: float(0.0); description: "The amount of fader alpha on distant map areas."; >; void evaluatePixel() { float2 pos = outCoord(); float amount = sampleLinear(map, pos); float2 displacedPos = float2( pos.x + dx * amount, pos.y + dy * amount); dst = sampleLinear(src, displacedPos); float4 faderData = sampleLinear(fader, displacedPos); float fadeAmount = fadeDistant - amount * (fadeDistant - fadeNear); float sourceAmount = 1.0 - fadeAmount; dst = dst * float4(sourceAmount) + faderData * float4(fadeAmount); } }