开发者

Limiting custom BlendMode made with PixelBender - how to merge images

开发者 https://www.devze.com 2023-01-19 17:05 出处:网络
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

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 开发者_如何学Pythonhelp! i know that this is quite a long and complex question, especially for my english :-)


I assume that you are using this BlendMode on generic DisplayObjects and not directly on BitmapData. In this case PixelBender can only work with the data that gets passed in from the drawing API, so you have to make sure that only those layers are used. They way to do it is to add only the placeholder object and the image object to one holder Sprite.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号