Hi all.
I want to blend two gradients together. What I'm doing now is add their color values. The problem is that this creates a weird effect in the area where the fills intersect, when both have a value in the same color component. For example, two green fills show effect, but there's no problem with a green and a red one. See the images below.
This code calculates each pixel color:
Is there anybody who knows what rule to use for this? I hope you understand how my code works. Thanks in advance.Code:void PixelValue(int x, int y, unsigned char *pR, unsigned char *pG, unsigned char *pB) { int iR = 0, iG = 0, iB = 0; // resulting pixel color to be returned // for each object, in this case only two: // iShapeX stands for the color of the current shape // iRadius is the radius of the current object // iDist is the distance to the object iR += (iDist>=iRadius) ? 0 : iShapeR * (iRadius-iDist) / iRadius; //add up the color values of every object, iG += (iDist>=iRadius) ? 0 : iShapeG * (iRadius-iDist) / iRadius; iB += (iDist>=iRadius) ? 0 : iShapeB * (iRadius-iDist) / iRadius; *pB = (unsigned char) min(iB, 255); *pG = (unsigned char) min(iG, 255); *pR = (unsigned char) min(iR, 255); }
Edit: the only difference between the images below is the color of the rightmost gradient.