转义色度键颜色 [英] Escape chroma key color

查看:82
本文介绍了转义色度键颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用基于chromakeyVideo示例项目的ARCore的Sceneform框架播放视频.

I'm trying to use the Sceneform framework from ARCore to play a video, based on the chromakeyVideo example project.

在创建模型时:

 ModelRenderable.builder()
        .setSource(this, R.raw.chroma_key_video)
        .build()
        .thenAccept(
            renderable -> {
              videoRenderable = renderable;
              renderable.getMaterial().setExternalTexture("videoTexture", texture);
              renderable.getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);
            })
        .exceptionally(
            throwable -> {
              Toast toast =
                  Toast.makeText(this, "Unable to load video renderable", Toast.LENGTH_LONG);
              toast.setGravity(Gravity.CENTER, 0, 0);
              toast.show();
              return null;
            });

代码将关键色设置为从渲染中删除(在这种情况下为绿色),但是我不希望从渲染中删除任何颜色. 这是设置该属性的行:

The code sets the keycolor to delete from the rendering (green, in this case), but I don't want any color to be removed from my render. This is the line that sets that property:

renderable.getMaterial().setFloat4("keyColor", CHROMA_KEY_COLOR);

如果我注释该行或将颜色替换为null,则删除的颜色为黑色.我没有看到如何跳过此过程的信息,也没有找到有关

If I comment the line or replace the color with null, the color that is deleted is black. I don't see how to skip this process, and the documentation I found for the setFloat4 is incomplete.

有什么想法吗?

推荐答案

创建新的仅使用外部纹理的自定义材质可能要容易一些,而使色度调制成为可选参数则要容易得多.您可以在名为externalTexture.mat的sampledata/models目录中创建一个新的.mat文件:

It is probably easier to create a new custom material that just uses the external texture vs. making the chromakeying optional. You can create a new .mat file in the sampledata/models directory named externalTexture.mat:

// Copyright 2018 Google LLC. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
material {
    "name" : "Chroma Key Video Material",
    "defines" : [
        "baseColor"
    ],
    "parameters" : [
        {
           // The texture displaying the frames of the video.
           "type" : "samplerExternal",
           "name" : "videoTexture"
        }
    ],
    "requires" : [
        "position",
        "uv0"
    ],
    "shadingModel" : "unlit",
    // Blending is "masked" instead of "transparent" so that the shadows account for the
    // transparent regions of the video instead of just the shape of the mesh.
    "blending" : "masked",
    // Material is double sided so that the video is visible when walking behind it.
    "doubleSided" : true
}

fragment {
    void material(inout MaterialInputs material) {
        prepareMaterial(material);

        vec2 uv = getUV0();

        if (!gl_FrontFacing) {
          uv.x = 1.0 - uv.x;
        }

        material.baseColor = texture(materialParams_videoTexture, uv).rgba;
    }
}

然后在您的.sfa文件中,将材质源更改为externalTexture.mat:

Then in your .sfa file change the material source to externalTexture.mat:

     source: "sampledata/models/externalTexture.mat",

这篇关于转义色度键颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆