views:

11

answers:

1

Hi, i need to mix two images one photo and a placeholder. The idea is that we see the placeholder except where the palceholder has a particular color, in that case the user sees the photo. Something like chroma key.

For this purpose i wrote a Pixel Bender shader that acts as a BlendMode. If the background is in the right color output the pixel image otherwhise output the pixel from the placeholder.

<languageVersion : 1.0;>

kernel Crossfade
<   namespace : "mynamesp";
vendor : "Artbits snc";
version : 1;
description : "description ... "; >
{

input image4 placeHolder;
input image4 myImage;

output pixel4 dst;

const float3 SPECIAL_COLOR = float3(159.0, 160.0, 161.0); 

void evaluatePixel()
{
    float4 imgPixel = sample(myImagee, outCoord());
    float4 placeHolderPixel = sample(placeHolder, outCoord());

    dst = placeHolderPixel;

    if(placeHolderPixel.r == (SPECIAL_COLOR.r / 255.0) && placeHolderPixel.g == (SPECIAL_COLOR.g / 255.0) && placeHolderPixel.b == (SPECIAL_COLOR.b / 255.0)){
        dst = imgPixel;
    }
}
}

Everything works fine except for the fact that i had multiple placeholder, one over the other and my shader don't check the color of its own placeholder but the color of everything under the photo.

Is there a way to force BlendMode to consider only a layer or a specific background color ?

Is there a smarter way to obtain the same result ?

Thanks for your help! i know that this is quite a long and complex question, especially for my english :-)