限制使用 PixelBender 制作的自定义 BlendMode - 如何合并图像

发布于 2024-09-26 06:24:14 字数 1029 浏览 0 评论 0原文

我需要混合两张图像一张照片和一个占位符。我们的想法是,我们会看到占位符,除非占位符具有特定颜色,在这种情况下,用户会看到照片。像色度键之类的东西。

为此,我编写了一个用作 BlendMode 的 Pixel Bender 着色器。如果背景颜色正确,则输出像素图像,否则输出占位符中的像素。

<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;
    }
}
}

一切工作正常,除了我有多个占位符,一个占另一个,我的着色器不检查其自己的占位符的颜色,而是检查照片下所有内容的颜色。

有没有办法强制 BlendMode 仅考虑图层或特定背景颜色?

有没有更聪明的方法来获得相同的结果?

感谢您的帮助!我知道这是一个相当长且复杂的问题,特别是对于我的英语:-)

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 :-)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぇ气 2024-10-03 06:24:14

我假设您在通用 DisplayObjects 上使用此 BlendMode,而不是直接在 BitmapData 上使用。在这种情况下,PixelBender 只能处理从绘图 API 传入的数据,因此您必须确保仅使用这些图层。他们的方法是仅将占位符对象和图像对象添加到一个持有者 Sprite 中。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文