首页 > 解决方案 > 转义色度键颜色

问题描述

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

创建模型时:

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

代码设置要从渲染中删除的键颜色(在本例中为绿色),但我不希望从渲染中删除任何颜色。这是设置该属性的行:

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

如果我注释该行或将颜色替换为 null,则删除的颜色为黑色。我看不到如何跳过此过程,而且我找到的setFloat4文档不完整。

有任何想法吗?

标签: androidarcore

解决方案


创建仅使用外部纹理的新自定义材质可能更容易,而不是使色度控制可选。您可以在 sampledata/models 目录中创建一个新的 .mat 文件,名为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:

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

推荐阅读